| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- <?php
- namespace app\admin\controller;
- use app\admin\service\AuthService;
- use app\BaseController;
- use app\common\model\StoreModel;
- use think\App;
- use think\facade\View;
- class AuthGroup extends BaseController
- {
- private $authService;
- private $storeModel;
- public $reception_rules = [
- ["id" => 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);
- }
- }
|