123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- <?php
- namespace app\admin\controller\csmadmin;
- use think\Db;
- use fast\Tree;
- use think\Exception;
- use app\admin\model\AuthGroup;
- use think\exception\PDOException;
- use addons\csmadmin\library\CsmUtils;
- use addons\csmadmin\library\CsmNotify;
- use think\exception\ValidateException;
- use addons\csmadmin\library\CsmBackend;
- use addons\csmadmin\library\CsmadminUtils;
- /**
- * 管理员注册申请管理
- *
- * @icon fa fa-circle-o
- */
- class Adminapply extends CsmBackend
- {
- /**
- * Adminapply模型对象
- *
- * @var \app\admin\model\csmadmin\Adminapply
- */
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = new \app\admin\model\csmadmin\Adminapply();
- $this->view->assign("applytypeList", $this->model->getApplytypeList());
- $this->view->assign("auditstatusList", $this->model->getAuditstatusList());
- }
- public function index()
- {
- // 设置过滤方法
- $this->request->filter([
- 'strip_tags'
- ]);
- if ($this->request->isAjax()) {
- // 如果发送的来源是Selectpage,则转发到Selectpage
- if ($this->request->request('keyField')) {
- return $this->selectpage();
- }
- list ($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $total = $this->model->where($where)
- ->order($sort, $order)
- ->count();
- $list = $this->model->where($where)
- ->order($sort, $order)
- ->limit($offset, $limit)
- ->select();
- CsmUtils::convertListColumn($list, "faadmin_id", new \app\admin\model\Admin(), 'nickname');
- $list = collection($list)->toArray();
- $result = array(
- "total" => $total,
- "rows" => $list
- );
- return json($result);
- }
- return $this->view->fetch();
- }
- public function submitauditok()
- {
- $id = $this->csmreq("id", true);
- $auth_group_ids = $this->csmreq('auth_group_ids', true);
- //更新角色
- if(true){
- $dao = new \app\admin\model\csmadmin\Adminapply();
- $dao->where('id','=',$id)->update([
- 'auth_group_ids'=>$auth_group_ids
- ]);
- }
- CsmadminUtils::createAdminByApply($id, $this->auth);
- $this->success();
- }
- public function submitauditreturn()
- {
- $id = $this->csmreq("id", true);
- $dao = new \app\admin\model\csmadmin\Adminapply();
- $row = $dao->where("id", "=", $id)->find();
- if (! $row) {
- $this->error("id不存在:" . $id);
- }
- $auditreturn = $this->csmreq("auditreturn", false);
- // 更新审核状态
- $sessionuser = $this->auth;
- $params = [
- "auditstatus" => "-1",
- "audittime" => time(),
- "auditreturn" => $auditreturn,
- "audituser_id" => $sessionuser->id,
- "audituser" => $sessionuser->username,
- "updatetime" => time()
- ];
- $dao->where("id","=",$id)->update($params);
-
- // 退回发送邮件
- CsmNotify::notifyToAdminapplyid($id, '注册审核退回', '注册审核退回', ['desc'=>$auditreturn]);
- $this->success();
- }
- public function edit($ids = null)
- {
- $row = $this->model->get($ids);
- if (!$row) {
- $this->error(__('No Results were found'));
- }
- $adminIds = $this->getDataLimitAdminIds();
- if (is_array($adminIds) && !in_array($row[$this->dataLimitField], $adminIds)) {
- $this->error(__('You have no permission'));
- }
- if (false === $this->request->isPost()) {
- $this->view->assign('row', $row);
- $this->_assignGroupSelect($row);
- return $this->view->fetch();
- }
- $params = $this->request->post('row/a');
- if (empty($params)) {
- $this->error(__('Parameter %s can not be empty', ''));
- }
- $params = $this->preExcludeFields($params);
- $result = false;
- Db::startTrans();
- try {
- //是否采用模型验证
- if ($this->modelValidate) {
- $name = str_replace("\\model\\", "\\validate\\", get_class($this->model));
- $validate = is_bool($this->modelValidate) ? ($this->modelSceneValidate ? $name . '.edit' : $name) : $this->modelValidate;
- $row->validateFailException()->validate($validate);
- }
- $result = $row->allowField(true)->save($params);
- Db::commit();
- } catch (ValidateException|PDOException|Exception $e) {
- Db::rollback();
- $this->error($e->getMessage());
- }
- if (false === $result) {
- $this->error(__('No rows were updated'));
- }
- $this->success();
- }
- /**
- * 生成角色设置的下拉框
- * 代码参考:app\admin\controller\auth\Admin.php#_initialize
- *
- * @param [type] $row
- * @return void
- */
- private function _assignGroupSelect($row){
- if(true){
- $this->childrenAdminIds = $this->auth->getChildrenAdminIds($this->auth->isSuperAdmin());
- $this->childrenGroupIds = $this->auth->getChildrenGroupIds($this->auth->isSuperAdmin());
-
- $groupList = collection(AuthGroup::where('id', 'in', $this->childrenGroupIds)->select())->toArray();
-
- Tree::instance()->init($groupList);
- $groupdata = [];
- if ($this->auth->isSuperAdmin()) {
- $result = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0));
- foreach ($result as $k => $v) {
- $groupdata[$v['id']] = $v['name'];
- }
- } else {
- $result = [];
- $groups = $this->auth->getGroups();
- foreach ($groups as $m => $n) {
- $childlist = Tree::instance()->getTreeList(Tree::instance()->getTreeArray($n['id']));
- $temp = [];
- foreach ($childlist as $k => $v) {
- $temp[$v['id']] = $v['name'];
- }
- $result[__($n['name'])] = $temp;
- }
- $groupdata = $result;
- }
- $this->view->assign("groupdata", $groupdata);
- $groupids = explode(',',$row['auth_group_ids']);
- $this->view->assign("groupids", $groupids);
- }
- }
- }
|