UserRecharge.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 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\store\user;
  12. use app\services\user\UserServices;
  13. use think\facade\App;
  14. use app\controller\store\AuthController;
  15. use app\services\user\UserRechargeServices;
  16. /**
  17. * 充值类
  18. * Class UserRechargeController
  19. * @package app\api\controller\user
  20. */
  21. class UserRecharge extends AuthController
  22. {
  23. protected $services = NUll;
  24. /**
  25. * UserRechargeController constructor.
  26. * @param App $app
  27. * @param UserRechargeServices $services
  28. */
  29. public function __construct(App $app, UserRechargeServices $services)
  30. {
  31. parent::__construct($app);
  32. $this->services = $services;
  33. }
  34. /**
  35. * 充值额度选择
  36. * @return mixed
  37. */
  38. public function index()
  39. {
  40. $rechargeQuota = sys_data('user_recharge_quota') ?? [];
  41. $data['recharge_quota'] = $rechargeQuota;
  42. $recharge_attention = sys_config('recharge_attention');
  43. $recharge_attention = explode("\n", $recharge_attention);
  44. $data['recharge_attention'] = $recharge_attention;
  45. return app('json')->successful($data);
  46. }
  47. /**
  48. * 充值
  49. * @param UserServices $userServices
  50. * @return mixed
  51. * @throws \think\db\exception\DataNotFoundException
  52. * @throws \think\db\exception\ModelNotFoundException
  53. */
  54. public function recharge(UserServices $userServices)
  55. {
  56. [$uid, $price, $recharId, $payType, $authCode] = $this->request->postMore([
  57. ['uid', 0],
  58. ['price', 0],
  59. ['rechar_id', 0],
  60. ['pay_type', 2], //2=用户扫码支付,3=付款码扫码支付
  61. ['auth_code', '']
  62. ], true);
  63. $payType = (int)$payType;
  64. if (!$authCode && $payType === 3) {
  65. return app('json')->fail('缺少付款码二维码CODE');
  66. }
  67. if (!$price || $price <= 0) return app('json')->fail('充值金额不能为0元!');
  68. $storeMinRecharge = sys_config('store_user_min_recharge');
  69. if ($price < $storeMinRecharge) return app('json')->fail('充值金额不能低于' . $storeMinRecharge);
  70. if (!$userServices->userExist($uid)) {
  71. return app('json')->fail('用户不存在');
  72. }
  73. $re = $this->services->recharge($uid, $price, $recharId, $payType, 'store', $this->storeStaffInfo, $authCode);
  74. if ($re) {
  75. $msg = $re['msg'];
  76. unset($re['msg']);
  77. return app('json')->successful($msg, $re);
  78. }
  79. return app('json')->fail('充值失败');
  80. }
  81. }