|
|
@@ -8,6 +8,7 @@ use app\BaseController;
|
|
|
use app\common\model\AdminModel;
|
|
|
use app\common\model\AuthGroupAccessModel;
|
|
|
use app\common\model\AuthGroupModel;
|
|
|
+use app\common\model\DepartmentModel;
|
|
|
use app\common\model\StoreModel;
|
|
|
use think\App;
|
|
|
use think\facade\View;
|
|
|
@@ -19,26 +20,7 @@ class Admin extends BaseController
|
|
|
private $authGroupModel;
|
|
|
private $authGroupAccessModel;
|
|
|
private $storeModel;
|
|
|
-
|
|
|
- public $rules = [
|
|
|
- ["id" => 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],
|
|
|
- ];
|
|
|
+ private $departmentModel;
|
|
|
|
|
|
public function __construct(App $app)
|
|
|
{
|
|
|
@@ -46,6 +28,7 @@ class Admin extends BaseController
|
|
|
$this->authGroupModel = new AuthGroupModel();
|
|
|
$this->authGroupAccessModel = new AuthGroupAccessModel();
|
|
|
$this->storeModel = new StoreModel();
|
|
|
+ $this->departmentModel = new DepartmentModel();
|
|
|
parent::__construct($app);
|
|
|
}
|
|
|
|
|
|
@@ -59,11 +42,12 @@ class Admin extends BaseController
|
|
|
$params = $request->param();
|
|
|
$format_params = [
|
|
|
'group_id' => format_string($params['group_id'] ?? null),
|
|
|
+ 'department_id' => format_string($params['department_id'] ?? null),
|
|
|
];
|
|
|
$list = $this->model->findByPaginate($format_params);
|
|
|
$all_groups = $this->authGroupModel->fetchAllGroups();
|
|
|
View::assign([
|
|
|
- 'rules' => $this->rules,
|
|
|
+ 'all_department' => recursion($this->departmentModel->findAllDepartment()->toArray(),0),
|
|
|
'list' => $list,
|
|
|
'all_groups' => recursion($all_groups, 0),
|
|
|
'params' => $format_params
|
|
|
@@ -84,14 +68,17 @@ class Admin extends BaseController
|
|
|
$admin = $this->model->doesItExist($params['account']);
|
|
|
if($admin)
|
|
|
return $this->fail(lang("The account already exists."));
|
|
|
+ $department = $this->departmentModel->findById($params['department_id']);
|
|
|
+ if(!$department)
|
|
|
+ return $this->fail('部门不存在!');
|
|
|
$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,
|
|
|
+ 'department_id' => $params['department_id'],
|
|
|
+ 'store_ids' => isset($params['store_ids']) ? join(',', $params['store_ids']) : $department->store_id,
|
|
|
'is_login_backstage' => $params['is_login_backstage'],
|
|
|
- 'rule' => $params['rule']
|
|
|
]);
|
|
|
$this->authGroupAccessModel->save([
|
|
|
'admin_id' => $res->id,
|
|
|
@@ -100,14 +87,17 @@ class Admin extends BaseController
|
|
|
return $this->ok(true);
|
|
|
}
|
|
|
$all_groups = $this->authGroupModel->fetchAllGroups();
|
|
|
+ $all_department = recursion($this->departmentModel->findAllDepartment()->toArray(),0);
|
|
|
View::assign([
|
|
|
- 'stores' => $this->storeModel->findAllStore(),
|
|
|
- 'rules' => recursion($this->rules,0),
|
|
|
- 'all_groups' => recursion($all_groups, 0)
|
|
|
+ 'stores' => $this->storeModel->findAllStore()->toArray(),
|
|
|
+ 'all_department' => $all_department,
|
|
|
+ 'all_group' => recursion($all_groups, 0),
|
|
|
+ 'now_group' => $all_department[0] && $all_department[0]['auth_group_ids'] != null ?$this->authGroupModel->findByIds(explode(',', $all_department[0]['auth_group_ids'])) : []
|
|
|
]);
|
|
|
return view();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* @return \think\response\Json|\think\response\View
|
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
|
@@ -118,18 +108,22 @@ class Admin extends BaseController
|
|
|
$params = $this->request->param();
|
|
|
if(!isset($params['id']))
|
|
|
return $this->fail(lang('ID not exist'));
|
|
|
+ $admin = $this->model->findById($params['id']);
|
|
|
if ($this->request->isAjax()) {
|
|
|
$admin = $this->model->doesItExist($params['account']);
|
|
|
if($admin && $admin->id != $params['id'])
|
|
|
return $this->fail(lang("The account already exists."));
|
|
|
+ $department = $this->departmentModel->findById($params['department_id']);
|
|
|
+ if(!$department)
|
|
|
+ return $this->fail('部门不存在!');
|
|
|
$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,
|
|
|
+ 'department_id' => $params['department_id'],
|
|
|
+ 'store_ids' => isset($params['store_ids']) ? join(',', $params['store_ids']) : $department->store_id,
|
|
|
'is_login_backstage' => $params['is_login_backstage'],
|
|
|
- 'rule' => $params['rule'] > 0 ? $params['rule'] : null,
|
|
|
'update_time' => time()
|
|
|
]);
|
|
|
$relation = $this->authGroupAccessModel->findByAdminId($admin->id);
|
|
|
@@ -140,16 +134,26 @@ class Admin extends BaseController
|
|
|
}
|
|
|
return $this->ok(true);
|
|
|
}
|
|
|
+ $all_department = recursion($this->departmentModel->findAllDepartment()->toArray(),0);
|
|
|
+ $stores = $this->storeModel->findAllStore();
|
|
|
+ foreach ($stores as $store) $store->isChecked = in_array($store->id, explode(',', $admin->store_ids ?? ''));
|
|
|
+ $group_ids = $admin->department->auth_group_ids;
|
|
|
View::assign([
|
|
|
- 'stores' => $this->storeModel->findAllStore(),
|
|
|
- 'all_groups' => recursion($this->authGroupModel->fetchAllGroups(), 0),
|
|
|
- 'rules' => recursion($this->rules,0),
|
|
|
- 'admin' => $this->model->findById($params['id']),
|
|
|
+ 'stores' => $stores,
|
|
|
+ 'all_department' => $all_department,
|
|
|
+ 'admin' => $admin,
|
|
|
+ 'now_group' => $group_ids != null ? $this->authGroupModel->findByIds(explode(',', $group_ids)) : []
|
|
|
]);
|
|
|
return view();
|
|
|
}
|
|
|
|
|
|
|
|
|
+ public function getBindRules($department_id) {
|
|
|
+ $department = $this->departmentModel->findById($department_id);
|
|
|
+ if (!$department || $department->auth_group_ids == null)
|
|
|
+ return $this->ok([]);
|
|
|
+ return $this->ok($this->authGroupModel->findByIds(explode(',',$department->auth_group_ids)));
|
|
|
+ }
|
|
|
|
|
|
public function delete(\think\Request $request) {
|
|
|
$params = $request->param();
|
|
|
@@ -167,7 +171,6 @@ class Admin extends BaseController
|
|
|
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();
|