Pilot.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace app\admin\controller\user;
  3. use app\common\controller\Backend;
  4. use app\admin\model\User as UserModel;
  5. class Pilot extends Backend
  6. {
  7. protected $model = null;
  8. protected $withJoinTable = ['group'];
  9. // 排除字段
  10. protected $preExcludeFields = ['lastlogintime', 'loginfailure', 'password', 'salt', 'money', 'score'];
  11. protected $quickSearchField = ['username', 'nickname', 'id'];
  12. public function initialize()
  13. {
  14. parent::initialize();
  15. $this->model = new UserModel();
  16. }
  17. /**
  18. * 查看
  19. */
  20. public function index()
  21. {
  22. $this->request->filter(['strip_tags', 'trim']);
  23. if ($this->request->param('select')) {
  24. $this->select();
  25. }
  26. list($where, $alias, $limit, $order) = $this->queryBuilder();
  27. $res = $this->model
  28. ->withoutField('password,salt')
  29. ->withJoin($this->withJoinTable, $this->withJoinType)
  30. ->alias($alias)
  31. ->where($where)
  32. ->where(['group_id' => 2, 'real_name_status' => 1, 'certified' => 1])
  33. ->order($order)
  34. ->paginate($limit);
  35. $this->success('', [
  36. 'list' => $res->items(),
  37. 'total' => $res->total(),
  38. 'remark' => get_route_remark(),
  39. ]);
  40. }
  41. /**
  42. * 加载为select(远程下拉选择框)数据,默认还是走$this->index()方法
  43. * 必要时请在对应控制器类中重写
  44. */
  45. public function select()
  46. {
  47. $this->request->filter(['strip_tags', 'trim']);
  48. list($where, $alias, $limit, $order) = $this->queryBuilder();
  49. $res = $this->model
  50. ->withJoin($this->withJoinTable, $this->withJoinType)
  51. ->alias($alias)
  52. ->where($where)
  53. ->order($order)
  54. ->paginate($limit);
  55. foreach ($res as $re) {
  56. $re->nickname_text = $re->username . '(ID:' . $re->id . ')';
  57. }
  58. $this->success('', [
  59. 'list' => $res->items(),
  60. 'total' => $res->total(),
  61. 'remark' => get_route_remark(),
  62. ]);
  63. }
  64. }