104 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			PHP
		
	
	
			
		
		
	
	
			104 lines
		
	
	
		
			2.9 KiB
		
	
	
	
		
			PHP
		
	
	
| <?php
 | |
| namespace app\admin\controller\user;
 | |
| 
 | |
| 
 | |
| use app\admin\logic\user\AppLogic;
 | |
| use app\admin\validate\user\AppValidate;
 | |
| use app\common\basics\AdminBase;
 | |
| use app\common\server\JsonServer;
 | |
| use think\exception\ValidateException;
 | |
| 
 | |
| class App extends AdminBase
 | |
| {
 | |
|     public function lists()
 | |
|     {
 | |
|         if($this->request->isAjax()){
 | |
|             $get = $this->request->get();
 | |
|             $lists = AppLogic::lists($get);
 | |
|             return JsonServer::success('', $lists);
 | |
|         }
 | |
|         return view();
 | |
|     }
 | |
| 
 | |
|     public function add()
 | |
|     {
 | |
|         if($this->request->isAjax()) {
 | |
|             try{
 | |
|                 $post = $this->request->post();
 | |
|                 validate(AppValidate::class)->scene('add')->check($post);
 | |
|             }catch(ValidateException $e) {
 | |
|                 return JsonServer::error($e->getError());
 | |
|             }
 | |
|             $result = AppLogic::add($post);
 | |
|             if($result === true) {
 | |
|                 return JsonServer::success('添加成功');
 | |
|             }
 | |
|             return JsonServer::error(AppLogic::getError());
 | |
|         }
 | |
| 
 | |
|         return view();
 | |
|     }
 | |
| 
 | |
|     public function getUserList()
 | |
|     {
 | |
|         $keyword = input('keyword/s');
 | |
|         $page = input('page/d', 1);
 | |
|         $size = 10;
 | |
| 
 | |
|         $q = \app\common\model\user\User::where('nickname|mobile', 'like', '%'.$keyword.'%');
 | |
|         $total = $q->count();
 | |
|         $userList = $q->page($page, $size)
 | |
|             ->field('id,nickname,mobile')
 | |
|             ->select()
 | |
|             ->toArray();
 | |
| 
 | |
|         foreach ($userList as &$item) {
 | |
|             $item['name'] = $item['nickname'].'-'.$item['mobile'];
 | |
|             $item['value'] = $item['id'];
 | |
|         }
 | |
|         $res = [
 | |
|             'code' => 0,
 | |
|             'data' => [
 | |
|                 'total' => $total,
 | |
|                 'totalPage' => ceil($total/$size),
 | |
|                 'list' => $userList,
 | |
|                 'page' => $page,
 | |
|                 'size' => $size,
 | |
|             ],
 | |
|             'msg' => 'success'
 | |
|         ];
 | |
|         return json($res);
 | |
|     }
 | |
| 
 | |
|     public function edit(){
 | |
|         if($this->request->isAjax()){
 | |
|             try{
 | |
|                 $post = $this->request->post();
 | |
|                 validate(AppValidate::class)->scene('edit')->check($post);
 | |
|             }catch(ValidateException $e) {
 | |
|                 return JsonServer::error($e->getError());
 | |
|             }
 | |
|             $result = AppLogic::edit($post);
 | |
|             if($result === true) {
 | |
|                 return JsonServer::success('编辑成功');
 | |
|             }
 | |
|             return JsonServer::error(AppLogic::getError());
 | |
|         }
 | |
| 
 | |
|         $id = $this->request->get('id', '', 'intval');
 | |
|         $detail = AppLogic::getUserApi($id);
 | |
|         return view('', [
 | |
|             'detail' => $detail
 | |
|         ]);
 | |
|     }
 | |
| 
 | |
|     public function del()
 | |
|     {
 | |
|         $id = $this->request->post('id', '',  'intval');
 | |
|         $result = AppLogic::del($id);
 | |
|         if($result === true) {
 | |
|             return JsonServer::success('删除成功');
 | |
|         }
 | |
|         return JsonServer::error(AppLogic::getError());
 | |
|     }
 | |
| } |