Mail.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace app\user\controller;
  3. use app\base\controller\Base;
  4. class Mail extends Base{
  5. private $mailModel, $userModel;
  6. public function _initialize(){
  7. parent::_initialize();
  8. $this->mailModel = new \app\user\model\Mail();
  9. $this->userModel = new \app\user\model\User();
  10. }
  11. public function index(){
  12. $p = $this->request->get('page', 0);
  13. $nick = $this->request->get('n');
  14. $where = [];
  15. if($nick) $where['title'] = ['like', "%$nick%"];
  16. $info = $this->mailModel->getInfo($p, $where);
  17. $page = $this->mailModel->getPage($where);
  18. $this->assign("info", $info);
  19. $this->assign("page", $page);
  20. return $this->fetch();
  21. }
  22. public function edit(){
  23. $id = $this->request->get('id');
  24. $info = $this->mailModel->getMailById($id);
  25. $this->assign("info", $info);
  26. return $this->fetch('edit');
  27. }
  28. public function select(){
  29. if($this->request->isAjax()){
  30. $p = $this->request->get('page', 0);
  31. $limit = $this->request->get('limit');
  32. $nick = $this->request->get('n');
  33. $id = $this->request->get('i');
  34. $where = [];
  35. if($nick) $where['nickname'] = ['like', "%$nick%"];
  36. if($id) $where['id'] = ['=', $id];
  37. $count = $this->userModel->where($where)->count();
  38. $data = $this->userModel
  39. ->where($where)
  40. ->page($p, $limit)
  41. ->order('registertime', 'desc')
  42. ->select();
  43. // 需要把long类型转换成字符串,不然js无法解析
  44. foreach($data as &$val){
  45. $val['id'] = strval($val['id']);
  46. }
  47. $result = ['code'=>0, 'msg'=>'success', 'count'=>$count, 'data'=>$data];
  48. return json($result);
  49. }
  50. $this->view->engine->layout(false);
  51. return $this->fetch();
  52. }
  53. public function save(){
  54. $res = $this->mailModel->addAndSave();
  55. if($res){
  56. $this->success('保存成功!', 'index');
  57. }else{
  58. $this->error('保存失败!');
  59. }
  60. }
  61. }