CallbackPageController.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Name: 芸众商城系统
  5. * Author: 广州市芸众信息科技有限公司
  6. * Profile: 广州市芸众信息科技有限公司位于国际商贸中心的广州,专注于移动电子商务生态系统打造,拥有芸众社交电商系统、区块链数字资产管理系统、供应链管理系统、电子合同等产品/服务。官网 :www.yunzmall.com www.yunzshop.com
  7. * Date: 2021/7/20
  8. * Time: 11:15
  9. */
  10. namespace app\frontend\modules\payment\controllers;
  11. use app\common\components\BaseController;
  12. use app\common\events\order\AfterOrderPaidRedirectEvent;
  13. use app\common\models\Order;
  14. use app\common\models\OrderPay;
  15. use app\common\helpers\Url;
  16. /**
  17. * 废弃,现在支付完成使用新接口 order.merge-pay.check-order-pay
  18. * Class CallbackPageController
  19. * @package app\frontend\modules\payment\controllers
  20. */
  21. class CallbackPageController extends BaseController
  22. {
  23. public function index()
  24. {
  25. $pay_sn = request()->input('sn');
  26. if ($this->getPayType($pay_sn) != 'PN') {
  27. return $this->successJson('不是订单支付', ['redirect' => Url::absoluteApp('home')]);
  28. }
  29. $orderPay = OrderPay::where('pay_sn', $pay_sn)->with(['orders'])->first();
  30. $redirect = $this->shopRedirect($orderPay);
  31. event($event = new AfterOrderPaidRedirectEvent($orderPay->orders,$orderPay->id));
  32. $plugin_redirect = $event->getData()['redirect'];
  33. if ($plugin_redirect) {
  34. $redirect = $plugin_redirect;
  35. }
  36. if (strexists($redirect, 'http://') || strexists($redirect, 'https://')) {
  37. $min_redirect_url = $this->shopAppletsRedirect($orderPay);
  38. } else {
  39. $min_redirect_url = $redirect;
  40. }
  41. $data = [
  42. 'redirect' => $redirect,
  43. 'min_redirect' => $min_redirect_url,
  44. ];
  45. return $this->successJson('重定向地址', $data);
  46. }
  47. protected function getPayType($sn)
  48. {
  49. if (!empty($sn)) {
  50. $tag = substr($sn, 0, 2);
  51. return $tag;
  52. }
  53. return '';
  54. }
  55. protected function shopAppletsRedirect($orderPay)
  56. {
  57. //支付跳转
  58. $min_redirect_url = '';
  59. $trade = \Setting::get('shop.trade');
  60. if (!is_null($trade) && isset($trade['min_redirect_url']) && !empty($trade['min_redirect_url'])) {
  61. $min_redirect_url = $trade['min_redirect_url'];
  62. }
  63. if($orderPay) {
  64. //优惠卷分享页
  65. $share_bool = \app\frontend\modules\coupon\services\ShareCouponService::showIndex($orderPay->order_ids, $orderPay->uid);
  66. if ($share_bool) {
  67. $ids = rtrim(implode('_', $orderPay->order_ids), '_');
  68. $min_redirect_url = '/packageD/coupon_share/coupon_share?orderid=' . $ids;
  69. }
  70. }
  71. return $min_redirect_url;
  72. }
  73. protected function shopRedirect(OrderPay $orderPay)
  74. {
  75. $redirect = Url::absoluteApp('home');
  76. $trade = \Setting::get('shop.trade');
  77. if (!is_null($trade) && isset($trade['redirect_url']) && !empty($trade['redirect_url'])) {
  78. // $redirect = $trade['redirect_url'] . '&outtradeno=' . request()->input('sn'); //如果设置的链接不是当前域名,带参数跳转空白
  79. $redirect = $trade['redirect_url'];
  80. }
  81. //优惠卷分享页
  82. $share_bool = \app\frontend\modules\coupon\services\ShareCouponService::showIndex($orderPay->order_ids, $orderPay->uid);
  83. if ($share_bool) {
  84. $ids = rtrim(implode('_', $orderPay->order_ids), '_');
  85. $redirect = Url::absoluteApp('coupon/share/'.$ids, ['i' => \YunShop::app()->uniacid, 'mid'=> $orderPay->uid]);
  86. }
  87. return $redirect;
  88. }
  89. protected function tempData(OrderPay $orderPay)
  90. {
  91. $redirect = '';
  92. $orders = $orderPay->orders;
  93. //优惠卷分享页
  94. $share_bool = \app\frontend\modules\coupon\services\ShareCouponService::showIndex($orderPay->order_ids, $orderPay->uid);
  95. if ($share_bool) {
  96. $ids = rtrim(implode('_', $orderPay->order_ids), '_');
  97. $redirect = Url::absoluteApp('coupon/share/'.$ids, ['i' => \YunShop::app()->uniacid, 'mid'=> $orderPay->uid]);
  98. }
  99. // 拼团订单支付成功后跳转该团页面
  100. // 插件开启
  101. if (app('plugins')->isEnabled('fight-groups')) {
  102. // 只有一个订单
  103. if ($orders->count() == 1) {
  104. $order = $orders[0];
  105. // 是拼团的订单
  106. if ($order->plugin_id == 54 || $order->plugin_id == 32) {
  107. $fightGroupsTeamMember = \Yunshop\FightGroups\common\models\FightGroupsTeamMember::uniacid()->with(['hasOneTeam'])->where('order_id', $order->id)->first();
  108. // 有团员并且有团队,跳到拼团详情页
  109. if (!empty($fightGroupsTeamMember) && !empty($fightGroupsTeamMember->hasOneTeam)) {
  110. if ($fightGroupsTeamMember['store_id'] != 0) {
  111. $redirect = Url::absoluteApp('group_detail/' . $fightGroupsTeamMember->hasOneTeam->id . '/' . $fightGroupsTeamMember['store_id'], ['i' => \YunShop::app()->uniacid]);
  112. } else {
  113. $redirect = Url::absoluteApp('group_detail/' . $fightGroupsTeamMember->hasOneTeam->id, ['i' => \YunShop::app()->uniacid]);
  114. }
  115. }
  116. }
  117. }
  118. }
  119. if (app('plugins')->isEnabled('snatch-regiment')) {
  120. // 只有一个订单
  121. if ($orders->count() == 1) {
  122. $order = $orders[0];
  123. //抢团订单
  124. if ($order->plugin_id == 69) {
  125. $league = \Yunshop\SnatchRegiment\models\LeagueModel::uniacid()->where("order_id", $order->id)->first();
  126. if (request()->type == 5) {
  127. $redirect = Url::absoluteApp('grabGroup_detail/' . $league['leader_id'], ['i' => \YunShop::app()->uniacid]);
  128. }
  129. if (request()->type == 2) {
  130. $redirect = '/packageE/grab_group/grab_group_detail/grab_group_detail?id=' . $league['leader_id'];
  131. }
  132. }
  133. }
  134. }
  135. //预约商品订单支付成功后跳转预约插件设置的页面
  136. if (\app\common\modules\shop\ShopConfig::current()->get('plugin.appointment.exits')) {
  137. \Log::debug('pay appointment order $orders:', $orders);
  138. // 只有一个订单
  139. if ($orders->count() == 1) {
  140. $order = $orders[0];
  141. // 是预约商品的订单
  142. if ($order->plugin_id == 101) {
  143. \Log::debug('pay appointment order $order->plugin_id:', $order->plugin_id);
  144. $redirect = \Yunshop\Appointment\common\service\SetService::getPayReturnUrl();
  145. \Log::debug('pay appointment order $appointment_redirect:', $redirect);
  146. }
  147. }
  148. }
  149. //慈善基金跳转小程序
  150. if (app('plugins')->isEnabled('charity-fund')) {
  151. // 只有一个订单
  152. if ($orders->count() == 1) {
  153. $order = $orders[0];
  154. $mini_type = 2;
  155. $is_open = \Yunshop\CharityFund\services\SetConfigService::getSetConfig('is_open');
  156. \Log::debug('慈善基金调试-微信支付', [$is_open, request()->type, $mini_type, $orders]);
  157. //todo 支付监听添加捐赠记录不是同步进行,导致没有查询到记录,此处不使用捐赠记录判断
  158. //开启了插件 && 当前端口为小程序 附加跳转链接参数2
  159. if ($is_open && request()->type == $mini_type) {
  160. \Log::debug('pay charityFund order $order->id:', $order->id);
  161. //跳转小程序
  162. $redirect = '/packageG/index/index?is_charity_fund=1&order_id=' . $order->id;
  163. }
  164. }
  165. }
  166. //消费奖励跳转链接
  167. if (app('plugins')->isEnabled('consumer-reward')) {
  168. $pay_id = request()->input('order_pay_id');
  169. $plugin_ids = [31,32,0,44,92];
  170. foreach ($orders as $item){
  171. if (in_array($item->plugin_id,$plugin_ids)){//判断在消费奖励的订单内
  172. if (request()->type == 2) {//小程序
  173. //跳转小程序 携带参数is_show_charity_fund_poster
  174. $redirect = '/packageH/consumerReward/consumerRewardPaySuccess/consumerRewardPaySuccess?pay_id=' . $pay_id;
  175. }else{//公众号
  176. $redirect = yzAppFullUrl('consumerRewardPaySuccess').'&pay_id='. $pay_id;
  177. }
  178. break;
  179. }
  180. }
  181. }
  182. //商品免单抽奖
  183. if (app('plugins')->isEnabled('free-lottery')) {
  184. $lotteryOrderCount = \Yunshop\FreeLottery\services\LotteryDrawService::isLotteryOrder($orderPay->order_ids);
  185. if ($lotteryOrderCount > 0) {
  186. if (request()->type == 2) {//小程序
  187. //跳转小程序 携带参数is_show_charity_fund_poster
  188. $redirect = '/packageH/free_of_charge/FreeLottery/FreeLottery?order_ids=' . implode(",",$orderPay->order_ids);
  189. }else{//公众号
  190. $redirect = yzAppFullUrl('FreeLottery',['i' => \YunShop::app()->uniacid,'order_ids'=>implode(",",$orderPay->order_ids)]);
  191. }
  192. }
  193. }
  194. return $redirect;
  195. }
  196. }