| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
- namespace app\admin\controller\users;
- use app\common\controller\AdminController;
- use app\http\IResponse;
- class Group extends AdminController
- {
- /**
- * 获取系统会员列表
- *
- * @return mixed
- * @throws \think\exception\DbException
- */
- public function index()
- {
- $where = [];
- //组合搜索
- !empty(input('name')) && $where[]
- = ['name', 'like', '%' . input('name') . '%'];
- return IResponse::paginate(model('common/UsersGroup')->withTrashed()->where($where)
- ->paginate(input('limit'),false));
- }
- /**
- *
- * @return mixed
- */
- public function save()
- {
- // 接收数据
- $params = $this->request->param();
- // 数据校验
- $valid = $this->validate($params,[
- 'name|用户组名称' => 'require|chs|unique:UsersGroup',
- 'introduce|用户组描述' => 'require'
- ],[
- 'name.chs' => '用户组名称仅支持中文!',
- 'name.unique' => '用户组名称已存在!'
- ]);
- (true !== $valid) && IResponse::failure($valid);
- // 保存数据
- $res = model('common/UsersGroup')->storeBy($params);
- return $res ? IResponse::success([],'新增用户组成功'):
- IResponse::failure('新增用户组异常');
- }
- /**
- * 更新数据
- *
- * @author 许祖兴 < zuxing.xu@lettered.cn>
- * @date 2020/6/5 14:24
- *
- * @param $id
- * @return \think\response\Json
- */
- public function update($id)
- {
- // 接收数据
- $params = $this->request->param();
- // 数据校验
- $valid = $this->validate($params,[
- 'name|用户组名称' => 'require|chs',
- 'introduce|用户组描述' => 'require'
- ],[
- 'name.chs' => '用户组名称仅支持中文!',
- ]);
- // 校验失败
- (true !== $valid) && IResponse::failure($valid);
- // 查改
- $role = model('common/UsersGroup')->findBy($id);
- $role->updateBy($id, $params);
- return IResponse::success('更新用户组信息成功');
- }
- /**
- * 删除用户组
- *
- * @author 许祖兴 < zuxing.xu@lettered.cn>
- * @date 2020/6/5 14:22
- *
- * @param $id
- * @return \think\response\Json
- */
- public function delete($id)
- {
- model('common/UsersGroup')->deleteBy($id);
- return IResponse::success([],'删除用户组成功');
- }
- /**
- * 恢复删除用户组
- *
- * @author 许祖兴 < zuxing.xu@lettered.cn>
- * @date 2020/6/6 13:05
- *
- * @param $id
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function restore($id)
- {
- // 查询数据
- $userGroup = model('common/UsersGroup')->onlyTrashed()->find($id);
- if (!$userGroup){
- return IResponse::failure('用户组不存在!');
- }
- // 恢复
- return $userGroup->restore() ? IResponse::success('恢复用户组成功!')
- : IResponse::failure('恢复用户组失败!');
- }
- }
|