10001, "zh" => "客户资料", "en" => "Customer information", "icon" => ""], ["id" => 10002, "zh" => "查询业绩", "en" => "Query performance", "icon" => ""], ["id" => 10003, "zh" => "历史订单", "en" => "Historical Orders", "icon" => ""], ["id" => 10004, "zh" => "定金订单", "en" => "Deposit order", "icon" => ""], ["id" => 10005, "zh" => "退货", "en" => "Return goods", "icon" => ""], ["id" => 10006, "zh" => "换货", "en" => "Exchange goods", "icon" => ""], ["id" => 10007, "zh" => "年费管理", "en" => "Annual fee management", "icon" => ""], ["id" => 10008, "zh" => "生成X-report", "en" => "生成X-report", "icon" => ""], ["id" => 10009, "zh" => "生成Z-report", "en" => "生成Z-report", "icon" => ""] ]; public function __construct(App $app) { parent::__construct($app); $this->authService = new AuthService(); $this->storeModel = new StoreModel(); } public function index() { 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() { $all_groups = $this->authService->authGroupModel->fetchAllGroups(); if ($this->request->isAjax()) { $params = $this->request->param(); $res = $this->authService->authGroupModel->save([ 'pid' => 0, 'name' => format_string($params['name'] ?? null), 'rules' => format_string($params['rule_ids'] ?? null), "reception_rules" => isset($params["reception_rules"]) ? join(',', $params['reception_rules']) : null, 'describe' => format_string($params['describe'] ?? null), ]); return $this->ok($res); } View::assign([ "reception_rules" => $this->reception_rules, "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(); $id = $params['id']; $all_groups = $this->authService->authGroupModel->fetchAllGroups(); $group = $this->authService->authGroupModel->findById($id); if ($this->request->isAjax()) { $res = $this->authService->authGroupModel->where('id', $params['id'])->save([ 'pid' => 0, 'name' => $params['name'] ?? $group->name, 'rules' => !isset($params['rule_ids']) ? null : $params['rule_ids'], "reception_rules" => isset($params["reception_rules"]) ? join(',', $params['reception_rules']) : null, 'describe' => $params['describe'] ?? $group->describe, 'update_time' => time() ]); return $this->ok($res); } $reception_rules = $group->reception_rules ? explode(',',$group->reception_rules) : []; foreach ($this->reception_rules as &$item) $item['isChecked'] = in_array($item['id'], $reception_rules); View::assign([ 'group' => $group, "all_groups" => recursion($all_groups, 0), "reception_rules" => $this->reception_rules, ]); 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->authService->authGroupModel->deleteByIds(explode(',', $params['ids'])); return $this->ok(true); } public function findAllAuthGroups() { $groups = $this->authService->authGroupModel->fetchAllGroups()->toArray(); $format_groups = array_map(function ($data) { return [ 'id' => $data['id'], 'title' => $data['name'], 'field' => $data['name'], 'spread' => true, 'checked' => false, 'disabled' => $data['id'] == 1 ]; }, $groups); return $this->ok($format_groups); } }