| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- <?php
- namespace app\admin\model;
- use\think\Model;
- use think\Session;
- use think\cache\driver\Redis;
- use think\Loader;
- use think\Cache;
- class User extends Model
- {
- /**
- * 用户列表
- */
- public function userList()
- {
- $code = -2;
- $limit = (input('pageSize') ?? 10);
- $currentPage = (input('currentPage') ?? 1);
- $userName = input('userName');
- $getData = [
- 'pageSize' => $limit,
- 'currentPage' => $currentPage,
- 'userName' => $userName,
- ];
- // 验证传参.
- $validate = Loader::validate('Common');
- if (!$validate->scene('userList')->check($getData)) {
- return [
- 'code' => $code,
- 'msg' => $validate->getError(),
- 'data' => [
- 'userList' => [],
- 'userCount' => 0,
- 'currentPage' => 1,
- 'page' => [],
- ],
- ];
- }
- $offset = (($currentPage - 1) * $limit);
- $where = [];
- if (strlen($userName)) {
- $where['user_name'] = [
- 'like',
- "%$userName%"
- ];
- }
- // 获取用户列表.
- $userList = $this;
- if ($where) {
- $userList = $userList->where($where);
- }
- $userList = $userList
- ->limit($offset, $limit)
- ->select();
- // 查询总数.
- $userCount = $this;
- if ($where) {
- $userCount = $userCount->where($where);
- }
- $userCount = $userCount->count();
- // 分页.
- $page = getPage($userCount, $limit, $currentPage);
- return [
- 'code' => 1,
- 'msg' => lang('MC01005'),
- 'data' => [
- 'userList' => $userList,
- 'userCount' => $userCount,
- 'currentPage' => $currentPage,
- 'page' => $page,
- ],
- ];
- }//end userList()
- /**
- * 修改用户
- */
- public function updateUser()
- {
- $code = -2;
- $userId = input('id');
- $userStatus = input('status');
- $getData = [
- 'user_id' => $userId,
- 'user_status' => $userStatus,
- ];
- // 验证传参.
- $validate = Loader::validate('Common');
- if (!$validate->scene('userList')->check($getData)) {
- return [
- 'code' => $code,
- 'msg' => $validate->getError(),
- 'data' => [],
- ];
- }
- // 修改用户.
- $where['user_id'] = $userId;
- $data['user_status'] = $userStatus;
- $updateUser = $this
- ->where($where)
- ->update($data);
- return [
- 'code' => 1,
- 'msg' => lang('MC01004'),
- 'data' => [],
- ];
- }//end updateUser()
- /**
- * 删除所选用户
- */
- public function delUser($ids)
- {
- $this->wherein('user_id',$ids)->delete();
- return [
- 'code' => 1,
- 'msg' => lang('MC01003'),
- 'data' => [],
- ];
- }//end delUser()
- }
|