Group.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace app\admin\controller\user;
  3. use think\Db;
  4. use Exception;
  5. use think\exception\DbException;
  6. use think\exception\PDOException;
  7. use app\common\controller\Backend;
  8. use think\exception\ValidateException;
  9. /**
  10. * 会员组管理
  11. *
  12. * @icon fa fa-users
  13. */
  14. class Group extends Backend
  15. {
  16. /**
  17. * @var \app\admin\model\UserGroup
  18. */
  19. protected $model = null;
  20. public function _initialize()
  21. {
  22. parent::_initialize();
  23. $this->model = model('User');
  24. $this->view->assign("statusList", $this->model->getStatusList());
  25. }
  26. /**
  27. * 查看
  28. */
  29. public function index()
  30. {
  31. //设置过滤方法
  32. $this->request->filter(['strip_tags', 'trim']);
  33. if ($this->request->isAjax()) {
  34. //如果发送的来源是Selectpage,则转发到Selectpage
  35. if ($this->request->request('keyField')) {
  36. return $this->selectpage();
  37. }
  38. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  39. $list = $this->model
  40. ->where($where)->where('is_agent', 1)
  41. ->order($sort, $order)
  42. ->paginate($limit);
  43. $result = array("total" => $list->total(), "rows" => $list->items());
  44. return json($result);
  45. }
  46. return $this->view->fetch();
  47. }
  48. /**
  49. * 禁用
  50. * @param $ids
  51. * @return string
  52. * @throws DbException
  53. * @throws \think\Exception
  54. */
  55. public function disable($ids = null, $is_lock=0)
  56. {
  57. $row = $this->model->get($ids);
  58. if (!$row) {
  59. $this->error(__('No Results were found'));
  60. }
  61. $result = false;
  62. try {
  63. $result = $row->allowField(true)->save(['is_lock'=>$is_lock]);
  64. } catch (ValidateException|PDOException|Exception $e) {
  65. $this->error($e->getMessage());
  66. }
  67. if (false === $result) {
  68. $this->error(__('No rows were updated'));
  69. }
  70. $this->success();
  71. }
  72. }