User.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2024 https://www.yiovo.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
  8. // +----------------------------------------------------------------------
  9. // | Author: 萤火科技 <admin@yiovo.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\store\controller;
  13. use think\response\Json;
  14. use app\store\model\User as UserModel;
  15. /**
  16. * 用户管理
  17. * Class User
  18. * @package app\store\controller
  19. */
  20. class User extends Controller
  21. {
  22. /**
  23. * 用户列表
  24. * @return Json
  25. * @throws \think\db\exception\DbException
  26. */
  27. public function list(): Json
  28. {
  29. // 用户列表
  30. $model = new UserModel;
  31. $list = $model->getList($this->request->param());
  32. return $this->renderSuccess(compact('list'));
  33. }
  34. /**
  35. * 删除用户
  36. * @param int $userId
  37. * @return Json
  38. */
  39. public function delete(int $userId): Json
  40. {
  41. // 用户详情
  42. $model = UserModel::detail($userId);
  43. if ($model->setDelete()) {
  44. return $this->renderSuccess('删除成功');
  45. }
  46. return $this->renderError($model->getError() ?: '删除失败');
  47. }
  48. /**
  49. * 用户充值
  50. * @param int $userId
  51. * @param string $target
  52. * @return Json
  53. */
  54. public function recharge(int $userId, string $target): Json
  55. {
  56. // 用户详情
  57. $model = UserModel::detail($userId);
  58. if ($model->recharge($target, $this->postForm())) {
  59. return $this->renderSuccess('操作成功');
  60. }
  61. return $this->renderError($model->getError() ?: '操作失败');
  62. }
  63. /**
  64. * 修改会员等级
  65. * @param int $userId
  66. * @return Json
  67. */
  68. public function grade(int $userId): Json
  69. {
  70. // 用户详情
  71. $model = UserModel::detail($userId);
  72. if ($model->updateGrade($this->postForm())) {
  73. return $this->renderSuccess('操作成功');
  74. }
  75. return $this->renderError($model->getError() ?: '操作失败');
  76. }
  77. }