You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Recharge.php 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace app\controller\cashier;
  3. use app\Request;
  4. use app\services\user\UserRechargeServices;
  5. use app\services\user\UserServices;
  6. /**
  7. * 收银台用户充值
  8. */
  9. class Recharge extends AuthController
  10. {
  11. /**
  12. * 充值数据
  13. * @return mixed
  14. */
  15. public function rechargeInfo()
  16. {
  17. $rechargeQuota = sys_data('user_recharge_quota') ?? [];
  18. $data['recharge_quota'] = $rechargeQuota;
  19. $recharge_attention = sys_config('recharge_attention');
  20. $recharge_attention = explode("\n", $recharge_attention);
  21. $data['recharge_attention'] = $recharge_attention;
  22. return $this->success($data);
  23. }
  24. /**
  25. * 收银台用户充值
  26. * @param Request $request
  27. * @param UserServices $userServices
  28. * @param UserRechargeServices $userRechargeServices
  29. * @return mixed
  30. * @throws \think\db\exception\DataNotFoundException
  31. * @throws \think\db\exception\ModelNotFoundException
  32. */
  33. public function recharge(Request $request, UserServices $userServices, UserRechargeServices $userRechargeServices)
  34. {
  35. [$uid, $price, $recharId, $payType, $authCode] = $request->postMore([
  36. ['uid', 0],
  37. ['price', 0],
  38. ['rechar_id', 0],
  39. [['pay_type', 'd'], 2], //2=用户扫码支付,3=付款码扫码支付
  40. ['auth_code', '']
  41. ], true);
  42. if (!$authCode && $payType == 3) {
  43. return $this->fail('缺少付款码二维码CODE');
  44. }
  45. if (!$price || $price <= 0) {
  46. return $this->fail('充值金额不能为0元!');
  47. }
  48. $storeMinRecharge = sys_config('store_user_min_recharge');
  49. if ($price < $storeMinRecharge) return $this->fail('充值金额不能低于' . $storeMinRecharge);
  50. if (!$userServices->userExist($uid)) {
  51. return $this->fail('用户不存在');
  52. }
  53. $re = $userRechargeServices->recharge($uid, $price, $recharId, (int)$payType, 'store', $this->cashierInfo, $authCode);
  54. if ($re) {
  55. $msg = $re['msg'];
  56. unset($re['msg']);
  57. return $this->success($msg, $re);
  58. }
  59. return $this->fail('充值失败');
  60. }
  61. }