UserRechargeController.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\api\controller\v1\user;
  12. use app\Request;
  13. use app\services\pay\PayServices;
  14. use app\services\user\UserRechargeServices;
  15. /**
  16. * 充值类
  17. * Class UserRechargeController
  18. * @package app\api\controller\user
  19. */
  20. class UserRechargeController
  21. {
  22. protected $services = NUll;
  23. /**
  24. * UserRechargeController constructor.
  25. * @param UserRechargeServices $services
  26. */
  27. public function __construct(UserRechargeServices $services)
  28. {
  29. $this->services = $services;
  30. }
  31. /**
  32. * 用户充值
  33. * @param Request $request
  34. * @return mixed
  35. */
  36. public function recharge(Request $request)
  37. {
  38. [$price, $recharId, $type, $from] = $request->postMore([
  39. ['price', 0],
  40. ['rechar_id', 0],
  41. ['type', 0],
  42. ['from', 'weixin']
  43. ], true);
  44. if (!$price || $price <= 0) return app('json')->fail(410122);
  45. if (!in_array($type, [0, 1])) return app('json')->fail(410123);
  46. if (!in_array($from, [PayServices::WEIXIN_PAY, 'weixinh5', 'routine', PayServices::ALIAPY_PAY])) return app('json')->fail(410123);
  47. $storeMinRecharge = sys_config('store_user_min_recharge');
  48. if (!$recharId && $price < $storeMinRecharge) return app('json')->fail(410124, null, ['money' => $storeMinRecharge]);
  49. $uid = (int)$request->uid();
  50. $re = $this->services->recharge($uid, $price, $recharId, $type, $from, true);
  51. if ($re) {
  52. $payType = $re['pay_type'] ?? '';
  53. unset($re['pay_type']);
  54. return app('json')->status($payType, 410125, $re);
  55. }
  56. return app('json')->fail(410126);
  57. }
  58. /**
  59. * TODO 小程序充值 弃用
  60. * @param Request $request
  61. * @return mixed
  62. */
  63. public function routine(Request $request)
  64. {
  65. list($price, $recharId, $type) = $request->postMore([['price', 0], ['rechar_id', 0], ['type', 0]], true);
  66. if (!$price || $price <= 0) return app('json')->fail(410122);
  67. $storeMinRecharge = sys_config('store_user_min_recharge');
  68. if ($price < $storeMinRecharge) return app('json')->fail(410124, null, ['money' => $storeMinRecharge]);
  69. $from = 'routine';
  70. $uid = (int)$request->uid();
  71. $re = $this->services->recharge($uid, $price, $recharId, $type, $from);
  72. if ($re) {
  73. unset($re['msg']);
  74. return app('json')->success(410125, $re['data']);
  75. }
  76. return app('json')->fail(410126);
  77. }
  78. /**
  79. * TODO 公众号充值 弃用
  80. * @param Request $request
  81. * @return mixed
  82. */
  83. public function wechat(Request $request)
  84. {
  85. list($price, $recharId, $from, $type) = $request->postMore([['price', 0], ['rechar_id', 0], ['from', 'weixin'], ['type', 0]], true);
  86. if (!$price || $price <= 0) return app('json')->fail(410122);
  87. $storeMinRecharge = sys_config('store_user_min_recharge');
  88. if ($price < $storeMinRecharge) return app('json')->fail(410124, null, ['money' => $storeMinRecharge]);
  89. $uid = (int)$request->uid();
  90. $re = $this->services->recharge($uid, $price, $recharId, $type, $from);
  91. if ($re) {
  92. unset($re['msg']);
  93. return app('json')->success(410125, $re);
  94. }
  95. return app('json')->fail(410126);
  96. }
  97. /**
  98. * 充值额度选择
  99. * @return mixed
  100. */
  101. public function index()
  102. {
  103. $rechargeQuota = sys_data('user_recharge_quota') ?? [];
  104. $data['recharge_quota'] = $rechargeQuota;
  105. $recharge_attention = sys_config('recharge_attention');
  106. $recharge_attention = explode("\n", $recharge_attention);
  107. $data['recharge_attention'] = $recharge_attention;
  108. return app('json')->success($data);
  109. }
  110. }