MobileRechargeController.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. namespace app\api\controller\user;
  3. use app\models\system\SystemGroupData;
  4. use app\models\user\UserMobileRecharge;
  5. use app\Request;
  6. use crmeb\services\UtilService;
  7. use think\facade\Log;
  8. /**
  9. * 充值类
  10. * Class UserRechargeController
  11. * @package app\api\controller\user
  12. */
  13. class MobileRechargeController
  14. {
  15. /**
  16. * 小程序充值
  17. *
  18. * @param Request $request
  19. * @return mixed
  20. */
  21. public function routine(Request $request)
  22. {
  23. list($recharId, $mobile) = UtilService::postMore([['rechar_id', 0], ['mobile', '']], $request, true);
  24. if (!$recharId) return app('json')->fail('请选择充值金额!');
  25. if (!not_empty_check($mobile) || !mobile_check($mobile)) return app('json')->fail('请输入正确的手机号码!');
  26. if ($recharId) {
  27. $data = SystemGroupData::getDateValue($recharId);
  28. if ($data === false) {
  29. return app('json')->fail('您选择的充值方式已下架!');
  30. } else {
  31. $get_money = $data['get_money'] ?? 0;
  32. }
  33. }
  34. $price = $data['price'];
  35. $rechargeOrder = UserMobileRecharge::addRecharge($request->uid(), $mobile, $price, 'weixin', $get_money);
  36. if (!$rechargeOrder) return app('json')->fail('充值订单生成失败!');
  37. try {
  38. return app('json')->successful(UserMobileRecharge::jsPay($rechargeOrder));
  39. } catch (\Exception $e) {
  40. return app('json')->fail($e->getMessage());
  41. }
  42. }
  43. /**
  44. * 支付宝充值
  45. *
  46. * @param Request $request
  47. * @return mixed
  48. */
  49. public function ali(Request $request)
  50. {
  51. list($recharId, $mobile) = UtilService::postMore([['rechar_id', 0], ['mobile', '']], $request, true);
  52. if (!$recharId) return app('json')->fail('请选择充值金额!');
  53. if (!not_empty_check($mobile) || !mobile_check($mobile)) return app('json')->fail('请输入正确的手机号码!');
  54. if ($recharId) {
  55. $data = SystemGroupData::getDateValue($recharId);
  56. if ($data === false) {
  57. return app('json')->fail('您选择的充值方式已下架!');
  58. } else {
  59. $get_money = $data['get_money'] ?? 0;
  60. }
  61. }
  62. $price = $data['price'];
  63. $rechargeOrder = UserMobileRecharge::addRecharge($request->uid(), $mobile, $price, 'ali', $get_money);
  64. if (!$rechargeOrder) return app('json')->fail('充值订单生成失败!');
  65. try {
  66. return app('json')->successful(UserMobileRecharge::aliPay($rechargeOrder));
  67. } catch (\Exception $e) {
  68. return app('json')->fail($e->getMessage());
  69. }
  70. }
  71. /**
  72. * 支付宝充值
  73. *
  74. * @param Request $request
  75. * @return mixed
  76. */
  77. public function app(Request $request)
  78. {
  79. list($recharId, $mobile) = UtilService::postMore([['rechar_id', 0], ['mobile', '']], $request, true);
  80. if (!$recharId) return app('json')->fail('请选择充值金额!');
  81. if (!not_empty_check($mobile) || !mobile_check($mobile)) return app('json')->fail('请输入正确的手机号码!');
  82. if ($recharId) {
  83. $data = SystemGroupData::getDateValue($recharId);
  84. if ($data === false) {
  85. return app('json')->fail('您选择的充值方式已下架!');
  86. } else {
  87. $get_money = $data['get_money'] ?? 0;
  88. }
  89. }
  90. $price = $data['price'];
  91. $rechargeOrder = UserMobileRecharge::addRecharge($request->uid(), $mobile, $price, 'app', $get_money);
  92. if (!$rechargeOrder) return app('json')->fail('充值订单生成失败!');
  93. try {
  94. return app('json')->successful(UserMobileRecharge::appPay($rechargeOrder));
  95. } catch (\Exception $e) {
  96. return app('json')->fail($e->getMessage());
  97. }
  98. }
  99. /**
  100. * 公众号充值
  101. *
  102. * @param Request $request
  103. * @return mixed
  104. */
  105. public function wechat(Request $request)
  106. {
  107. list($recharId, $mobile, $from) = UtilService::postMore([['rechar_id', 0], ['mobile', ''], ['from', 'weixin']], $request, true);
  108. if (!$recharId) return app('json')->fail('请选择充值金额!');
  109. if (!not_empty_check($mobile) || !mobile_check($mobile)) return app('json')->fail('请输入正确的手机号码!');
  110. if ($recharId) {
  111. $data = SystemGroupData::getDateValue($recharId);
  112. if ($data === false) {
  113. return app('json')->fail('您选择的充值方式已下架!');
  114. } else {
  115. $get_money = $data['get_money'] ?? 0;
  116. }
  117. }
  118. $price = $data['price'];
  119. $rechargeOrder = UserMobileRecharge::addRecharge($request->uid(), $mobile, $price, 'weixin', $get_money);
  120. if (!$rechargeOrder) return app('json')->fail('充值订单生成失败!');
  121. try {
  122. if ($from == 'weixinh5') {
  123. $recharge = UserMobileRecharge::wxH5Pay($rechargeOrder);
  124. } else {
  125. $recharge = UserMobileRecharge::wxPay($rechargeOrder);
  126. }
  127. } catch (\Exception $e) {
  128. return app('json')->fail($e->getMessage());
  129. }
  130. return app('json')->successful(['type' => $from, 'data' => $recharge]);
  131. }
  132. /**
  133. * 充值额度选择
  134. * @return mixed
  135. */
  136. public function index()
  137. {
  138. $rechargeQuota = sys_data('user_mobile_recharge_quota') ?? [];
  139. $data['recharge_quota'] = $rechargeQuota;
  140. $recharge_attention = sys_config('mobile_recharge__attention');
  141. $recharge_attention = explode("\n", $recharge_attention);
  142. $data['recharge_attention'] = $recharge_attention;
  143. return app('json')->successful($data);
  144. }
  145. public function notify(Request $request)
  146. {
  147. $date = $request->post();
  148. if ($date['status'] == 'SUCCESS') {
  149. UserMobileRecharge::where('order_id', $date['orderId'])->update(['status', 1]);
  150. return 'SUCCESS';
  151. } else {
  152. UserMobileRecharge::where('order_id', $date['orderId'])->update(['status', 2]);
  153. Log::error($date['orderId'] . '充值失败');
  154. return 'SUCCESS';
  155. }
  156. }
  157. }