123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- <?php
- /**
- * @Created by PhpStorm
- * @author: Kirin
- * @day: 2024/11/21
- * @time: 17:39
- */
- namespace app\controller\admin\system;
- use app\common\AdminBaseController;
- use app\Request;
- use app\services\system\admin\SystemAdminServices;
- use app\services\system\admin\SystemRoleServices;
- use app\validate\admin\SystemAdminValidate;
- use think\exception\ValidateException;
- class SystemAdmins extends AdminBaseController
- {
- public function __construct(Request $request, SystemAdminServices $service)
- {
- parent::__construct($request);
- $this->service = $service;
- $this->request->filter(['addslashes', 'trim']);
- $this->validate = new SystemAdminValidate();
- $this->createParams = [
- ['account', ''],
- ['conf_pwd', ''],
- ['pwd', ''],
- ['real_name', ''],
- ['phone', ''],
- ['roles', []],
- ['status', 0]
- ];
- $this->searchable = [
- ['name', '', '', 'account_like'],
- ['roles', ''],
- ['status', '']
- ];
- $this->saveDeal = $this->updateDeal = function (&$data) {
- $data['level'] = $this->adminInfo['level'] + 1;
- };
- }
- /**
- * 显示管理员资源列表
- *
- * @return \think\Response
- */
- public function index()
- {
- $where = $this->request->getMore($this->searchable);
- $where['level'] = $this->adminInfo['level'] + 1;
- $where['admin_type'] = 1;
- return $this->success($this->service->getAdminList($where));
- }
- /**
- * @param $id
- * @return mixed
- */
- public function read($id)
- {
- $info = $this->service->get($id);
- if (!$info)
- return $this->error('数据不存在');
- if ($info['level'] != $this->adminInfo['level'] + 1)
- return $this->error('数据不存在');
- /** @var SystemRoleServices $services */
- $services = app()->make(SystemRoleServices::class);
- $info['roles'] = $services->getRoleArray(['level' => $this->adminInfo['level'] + 1]);
- return $this->success('ok', $info->toArray());
- }
- /**
- * 修改状态
- * @param $id
- * @param $status
- * @return mixed
- */
- public function setStatus($id, $status)
- {
- $this->service->update((int)$id, ['status' => $status]);
- return $this->success($status == 0 ? '关闭成功' : '开启成功');
- }
- /**
- * 修改当前登陆admin信息
- * @return mixed
- * @throws \Psr\SimpleCache\InvalidArgumentException
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function update_admin()
- {
- $data = $this->request->postMore([
- ['real_name', ''],
- ['head_pic', ''],
- ['pwd', ''],
- ['new_pwd', ''],
- ['conf_pwd', ''],
- ['phone', ''],
- ['code', '']
- ]);
- if ($this->service->updateAdmin($this->adminId, $data))
- return $this->success('修改成功');
- else
- return $this->error('修改失败');
- }
- }
|