1, "name" => "后台管理员", "pid" => 0], ["id" => 2, "name" => "门店", "pid" => 0], ["id" => 3, "name" => "门店主管", "pid" => 2], ["id" => 4, "name" => "门店老师", "pid" => 2], ["id" => 5, "name" => "门店顾问", "pid" => 2], ["id" => 6, "name" => "门店促销员", "pid" => 2], ["id" => 7, "name" => "佛堂", "pid" => 0], ["id" => 8, "name" => "佛堂负责人", "pid" => 7], ["id" => 9, "name" => "佛堂前台", "pid" => 7], ["id" => 10, "name" => "佛堂道士", "pid" => 7], ["id" => 11, "name" => "佛堂和尚", "pid" => 7], ["id" => 12, "name" => "物流部", "pid" => 0], ["id" => 13, "name" => "物流负责人", "pid" => 12], ["id" => 14, "name" => "物流助理", "pid" => 12], ["id" => 15, "name" => "财务", "pid" => 0], ["id" => 16, "name" => "财务负责人", "pid" => 15], ["id" => 17, "name" => "门店经销商", "pid" => 2], ]; public function __construct(App $app) { $this->model = new AdminModel(); $this->authGroupModel = new AuthGroupModel(); $this->authGroupAccessModel = new AuthGroupAccessModel(); $this->storeModel = new StoreModel(); parent::__construct($app); } /** * @param Request $request * @return \think\response\View * @throws \think\db\exception\DbException */ public function index(Request $request) { $params = $request->param(); $list = $this->model->findByPaginate(); $all_groups = $this->authGroupModel->fetchAllGroups(); $format_params = [ 'group_id' => format_string($params['group_id'] ?? null), ]; View::assign([ 'rules' => $this->rules, 'list' => $list, 'all_groups' => recursion($all_groups, 0), 'params' => $format_params ]); return view(); } /** * @return \think\response\Json|\think\response\View * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function add() { if ($this->request->isAjax()) { $params = $this->request->param(); $admin = $this->model->doesItExist($params['account']); if($admin) return $this->fail(lang("The account already exists.")); $res = $this->model->create([ 'account' => $params['account'], 'nickname' => $params['nickname'], 'mobile' => $params['mobile'], 'password' => md5($params['password']), 'store_id' => isset($params['store_id']) && $params['store_id'] > 0 ? $params : null, 'is_login_backstage' => $params['is_login_backstage'], 'rule' => $params['rule'] ]); $this->authGroupAccessModel->save([ 'admin_id' => $res->id, 'group_id' => $params['group_id'] ]); return $this->ok(true); } $all_groups = $this->authGroupModel->fetchAllGroups(); View::assign([ 'stores' => $this->storeModel->findAllStore(), 'rules' => recursion($this->rules,0), 'all_groups' => recursion($all_groups, 0) ]); return view(); } /** * @return \think\response\Json|\think\response\View * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function edit() { $params = $this->request->param(); if(!isset($params['id'])) return $this->fail(lang('ID not exist')); if ($this->request->isAjax()) { $admin = $this->model->doesItExist($params['account']); if($admin && $admin->id != $params['id']) return $this->fail(lang("The account already exists.")); $this->model->where('id',$params['id'])->update([ 'account' => $params['account'], 'nickname' => $params['nickname'], 'mobile' => $params['mobile'], 'password' => isset($params['password']) && $params['password'] != $admin->password ? md5($params['password']) : $admin['password'], 'store_id' => isset($params['store_id']) && $params['store_id'] > 0 ? $params['store_id'] : null, 'is_login_backstage' => $params['is_login_backstage'], 'rule' => $params['rule'] > 0 ? $params['rule'] : null, 'update_time' => time() ]); $relation = $this->authGroupAccessModel->findByAdminId($admin->id); if($relation && $relation->group_id != $params['group_id']) { $relation->where('id', $relation->id)->update([ 'group_id' => $params['group_id'] ]); } return $this->ok(true); } View::assign([ 'stores' => $this->storeModel->findAllStore(), 'all_groups' => recursion($this->authGroupModel->fetchAllGroups(), 0), 'rules' => recursion($this->rules,0), 'admin' => $this->model->findById($params['id']), ]); return view(); } public function delete(\think\Request $request) { $params = $request->param(); if(!isset($params['ids'])) return $this->fail(lang("Please select the data you want to delete")); $this->model->deleteByIds(explode(',', $params['ids'])); return $this->ok(true); } public function total_data() { $params = $this->request->param(); if(!isset($params['id'])) return $this->fail(lang('ID not exist')); View::assign([ 'stores' => $this->storeModel->findAllStore(), 'all_groups' => recursion($this->authGroupModel->fetchAllGroups(), 0), 'rules' => recursion($this->rules,0), 'admin' => $this->model->findById($params['id']), ]); return view(); } }