Mail.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 = ['is_del'=>0];
  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. $this->assign('id', $id);
  27. return $this->fetch('edit');
  28. }
  29. public function users(){
  30. $id = $this->request->get('id');
  31. $info = $this->mailModel->getMailById($id);
  32. $arr = [];
  33. if($info['users']) {
  34. $arr = $this->userModel->field('id, nickname')->where('id', 'in', $info['users'])->select();
  35. // 需要把long类型转换成字符串,不然js无法解析
  36. foreach($arr as &$val){
  37. $val['id'] = strval($val['id']);
  38. }
  39. }
  40. return json($arr);
  41. }
  42. public function select(){
  43. if($this->request->isAjax()){
  44. $p = $this->request->get('page', 0);
  45. $limit = $this->request->get('limit');
  46. $nick = $this->request->get('n');
  47. $id = $this->request->get('i');
  48. $where = [];
  49. if($nick) $where['nickname'] = ['like', "%$nick%"];
  50. if($id) $where['id'] = ['=', $id];
  51. $count = $this->userModel->where($where)->count();
  52. $data = $this->userModel
  53. ->where($where)
  54. ->page($p, $limit)
  55. ->order('registertime', 'desc')
  56. ->select();
  57. // 需要把long类型转换成字符串,不然js无法解析
  58. foreach($data as &$val){
  59. $val['id'] = strval($val['id']);
  60. }
  61. $result = ['code'=>0, 'msg'=>'success', 'count'=>$count, 'data'=>$data];
  62. return json($result);
  63. }
  64. $this->view->engine->layout(false);
  65. return $this->fetch();
  66. }
  67. public function save(){
  68. $res = $this->mailModel->addAndSave();
  69. if($res){
  70. $this->success('保存成功!', 'index');
  71. }else{
  72. $this->error('保存失败!');
  73. }
  74. }
  75. public function delete(){
  76. $res = $this->mailModel->where(['id'=>$this->request->get('id')])->update(['is_del'=>1]);
  77. if($res){
  78. $this->success('删除成功!', 'index');
  79. }else{
  80. $this->error('删除失败!');
  81. }
  82. }
  83. }