Adminapply.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <?php
  2. namespace app\admin\controller\csmadmin;
  3. use think\Db;
  4. use fast\Tree;
  5. use think\Exception;
  6. use app\admin\model\AuthGroup;
  7. use think\exception\PDOException;
  8. use addons\csmadmin\library\CsmUtils;
  9. use addons\csmadmin\library\CsmNotify;
  10. use think\exception\ValidateException;
  11. use addons\csmadmin\library\CsmBackend;
  12. use addons\csmadmin\library\CsmadminUtils;
  13. /**
  14. * 管理员注册申请管理
  15. *
  16. * @icon fa fa-circle-o
  17. */
  18. class Adminapply extends CsmBackend
  19. {
  20. /**
  21. * Adminapply模型对象
  22. *
  23. * @var \app\admin\model\csmadmin\Adminapply
  24. */
  25. protected $model = null;
  26. public function _initialize()
  27. {
  28. parent::_initialize();
  29. $this->model = new \app\admin\model\csmadmin\Adminapply();
  30. $this->view->assign("applytypeList", $this->model->getApplytypeList());
  31. $this->view->assign("auditstatusList", $this->model->getAuditstatusList());
  32. }
  33. public function index()
  34. {
  35. // 设置过滤方法
  36. $this->request->filter([
  37. 'strip_tags'
  38. ]);
  39. if ($this->request->isAjax()) {
  40. // 如果发送的来源是Selectpage,则转发到Selectpage
  41. if ($this->request->request('keyField')) {
  42. return $this->selectpage();
  43. }
  44. list ($where, $sort, $order, $offset, $limit) = $this->buildparams();
  45. $total = $this->model->where($where)
  46. ->order($sort, $order)
  47. ->count();
  48. $list = $this->model->where($where)
  49. ->order($sort, $order)
  50. ->limit($offset, $limit)
  51. ->select();
  52. CsmUtils::convertListColumn($list, "faadmin_id", new \app\admin\model\Admin(), 'nickname');
  53. $list = collection($list)->toArray();
  54. $result = array(
  55. "total" => $total,
  56. "rows" => $list
  57. );
  58. return json($result);
  59. }
  60. return $this->view->fetch();
  61. }
  62. public function submitauditok()
  63. {
  64. $id = $this->csmreq("id", true);
  65. $auth_group_ids = $this->csmreq('auth_group_ids', true);
  66. //更新角色
  67. if(true){
  68. $dao = new \app\admin\model\csmadmin\Adminapply();
  69. $dao->where('id','=',$id)->update([
  70. 'auth_group_ids'=>$auth_group_ids
  71. ]);
  72. }
  73. CsmadminUtils::createAdminByApply($id, $this->auth);
  74. $this->success();
  75. }
  76. public function submitauditreturn()
  77. {
  78. $id = $this->csmreq("id", true);
  79. $dao = new \app\admin\model\csmadmin\Adminapply();
  80. $row = $dao->where("id", "=", $id)->find();
  81. if (! $row) {
  82. $this->error("id不存在:" . $id);
  83. }
  84. $auditreturn = $this->csmreq("auditreturn", false);
  85. // 更新审核状态
  86. $sessionuser = $this->auth;
  87. $params = [
  88. "auditstatus" => "-1",
  89. "audittime" => time(),
  90. "auditreturn" => $auditreturn,
  91. "audituser_id" => $sessionuser->id,
  92. "audituser" => $sessionuser->username,
  93. "updatetime" => time()
  94. ];
  95. $dao->where("id","=",$id)->update($params);
  96. // 退回发送邮件
  97. CsmNotify::notifyToAdminapplyid($id, '注册审核退回', '注册审核退回', ['desc'=>$auditreturn]);
  98. $this->success();
  99. }
  100. public function edit($ids = null)
  101. {
  102. $row = $this->model->get($ids);
  103. if (!$row) {
  104. $this->error(__('No Results were found'));
  105. }
  106. $adminIds = $this->getDataLimitAdminIds();
  107. if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
  108. $this->error(__('You have no permission'));
  109. }
  110. if (false === $this->request->isPost()) {
  111. $this->view->assign('row', $row);
  112. $this->_assignGroupSelect($row);
  113. return $this->view->fetch();
  114. }
  115. $params = $this->request->post('row/a');
  116. if (empty($params)) {
  117. $this->error(__('Parameter %s can not be empty', ''));
  118. }
  119. $params = $this->preExcludeFields($params);
  120. $result = false;
  121. Db::startTrans();
  122. try {
  123. //是否采用模型验证
  124. if ($this->modelValidate) {
  125. $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
  126. $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
  127. $row->validateFailException()->validate($validate);
  128. }
  129. $result = $row->allowField(true)->save($params);
  130. Db::commit();
  131. } catch (ValidateException|PDOException|Exception $e) {
  132. Db::rollback();
  133. $this->error($e->getMessage());
  134. }
  135. if (false === $result) {
  136. $this->error(__('No rows were updated'));
  137. }
  138. $this->success();
  139. }
  140. /**
  141. * 生成角色设置的下拉框
  142. * 代码参考:app\admin\controller\auth\Admin.php#_initialize
  143. *
  144. * @param [type] $row
  145. * @return void
  146. */
  147. private function _assignGroupSelect($row){
  148. if(true){
  149. $this->childrenAdminIds = $this->auth->getChildrenAdminIds($this->auth->isSuperAdmin());
  150. $this->childrenGroupIds = $this->auth->getChildrenGroupIds($this->auth->isSuperAdmin());
  151. $groupList = collection(AuthGroup::where('id', 'in', $this->childrenGroupIds)->select())->toArray();
  152. Tree::instance()->init($groupList);
  153. $groupdata = [];
  154. if ($this->auth->isSuperAdmin()) {
  155. $result = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0));
  156. foreach ($result as $k => $v) {
  157. $groupdata[$v['id']] = $v['name'];
  158. }
  159. } else {
  160. $result = [];
  161. $groups = $this->auth->getGroups();
  162. foreach ($groups as $m => $n) {
  163. $childlist = Tree::instance()->getTreeList(Tree::instance()->getTreeArray($n['id']));
  164. $temp = [];
  165. foreach ($childlist as $k => $v) {
  166. $temp[$v['id']] = $v['name'];
  167. }
  168. $result[__($n['name'])] = $temp;
  169. }
  170. $groupdata = $result;
  171. }
  172. $this->view->assign("groupdata", $groupdata);
  173. $groupids = explode(',',$row['auth_group_ids']);
  174. $this->view->assign("groupids", $groupids);
  175. }
  176. }
  177. }