User.php 2.3 KB

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