UserRechargeController.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. <?php
  2. namespace app\api\controller\user;
  3. use app\models\system\SystemGroupData;
  4. use app\models\user\UserRecharge;
  5. use app\Request;
  6. use crmeb\services\GroupDataService;
  7. use crmeb\services\SystemConfigService;
  8. use crmeb\services\UtilService;
  9. /**
  10. * 充值类
  11. * Class UserRechargeController
  12. * @package app\api\controller\user
  13. */
  14. class UserRechargeController
  15. {
  16. /**
  17. * 小程序充值
  18. *
  19. * @param Request $request
  20. * @return mixed
  21. */
  22. public function routine(Request $request)
  23. {
  24. list($price, $recharId, $type) = UtilService::postMore([
  25. [['price', 'f'], 0],
  26. [['rechar_id', 'd'], 0],
  27. ['type', 0]
  28. ], $request, true);
  29. if (!$price || $price <= 0) return app('json')->fail('参数错误');
  30. $storeMinRecharge = sys_config('store_user_min_recharge');
  31. if ($price < $storeMinRecharge) return app('json')->fail('充值金额不能低于' . $storeMinRecharge);
  32. switch ((int)$type) {
  33. case 0: //支付充值余额
  34. $paid_price = 0;
  35. if ($recharId) {
  36. $data = SystemGroupData::getDateValue($recharId);
  37. if ($data === false) {
  38. return app('json')->fail('您选择的充值方式已下架!');
  39. } else {
  40. $paid_price = $data['give_money'] ?? 0;
  41. }
  42. }
  43. $rechargeOrder = UserRecharge::addRecharge($request->uid(), $price, 'routine', $paid_price);
  44. if (!$rechargeOrder) return app('json')->fail('充值订单生成失败!');
  45. try {
  46. return app('json')->successful(UserRecharge::jsPay($rechargeOrder));
  47. } catch (\Exception $e) {
  48. return app('json')->fail($e->getMessage());
  49. }
  50. break;
  51. case 1: //佣金转入余额
  52. if (UserRecharge::importNowMoney($request->uid(), $price))
  53. return app('json')->successful('转入余额成功');
  54. else
  55. return app('json')->fail(UserRecharge::getErrorInfo());
  56. break;
  57. default:
  58. return app('json')->fail('缺少参数');
  59. break;
  60. }
  61. }
  62. /**
  63. * 公众号充值
  64. *
  65. * @param Request $request
  66. * @return mixed
  67. */
  68. public function wechat(Request $request)
  69. {
  70. list($price, $recharId, $from, $type) = UtilService::postMore([
  71. [['price', 'f'], 0],
  72. [['rechar_id', 'd'], 0],
  73. ['from', 'weixin'],
  74. ['type', 0]
  75. ], $request, true);
  76. if (!$price || $price <= 0) return app('json')->fail('参数错误');
  77. $storeMinRecharge = sys_config('store_user_min_recharge');
  78. if ($price < $storeMinRecharge) return app('json')->fail('充值金额不能低于' . $storeMinRecharge);
  79. switch ((int)$type) {
  80. case 0: //支付充值余额
  81. $paid_price = 0;
  82. if ($recharId) {
  83. $data = SystemGroupData::getDateValue($recharId);
  84. if ($data === false) {
  85. return app('json')->fail('您选择的充值方式已下架!');
  86. } else {
  87. $paid_price = $data['give_money'] ?? 0;
  88. }
  89. }
  90. $rechargeOrder = UserRecharge::addRecharge($request->uid(), $price, 'weixin', $paid_price);
  91. if (!$rechargeOrder) return app('json')->fail('充值订单生成失败!');
  92. try {
  93. if ($from == 'weixinh5') {
  94. $recharge = UserRecharge::wxH5Pay($rechargeOrder);
  95. } else {
  96. $recharge = UserRecharge::wxPay($rechargeOrder);
  97. }
  98. } catch (\Exception $e) {
  99. return app('json')->fail($e->getMessage());
  100. }
  101. return app('json')->successful(['type' => $from, 'data' => $recharge]);
  102. break;
  103. case 1: //佣金转入余额
  104. if (UserRecharge::importNowMoney($request->uid(), $price))
  105. return app('json')->successful('转入余额成功');
  106. else
  107. return app('json')->fail(UserRecharge::getErrorInfo());
  108. break;
  109. default:
  110. return app('json')->fail('缺少参数');
  111. break;
  112. }
  113. }
  114. /**
  115. * 支付宝充值
  116. *
  117. * @param Request $request
  118. * @return mixed
  119. */
  120. public function app(Request $request)
  121. {
  122. list($price, $recharId, $type, $get_money_type) = UtilService::postMore([['price', 0], ['rechar_id', 0], ['type', 0], ['get_money_type', 'now_money']], $request, true);
  123. if (!$price || $price <= 0) return app('json')->fail('参数错误');
  124. $storeMinRecharge = sys_config('store_user_min_recharge');
  125. if ($price < $storeMinRecharge) return app('json')->fail('充值金额不能低于' . $storeMinRecharge);
  126. switch ((int)$type) {
  127. case 0: //支付充值余额
  128. $paid_price = 0;
  129. if ($recharId) {
  130. $data = SystemGroupData::getDateValue($recharId);
  131. if ($data === false) {
  132. return app('json')->fail('您选择的充值方式已下架!');
  133. } else {
  134. $paid_price = $data['give_money'] ?? 0;
  135. }
  136. }
  137. $rechargeOrder = UserRecharge::addRecharge($request->uid(), $price, 'app', $paid_price);
  138. if (!$rechargeOrder) return app('json')->fail('充值订单生成失败!');
  139. try {
  140. return app('json')->successful(UserRecharge::appPay($rechargeOrder));
  141. } catch (\Exception $e) {
  142. return app('json')->fail($e->getMessage());
  143. }
  144. break;
  145. case 1: //佣金转入余额
  146. if (UserRecharge::importNowMoney($request->uid(), $price))
  147. return app('json')->successful('转入余额成功');
  148. else
  149. return app('json')->fail(UserRecharge::getErrorInfo());
  150. break;
  151. default:
  152. return app('json')->fail('缺少参数');
  153. break;
  154. }
  155. }
  156. /**
  157. * 充值额度选择
  158. * @return mixed
  159. */
  160. public function index()
  161. {
  162. $rechargeQuota = sys_data('user_recharge_quota') ?? [];
  163. $data['recharge_quota'] = $rechargeQuota;
  164. $recharge_attention = sys_config('recharge_attention');
  165. $recharge_attention = explode("\n", $recharge_attention);
  166. $data['recharge_attention'] = $recharge_attention;
  167. return app('json')->successful($data);
  168. }
  169. }