User.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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|bool|mixed
  32. * @throws \think\exception\DbException
  33. */
  34. public function edit($user_id)
  35. {
  36. // 会员等级详情
  37. $model = UserModel::detail($user_id);
  38. if (!$this->request->isAjax()) {
  39. return $this->fetch('edit', compact('model'));
  40. }
  41. // 编辑记录
  42. $post = $this->postData('user');
  43. $post['user_id'] = $user_id;
  44. if ($model->edit($post)) {
  45. return $this->renderSuccess('更新成功', url('user/index'));
  46. }
  47. return $this->renderError($model->getError() ?: '更新失败');
  48. }
  49. /**
  50. * 删除用户
  51. * @param $user_id
  52. * @return array
  53. * @throws \think\exception\DbException
  54. */
  55. public function delete($user_id)
  56. {
  57. // 用户详情
  58. $model = UserModel::detail($user_id);
  59. if ($model->setDelete()) {
  60. return $this->renderSuccess('删除成功');
  61. }
  62. return $this->renderError($model->getError() ?: '删除失败');
  63. }
  64. /**
  65. * 用户充值
  66. * @param $user_id
  67. * @param int $source 充值类型
  68. * @return array|bool
  69. * @throws \think\Exception
  70. * @throws \think\exception\DbException
  71. */
  72. public function recharge($user_id, $source)
  73. {
  74. // 用户详情
  75. $model = UserModel::detail($user_id);
  76. if ($model->recharge($this->store['user']['user_name'], $source, $this->postData('recharge'))) {
  77. return $this->renderSuccess('操作成功');
  78. }
  79. return $this->renderError($model->getError() ?: '操作失败');
  80. }
  81. /**
  82. * 修改会员等级
  83. * @param $user_id
  84. * @return array|bool
  85. * @throws \think\Exception
  86. * @throws \think\exception\DbException
  87. */
  88. public function grade($user_id)
  89. {
  90. // 用户详情
  91. $model = UserModel::detail($user_id);
  92. if ($model->updateGrade($this->postData('grade'))) {
  93. return $this->renderSuccess('操作成功');
  94. }
  95. return $this->renderError($model->getError() ?: '操作失败');
  96. }
  97. }