| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- <?php
- namespace app\store\controller;
- use app\store\model\User as UserModel;
- use app\store\model\user\Grade as GradeModel;
- /**
- * 用户管理
- * Class User
- * @package app\store\controller
- */
- class User extends Controller
- {
- /**
- * 用户列表
- * @param string $nickName 昵称
- * @param int $gender 性别
- * @param int $grade 会员等级
- * @return mixed
- * @throws \think\exception\DbException
- */
- public function index($nickName = '', $gender = null, $grade = null)
- {
- $model = new UserModel;
- $list = $model->getList($nickName, $gender, $grade);
- // 会员等级列表
- $gradeList = GradeModel::getUsableList();
- return $this->fetch('index', compact('list', 'gradeList'));
- }
- /**
- * 编辑会员
- * @param $user_id
- * @return array|bool|mixed
- * @throws \think\exception\DbException
- */
- public function edit($user_id)
- {
- // 会员等级详情
- $model = UserModel::detail($user_id);
- if (!$this->request->isAjax()) {
- return $this->fetch('edit', compact('model'));
- }
- // 编辑记录
- $post = $this->postData('user');
- $post['user_id'] = $user_id;
- if ($model->edit($post)) {
- return $this->renderSuccess('更新成功', url('user/index'));
- }
- return $this->renderError($model->getError() ?: '更新失败');
- }
- /**
- * 删除用户
- * @param $user_id
- * @return array
- * @throws \think\exception\DbException
- */
- public function delete($user_id)
- {
- // 用户详情
- $model = UserModel::detail($user_id);
- if ($model->setDelete()) {
- return $this->renderSuccess('删除成功');
- }
- return $this->renderError($model->getError() ?: '删除失败');
- }
- /**
- * 用户充值
- * @param $user_id
- * @param int $source 充值类型
- * @return array|bool
- * @throws \think\Exception
- * @throws \think\exception\DbException
- */
- public function recharge($user_id, $source)
- {
- // 用户详情
- $model = UserModel::detail($user_id);
- if ($model->recharge($this->store['user']['user_name'], $source, $this->postData('recharge'))) {
- return $this->renderSuccess('操作成功');
- }
- return $this->renderError($model->getError() ?: '操作失败');
- }
- /**
- * 修改会员等级
- * @param $user_id
- * @return array|bool
- * @throws \think\Exception
- * @throws \think\exception\DbException
- */
- public function grade($user_id)
- {
- // 用户详情
- $model = UserModel::detail($user_id);
- if ($model->updateGrade($this->postData('grade'))) {
- return $this->renderSuccess('操作成功');
- }
- return $this->renderError($model->getError() ?: '操作失败');
- }
- }
|