| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- <?php
- // +----------------------------------------------------------------------
- // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
- // +----------------------------------------------------------------------
- // | Author: CRMEB Team <admin@crmeb.com>
- // +----------------------------------------------------------------------
- namespace app\controller\admin\v1\system\admin;
- use app\controller\admin\AuthController;
- use app\services\system\admin\SystemAdminServices;
- use crmeb\services\CacheService;
- use think\facade\{App, Config};
- /**
- * Class SystemAdmin
- * @package app\controller\admin\v1\setting
- */
- class SystemAdmin extends AuthController
- {
- /**
- * SystemAdmin constructor.
- * @param App $app
- * @param SystemAdminServices $services
- */
- public function __construct(App $app, SystemAdminServices $services)
- {
- parent::__construct($app);
- $this->services = $services;
- }
- /**
- * 显示管理员资源列表
- *
- * @return \think\Response
- */
- public function index()
- {
- $where = $this->request->getMore([
- ['name', '', '', 'account_like'],
- ['roles', ''],
- ['is_del', 1],
- ['status', '']
- ]);
- $where['level'] = $this->adminInfo['level'] + 1;
- $where['admin_type'] = 1;
- return $this->success($this->services->getAdminList($where));
- }
- /**
- * 创建表单
- * @return mixed
- * @throws \FormBuilder\Exception\FormBuilderException
- */
- public function create()
- {
- return $this->success($this->services->createForm($this->adminInfo['level'] + 1));
- }
- /**
- * 保存管理员
- * @return mixed
- */
- public function save()
- {
- $data = $this->request->postMore([
- ['account', ''],
- ['conf_pwd', ''],
- ['pwd', ''],
- ['real_name', ''],
- ['phone', ''],
- ['roles', []],
- ['status', 0],
- ]);
- $this->validate($data, \app\validate\admin\setting\SystemAdminValidate::class);
- $data['level'] = $this->adminInfo['level'] + 1;
- $this->services->create($data);
- return $this->success('添加成功');
- }
- /**
- * 显示编辑资源表单页.
- *
- * @param int $id
- * @return \think\Response
- */
- public function edit($id)
- {
- if (!$id) {
- return $this->fail('管理员信息读取失败');
- }
- return $this->success($this->services->updateForm($this->adminInfo['level'] + 1, (int)$id));
- }
- /**
- * 修改管理员信息
- * @param $id
- * @return mixed
- */
- public function update($id)
- {
- $data = $this->request->postMore([
- ['account', ''],
- ['conf_pwd', ''],
- ['pwd', ''],
- ['real_name', ''],
- ['phone', ''],
- ['roles', []],
- ['status', 0],
- ]);
- $this->validate($data, \app\validate\admin\setting\SystemAdminValidate::class, 'update');
- if ($this->services->save((int)$id, $data)) {
- return $this->success('修改成功');
- } else {
- return $this->fail('修改失败');
- }
- }
- /**
- * 删除管理员
- * @param $id
- * @return mixed
- */
- public function delete($id)
- {
- if (!$id) return $this->fail('删除失败,缺少参数');
- if ($this->services->update((int)$id, ['is_del' => 1, 'status' => 0]))
- return $this->success('删除成功!');
- else
- return $this->fail('删除失败');
- }
- /**
- * 修改状态
- * @param $id
- * @param $status
- * @return mixed
- */
- public function set_status($id, $status)
- {
- $this->services->update((int)$id, ['status' => $status]);
- return $this->success($status == 0 ? '关闭成功' : '开启成功');
- }
- /**
- * 获取当前登陆管理员的信息
- * @return mixed
- */
- public function info()
- {
- return $this->success($this->adminInfo);
- }
- /**
- * 修改当前登陆admin信息
- * @return mixed
- */
- public function update_admin()
- {
- $data = $this->request->postMore([
- ['real_name', ''],
- ['head_pic', ''],
- ['pwd', ''],
- ['new_pwd', ''],
- ['conf_pwd', ''],
- ['phone', ''],
- ['code', '']
- ]);
- if ($this->services->updateAdmin($this->adminId, $data))
- return $this->success('修改成功');
- else
- return $this->fail('修改失败');
- }
- /**
- * 退出登陆
- * @return mixed
- */
- public function logout()
- {
- $key = trim(ltrim($this->request->header(Config::get('cookie.token_name')), 'Bearer'));
- CacheService::redisHandler()->delete(md5($key));
- return $this->success();
- }
- }
|