Recharge.php 2.8 KB

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