User.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace app\store\controller;
  3. use app\store\model\User as UserModel;
  4. use app\store\model\user\Grade as GradeModel;
  5. /**
  6. * 用户管理
  7. * Class User
  8. * @package app\store\controller
  9. */
  10. class User extends Controller
  11. {
  12. /**
  13. * 用户列表
  14. * @param string $nickName 昵称
  15. * @param int $gender 性别
  16. * @param int $grade 会员等级
  17. * @return mixed
  18. * @throws \think\exception\DbException
  19. */
  20. public function index($nickName = '', $gender = null, $grade = null)
  21. {
  22. $model = new UserModel;
  23. $list = $model->getList($nickName, $gender, $grade);
  24. // 会员等级列表
  25. $gradeList = GradeModel::getUsableList();
  26. return $this->fetch('index', compact('list', 'gradeList'));
  27. }
  28. /**
  29. * 删除用户
  30. * @param $user_id
  31. * @return array
  32. * @throws \think\exception\DbException
  33. */
  34. public function delete($user_id)
  35. {
  36. // 用户详情
  37. $model = UserModel::detail($user_id);
  38. if ($model->setDelete()) {
  39. return $this->renderSuccess('删除成功');
  40. }
  41. return $this->renderError($model->getError() ?: '删除失败');
  42. }
  43. /**
  44. * 用户充值
  45. * @param $user_id
  46. * @param int $source 充值类型
  47. * @return array|bool
  48. * @throws \think\Exception
  49. * @throws \think\exception\DbException
  50. */
  51. public function recharge($user_id, $source)
  52. {
  53. // 用户详情
  54. $model = UserModel::detail($user_id);
  55. if ($model->recharge($this->store['user']['user_name'], $source, $this->postData('recharge'))) {
  56. return $this->renderSuccess('操作成功');
  57. }
  58. return $this->renderError($model->getError() ?: '操作失败');
  59. }
  60. /**
  61. * 修改会员等级
  62. * @param $user_id
  63. * @return array|bool
  64. * @throws \think\Exception
  65. * @throws \think\exception\DbException
  66. */
  67. public function grade($user_id)
  68. {
  69. // 用户详情
  70. $model = UserModel::detail($user_id);
  71. if ($model->updateGrade($this->postData('grade'))) {
  72. return $this->renderSuccess('操作成功');
  73. }
  74. return $this->renderError($model->getError() ?: '操作失败');
  75. }
  76. }