User.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2017~2021 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 app\store\model\User as UserModel;
  14. /**
  15. * 用户管理
  16. * Class User
  17. * @package app\store\controller
  18. */
  19. class User extends Controller
  20. {
  21. /**
  22. * 用户列表
  23. * @return array
  24. * @throws \think\db\exception\DbException
  25. */
  26. public function list()
  27. {
  28. // 用户列表
  29. $model = new UserModel;
  30. $list = $model->getList($this->request->param());
  31. return $this->renderSuccess(compact('list'));
  32. }
  33. /**
  34. * 删除用户
  35. * @param int $userId
  36. * @return array
  37. */
  38. public function delete(int $userId)
  39. {
  40. // 用户详情
  41. $model = UserModel::detail($userId);
  42. if ($model->setDelete()) {
  43. return $this->renderSuccess('删除成功');
  44. }
  45. return $this->renderError($model->getError() ?: '删除失败');
  46. }
  47. /**
  48. * 用户充值
  49. * @param int $userId
  50. * @param string $target
  51. * @return array
  52. */
  53. public function recharge(int $userId, string $target)
  54. {
  55. // 用户详情
  56. $model = UserModel::detail($userId);
  57. if ($model->recharge($target, $this->postForm())) {
  58. return $this->renderSuccess('操作成功');
  59. }
  60. return $this->renderError($model->getError() ?: '操作失败');
  61. }
  62. /**
  63. * 修改会员等级
  64. * @param int $userId
  65. * @return array
  66. */
  67. public function grade(int $userId)
  68. {
  69. // 用户详情
  70. $model = UserModel::detail($userId);
  71. if ($model->updateGrade($this->postForm())) {
  72. return $this->renderSuccess('操作成功');
  73. }
  74. return $this->renderError($model->getError() ?: '操作失败');
  75. }
  76. }