UserExtract.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\api\user;
  12. use app\common\repositories\user\UserRepository;
  13. use crmeb\basic\BaseController;
  14. use app\common\repositories\system\groupData\GroupDataRepository;
  15. use think\App;
  16. use app\validate\api\UserExtractValidate as validate;
  17. use app\common\repositories\user\UserExtractRepository as repository;
  18. class UserExtract extends BaseController
  19. {
  20. /**
  21. * @var repository
  22. */
  23. public $repository;
  24. /**
  25. * UserExtract constructor.
  26. * @param App $app
  27. * @param repository $repository
  28. */
  29. public function __construct(App $app,repository $repository)
  30. {
  31. parent::__construct($app);
  32. $this->repository = $repository;
  33. }
  34. /**
  35. * 提现记录
  36. * @return \think\response\Json
  37. * @author wuhaotian
  38. * @email 442384644@qq.com
  39. * @date 2024/7/10
  40. */
  41. public function lst()
  42. {
  43. [$page,$limit] = $this->getPage();
  44. $where = $this->request->params(['status']);
  45. [$start,$stop]= $this->request->params(['start','stop'],true);
  46. $where['date'] = $start&&$stop ? date('Y/m/d',$start).'-'.date('Y/m/d',$stop) : '';
  47. $where['uid'] = $this->request->uid();
  48. return app('json')->success($this->repository->getList($where,$page,$limit));
  49. }
  50. /**
  51. * 提现记录详情
  52. *
  53. * @param $id
  54. * @return void
  55. */
  56. public function detail($id)
  57. {
  58. if(!$id) return app('json')->fail('参数错误');
  59. $info = $this->repository->get($id);
  60. if(!$info) {
  61. return app('json')->fail('提现记录不存在');
  62. }
  63. return app('json')->success($info);
  64. }
  65. /**
  66. * 用户提现
  67. * @param validate $validate
  68. * @return \think\response\Json
  69. * @author wuhaotian
  70. * @email 442384644@qq.com
  71. * @date 2024/7/10
  72. */
  73. public function create(validate $validate)
  74. {
  75. $data = $this->checkParams($validate);
  76. $user = $this->request->userInfo();
  77. $this->repository->create($user,$data);
  78. return app('json')->success($data['extract_type'] == $this->repository::EXTRACT_TYPE_YUE ? '已提现至余额' : '申请已提交');
  79. }
  80. /**
  81. * 验证数据
  82. * @param validate $validate
  83. * @return array|mixed|string|string[]
  84. * @author wuhaotian
  85. * @email 442384644@qq.com
  86. * @date 2024/7/10
  87. */
  88. public function checkParams(validate $validate)
  89. {
  90. $data = $this->request->params(['extract_type','bank_code','bank_address','alipay_code','wechat','extract_pic','extract_price','real_name','bank_name']);
  91. $validate->check($data);
  92. return $data;
  93. }
  94. /**
  95. * 银行列表
  96. * @return \think\response\Json
  97. * @author wuhaotian
  98. * @email 442384644@qq.com
  99. * @date 2024/7/10
  100. */
  101. public function bankLst()
  102. {
  103. [$page,$limit] = $this->getPage();
  104. $data = app()->make(GroupDataRepository::class)->groupData('bank_list',0,$page,100);
  105. return app('json')->success($data);
  106. }
  107. /**
  108. * 历史银行数据
  109. * @return \think\response\Json
  110. * @author wuhaotian
  111. * @email 442384644@qq.com
  112. * @date 2024/7/10
  113. */
  114. public function historyBank()
  115. {
  116. $data = $this->repository->getHistoryBank($this->request->userInfo()->uid);
  117. return app('json')->success($data ?? []);
  118. }
  119. /**
  120. * 用户分红积分提现
  121. * @return \think\response\Json
  122. */
  123. public function awardCreate()
  124. {
  125. $user = $this->request->userInfo();
  126. $where= $this->request->params(['num']);
  127. if ($where['num'] <= $user['award_integral']){
  128. throw new \Exception('提现积分不能大于可拥有积分');
  129. }
  130. app()->make(UserRepository::class)->extractIntegral($user['uid'],$where['num']);
  131. return app('json')->success('已提现至佣金');
  132. }
  133. /**
  134. * 历史提现数据
  135. * @return \think\response\Json
  136. * @author wuhaotian
  137. * @email 442384644@qq.com
  138. * @date 2024/7/10
  139. */
  140. public function history()
  141. {
  142. $where= $this->request->params(['type']);
  143. $data = $this->repository->getHistory($this->request->userInfo()->uid,$where);
  144. return app('json')->success($data ?? []);
  145. }
  146. }