DriverUser.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2020/12/24
  6. * Time: 13:44
  7. */
  8. namespace app\admin\controller;
  9. use app\common\controller\Backend;
  10. use think\Db;
  11. use think\Exception;
  12. use think\exception\PDOException;
  13. use think\exception\ValidateException;
  14. /**
  15. * 驾驶证认证管理
  16. *
  17. * @icon fa fa-circle-o
  18. */
  19. class DriverUser extends Backend
  20. {
  21. /**
  22. * DriverVerified模型对象
  23. * @var \app\admin\model\DriverVerified
  24. */
  25. protected $model = null;
  26. public function _initialize()
  27. {
  28. parent::_initialize();
  29. $this->model = new \app\admin\model\DriverVerified();
  30. $this->view->assign("statusList", $this->model->getStatusList());
  31. }
  32. public function import()
  33. {
  34. parent::import();
  35. }
  36. /**
  37. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  38. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  39. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  40. */
  41. public function index()
  42. {
  43. //设置过滤方法
  44. $this->request->filter(['strip_tags', 'trim']);
  45. if ($this->request->isAjax()) {
  46. //如果发送的来源是Selectpage,则转发到Selectpage
  47. if ($this->request->request('keyField')) {
  48. return $this->selectpage();
  49. }
  50. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  51. $where2 = [];
  52. $where2['driver_verified.status'] = '1';
  53. $list = $this->model
  54. ->with(['user'])
  55. ->where($where)
  56. ->where($where2)
  57. ->order($sort, $order)
  58. ->paginate($limit);
  59. foreach ($list as $row) {
  60. $row->getRelation('user')->visible(['username', 'mobile']);
  61. }
  62. $result = ["total" => $list->total(), "rows" => $list->items()];
  63. return json($result);
  64. }
  65. return $this->view->fetch();
  66. }
  67. /**
  68. * 批量操作
  69. * @param string $ids
  70. */
  71. public function multi($ids = "")
  72. {
  73. $params = $this->request->request('params');
  74. parse_str($params, $paramsArr);
  75. if (isset($paramsArr)) {
  76. $field = $this->model::get($ids);
  77. if ($paramsArr['status'] == 0) {
  78. $paramsArr['status'] = -1;
  79. Db::name('user_verified')->where('user_id', $field['user_id'])->setField('driver_verified', -1);
  80. }
  81. if ($paramsArr['status'] == 1) {
  82. Db::name('user_verified')->where('user_id', $field['user_id'])->setField('driver_verified', 1);
  83. }
  84. $field->save($paramsArr);
  85. $this->success('操作成功');
  86. }
  87. return parent::multi($ids);
  88. }
  89. }