Apply.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. namespace app\admin\controller\guild;
  3. use app\common\controller\Backend;
  4. use think\Db;
  5. /**
  6. * 公会开厅申请
  7. *
  8. * @icon fa fa-circle-o
  9. */
  10. class Apply extends Backend
  11. {
  12. protected $searchFields = 'user.u_id,user_name,user_nickname,user_mobile';
  13. /**
  14. * Apply模型对象
  15. * @var \app\admin\model\guild\Apply
  16. */
  17. protected $model = null;
  18. public function _initialize()
  19. {
  20. parent::_initialize();
  21. $this->model = new \app\admin\model\guild\Apply;
  22. $this->view->assign("statusList", $this->model->getStatusList());
  23. }
  24. public function import()
  25. {
  26. parent::import();
  27. }
  28. /**
  29. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  30. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  31. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  32. */
  33. /**
  34. * 查看
  35. */
  36. public function index()
  37. {
  38. //当前是否为关联查询
  39. $this->relationSearch = true;
  40. //设置过滤方法
  41. $this->request->filter(['strip_tags', 'trim']);
  42. if ($this->request->isAjax()) {
  43. //如果发送的来源是Selectpage,则转发到Selectpage
  44. if ($this->request->request('keyField')) {
  45. return $this->selectpage();
  46. }
  47. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  48. $list = $this->model
  49. ->with(['user'])
  50. ->where($where)
  51. ->order($sort, $order)
  52. ->paginate($limit);
  53. foreach ($list as $row) {
  54. $row->getRelation('user')->visible(['u_id','nickname']);
  55. }
  56. $result = array("total" => $list->total(), "rows" => $list->items());
  57. return json($result);
  58. }
  59. return $this->view->fetch();
  60. }
  61. /**
  62. * 编辑
  63. */
  64. public function edit($ids = null)
  65. {
  66. $row = $this->model->get($ids);
  67. if (!$row) {
  68. $this->error(__('No Results were found'));
  69. }
  70. $adminIds = $this->getDataLimitAdminIds();
  71. if (is_array($adminIds)) {
  72. if (!in_array($row[$this->dataLimitField], $adminIds)) {
  73. $this->error(__('You have no permission'));
  74. }
  75. }
  76. if ($this->request->isPost()) {
  77. $params = $this->request->post("row/a");
  78. if ($params) {
  79. $params = $this->preExcludeFields($params);
  80. $result = false;
  81. Db::startTrans();
  82. try {
  83. $data = [];
  84. switch ($params["status"]) {
  85. case 0:
  86. $data["is_guild"] = 1;
  87. break;
  88. case 1:
  89. $data["is_guild"] = 2;
  90. break;
  91. case 2:
  92. $data["is_guild"] = -1;
  93. break;
  94. default:
  95. $data["is_guild"] = 1;
  96. break;
  97. }
  98. \app\common\model\User::update($data,["id"=>$row["user_id"]]);
  99. //是否采用模型验证
  100. if ($this->modelValidate) {
  101. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  102. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  103. $row->validateFailException(true)->validate($validate);
  104. }
  105. $result = $row->allowField(true)->save($params);
  106. Db::commit();
  107. } catch (ValidateException $e) {
  108. Db::rollback();
  109. $this->error($e->getMessage());
  110. } catch (PDOException $e) {
  111. Db::rollback();
  112. $this->error($e->getMessage());
  113. } catch (Exception $e) {
  114. Db::rollback();
  115. $this->error($e->getMessage());
  116. }
  117. if ($result !== false) {
  118. $this->success();
  119. } else {
  120. $this->error(__('No rows were updated'));
  121. }
  122. }
  123. $this->error(__('Parameter %s can not be empty', ''));
  124. }
  125. $this->view->assign("row", $row);
  126. return $this->view->fetch();
  127. }
  128. }