1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
- namespace app\user\controller;
- use app\base\controller\Base;
- class Mail extends Base{
-
- private $mailModel, $userModel;
-
- public function _initialize(){
- parent::_initialize();
-
- $this->mailModel = new \app\user\model\Mail();
- $this->userModel = new \app\user\model\User();
- }
-
- public function index(){
- $p = $this->request->get('page', 0);
- $nick = $this->request->get('n');
- $where = [];
-
- if($nick) $where['title'] = ['like', "%$nick%"];
-
- $info = $this->mailModel->getInfo($p, $where);
- $page = $this->mailModel->getPage($where);
-
- $this->assign("info", $info);
- $this->assign("page", $page);
- return $this->fetch();
- }
-
- public function edit(){
- $id = $this->request->get('id');
- $info = $this->mailModel->getMailById($id);
-
- $this->assign("info", $info);
- return $this->fetch('edit');
- }
-
- public function select(){
-
- if($this->request->isAjax()){
- $p = $this->request->get('page', 0);
- $limit = $this->request->get('limit');
- $nick = $this->request->get('n');
- $id = $this->request->get('i');
- $where = [];
-
- if($nick) $where['nickname'] = ['like', "%$nick%"];
- if($id) $where['id'] = ['=', $id];
-
- $count = $this->userModel->where($where)->count();
-
- $data = $this->userModel
- ->where($where)
- ->page($p, $limit)
- ->order('registertime', 'desc')
- ->select();
-
- // 需要把long类型转换成字符串,不然js无法解析
- foreach($data as &$val){
- $val['id'] = strval($val['id']);
- }
-
- $result = ['code'=>0, 'msg'=>'success', 'count'=>$count, 'data'=>$data];
-
- return json($result);
- }
-
- $this->view->engine->layout(false);
- return $this->fetch();
- }
-
- public function save(){
- $res = $this->mailModel->addAndSave();
-
- if($res){
- $this->success('保存成功!', 'index');
- }else{
- $this->error('保存失败!');
- }
- }
- }
|