作者 王智

daima

@@ -39,45 +39,35 @@ class Renwu extends Backend @@ -39,45 +39,35 @@ class Renwu extends Backend
39 */ 39 */
40 public function index() 40 public function index()
41 { 41 {
42 - $pid = input('pid');  
43 //当前是否为关联查询 42 //当前是否为关联查询
44 $this->relationSearch = true; 43 $this->relationSearch = true;
45 //设置过滤方法 44 //设置过滤方法
46 $this->request->filter(['strip_tags', 'trim']); 45 $this->request->filter(['strip_tags', 'trim']);
47 - if ($this->request->isAjax()) {  
48 - list($where, $sort, $order, $offset, $limit) = $this->buildparams();  
49 - if (empty($pid)) {  
50 - //如果发送的来源是Selectpage,则转发到Selectpage  
51 - if ($this->request->request('keyField')) {  
52 - return $this->selectpage();  
53 - }  
54 - }  
55 - $map = [];  
56 - if ($pid == 1) {  
57 - $map['type'] = ['eq', 3];  
58 - }  
59 - if ($pid == 2) {  
60 - $map['type'] = ['eq', 2]; 46 + if ($this->request->isAjax())
  47 + {
  48 + //如果发送的来源是Selectpage,则转发到Selectpage
  49 + if ($this->request->request('keyField'))
  50 + {
  51 + return $this->selectpage();
61 } 52 }
  53 + list($where, $sort, $order, $offset, $limit) = $this->buildparams();
62 $total = $this->model 54 $total = $this->model
63 - ->with(['user', 'vip'])  
64 - ->where($where)  
65 - ->order($sort, $order)  
66 - ->where($map)  
67 - ->count(); 55 + ->with(['user','vip'])
  56 + ->where($where)
  57 + ->order($sort, $order)
  58 + ->count();
68 59
69 $list = $this->model 60 $list = $this->model
70 - ->with(['user', 'vip'])  
71 - ->where($where)  
72 - ->order($sort, $order)  
73 - ->limit($offset, $limit)  
74 - ->where($map)  
75 - ->select(); 61 + ->with(['user','vip'])
  62 + ->where($where)
  63 + ->order($sort, $order)
  64 + ->limit($offset, $limit)
  65 + ->select();
76 66
77 foreach ($list as $row) { 67 foreach ($list as $row) {
78 68
79 - $row->getRelation('user')->visible(['nickname', 'mobile', 'address', 'address_con', 'car_num', 'color', 'car_type', 'vip']);  
80 - $row->getRelation('vip')->visible(['title']); 69 + $row->getRelation('user')->visible(['nickname','mobile','address','address_con','car_num','color','car_type','vip']);
  70 + $row->getRelation('vip')->visible(['title']);
81 } 71 }
82 $list = collection($list)->toArray(); 72 $list = collection($list)->toArray();
83 $result = array("total" => $total, "rows" => $list); 73 $result = array("total" => $total, "rows" => $list);
@@ -5,13 +5,13 @@ namespace app\admin\controller; @@ -5,13 +5,13 @@ namespace app\admin\controller;
5 use app\common\controller\Backend; 5 use app\common\controller\Backend;
6 6
7 /** 7 /**
8 - * 8 + *
9 * 9 *
10 * @icon fa fa-user 10 * @icon fa fa-user
11 */ 11 */
12 class User extends Backend 12 class User extends Backend
13 { 13 {
14 - 14 +
15 /** 15 /**
16 * User模型对象 16 * User模型对象
17 * @var \app\admin\model\User 17 * @var \app\admin\model\User
@@ -26,12 +26,59 @@ class User extends Backend @@ -26,12 +26,59 @@ class User extends Backend
26 $this->view->assign("isBlackList", $this->model->getIsBlackList()); 26 $this->view->assign("isBlackList", $this->model->getIsBlackList());
27 $this->view->assign("typeList", $this->model->getTypeList()); 27 $this->view->assign("typeList", $this->model->getTypeList());
28 } 28 }
29 - 29 +
  30 +
  31 + /**
  32 + * 查看
  33 + */
  34 + public function index()
  35 + {
  36 + $pid = input('pid');
  37 + //当前是否为关联查询
  38 + $this->relationSearch = true;
  39 + //设置过滤方法
  40 + $this->request->filter(['strip_tags', 'trim']);
  41 + if ($this->request->isAjax()) {
  42 + list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  43 + if (empty($pid)) {
  44 + //如果发送的来源是Selectpage,则转发到Selectpage
  45 + if ($this->request->request('keyField')) {
  46 + return $this->selectpage();
  47 + }
  48 + }
  49 + $map = [];
  50 + if ($pid == 1) {
  51 + $map['type'] = ['eq', 3];
  52 + }
  53 + if ($pid == 2) {
  54 + $map['type'] = ['eq', 2];
  55 + }
  56 + list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  57 + $total = $this->model
  58 + ->where($where)
  59 + ->order($sort, $order)
  60 + ->where($map)
  61 + ->count();
  62 +
  63 + $list = $this->model
  64 + ->where($where)
  65 + ->order($sort, $order)
  66 + ->where($map)
  67 + ->limit($offset, $limit)
  68 + ->select();
  69 +
  70 + $list = collection($list)->toArray();
  71 + $result = array("total" => $total, "rows" => $list);
  72 +
  73 + return json($result);
  74 + }
  75 + return $this->view->fetch();
  76 + }
30 /** 77 /**
31 * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法 78 * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
32 * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑 79 * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
33 * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改 80 * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
34 */ 81 */
35 - 82 +
36 83
37 } 84 }