MergePayController.php 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * Author: 芸众商城 www.yunzshop.com
  5. * Date: 2017/4/25
  6. * Time: 上午11:00
  7. */
  8. namespace app\frontend\modules\order\controllers;
  9. use app\common\components\ApiController;
  10. use app\common\components\BaseController;
  11. use app\common\events\order\AfterOrderPaidRedirectEvent;
  12. use app\common\events\order\BeforeOrderPayEvent;
  13. use app\common\events\payment\GetOrderPaymentTypeEvent;
  14. use app\common\exceptions\AppException;
  15. use app\common\exceptions\GoodsStockNotEnough;
  16. use app\common\facades\Setting;
  17. use app\common\models\DispatchType;
  18. use app\common\models\Order;
  19. use app\common\models\OrderBehalfPayRecord;
  20. use app\common\models\OrderPaidJob;
  21. use app\common\models\OrderPay;
  22. use app\common\models\PayType;
  23. use app\common\modules\alipay\models\AlipayPayOrder;
  24. use app\common\payment\PaymentConfig;
  25. use app\common\services\password\PasswordService;
  26. use app\common\services\PayFactory;
  27. use app\common\services\Session;
  28. use app\frontend\models\Member;
  29. use app\frontend\modules\order\OrderCollection;
  30. use app\frontend\modules\order\services\OrderService;
  31. use app\frontend\modules\orderPay\models\PreOrderPay;
  32. use app\frontend\modules\payment\orderPayments\BasePayment;
  33. use Illuminate\Support\Collection;
  34. use Illuminate\Support\Facades\DB;
  35. use app\common\helpers\Url;
  36. use Yunshop\ShopPos\models\CashPayLog;
  37. use Yunshop\ShopPos\services\ClerkService;
  38. use Yunshop\StoreCashier\common\models\StoreOrder;
  39. use Yunshop\StoreCashier\common\models\StoreSetting;
  40. use Yunshop\WechatTrade\models\WechatTradeTestOrder;
  41. use app\common\events\payment\ChargeComplatedEvent;
  42. use app\common\models\PayOrder;
  43. class MergePayController extends ApiController
  44. {
  45. public $transactionActions = ['*'];
  46. /**
  47. * @var OrderCollection
  48. */
  49. protected $orders;
  50. protected $publicAction = ['alipay', 'alipayPayHj', 'yopAlipay', 'yopProAlipay', 'alipayScanPayHj', 'alipayJsapiPay', 'alipayToutiao', 'cloudAliPay', 'yunPayAlipay', 'wftAlipay'];
  51. protected $ignoreAction = ['alipay', 'alipayPayHj', 'yopAlipay', 'yopProAlipay', 'alipayScanPayHj', 'alipayJsapiPay', 'alipayToutiao', 'cloudAliPay', 'yunPayAlipay', 'wftAlipay'];
  52. /**
  53. * 获取支付按钮列表接口
  54. * @return \Illuminate\Http\JsonResponse
  55. * @throws AppException
  56. * @throws \app\common\exceptions\ShopException
  57. */
  58. public function index()
  59. {
  60. // 验证
  61. $this->validate([
  62. 'order_ids' => 'required'
  63. ]);
  64. $store_id = request()->store_id;
  65. // 订单集合
  66. $orders = $this->orders(request()->input('order_ids'));
  67. // 用户余额
  68. $member = $orders->first()->belongsToMember()->select(['credit2'])->first()->toArray();
  69. // 生成支付记录 记录订单号,支付金额,用户,支付号
  70. $orderPay = new PreOrderPay();
  71. $orderPay->setOrders($orders);
  72. $orderPay->store();
  73. // 支付类型
  74. $orderPaymentTypesClass = PaymentConfig::getOrderPayment($orders->first()->plugin_id);
  75. $orderPaymentTypes = new $orderPaymentTypesClass($orderPay);
  76. $buttons = app('Payment')->setPaymentTypes($orderPaymentTypes)->getPaymentButton();
  77. $pay_set = Setting::get('shop.pay');
  78. if (!$buttons->isEmpty()) {
  79. $buttons = $buttons->toArray();
  80. foreach ($buttons as $key => &$button) {
  81. if ($button['code'] == 'anotherPay') {
  82. $button['another_share_type'] = $pay_set['another_share_type'] == 2 ? $pay_set['another_share_type'] : 1;
  83. }
  84. if (app('plugins')->isEnabled('store_cashier') && $store_id) {
  85. $storeSetting = StoreSetting::getStoreSettingByStoreId($store_id)->get();
  86. $store_set = $storeSetting->where('key', 'store')->first();
  87. if (!$store_set->value['payment_types']['another']) {
  88. unset($buttons[$key]);
  89. }
  90. }
  91. }
  92. $buttons = collect($buttons);
  93. }
  94. //支付跳转
  95. $min_redirect_url = '';
  96. $trade = \Setting::get('shop.trade');
  97. if (!is_null($trade) && isset($trade['min_redirect_url']) && !empty($trade['min_redirect_url'])) {
  98. $min_redirect_url = $trade['min_redirect_url'];
  99. }
  100. $data = ['order_pay' => $orderPay, 'member' => $member, 'buttons' => $buttons, 'typename' => '', 'min_redirect_url' => $min_redirect_url];
  101. $order_contract = [];
  102. $data['order_contract'] = $order_contract;
  103. return $this->successJson('成功', $data);
  104. }
  105. /**
  106. * 跳转链接验证
  107. * @return \Illuminate\Http\JsonResponse
  108. */
  109. public function checkOrderPay()
  110. {
  111. $order_pay_id = request()->input('order_pay_id');
  112. $orderPay = OrderPay::find($order_pay_id);
  113. if (empty($orderPay)) {
  114. return $this->errorJson('未找到支付单');
  115. }
  116. $paid_job = OrderPaidJob::whereIn('order_id',$orderPay->order_ids)->where('status','finished')->count();
  117. if ($orderPay->status > 0 && $paid_job >= count($orderPay->order_ids)) {
  118. $redirect = Url::absoluteApp('home');
  119. $trade = \Setting::get('shop.trade');
  120. if (!empty($trade['redirect_url'])) {
  121. $redirect = $trade['redirect_url'];
  122. }
  123. if (!empty($trade['min_redirect_url']) && request()->input('type') == 2) {
  124. $redirect = $trade['min_redirect_url'];
  125. }
  126. //优惠卷分享页
  127. $share_bool = \app\frontend\modules\coupon\services\ShareCouponService::showIndex($orderPay->order_ids, $orderPay->uid);
  128. if ($share_bool) {
  129. $ids = rtrim(implode('_', $orderPay->order_ids), '_');
  130. $redirect = Url::absoluteApp('coupon/share/'.$ids, ['i' => \YunShop::app()->uniacid, 'mid'=> $orderPay->uid]);
  131. request()->input('type') == 2 && $redirect = '/packageD/coupon_share/coupon_share?orderid=' . $ids;
  132. }
  133. //跳转页面
  134. $orders = Order::whereIn('id', $orderPay->order_ids)->get();
  135. event($event = new AfterOrderPaidRedirectEvent($orders, $orderPay->id));
  136. $redirect = $event->getData()['redirect'] ?: $redirect;
  137. return $this->successJson('',['status'=>1,'redirect'=>$redirect]);
  138. } else {
  139. return $this->successJson('',['status'=>0]);
  140. }
  141. }
  142. /**
  143. * @return \Illuminate\Http\JsonResponse
  144. * @throws AppException
  145. * @throws \app\common\exceptions\ShopException
  146. */
  147. public function anotherPayOrder()
  148. {
  149. $this->validate([
  150. 'order_ids' => 'required',
  151. 'pid' => 'required'
  152. ]);
  153. // 订单集合
  154. $orders = $this->orders(request()->input('order_ids'));
  155. // 生成支付记录 记录订单号,支付金额,用户,支付号
  156. $orderPay = new PreOrderPay();
  157. $orderPay->setOrders($orders);
  158. $orderPay->store();
  159. // 支付类型
  160. $orderPaymentTypesClass = PaymentConfig::getOrderPayment($orders->first()->plugin_id);
  161. $orderPaymentTypes = new $orderPaymentTypesClass($orderPay);
  162. $buttons = app('Payment')->setPaymentTypes($orderPaymentTypes)->getPaymentButton();
  163. // todo bad taste
  164. $type = \YunShop::request()->type ?: 0;
  165. $buttons = collect($buttons)->filter(function ($value, $key) use ($type) {
  166. if ($value['name'] != '找人代付') {
  167. return $value;
  168. }
  169. })->values();
  170. $member = Member::getMemberById(request()->input('pid'));
  171. //添加代付记录
  172. if (\YunShop::app()->getMemberId() != $orderPay->uid) {
  173. OrderBehalfPayRecord::create([
  174. 'uniacid' => \YunShop::app()->uniacid,
  175. 'order_ids' => $orderPay->order_ids,
  176. 'order_pay_id' => $orderPay->id,
  177. 'pay_sn' => $orderPay->pay_sn,
  178. 'member_id' => $orderPay->uid,
  179. 'behalf_type' => $this->behalfType(),
  180. 'behalf_id' => \YunShop::app()->getMemberId()
  181. ]);
  182. }
  183. $data = ['order_pay' => $orderPay, 'member' => $member, 'buttons' => $buttons, 'typename' => ''];
  184. $data['plugin_name'] = app('plugins')->isEnabled('parent-payment') ? PARENT_PAYMENT : '上级代付';
  185. return $this->successJson('成功', $data);
  186. }
  187. protected function behalfType()
  188. {
  189. return request()->input('plugin') == 'parent_payment' ? 2 : 1;
  190. }
  191. /**
  192. * 支付的时候,生成支付记录的时候,通过订单ids获取订单集合
  193. * @param $orderIds
  194. * @return OrderCollection
  195. * @throws AppException
  196. */
  197. protected function orders($orderIds)
  198. {
  199. if (!is_array($orderIds)) {
  200. $orderIds = explode(',', $orderIds);
  201. }
  202. array_walk($orderIds, function ($orderId) {
  203. if (!is_numeric($orderId)) {
  204. throw new AppException('(ID:' . $orderId . ')订单号id必须为数字');
  205. }
  206. });
  207. $this->orders = OrderCollection::make(Order::select(['status', 'id', 'order_sn', 'price', 'uid', 'plugin_id','is_pending'])->whereIn('id', $orderIds)->get());
  208. if ($this->orders->count() != count($orderIds)) {
  209. throw new AppException('(ID:' . implode(',', $orderIds) . ')未找到订单');
  210. }
  211. $this->orders->load('orderGoods');
  212. return $this->orders;
  213. }
  214. /**
  215. * 通过事件获取支付按钮
  216. * @param \app\frontend\models\OrderPay $orderPay
  217. * @return Collection
  218. */
  219. protected function getPayTypeButtons(\app\frontend\models\OrderPay $orderPay)
  220. {
  221. // 获取可用的支付方式
  222. $result = $orderPay->getPaymentTypes()->map(function (BasePayment $paymentType) {
  223. //余额
  224. if ($paymentType->getCode() == 'balance') {
  225. if ($paymentType->getName() !== \Setting::get('shop.shop.credit')) {
  226. $names = \Setting::get('shop.shop.credit');
  227. }
  228. }
  229. //预存款
  230. if ($paymentType->getCode() == 'DepositPay') {
  231. if (app('plugins')->isEnabled('team-rewards')) {
  232. $names = TEAM_REWARDS_DEPOSIT . '支付';
  233. }
  234. }
  235. //上级代付
  236. if ($paymentType->getCode() == 'parentPayment') {
  237. if (app('plugins')->isEnabled('parent-payment')) {
  238. $names = PARENT_PAYMENT;
  239. }
  240. }
  241. return [
  242. 'name' => $names ?: $paymentType->getName(),
  243. 'value' => $paymentType->getId(),
  244. 'need_password' => $paymentType->needPassword(),
  245. 'code' => $paymentType->getCode(),
  246. ];
  247. });
  248. return $result;
  249. }
  250. /**
  251. * 微信支付
  252. * @return \Illuminate\Http\JsonResponse
  253. * @throws AppException
  254. * @throws \app\common\exceptions\ShopException
  255. */
  256. public function wechatPay()
  257. {
  258. $this->validate([
  259. 'order_pay_id' => 'required|integer'
  260. ]);
  261. // if (\Setting::get('shop.pay.weixin') == false) {
  262. // throw new AppException('商城未开启微信支付');
  263. // }
  264. /**
  265. * @var \app\frontend\models\OrderPay $orderPay
  266. */
  267. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  268. //支付类型 小程序、公众号
  269. if (request()->input('type') == 2 || \YunShop::request()->app_type == 'wechat') {
  270. $payTypeId = PayFactory::WECHAT_MIN_PAY;
  271. if (app('plugins')->isEnabled('wechat-trade') && Setting::get('plugin.wechat_trade.open_state')) { //自定义交易组件特殊支付判断
  272. $order_ids = $orderPay->order_ids;
  273. if (in_array(request()->senceKey, [1175, 1176, 1177, 1184, 1191, 1193, 1195])) {
  274. if (count($order_ids) > 1) {
  275. throw new AppException('视频号场景下不支持合单支付');
  276. }
  277. request()->offsetSet('wechat_trade_order_type', 1);
  278. } elseif (count($order_ids) == 1) {
  279. if ($test_order = WechatTradeTestOrder::uniacid()->where('order_id', $order_ids[0])->first()) {
  280. request()->offsetSet('wechat_trade_order_type', $test_order->order_type);
  281. }
  282. }
  283. }
  284. } else {
  285. $payTypeId = PayFactory::PAY_WEACHAT;
  286. }
  287. $data = $orderPay->getPayResult($payTypeId);
  288. $data['js'] = $data['js']? json_decode($data['js'], 1) : '';
  289. $trade = \Setting::get('shop.trade');
  290. $redirect = $admin_set_redirect = '';
  291. if (!is_null($trade) && isset($trade['redirect_url']) && !empty($trade['redirect_url'])) {
  292. $redirect = $trade['redirect_url'] . '&outtradeno=' . request()->input('order_pay_id');
  293. }
  294. //跳转页面
  295. $orders = Order::whereIn('id', $orderPay->order_ids)->get();
  296. event($event = new AfterOrderPaidRedirectEvent($orders,$orderPay->id));
  297. $data['redirect'] = $event->getData()['redirect']?:$redirect;
  298. return $this->successJson('成功', $data);
  299. }
  300. /**
  301. * 支付宝支付
  302. * @return \Illuminate\Http\JsonResponse
  303. * @throws AppException
  304. */
  305. public function alipay()
  306. {
  307. /**
  308. * @var \app\frontend\models\OrderPay $orderPay
  309. */
  310. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  311. $data = $orderPay->getPayResult(PayFactory::PAY_ALIPAY);
  312. return $this->successJson('成功', $data);
  313. }
  314. /**
  315. * 第三方小程序支付
  316. * @return \Illuminate\Http\JsonResponse
  317. * @throws AppException
  318. */
  319. public function thirdPartyPay()
  320. {
  321. /**
  322. * @var \app\frontend\models\OrderPay $orderPay
  323. */
  324. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  325. $data = $orderPay->getPayResult(PayFactory::THIRD_PARTY_MINI_PAY);
  326. return $this->successJson('成功', $data);
  327. }
  328. /**
  329. * 微信app支付
  330. * @return \Illuminate\Http\JsonResponse
  331. * @throws AppException
  332. */
  333. public function wechatAppPay()
  334. {
  335. // if (\Setting::get('shop_app.pay.weixin') == false) {
  336. // throw new AppException('商城未开启微信支付');
  337. // }
  338. /**
  339. * @var \app\frontend\models\OrderPay $orderPay
  340. */
  341. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  342. $data = $orderPay->getPayResult(PayFactory::PAY_APP_WEACHAT);
  343. return $this->successJson('成功', $data);
  344. }
  345. /**
  346. * 微信付款码支付
  347. * @return \Illuminate\Http\JsonResponse
  348. * @throws AppException
  349. * @throws \app\common\exceptions\ShopException
  350. */
  351. public function wechatMicroPay()
  352. {
  353. $this->validate([
  354. 'order_pay_id' => 'required|integer',
  355. 'auth_code' => 'required',
  356. ]);
  357. // if (!Setting::get('shop.pay.wechat_micro')) {
  358. // return $this->errorJson('微信付款码支付未开启');
  359. // }
  360. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  361. $data = $orderPay->getPayResult(PayFactory::WECHAT_MICRO_PAY);
  362. if ($data !== true){
  363. return $this->errorJson('支付失败,未知错误');
  364. }
  365. $data = [];
  366. $data['redirect_url'] = \Setting::get('shop.trade.redirect_url') ? : '';
  367. return $this->successJson('成功', $data);
  368. }
  369. /**
  370. * 微信聚合CPSAPP支付
  371. * @return \Illuminate\Http\JsonResponse
  372. * @throws AppException
  373. * @throws \app\common\exceptions\ShopException
  374. */
  375. public function wechatCpsAppPay()
  376. {
  377. $this->validate([
  378. 'order_pay_id' => 'required|integer'
  379. ]);
  380. if (!app('plugins')->isEnabled('aggregation-cps')){
  381. throw new AppException('聚合CPS插件未开启');
  382. }
  383. $setting = \Setting::get('plugin.aggregation-cps.pay_info');
  384. if (!$setting['weixin_pay']){
  385. throw new AppException((defined('CPS_PLUGIN_NAME') ? CPS_PLUGIN_NAME : '聚合CPS').'未开启微信支付');
  386. }
  387. if (request()->input('order_pay_id') == -100 && app('plugins')->isEnabled('real-name-auth')) {
  388. //兼容实名认证支付
  389. return (new \Yunshop\RealNameAuth\frontend\PayController())->wechatCpsAppPay();
  390. }
  391. /**
  392. * @var \app\frontend\models\OrderPay $orderPay
  393. */
  394. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  395. $data = $orderPay->getPayResult(PayFactory::WECHAT_CPS_APP_PAY);
  396. $arr = [
  397. 'appid'=>$data['config']['appId'],
  398. 'partnerid'=>$data['config']['partnerid'],
  399. 'prepayid'=>$data['config']['prepayId'],
  400. 'package'=>'Sign=WXPay',
  401. 'noncestr'=>$data['config']['nonceStr'],
  402. 'timestamp'=>$data['config']['timestamp'],
  403. ];
  404. ksort($arr);
  405. $str = '';
  406. foreach ($arr as $k=>$v){
  407. $str .=$k.'='.$v.'&';
  408. }
  409. $str .='key='.$setting['weixin_apisecret'];
  410. $data['config']['paySign'] = strtoupper(md5($str));
  411. $data['redirect_url'] = \Setting::get('shop.trade.redirect_url') ? : '';
  412. return $this->successJson('成功', $data);
  413. }
  414. /**
  415. * 支付宝app支付
  416. * @return \Illuminate\Http\JsonResponse
  417. * @throws AppException
  418. */
  419. public function alipayAppRay()
  420. {
  421. /**
  422. * @var \app\frontend\models\OrderPay $orderPay
  423. */
  424. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  425. $data['payurl'] = $orderPay->getPayResult(PayFactory::PAY_APP_ALIPAY);
  426. $data['order_sn'] = \YunShop::app()->uniacid . '_' . $orderPay->pay_sn;
  427. $data['isnewalipay'] = \Setting::get('shop_app.pay.newalipay');
  428. return $this->successJson('成功', $data);
  429. }
  430. /**
  431. * 微信云支付
  432. * @return \Illuminate\Http\JsonResponse
  433. * @throws AppException
  434. */
  435. public function cloudWechatPay()
  436. {
  437. // if (\Setting::get('plugin.cloud_pay_set') == false) {
  438. // throw new AppException('商城未开启微信支付');
  439. // }
  440. /**
  441. * @var \app\frontend\models\OrderPay $orderPay
  442. */
  443. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  444. $data = $orderPay->getPayResult(PayFactory::PAY_CLOUD_WEACHAT);
  445. return $this->successJson('成功', $data);
  446. }
  447. /**
  448. * 芸支付
  449. *
  450. * @return \Illuminate\Http\JsonResponse
  451. * @throws AppException
  452. */
  453. public function yunPayWechat()
  454. {
  455. // if (\Setting::get('plugin.yun_pay_set') == false) {
  456. // throw new AppException('商城未开启芸支付');
  457. // }
  458. /**
  459. * @var \app\frontend\models\OrderPay $orderPay
  460. */
  461. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  462. $data = $orderPay->getPayResult(PayFactory::PAY_YUN_WEACHAT);
  463. return $this->successJson('成功', $data);
  464. }
  465. /**
  466. * 支付宝云支付
  467. * @return \Illuminate\Http\JsonResponse
  468. * @throws AppException
  469. */
  470. public function cloudAliPay()
  471. {
  472. // if (\Setting::get('plugin.cloud_pay_set') == false) {
  473. // throw new AppException('商城未开启支付宝支付');
  474. // }
  475. /**
  476. * @var \app\frontend\models\OrderPay $orderPay
  477. */
  478. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  479. $data = $orderPay->getPayResult(PayFactory::PAY_CLOUD_ALIPAY, ['pay' => 'cloud_alipay']);
  480. return $this->successJson('成功', $data);
  481. }
  482. /**
  483. * 找人代付
  484. * @return \Illuminate\Http\JsonResponse
  485. * @throws AppException
  486. */
  487. public function anotherPay()
  488. {
  489. if (\Setting::get('another_pay_set') == false) {
  490. throw new AppException('商城未开启支付宝支付');
  491. }
  492. return $this->successJson('成功', []);
  493. }
  494. /**
  495. * 支付宝—YZ
  496. * @return \Illuminate\Http\JsonResponse
  497. * @throws AppException
  498. */
  499. public function yunPayAlipay()
  500. {
  501. // if (\Setting::get('plugin.yun_pay_set') == false) {
  502. // throw new AppException('商城未开启芸支付');
  503. // }
  504. /**
  505. * @var \app\frontend\models\OrderPay $orderPay
  506. */
  507. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  508. $data = $orderPay->getPayResult(PayFactory::PAY_YUN_WEACHAT, ['pay' => 'alipay']);
  509. return $this->successJson('成功', $data);
  510. }
  511. /**
  512. * 货到付款
  513. * @return \Illuminate\Http\JsonResponse
  514. * @throws AppException
  515. * @throws \app\common\exceptions\ShopException
  516. */
  517. public function COD()
  518. {
  519. $this->validate([
  520. 'order_pay_id' => 'required|integer'
  521. ]);
  522. if (\Setting::get('shop.pay.COD') == false) {
  523. throw new AppException('商城未开启货到付款');
  524. }
  525. /**
  526. * @var \app\frontend\models\OrderPay $orderPay
  527. */
  528. $trade = \Setting::get('shop.trade');
  529. $redirect = '';
  530. if (!is_null($trade) && isset($trade['redirect_url']) && !empty($trade['redirect_url'])) {
  531. $redirect = $trade['redirect_url'];
  532. }
  533. if (app('plugins')->isEnabled('consumer-reward')) {
  534. if (request()->type == 2) {//小程序
  535. //跳转小程序 携带参数is_show_charity_fund_poster
  536. $redirect = '/packageH/consumerReward/consumerRewardPaySuccess/consumerRewardPaySuccess?pay_id=' . request()->input('order_pay_id');
  537. } else {//公众号
  538. $redirect = yzAppFullUrl('consumerRewardPaySuccess') . '&pay_id=' . request()->input('order_pay_id');
  539. }
  540. }
  541. if (!is_null($event_arr = \app\common\modules\shop\ShopConfig::current()->get('plugin_delivery_pay_function'))) {
  542. foreach ($event_arr as $v) {
  543. $class = array_get($v, 'class');
  544. $function = array_get($v, 'function');
  545. $res = $class::$function(request()->input('order_pay_id'));
  546. if (!$res['result']) {
  547. throw new AppException($res['msg']);
  548. }
  549. if ($res['result'] && $res['data']['process'] == 'break') {
  550. return $this->successJson('成功', ['redirect' => $redirect]);
  551. }
  552. }
  553. }
  554. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  555. $orderPay->getPayResult(PayFactory::PAY_COD);
  556. $orderPay->pay();
  557. return $this->successJson('成功', ['redirect' => $redirect]);
  558. }
  559. /**
  560. * 货到付款
  561. * @return \Illuminate\Http\JsonResponse
  562. * @throws AppException
  563. * @throws \app\common\exceptions\ShopException
  564. */
  565. public function remittance()
  566. {
  567. $this->validate([
  568. 'order_pay_id' => 'required|integer'
  569. ]);
  570. if (\Setting::get('shop.pay.remittance') == false) {
  571. throw new AppException('商城未开启转账付款');
  572. }
  573. /**
  574. * @var \app\frontend\models\OrderPay $orderPay
  575. */
  576. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  577. $data = $orderPay->getPayResult(PayType::REMITTANCE);
  578. $orderPay->applyPay();
  579. $orderPay->save();
  580. $trade = \Setting::get('shop.trade');
  581. $redirect = '';
  582. if (!is_null($trade) && isset($trade['redirect_url']) && !empty($trade['redirect_url'])) {
  583. $redirect = $trade['redirect_url'];
  584. }
  585. $data['redirect'] = $redirect;
  586. return $this->successJson('成功', $data);
  587. }
  588. /**
  589. * 环迅快捷支付
  590. *
  591. * @param \Request $request
  592. * @return \Illuminate\Http\JsonResponse
  593. * @throws AppException
  594. */
  595. public function huanxunQuick()
  596. {
  597. if (\Setting::get('plugin.huanxun_set') == false) {
  598. throw new AppException('商城未开启快捷支付');
  599. }
  600. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  601. $data = $orderPay->getPayResult(PayFactory::PAY_Huanxun_Quick, ['pay' => 'quick']);
  602. return $this->successJson('成功', $data);
  603. }
  604. /**
  605. * 威富通公众号支付
  606. * @return \Illuminate\Http\JsonResponse
  607. * @throws AppException
  608. */
  609. public function wftWechat()
  610. {
  611. if (\Setting::get('plugin.wft_pay') == false) {
  612. throw new AppException('商城未开启威富通公众号支付');
  613. }
  614. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  615. $data = $orderPay->getPayResult(PayFactory::WFT_PAY);
  616. return $this->successJson('成功', $data);
  617. }
  618. /**
  619. * 威富通支付宝支付
  620. * @return \Illuminate\Http\JsonResponse
  621. * @throws AppException
  622. */
  623. public function wftAlipay()
  624. {
  625. if (\Setting::get('plugin.wft_alipay') == false) {
  626. throw new AppException('商城未开启威富通公众号支付');
  627. }
  628. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  629. $data = $orderPay->getPayResult(PayFactory::WFT_ALIPAY);
  630. return $this->successJson('成功', $data);
  631. }
  632. /**
  633. * 环迅微信支付
  634. *
  635. * @param \Request $request
  636. * @return \Illuminate\Http\JsonResponse
  637. * @throws AppException
  638. */
  639. public function huanxunWx()
  640. {
  641. if (\Setting::get('plugin.dian_bang_scan_set') == false) {
  642. throw new AppException('商城未开启快捷支付');
  643. }
  644. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  645. $data = $orderPay->getPayResult(PayFactory::PAY_Huanxun_Wx, ['pay' => 'wx']);
  646. return $this->successJson('成功', $data);
  647. }
  648. /**
  649. * 店帮支付
  650. *
  651. * @param \Request $request
  652. * @return \Illuminate\Http\JsonResponse
  653. * @throws AppException
  654. */
  655. public function dianBangScan()
  656. {
  657. if (\Setting::get('plugin.dian-bang-scan') == false) {
  658. throw new AppException('商城未开启店帮扫码支付');
  659. }
  660. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  661. $data = $orderPay->getPayResult(PayFactory::PAY_DIANBANG, ['pay' => 'scan']);
  662. return $this->successJson('成功', $data);
  663. }
  664. public function yopPay()
  665. {
  666. if (!app('plugins')->isEnabled('yop-pay')) {
  667. throw new AppException('商城未开启易宝支付未开启');
  668. }
  669. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  670. $data = $orderPay->getPayResult(PayFactory::YOP);
  671. return $this->successJson('成功', $data);
  672. }
  673. public function yopAlipay()
  674. {
  675. if (!app('plugins')->isEnabled('yop-pay')) {
  676. throw new AppException('商城未开启易宝支付未开启');
  677. }
  678. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  679. $data = $orderPay->getPayResult(PayFactory::YOP_ALIPAY, ['pay_type' => 'yop_alipay']);
  680. return $this->successJson('成功', $data);
  681. }
  682. //易宝专业版
  683. public function yopProWechat()
  684. {
  685. if (!app('plugins')->isEnabled('yop-pro')) {
  686. throw new AppException('商城未开启易宝支付未开启');
  687. }
  688. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  689. $data = $orderPay->getPayResult(PayFactory::YOP_PRO_WECHAT);
  690. return $this->successJson('成功', $data);
  691. }
  692. //易宝专业版
  693. public function yopProAlipay()
  694. {
  695. if (!app('plugins')->isEnabled('yop-pro')) {
  696. throw new AppException('商城未开启易宝支付未开启');
  697. }
  698. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  699. $data = $orderPay->getPayResult(PayFactory::YOP_PRO_ALIPAY, ['pay_type' => 'alipay']);
  700. return $this->successJson('成功', $data);
  701. }
  702. /**
  703. * Usdt支付
  704. *
  705. * @param \Request $request
  706. * @return \Illuminate\Http\JsonResponse
  707. * @throws AppException
  708. */
  709. public function usdtPay()
  710. {
  711. if (\Setting::get('plugin.usdtpay_set') == false) {
  712. throw new AppException('商城未开启Usdt支付');
  713. }
  714. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  715. $data = $orderPay->getPayResult(PayFactory::PAY_Usdt);
  716. return $this->successJson('成功', $data);
  717. }
  718. /**
  719. * 微信支付-HJ
  720. *
  721. * @param \Request $request
  722. * @return \Illuminate\Http\JsonResponse
  723. * @throws AppException
  724. */
  725. public function wechatPayHj()
  726. {
  727. if (\Setting::get('plugin.convergePay_set.wechat') == false && !app('plugins')->isEnabled('converge_pay')) {
  728. throw new AppException('商城未开启微信支付-HJ');
  729. }
  730. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  731. $data = $orderPay->getPayResult(PayFactory::PAY_WECHAT_HJ);
  732. if ($data['msg'] == '成功') {
  733. $trade = \Setting::get('shop.trade');
  734. //跳转页面
  735. $orders = Order::whereIn('id', $orderPay->order_ids)->get();
  736. event($event = new AfterOrderPaidRedirectEvent($orders,$orderPay->id));
  737. $data['redirect_url'] = $event->getData()['redirect']?:$trade['redirect_url'];
  738. return $this->successJson($data['msg'], $data);
  739. } else {
  740. return $this->errorJson($data['msg']);
  741. }
  742. }
  743. /**
  744. * 支付宝支付-HJ
  745. *
  746. * @param \Request $request
  747. * @return \Illuminate\Http\JsonResponse
  748. * @throws AppException
  749. */
  750. public function alipayPayHj()
  751. {
  752. if (\Setting::get('plugin.convergePay_set.alipay') == false && !app('plugins')->isEnabled('converge_pay')) {
  753. throw new AppException('商城未开启支付宝支付-HJ');
  754. }
  755. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  756. $data = $orderPay->getPayResult(PayFactory::PAY_ALIPAY_HJ);
  757. if ($data['msg'] == '成功') {
  758. return $this->successJson($data['msg'], $data);
  759. } else {
  760. return $this->errorJson($data['msg']);
  761. }
  762. }
  763. /**
  764. * 微信扫码支付-HJ
  765. * @param \Request $request
  766. * @return \Illuminate\Http\JsonResponse
  767. * @throws AppException
  768. */
  769. public function wechatScanPayHj()
  770. {
  771. if (\Setting::get('plugin.convergePay_set.wechat') == false && !app('plugins')->isEnabled('converge_pay')) {
  772. throw new AppException('商城未开启微信支付-HJ');
  773. }
  774. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  775. $data = $orderPay->getPayResult(PayFactory::PAY_WECHAT_SCAN_HJ);
  776. if ($data['msg'] == '成功') {
  777. return $this->successJson($data['msg'], $data);
  778. } else {
  779. return $this->errorJson($data['msg']);
  780. }
  781. }
  782. /**
  783. * 支付宝扫码支付-HJ
  784. *
  785. * @param \Request $request
  786. * @return \Illuminate\Http\JsonResponse
  787. * @throws AppException
  788. */
  789. public function alipayScanPayHj()
  790. {
  791. if (\Setting::get('plugin.convergePay_set.alipay') == false && !app('plugins')->isEnabled('converge_pay')) {
  792. throw new AppException('商城未开启支付宝支付-HJ');
  793. }
  794. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  795. $data = $orderPay->getPayResult(PayFactory::PAY_ALIPAY_SCAN_HJ);
  796. if ($data['msg'] == '成功') {
  797. return $this->successJson($data['msg'], $data);
  798. } else {
  799. return $this->errorJson($data['msg']);
  800. }
  801. }
  802. /**
  803. * 微信支付-juqi
  804. * @param \Request $request
  805. * @return \Illuminate\Http\JsonResponse
  806. * @throws AppException
  807. */
  808. public function wechatPayJueqi()
  809. {
  810. if (\Setting::get('plugin.jueqi_pay_set.switch') == false && !app('plugins')->isEnabled('jueqi_pay')) {
  811. throw new AppException('商城未开启崛企支付');
  812. }
  813. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  814. $data = $orderPay->getPayResult(PayFactory::PAY_WECHAT_JUEQI);
  815. return $this->successJson('ok', $data);
  816. }
  817. /**
  818. * 为农 电子钱包-余额支付
  819. * @return \Illuminate\Http\JsonResponse
  820. * @throws AppException
  821. */
  822. public function lcgBalance()
  823. {
  824. if (!app('plugins')->isEnabled('dragon-deposit') && \Setting::get('plugin.dragon_deposit.lcgBalance') == '1') {
  825. throw new AppException('商城未开启钱包支付');
  826. }
  827. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  828. $data = $orderPay->getPayResult(PayFactory::LCG_BALANCE, ['pay_type' => 'lcgBalance']);
  829. return $this->successJson('ok', $data);
  830. }
  831. /**
  832. * 为农 电子钱包-绑定卡支付
  833. * @return \Illuminate\Http\JsonResponse
  834. * @throws AppException
  835. */
  836. public function lcgBankCard()
  837. {
  838. if (!app('plugins')->isEnabled('dragon-deposit') && \Setting::get('plugin.dragon_deposit.lcgBankCard') == '1') {
  839. throw new AppException('商城未开启钱包绑卡支付');
  840. }
  841. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  842. $data = $orderPay->getPayResult(PayFactory::LCG_BANK_CARD, ['pay_type' => 'lcgBankCard']);
  843. return $this->successJson('ok', $data);
  844. }
  845. /**
  846. * 微信扫码支付
  847. * @param \Request $request
  848. * @return \Illuminate\Http\JsonResponse
  849. * @throws AppException
  850. */
  851. public function wechatScanPay()
  852. {
  853. //验证开启
  854. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  855. $data = $orderPay->getPayResult(PayFactory::WECHAT_SCAN_PAY);
  856. if ($data['msg'] == '成功') {
  857. return $this->successJson($data['msg'], $data);
  858. } else {
  859. return $this->errorJson($data['msg']);
  860. }
  861. }
  862. /**
  863. * 微信人脸支付
  864. * @param \Request $request
  865. * @return \Illuminate\Http\JsonResponse
  866. * @throws AppException
  867. */
  868. public function wechatFacePay()
  869. {
  870. //验证开启
  871. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  872. $data = $orderPay->getPayResult(PayFactory::WECHAT_FACE_PAY);
  873. if ($data['msg'] == '成功') {
  874. return $this->successJson($data['msg'], $data);
  875. } else {
  876. return $this->errorJson($data['msg']);
  877. }
  878. }
  879. /**
  880. * 微信JSAPI支付
  881. * @param \Request $request
  882. * @return \Illuminate\Http\JsonResponse
  883. * @throws AppException
  884. */
  885. public function wechatJsapiPay()
  886. {
  887. $this->validate([
  888. 'order_pay_id' => 'required|integer'
  889. ]);
  890. /**
  891. * @var \app\frontend\models\OrderPay $orderPay
  892. */
  893. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  894. if (app('plugins')->isEnabled('store-cashier')) {
  895. $store_id = StoreOrder::where('order_id', $orderPay->orders->first()->id)->value('store_id');
  896. if ($store_id) {
  897. request()->offsetSet('store_id', $store_id);
  898. }
  899. }
  900. $data = $orderPay->getPayResult(PayFactory::WECHAT_JSAPI_PAY);
  901. // $data['js'] = json_decode($data['js'], 1);
  902. $trade = \Setting::get('shop.trade');
  903. $redirect = '';
  904. if (!is_null($trade) && isset($trade['redirect_url']) && !empty($trade['redirect_url'])) {
  905. $redirect = $trade['redirect_url'] . '&outtradeno=' . request()->input('order_pay_id');
  906. }
  907. $data['redirect'] = $redirect;
  908. return $this->successJson('成功', $data);
  909. }
  910. /**
  911. * 支付宝支付
  912. * @return \Illuminate\Http\JsonResponse
  913. * @throws AppException
  914. */
  915. public function alipayJsapiPay()
  916. {
  917. /**
  918. * @var \app\frontend\models\OrderPay $orderPay
  919. */
  920. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  921. if (app('plugins')->isEnabled('store-cashier')) {
  922. $store_id = StoreOrder::where('order_id', $orderPay->orders->first()->id)->value('store_id');
  923. request()->offsetSet('store_id', $store_id);
  924. }
  925. $data = $orderPay->getPayResult(PayFactory::ALIPAY_JSAPI_PAY);
  926. return $this->successJson('成功', $data);
  927. }
  928. public function wechatPayToutiao()
  929. {
  930. // if (\Setting::get('shop.pay.weixin') == false) {
  931. // throw new AppException('商城未开启微信支付');
  932. // }
  933. if (\Setting::get('plugin.toutiao-mini.wx_switch') != 1 && !app('plugins')->isEnabled('toutiao-mini')) {
  934. throw new AppException('商城未开启微信支付(头条支付)');
  935. }
  936. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  937. $data = $orderPay->getPayResult(PayFactory::PAY_WECHAT_TOUTIAO);
  938. if ($data['msg'] == '成功') {
  939. return $this->successJson($data['msg'], $data);
  940. } else {
  941. return $this->errorJson($data['msg']);
  942. }
  943. }
  944. public function alipayToutiao()
  945. {
  946. // if (\Setting::get('shop.pay.alipay') == false) {
  947. // throw new AppException('商城未开启支付宝支付');
  948. // }
  949. if (\Setting::get('plugin.toutiao-mini.alipay_switch') != 1 && !app('plugins')->isEnabled('toutiao-mini')) {
  950. throw new AppException('商城未开启支付宝支付(头条支付)');
  951. }
  952. /**
  953. * @var \app\frontend\models\OrderPay $orderPay
  954. */
  955. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  956. $data = $orderPay->getPayResult(PayFactory::PAY_ALIPAY_TOUTIAO);
  957. return $this->successJson('成功', $data);
  958. }
  959. public function membercardpay()
  960. {
  961. if (\Setting::get('plugin.pet.is_open_pet') != 1) {
  962. throw new AppException('商城未开启会员卡支付(宠物医院会员卡支付)');
  963. }
  964. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  965. $data = $orderPay->getPayResult(PayFactory::MEMBER_CARD_PAY);
  966. if ($data['msg'] == '成功') {
  967. return $this->successJson($data['msg'], $data);
  968. } else {
  969. return $this->errorJson($data['msg']);
  970. }
  971. }
  972. /**
  973. * 微信香港扫码支付
  974. * @param \Request $request
  975. * @return \Illuminate\Http\JsonResponse
  976. * @throws AppException
  977. */
  978. public function hkScanPay()
  979. {
  980. //验证开启
  981. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  982. $data = $orderPay->getPayResult(PayFactory::HK_SCAN_PAY);
  983. return $this->successJson('成功', $data);
  984. }
  985. public function payPal()
  986. {
  987. if (!app('plugins')->isEnabled('pay-pal') && \Setting::get('plugin.pay_pal.is_open') == '1') {
  988. throw new AppException('商城未开启PayPal支付');
  989. }
  990. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  991. $data = $orderPay->getPayResult(PayFactory::PAY_PAL);
  992. if ($data['code'] == 500) {
  993. return $this->errorJson($data['msg'], $data['data']);
  994. }
  995. return $this->successJson('ok', $data['data']);
  996. }
  997. /**
  998. * 汇聚快捷支付
  999. * @return \Illuminate\Http\JsonResponse
  1000. * @throws AppException
  1001. */
  1002. public function conbergeQuickPay()
  1003. {
  1004. if (!app('plugins')->isEnabled('converge_pay')) {
  1005. throw new AppException('商城未开启汇聚支付插件');
  1006. }
  1007. $card_no = request()->input('card_no');
  1008. if (empty($card_no)) {
  1009. throw new AppException('请选择支付银行卡');
  1010. }
  1011. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  1012. $data = $orderPay->getPayResult(PayFactory::CONVERGE_QUICK_PAY, ['card_no' => $card_no]);
  1013. return $this->successJson('ok', $data);
  1014. }
  1015. /**
  1016. * 香港支付宝H5支付
  1017. * @param \Request $request
  1018. * @return \Illuminate\Http\JsonResponse
  1019. * @throws AppException
  1020. */
  1021. public function hkScanAlipay()
  1022. {
  1023. //验证开启
  1024. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  1025. $data = $orderPay->getPayResult(PayFactory::HK_SCAN_ALIPAY);
  1026. return $this->successJson('成功', $data);
  1027. }
  1028. /**
  1029. * 确认支付
  1030. * @return \Illuminate\Http\JsonResponse
  1031. * @throws AppException
  1032. * @throws \app\common\exceptions\ShopException
  1033. */
  1034. public function confirmPay()
  1035. {
  1036. $this->validate([
  1037. 'order_pay_id' => 'required|integer'
  1038. ]);
  1039. /**
  1040. * @var \app\frontend\models\OrderPay $orderPay
  1041. */
  1042. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  1043. $orderPay->getPayResult(PayFactory::CONFIRM_PAY);
  1044. $orderPay->pay();
  1045. $trade = \Setting::get('shop.trade');
  1046. $redirect = '';
  1047. if (!is_null($trade) && isset($trade['redirect_url']) && !empty($trade['redirect_url'])) {
  1048. $redirect = $trade['redirect_url'];
  1049. }
  1050. // 盲盒订单支付成功后跳转盲盒订单详情页
  1051. if (app('plugins')->isEnabled('blind-box')) {
  1052. $orders = Order::whereIn('id', $orderPay->order_ids)->get();
  1053. // 只有一个订单
  1054. if ($orders->count() == 1) {
  1055. $order = $orders[0];
  1056. // 是拼团的订单
  1057. if ($order->plugin_id == 107) {
  1058. $redirect = Url::absoluteApp('member/orderdetail/' . $order->id . '/shop/', ['i' => \YunShop::app()->uniacid]);
  1059. }
  1060. }
  1061. }
  1062. return $this->successJson('成功', ['redirect' => $redirect]);
  1063. }
  1064. /**
  1065. * 微信H5支付
  1066. * @return \Illuminate\Http\JsonResponse
  1067. * @throws AppException
  1068. * @throws \app\common\exceptions\ShopException
  1069. */
  1070. public function wechatH5()
  1071. {
  1072. $this->validate([
  1073. 'order_pay_id' => 'required|integer'
  1074. ]);
  1075. // if (\Setting::get('shop.pay.weixin') == false) {
  1076. // throw new AppException('商城未开启微信支付');
  1077. // }
  1078. /**
  1079. * @var $orderPay \app\frontend\models\OrderPay
  1080. */
  1081. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  1082. $data = $orderPay->getPayResult(PayFactory::WECHAT_H5);
  1083. return $this->successJson('成功', $data);
  1084. }
  1085. /**
  1086. * 微信H5支付
  1087. * @return \Illuminate\Http\JsonResponse
  1088. * @throws AppException
  1089. * @throws \app\common\exceptions\ShopException
  1090. */
  1091. public function wechatNative()
  1092. {
  1093. $this->validate([
  1094. 'order_pay_id' => 'required|integer'
  1095. ]);
  1096. // if (\Setting::get('shop.pay.weixin') == false) {
  1097. // throw new AppException('商城未开启微信支付');
  1098. // }
  1099. /**
  1100. * @var $orderPay \app\frontend\models\OrderPay
  1101. */
  1102. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  1103. $data = $orderPay->getPayResult(PayFactory::WECHAT_NATIVE);
  1104. return $this->successJson('成功', $data);
  1105. }
  1106. /**
  1107. * Dcm扫码支付
  1108. * @return \Illuminate\Http\JsonResponse
  1109. * @throws AppException
  1110. * @throws \Exception
  1111. */
  1112. public function dcmScanPay()
  1113. {
  1114. $this->validate([
  1115. 'order_pay_id' => 'required|integer'
  1116. ]);
  1117. if (\Setting::get('plugin.dcm-scan-pay.switch') == false) {
  1118. throw new AppException('未开启该付款方式');
  1119. }
  1120. /**
  1121. * @var \app\frontend\models\OrderPay $orderPay
  1122. */
  1123. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  1124. $data = $orderPay->getPayResult(PayType::DCM_SCAN_PAY);
  1125. $trade = \Setting::get('shop.trade');
  1126. $redirect = '';
  1127. if (!is_null($trade) && isset($trade['redirect_url']) && !empty($trade['redirect_url'])) {
  1128. $redirect = $trade['redirect_url'];
  1129. }
  1130. $data['redirect'] = $redirect;
  1131. return $this->successJson('成功', $data);
  1132. }
  1133. /**
  1134. * 商云客支付-支付宝
  1135. *
  1136. * @param \Request $request
  1137. * @return \Illuminate\Http\JsonResponse
  1138. * @throws AppException
  1139. */
  1140. public function xfpayAlipay()
  1141. {
  1142. if (\Setting::get('plugin.xfpay_set.xfpay.pay_type.alipay.enabled') == false && !app('plugins')->isEnabled('xfpay')) {
  1143. throw new AppException('商城未开启支付宝支付-商云客聚合支付');
  1144. }
  1145. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  1146. $data = $orderPay->getPayResult(PayFactory::XFPAY_ALIPAY);
  1147. if ($data['msg'] == '成功') {
  1148. return $this->successJson($data['msg'], $data);
  1149. } else {
  1150. return $this->errorJson($data['msg']);
  1151. }
  1152. }
  1153. /**
  1154. * 商云客支付-微信
  1155. *
  1156. * @param \Request $request
  1157. * @return \Illuminate\Http\JsonResponse
  1158. * @throws AppException
  1159. */
  1160. public function xfpayWechat()
  1161. {
  1162. if (\Setting::get('plugin.xfpay_set.xfpay.pay_type.wechat.enabled') == false && !app('plugins')->isEnabled('xfpay')) {
  1163. throw new AppException('商城未开启支付宝支付-商云客聚合支付');
  1164. }
  1165. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  1166. $data = $orderPay->getPayResult(PayFactory::XFPAY_WECHAT);
  1167. if ($data['msg'] == '成功') {
  1168. return $this->successJson($data['msg'], $data);
  1169. } else {
  1170. return $this->errorJson($data['msg']);
  1171. }
  1172. }
  1173. /**
  1174. * 杉德支付-支付宝
  1175. *
  1176. * @param \Request $request
  1177. * @return \Illuminate\Http\JsonResponse
  1178. * @throws AppException
  1179. */
  1180. public function sandpayAlipay()
  1181. {
  1182. if (!app('plugins')->isEnabled('sandpay')
  1183. && \Setting::get('sandpay.set.plugin_enable') == 0
  1184. && \Setting::get('sandpay.set.alipay.enable') == 0) {
  1185. throw new AppException('未开启杉德支付宝支付');
  1186. }
  1187. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  1188. $data = $orderPay->getPayResult(PayFactory::SANDPAY_ALIPAY);
  1189. if ($data['msg'] == '成功') {
  1190. return $this->successJson($data['msg'], $data);
  1191. } else {
  1192. return $this->errorJson($data['msg']);
  1193. }
  1194. }
  1195. /**
  1196. * 杉德支付-微信
  1197. *
  1198. * @param \Request $request
  1199. * @return \Illuminate\Http\JsonResponse
  1200. * @throws AppException
  1201. */
  1202. public function sandpayWechat()
  1203. {
  1204. if (!app('plugins')->isEnabled('sandpay')
  1205. && \Setting::get('sandpay.set.plugin_enable') == 0
  1206. && \Setting::get('sandpay.set.wechat.enable') == 0) {
  1207. throw new AppException('未开启杉德微信支付');
  1208. }
  1209. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  1210. $data = $orderPay->getPayResult(PayFactory::SANDPAY_WECHAT);
  1211. if ($data['msg'] == '成功') {
  1212. return $this->successJson($data['msg'], $data);
  1213. } else {
  1214. return $this->errorJson($data['msg']);
  1215. }
  1216. }
  1217. /**
  1218. * 拉卡拉-支付宝
  1219. *
  1220. * @param \Request $request
  1221. * @return \Illuminate\Http\JsonResponse
  1222. * @throws AppException
  1223. */
  1224. public function lakalaAlipay()
  1225. {
  1226. if (!app('plugins')->isEnabled('lakala_pay')
  1227. && \Setting::get('lakala_pay.set.plugin_enable') == 0
  1228. && \Setting::get('lakala_pay.set.alipay_enable') == 0) {
  1229. throw new AppException('未开启拉卡拉支付宝支付');
  1230. }
  1231. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  1232. $data = $orderPay->getPayResult(PayFactory::LAKALA_ALIPAY);
  1233. if ($data['msg'] == '成功') {
  1234. return $this->successJson($data['msg'], $data);
  1235. } else {
  1236. return $this->errorJson($data['msg']);
  1237. }
  1238. }
  1239. /**
  1240. * 拉卡拉-微信
  1241. *
  1242. * @param \Request $request
  1243. * @return \Illuminate\Http\JsonResponse
  1244. * @throws AppException
  1245. */
  1246. public function lakalaWechat()
  1247. {
  1248. if (!app('plugins')->isEnabled('lakala_pay')
  1249. && \Setting::get('lakala_pay.set.plugin_enable') == 0
  1250. && \Setting::get('lakala_pay.set.wechat_enable') == 0) {
  1251. throw new AppException('未开启拉卡拉微信支付');
  1252. }
  1253. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  1254. $data = $orderPay->getPayResult(PayFactory::LAKALA_WECHAT);
  1255. if ($data['msg'] == '成功') {
  1256. return $this->successJson($data['msg'], $data);
  1257. } else {
  1258. return $this->errorJson($data['msg']);
  1259. }
  1260. }
  1261. /**
  1262. * 乐刷聚合支付-支付宝
  1263. *
  1264. * @param \Request $request
  1265. * @return \Illuminate\Http\JsonResponse
  1266. * @throws AppException
  1267. */
  1268. public function leshuaAlipay()
  1269. {
  1270. if (!app('plugins')->isEnabled('leshua-pay')
  1271. && \Setting::get('leshua-pay.set.plugin_enable') == 0
  1272. && \Setting::get('leshua-pay.set.alipay_enable') == 0) {
  1273. throw new AppException('未开启乐刷聚合支付-支付宝');
  1274. }
  1275. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  1276. $data = $orderPay->getPayResult(PayFactory::LESHUA_ALIPAY);
  1277. if ($data['msg'] == '成功') {
  1278. return $this->successJson($data['msg'], $data);
  1279. } else {
  1280. return $this->errorJson($data['msg']);
  1281. }
  1282. }
  1283. /**
  1284. * 乐刷聚合支付-微信
  1285. *
  1286. * @param \Request $request
  1287. * @return \Illuminate\Http\JsonResponse
  1288. * @throws AppException
  1289. */
  1290. public function leshuaWechat()
  1291. {
  1292. if (!app('plugins')->isEnabled('leshua-pay')
  1293. && \Setting::get('leshua-pay.set.plugin_enable') == 0
  1294. && \Setting::get('leshua-pay.set.wechat_enable') == 0) {
  1295. throw new AppException('未开启乐刷聚合支付-微信');
  1296. }
  1297. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  1298. $data = $orderPay->getPayResult(PayFactory::LESHUA_WECHAT);
  1299. if ($data['msg'] == '成功') {
  1300. return $this->successJson($data['msg'], $data);
  1301. } else {
  1302. return $this->errorJson($data['msg']);
  1303. }
  1304. }
  1305. /**
  1306. * 乐刷聚合支付-微信
  1307. *
  1308. * @param \Request $request
  1309. * @return \Illuminate\Http\JsonResponse
  1310. * @throws AppException
  1311. */
  1312. public function leshuaPos()
  1313. {
  1314. if (!app('plugins')->isEnabled('leshua-pay')
  1315. && \Setting::get('leshua-pay.set.plugin_enable') == 0
  1316. && \Setting::get('leshua-pay.set.pos_enable') == 0) {
  1317. throw new AppException('未开启乐刷聚合-扫码收款');
  1318. }
  1319. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  1320. $data = $orderPay->getPayResult(PayFactory::LESHUA_POS);
  1321. if ($data['msg'] == '成功') {
  1322. return $this->successJson($data['msg'], $data);
  1323. } else {
  1324. return $this->errorJson($data['msg']);
  1325. }
  1326. }
  1327. /**
  1328. *汇聚云闪付支付
  1329. * @return \Illuminate\Http\JsonResponse
  1330. * @throws AppException
  1331. */
  1332. public function convergeUnionPay()
  1333. {
  1334. if (!app('plugins')->isEnabled('converge_pay') && !\Setting::get('plugin.convergePay_set')['converge_union_pay']) {
  1335. throw new AppException('商城未开启汇聚云闪付支付');
  1336. }
  1337. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  1338. $data = $orderPay->getPayResult(PayFactory::CONVERGE_UNION_PAY);
  1339. if ($data['code'] == 200) {
  1340. return $this->successJson($data['msg'], $data);
  1341. } else {
  1342. return $this->errorJson($data['msg']);
  1343. }
  1344. }
  1345. /**
  1346. * 支付宝当面付
  1347. * @return \Illuminate\Http\JsonResponse
  1348. * @throws AppException
  1349. */
  1350. public function alipayScanPay()
  1351. {
  1352. //验证开启
  1353. $pay_type_id = PayFactory::ALIPAY_SCAN_PAY;
  1354. $auth_code = trim(request()->auth_code);
  1355. // $this->setMember($buy_id);
  1356. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  1357. // $orderIds = (new OrderCreateController($this->is_cashier))->index();
  1358. // $orderPayModel = $this->getOrderPay($orderIds);
  1359. //支付校验
  1360. // $orderPay = OrderPay::find($orderPayModel->id);
  1361. $payParams = [
  1362. 'pay_sn' => $orderPay->pay_sn,
  1363. 'order_no' => $orderPay->pay_sn,
  1364. 'pay_type' => 'alipay',
  1365. 'amount' => $orderPay->amount,
  1366. 'subject' => 'pos收银消费',
  1367. 'body' => $orderPay->orders->first()->hasManyOrderGoods[0]->title,
  1368. 'auth_code' => $auth_code,
  1369. ];
  1370. $data = $orderPay->getPayResult($pay_type_id, $payParams);
  1371. //订单支付
  1372. $payData = [
  1373. 'out_trade_no' => $data['out_trade_no'],
  1374. 'trade_no' => $data['trade_no'],
  1375. 'pay_type_id' => $pay_type_id,
  1376. ];
  1377. $pay_order_model = PayOrder::getPayOrderInfo($payData['out_trade_no'])->first();
  1378. if ($pay_order_model) {
  1379. $pay_order_model->status = 2;
  1380. $pay_order_model->trade_no = $payData['trade_no'];
  1381. $pay_order_model->save();
  1382. }
  1383. $orderPay = OrderPay::where('pay_sn', $payData['out_trade_no'])->orderBy('id', 'desc')->first();
  1384. \Log::debug('更新订单状态');
  1385. OrderService::ordersPay(['order_pay_id' => $orderPay->id, 'pay_type_id' => $payData['pay_type_id']]);
  1386. event(new ChargeComplatedEvent([
  1387. 'order_sn' => $payData['out_trade_no'],
  1388. 'pay_sn' => $payData['trade_no'],
  1389. 'order_pay_id' => $orderPay->id
  1390. ]));
  1391. $order_ids = $orderPay->order_ids;
  1392. foreach ($order_ids as $v){
  1393. $order = Order::find($v);
  1394. $data = [
  1395. 'uniacid' => \Yunshop::app()->uniacid,
  1396. 'order_id' => $order->id,
  1397. 'order_sn' => $order->order_sn,
  1398. 'member_id' => $order->uid,
  1399. 'account_id' => request()->store_id,
  1400. 'pay_sn' => $data['out_trade_no'],
  1401. 'trade_no' => $data['trade_no'],
  1402. 'total_amount' => $data['total_amount'],
  1403. 'royalty' => $data['royalty'],
  1404. ];
  1405. AlipayPayOrder::create($data);
  1406. }
  1407. return $this->successJson($data['msg'], $data);
  1408. }
  1409. /**
  1410. * @return \Illuminate\Http\JsonResponse
  1411. * 汇聚支付-支付宝付款码
  1412. */
  1413. public function alipayCardPayHj()
  1414. {
  1415. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  1416. $data = $orderPay->getPayResult(PayFactory::CONVERGE_ALIPAY_CARD_PAY);
  1417. if ($data['msg'] == '成功') {
  1418. return $this->successJson($data['msg'], $data);
  1419. } else {
  1420. return $this->errorJson($data['msg']);
  1421. }
  1422. }
  1423. /**
  1424. * @return \Illuminate\Http\JsonResponse
  1425. * 汇聚支付-微信付款码
  1426. */
  1427. public function wechatCardPayHj()
  1428. {
  1429. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  1430. $data = $orderPay->getPayResult(PayFactory::CONVERGE_WECHAT_CARD_PAY);
  1431. if ($data['msg'] == '成功') {
  1432. $trade = \Setting::get('shop.trade');
  1433. //跳转页面
  1434. $orders = Order::whereIn('id', $orderPay->order_ids)->get();
  1435. event($event = new AfterOrderPaidRedirectEvent($orders,$orderPay->id));
  1436. $data['redirect_url'] = $event->getData()['redirect']?:$trade['redirect_url'];
  1437. return $this->successJson($data['msg'], $data);
  1438. } else {
  1439. return $this->errorJson($data['msg']);
  1440. }
  1441. }
  1442. /**
  1443. *汇聚-支付宝H5
  1444. * @return \Illuminate\Http\JsonResponse
  1445. * @throws AppException
  1446. */
  1447. public function convergeAlipayH5Pay()
  1448. {
  1449. if (!app('plugins')->isEnabled('converge_pay') && !\Setting::get('plugin.convergePay_set')['alipay']['alipay_h5_status']) {
  1450. throw new AppException('商城未开启汇聚支付宝H5支付');
  1451. }
  1452. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  1453. $data = $orderPay->getPayResult(PayFactory::CONVERGE_ALIPAY_H5_PAY);
  1454. if ($data['code'] == 200) {
  1455. return $this->successJson($data['msg'], $data);
  1456. } else {
  1457. return $this->errorJson($data['msg']);
  1458. }
  1459. }
  1460. /**
  1461. * 银典支付-支付宝
  1462. *
  1463. * @param \Request $request
  1464. * @return \Illuminate\Http\JsonResponse
  1465. * @throws AppException
  1466. */
  1467. public function silverPointAlipay()
  1468. {
  1469. if (!app('plugins')->isEnabled('silver-point-pay')
  1470. && \Setting::get('silver-point-pay.set.plugin_enable') == 0
  1471. && \Setting::get('silver-point-pay.set.alipay_enable') == 0) {
  1472. throw new AppException('未开启银典支付-支付宝');
  1473. }
  1474. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  1475. $data = $orderPay->getPayResult(PayFactory::SILVER_POINT_ALIPAY);
  1476. if ($data['msg'] == '成功') {
  1477. return $this->successJson($data['msg'], $data);
  1478. } else {
  1479. return $this->errorJson($data['msg']);
  1480. }
  1481. }
  1482. /**
  1483. * 银典支付-微信
  1484. *
  1485. * @param \Request $request
  1486. * @return \Illuminate\Http\JsonResponse
  1487. * @throws AppException
  1488. */
  1489. public function silverPointWechat()
  1490. {
  1491. if (!app('plugins')->isEnabled('silver-point-pay')
  1492. && \Setting::get('silver-point-pay.set.plugin_enable') == 0
  1493. && \Setting::get('silver-point-pay.set.wechat_enable') == 0) {
  1494. throw new AppException('未开启银典支付-微信');
  1495. }
  1496. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  1497. $data = $orderPay->getPayResult(PayFactory::SILVER_POINT_WECHAT);
  1498. if ($data['msg'] == '成功') {
  1499. return $this->successJson($data['msg'], $data);
  1500. } else {
  1501. return $this->errorJson($data['msg']);
  1502. }
  1503. }
  1504. /**
  1505. * 银典支付-微信
  1506. *
  1507. * @param \Request $request
  1508. * @return \Illuminate\Http\JsonResponse
  1509. * @throws AppException
  1510. */
  1511. public function silverPointUnionPay()
  1512. {
  1513. if (!app('plugins')->isEnabled('silver-point-pay')
  1514. && \Setting::get('silver-point-pay.set.plugin_enable') == 0
  1515. && \Setting::get('silver-point-pay.set.union_enable') == 0) {
  1516. throw new AppException('未开启银典支付-银联快捷');
  1517. }
  1518. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  1519. $data = $orderPay->getPayResult(PayFactory::SILVER_POINT_UNION);
  1520. if ($data['msg'] == '成功') {
  1521. return $this->successJson($data['msg'], $data);
  1522. } else {
  1523. return $this->errorJson($data['msg']);
  1524. }
  1525. }
  1526. /**
  1527. * 豫章行代金券支付
  1528. *
  1529. * @param \Request $request
  1530. * @return \Illuminate\Http\JsonResponse
  1531. * @throws AppException
  1532. */
  1533. public function codeSciencePayYu()
  1534. {
  1535. if (!app('plugins')->isEnabled('code-science-pay')
  1536. && \Setting::get('code-science-pay.set.plugin_enable') == 0) {
  1537. throw new AppException('未开启豫章行代金券支付');
  1538. }
  1539. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  1540. $data = $orderPay->getPayResult(PayFactory::CODE_SCIENCE_PAY_YU);
  1541. if ($data['msg'] == '成功') {
  1542. $orderPay->pay();
  1543. return $this->successJson($data['msg'], $data);
  1544. } else {
  1545. return $this->errorJson($data['msg']);
  1546. }
  1547. }
  1548. public function eplusAliPay()
  1549. {
  1550. if (!app('plugins')->isEnabled('eplus-pay')
  1551. || !\Yunshop\EplusPay\services\SettingService::getSetting()['alipay_state']
  1552. ) {
  1553. return $this->errorJson('未开启支付宝支付(智E+)');
  1554. }
  1555. if (!$uid = \YunShop::app()->getMemberId()) {
  1556. return $this->errorJson('请先登录');
  1557. }
  1558. $user = \Yunshop\EplusPay\services\SettingService::getUser($uid);
  1559. if (!$user || !$user->is_bind_mobile) {
  1560. return $this->errorJson('请先绑定智E+账户手机号', ['eplus_bind_mobile' => 1]);
  1561. }
  1562. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  1563. $data = $orderPay->getPayResult(PayFactory::EPLUS_ALI_PAY);
  1564. $return_data['pay_url'] = $data['payInfo'] ?: '';
  1565. return $this->successJson('成功',$return_data);
  1566. }
  1567. public function eplusWechatPay()
  1568. {
  1569. if (!app('plugins')->isEnabled('eplus-pay')
  1570. || !\Yunshop\EplusPay\services\SettingService::getSetting()['wechat_state']
  1571. ) {
  1572. return $this->errorJson('未开启微信支付(智E+)');
  1573. }
  1574. if (!$uid = \YunShop::app()->getMemberId()) {
  1575. return $this->errorJson('请先登录');
  1576. }
  1577. $user = \Yunshop\EplusPay\services\SettingService::getUser($uid);
  1578. if (!$user || !$user->is_bind_mobile) {
  1579. return $this->errorJson('请先绑定智E+账户手机号', ['eplus_bind_mobile' => 1]);
  1580. }
  1581. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  1582. $data = $orderPay->getPayResult(PayFactory::EPLUS_WECHAT_PAY);
  1583. $return_data =json_decode($data['payInfo'],true) ? : [];
  1584. if ($return_data['timeStamp']){
  1585. $return_data['timestamp'] = $return_data['timeStamp'];
  1586. }
  1587. return $this->successJson('成功',$return_data);
  1588. }
  1589. public function eplusMiniPay()
  1590. {
  1591. if (!app('plugins')->isEnabled('eplus-pay')
  1592. || !\Yunshop\EplusPay\services\SettingService::getSetting()['wechat_state']
  1593. ) {
  1594. return $this->errorJson('未开启微信支付(智E+)');
  1595. }
  1596. if (!$uid = \YunShop::app()->getMemberId()) {
  1597. return $this->errorJson('请先登录');
  1598. }
  1599. $user = \Yunshop\EplusPay\services\SettingService::getUser($uid);
  1600. if (!$user || !$user->is_bind_mobile) {
  1601. return $this->errorJson('请先绑定智E+账户手机号', ['eplus_bind_mobile' => 1]);
  1602. }
  1603. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  1604. $data = $orderPay->getPayResult(PayFactory::EPLUS_MINI_PAY);
  1605. $return_data =json_decode($data['payInfo'],true) ? : [];
  1606. if ($return_data['timeStamp']){
  1607. $return_data['timestamp'] = $return_data['timeStamp'];
  1608. }
  1609. return $this->successJson('成功',$return_data);
  1610. }
  1611. /**
  1612. * 锦银E付
  1613. *
  1614. * @param \Request $request
  1615. * @return \Illuminate\Http\JsonResponse
  1616. * @throws AppException
  1617. */
  1618. public function jinepayH5()
  1619. {
  1620. if (!app('plugins')->isEnabled('jinepay')
  1621. && \Setting::get('jinepay.set.plugin_enable') == 0) {
  1622. throw new AppException('未开启锦银E付');
  1623. }
  1624. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  1625. $data = $orderPay->getPayResult(PayFactory::JINEPAY);
  1626. if ($data['msg'] == '成功') {
  1627. return $this->successJson($data['msg'], $data);
  1628. } else {
  1629. return $this->errorJson($data['msg']);
  1630. }
  1631. }
  1632. /**
  1633. * 借权支付
  1634. *
  1635. * @param \Request $request
  1636. * @return \Illuminate\Http\JsonResponse
  1637. * @throws AppException
  1638. */
  1639. public function authPay()
  1640. {
  1641. if (!app('plugins')->isEnabled('sub-auth-payment')
  1642. && \Setting::get('sub-auth-payment.set.plugin_enable') == 0) {
  1643. throw new AppException('未开启微信借权支付');
  1644. }
  1645. $orderPay = \app\frontend\models\OrderPay::find(request()->input('order_pay_id'));
  1646. $data = $orderPay->getPayResult(PayFactory::AUTH_PAY);
  1647. if ($data['msg'] == '成功') {
  1648. return $this->successJson($data['msg'], $data);
  1649. } else {
  1650. return $this->errorJson($data['msg']);
  1651. }
  1652. }
  1653. }