RefundService.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808
  1. <?php
  2. namespace app\common\modules\refund\services;
  3. use app\backend\modules\refund\models\RefundApply;
  4. use app\backend\modules\refund\services\RefundOperationService;
  5. use app\common\events\order\BeforeOrderApplyRefundedEvent;
  6. use app\common\events\order\BeforeOrderRefundedPendingEvent;
  7. use app\common\exceptions\AdminException;
  8. use app\common\facades\Setting;
  9. use app\common\models\finance\Balance;
  10. use app\common\models\Order;
  11. use app\common\models\PayType;
  12. use app\common\services\credit\ConstService;
  13. use app\common\services\finance\BalanceChange;
  14. use app\common\services\PayFactory;
  15. /**
  16. * Created by PhpStorm.
  17. * Author: 芸众商城 www.yunzshop.com
  18. * Date: 2017/5/10
  19. * Time: 下午4:29
  20. */
  21. class RefundService
  22. {
  23. protected $refundApply;
  24. public function fastRefund($order_id)
  25. {
  26. $order = Order::find($order_id);
  27. return RefundOperationService::orderCloseAndRefund($order);
  28. }
  29. public function pay($refund_id)
  30. {
  31. $this->refundApply = RefundApply::find($refund_id);
  32. if (!isset($this->refundApply)) {
  33. throw new AdminException('未找到退款记录');
  34. }
  35. if (bccomp($this->refundApply->price, 0, 2) !== 1) {
  36. throw new AdminException('退款金额为0,请使用:手动退款');
  37. }
  38. if ($this->refundApply->status < RefundApply::WAIT_CHECK) {
  39. throw new AdminException($this->refundApply->status_name . '的退款申请,无法执同意退款操作');
  40. }
  41. if (in_array($this->refundApply->status,[RefundApply::COMPLETE,RefundApply::CONSENSUS])) {
  42. throw new AdminException('已退款,无法执同意退款操作');
  43. }
  44. event(new BeforeOrderApplyRefundedEvent($this->refundApply->order));
  45. //订单锁定时不能退款
  46. if ($this->refundApply->order->isPending()) {
  47. event(new BeforeOrderRefundedPendingEvent($this->refundApply->order));
  48. if ($this->refundApply->order->isPending()){
  49. throw new AdminException("订单已锁定,无法继续操作");
  50. }
  51. }
  52. //必须保证请求支付退款接口成功才能改变售后状态
  53. //如果先改变退款状态会触发退款成功监听,实际请求支付退款接口失败了
  54. switch ($this->refundApply->order->pay_type_id) {
  55. case PayType::WECHAT_PAY:
  56. case PayType::WECHAT_MIN_PAY:
  57. case PayType::WECHAT_H5:
  58. case PayType::WECHAT_NATIVE:
  59. case PayType::WECHAT_JSAPI_PAY:
  60. case PayType::WECHAT_SCAN_PAY:
  61. $result = $this->wechat();
  62. break;
  63. case PayType::ALIPAY:
  64. case PayType::ALIPAY_JSAPI_PAY:
  65. $result = $this->alipay2();
  66. break;
  67. case PayType::CREDIT:
  68. $result = $this->balance();
  69. break;
  70. case PayType::BACKEND:
  71. $result = $this->backend();
  72. break;
  73. case PayType::WechatApp:
  74. $result = $this->wechat();
  75. break;
  76. case PayType::AlipayApp:
  77. $result = $this->alipayapp();
  78. break;
  79. case PayType::PAY_YUN_WECHAT:
  80. $result = $this->yunWechat();
  81. break;
  82. case PayType::HXQUICK:
  83. $result = $this->hxquick();
  84. break;
  85. case PayType::HXWECHAT:
  86. $result = $this->hxwechat();
  87. break;
  88. case PayType::STORE_PAY:
  89. $result = $this->backend();
  90. break;
  91. case PayType::YOP:
  92. $result = $this->yopWechat();
  93. break;
  94. case PayType::WECHAT_HJ_PAY:
  95. $result = $this->ConvergeWechat();
  96. break;
  97. case PayType::ALIPAY_HJ_PAY:
  98. $result = $this->ConvergeWechat();
  99. break;
  100. case PayType::PAY_TEAM_DEPOSIT:
  101. $result = $this->deposit();
  102. break;
  103. case PayType::LCG_BALANCE:
  104. case PayType::LCG_BANK_CARD:
  105. $result = $this->lcg();
  106. break;
  107. case PayType::YOP_PRO_WECHAT:
  108. case PayType::YOP_PRO_ALIPAY:
  109. $result = $this->yopPro();
  110. break;
  111. case PayType::HK_SCAN_PAY:
  112. $result = $this->hkPay();
  113. break;
  114. case PayType::PAY_PAL:
  115. $result = $this->payPal();
  116. break;
  117. case PayType::CONVERGE_QUICK_PAY:
  118. $result = $this->convergeQuickPay();
  119. break;
  120. case PayType::HK_SCAN_ALIPAY:
  121. $result = $this->hkAliPay();
  122. break;
  123. case PayType::CONFIRM_PAY:
  124. $result = $this->confirmPay();
  125. break;
  126. case PayType::STORE_AGGREGATE_WECHAT:
  127. $result = $this->storeAggregatePay();
  128. break;
  129. case PayType::STORE_AGGREGATE_ALIPAY:
  130. $result = $this->storeAggregatePay();
  131. break;
  132. case PayType::STORE_AGGREGATE_SCAN:
  133. $result = $this->storeAggregatePay();
  134. break;
  135. case PayType::WECHAT_CPS_APP_PAY:
  136. $result = $this->wechat();
  137. break;
  138. case PayType::XFPAY_WECHAT:
  139. case PayType::XFPAY_ALIPAY:
  140. $result = $this->xfpayPay();
  141. break;
  142. case PayType::SANDPAY_ALIPAY:
  143. case PayType::SANDPAY_WECHAT:
  144. $result = $this->sandpayPay();
  145. break;
  146. case PayType::LAKALA_ALIPAY:
  147. case PayType::LAKALA_WECHAT:
  148. $result = $this->lakalaPay();
  149. break;
  150. case PayType::LESHUA_ALIPAY:
  151. case PayType::LESHUA_WECHAT:
  152. case PayType::LESHUA_POS:
  153. $result = $this->leshuaPay();
  154. break;
  155. case PayType::LSP_PAY:
  156. $result = $this->lspPay();
  157. break;
  158. case PayType::WECHAT_TRADE_PAY:
  159. $result = $this->wechatTradePay();
  160. break;
  161. case PayType::CONVERGE_UNION_PAY:
  162. $result = $this->convergePayRefund();
  163. break;
  164. case PayType::SILVER_POINT_ALIPAY:
  165. case PayType::SILVER_POINT_WECHAT:
  166. case PayType::SILVER_POINT_UNION:
  167. $result = $this->silverPointRefund();
  168. break;
  169. case PayType::CODE_SCIENCE_PAY_YU:
  170. $result = $this->codeScienceRefund();
  171. break;
  172. case PayType::EPLUS_WECHAT_PAY:
  173. case PayType::EPLUS_MINI_PAY:
  174. case PayType::EPLUS_ALI_PAY:
  175. $result = $this->eplusPay();
  176. break;
  177. case PayType::LSP_WALLET_PAY:
  178. $result = $this->lspWalletPay();
  179. break;
  180. case PayType::JINEPAY:
  181. $result = $this->jinepayRefund();
  182. break;
  183. case PayType::AUTH_PAY:
  184. $result = $this->authPayRefund();
  185. break;
  186. default:
  187. $result = $this->unknownPay();
  188. }
  189. return $result;
  190. }
  191. private function unknownPay()
  192. {
  193. \Log::debug('------售后确认退款支付类型无对应退款方法--'.$this->refundApply->order->pay_type_id,[$this->refundApply->order->order_sn]);
  194. $payAdapter = new \app\common\modules\refund\RefundPayAdapter($this->refundApply->order->pay_type_id);
  195. $result = $payAdapter->pay($this->refundApply->order->hasOneOrderPay->pay_sn, $this->refundApply->order->hasOneOrderPay->amount, $this->refundApply->price);
  196. if (!$result['status']) {
  197. throw new AdminException($result['msg']);
  198. }
  199. //微信退款 同步改变退款和订单状态
  200. RefundOperationService::refundComplete(['id' => $this->refundApply->id]);
  201. return true;
  202. }
  203. private function eplusPay(){
  204. $pay = PayFactory::create($this->refundApply->order->pay_type_id);
  205. $result = $pay->doRefund($this->refundApply->order->hasOneOrderPay->pay_sn, $this->refundApply->order->hasOneOrderPay->amount, $this->refundApply->price);
  206. if (!$result) {
  207. throw new AdminException('智E+退款失败');
  208. }
  209. //微信退款 同步改变退款和订单状态
  210. RefundOperationService::refundComplete(['id' => $this->refundApply->id]);
  211. return $result;
  212. }
  213. private function wechatTradePay(){
  214. $pay = PayFactory::create($this->refundApply->order->pay_type_id);
  215. //dd([$this->refundApply->order->hasOneOrderPay->pay_sn, $this->refundApply->order->hasOneOrderPay->amount, $this->refundApply->price]);
  216. $result = $pay->doRefund($this->refundApply->order->hasOneOrderPay->pay_sn, $this->refundApply->order->hasOneOrderPay->amount, $this->refundApply->price);
  217. if (!$result) {
  218. throw new AdminException('微信视频号退款失败');
  219. }
  220. //微信退款 同步改变退款和订单状态
  221. RefundOperationService::refundComplete(['id' => $this->refundApply->id]);
  222. return $result;
  223. }
  224. //微信JSAPI、H5、NATIVE、小程序、APP支付退款入口
  225. private function wechat()
  226. {
  227. $pay = PayFactory::create($this->refundApply->order->pay_type_id);
  228. //dd([$this->refundApply->order->hasOneOrderPay->pay_sn, $this->refundApply->order->hasOneOrderPay->amount, $this->refundApply->price]);
  229. $result = $pay->doRefund($this->refundApply->order->hasOneOrderPay->pay_sn, $this->refundApply->order->hasOneOrderPay->amount, $this->refundApply->price);
  230. if (!$result) {
  231. throw new AdminException('微信退款失败');
  232. }
  233. //微信退款 同步改变退款和订单状态
  234. RefundOperationService::refundComplete(['id' => $this->refundApply->id]);
  235. return $result;
  236. }
  237. private function alipay()
  238. {
  239. //RefundOperationService::refundComplete(['id' => $this->refundApply->id]);
  240. $pay = PayFactory::create($this->refundApply->order->pay_type_id);
  241. $result = $pay->doRefund($this->refundApply->order->hasOneOrderPay->pay_sn, $this->refundApply->order->hasOneOrderPay->amount, $this->refundApply->price);
  242. if ($result === false) {
  243. throw new AdminException('支付宝退款失败');
  244. }
  245. //保存batch_no,回调成功后根据batch_no找到对应的退款记录
  246. $this->refundApply->alipay_batch_sn = $result['batch_no'];
  247. $this->refundApply->save();
  248. return $result['url'];
  249. }
  250. private function alipay2()
  251. {
  252. $pay = PayFactory::create($this->refundApply->order->pay_type_id);
  253. $result = $pay->doRefund($this->refundApply->order->hasOneOrderPay->pay_sn, $this->refundApply->order->hasOneOrderPay->amount, $this->refundApply->price);
  254. if ($result === false) {
  255. throw new AdminException('支付宝退款失败');
  256. }
  257. RefundOperationService::refundComplete(['id' => $this->refundApply->id]);
  258. return $result;
  259. }
  260. private function alipayapp()
  261. {
  262. $pay = PayFactory::create($this->refundApply->order->pay_type_id);
  263. $result = $pay->doRefund($this->refundApply->order->hasOneOrderPay->pay_sn, $this->refundApply->order->hasOneOrderPay->amount, $this->refundApply->price);
  264. if ($result === false) {
  265. throw new AdminException('支付宝退款失败');
  266. }
  267. RefundOperationService::refundComplete(['id' => $this->refundApply->id]);
  268. return $result;
  269. }
  270. private function backend()
  271. {
  272. $refundApply = $this->refundApply;
  273. //退款状态设为完成
  274. $result = RefundOperationService::refundComplete(['id' => $refundApply->id]);
  275. if ($result !== true) {
  276. throw new AdminException($result);
  277. }
  278. return $result;
  279. }
  280. private function yopWechat()
  281. {
  282. $result = PayFactory::create($this->refundApply->order->pay_type_id)->doRefund($this->refundApply->order->hasOneOrderPay->pay_sn, $this->refundApply->order->hasOneOrderPay->amount, $this->refundApply->price);
  283. if ($result !== true) {
  284. throw new AdminException($result);
  285. }
  286. //退款状态设为完成
  287. RefundOperationService::refundComplete(['id' => $this->refundApply->id]);
  288. return $result;
  289. }
  290. private function deposit()
  291. {
  292. $result = PayFactory::create($this->refundApply->order->pay_type_id)->doRefund($this->refundApply->order->hasOneOrderPay->pay_sn, $this->refundApply->order->hasOneOrderPay->amount, $this->refundApply->price);
  293. if ($result !== true) {
  294. throw new AdminException(TEAM_REWARDS_DEPOSIT . '退款失败');
  295. }
  296. //退款状态设为完成
  297. RefundOperationService::refundComplete(['id' => $this->refundApply->id]);
  298. return $result;
  299. }
  300. private function lspPay()
  301. {
  302. $refundApply = $this->refundApply;
  303. //退款状态设为完成
  304. RefundOperationService::refundComplete(['id' => $refundApply->id]);
  305. // $order = Order::select('id', 'order_pay_id')
  306. // ->with([
  307. // 'hasOneOrderPay'
  308. // ])
  309. // ->find($refundApply->order_id);
  310. // if (!$order || !$order->hasOneOrderPay) {
  311. // throw new AdminException("加速池支付:未找到订单");
  312. // }
  313. $order = $refundApply->order;
  314. $orderPay = $order->hasOneOrderPay;
  315. $pay = PayFactory::create($order->pay_type_id);
  316. //$lspPay = new LSPPay();
  317. return $pay->doRefund($orderPay->pay_sn, $orderPay->amount, $refundApply->price);
  318. }
  319. private function lspWalletPay(){
  320. $refundApply = $this->refundApply;
  321. $pay = PayFactory::create($refundApply->order->pay_type_id);
  322. $result = $pay->doRefund($refundApply->order->hasOneOrderPay->pay_sn, $refundApply->order->hasOneOrderPay->amount, $refundApply->price);
  323. if (!$result) {
  324. throw new AdminException('爱心值加速池钱包退款失败');
  325. }
  326. //退款状态设为完成
  327. RefundOperationService::refundComplete(['id' => $refundApply->id]);
  328. return $result;
  329. }
  330. private function balance()
  331. {
  332. $refundApply = $this->refundApply;
  333. //退款状态设为完成
  334. RefundOperationService::refundComplete(['id' => $refundApply->id]);
  335. $data = [
  336. 'member_id' => $refundApply->uid,
  337. 'remark' => '订单(ID' . $refundApply->order->id . ')余额支付退款(ID' . $refundApply->id . ')' . $refundApply->price,
  338. 'source' => ConstService::SOURCE_CANCEL_CONSUME,
  339. 'relation' => $refundApply->refund_sn,
  340. 'operator' => ConstService::OPERATOR_ORDER,
  341. 'operator_id' => $refundApply->uid,
  342. 'change_value' => $refundApply->price
  343. ];
  344. if ($refundApply->order->hasOneOrderPay->behalfPay) {
  345. $data['member_id'] = $refundApply->order->hasOneOrderPay->behalfPay->behalf_id;
  346. $data['remark'] .= "(代付退款)";
  347. }
  348. $result = (new BalanceChange())->cancelConsume($data);
  349. if ($result !== true) {
  350. throw new AdminException($result);
  351. }
  352. return $result;
  353. }
  354. private function yunWechat()
  355. {
  356. $pay = PayFactory::create($this->refundApply->order->pay_type_id);
  357. $result = $pay->doRefund($this->refundApply->order->hasOneOrderPay->pay_sn, $this->refundApply->order->hasOneOrderPay->amount, $this->refundApply->price);
  358. if (!$result) {
  359. throw new AdminException('芸支付微信退款失败');
  360. }
  361. //芸支付微信退款 同步改变退款和订单状态
  362. RefundOperationService::refundComplete(['id' => $this->refundApply->id]);
  363. return $result;
  364. }
  365. public static function allowRefund()
  366. {
  367. $refund_status = Setting::get('shop.trade.refund_status');
  368. if ($refund_status == 1 || $refund_status == null) {
  369. return true;
  370. }
  371. }
  372. private function hxquick()
  373. {
  374. $pay = PayFactory::create($this->refundApply->order->pay_type_id);
  375. $result = $pay->doRefund($this->refundApply->order->hasOneOrderPay->pay_sn, $this->refundApply->order->hasOneOrderPay->amount, $this->refundApply->price);
  376. if (!$result) {
  377. throw new AdminException('环迅快捷退款失败');
  378. }
  379. //环迅快捷退款 同步改变退款和订单状态
  380. RefundOperationService::refundComplete(['id' => $this->refundApply->id]);
  381. return $result;
  382. }
  383. private function hxwechat()
  384. {
  385. $pay = PayFactory::create($this->refundApply->order->pay_type_id);
  386. $result = $pay->doRefund($this->refundApply->order->hasOneOrderPay->pay_sn, $this->refundApply->order->hasOneOrderPay->amount, $this->refundApply->price);
  387. if (!$result) {
  388. throw new AdminException('环迅微信退款失败');
  389. }
  390. //环迅微信退款 同步改变退款和订单状态
  391. RefundOperationService::refundComplete(['id' => $this->refundApply->id]);
  392. return $result;
  393. }
  394. private function ConvergeWechat()
  395. {
  396. $pay = PayFactory::create(PayFactory::PAY_WECHAT_HJ); //修复支付宝无法退款,退款处理统一写在了汇聚微信支付类里了
  397. $result = $pay->doRefund($this->refundApply->order->hasOneOrderPay->pay_sn,
  398. $this->refundApply->order->hasOneOrderPay->amount, $this->refundApply->price);
  399. if ($result['ra_Status'] == '101') {
  400. \Log::debug('汇聚微信或支付宝退款失败,失败原因' . $result['rc_CodeMsg'] . '-----失败参数-----' . json_encode($result));
  401. throw new AdminException('汇聚微信或支付宝退款失败,失败原因' . $result['rc_CodeMsg'] . '-----失败参数-----' . json_encode($result));
  402. }
  403. //汇聚微信退款 同步改变退款和订单状态
  404. RefundOperationService::refundComplete(['id' => $this->refundApply->id]);
  405. return $result;
  406. }
  407. /**
  408. * 龙存管-支付退款
  409. * @return array
  410. * @throws AdminException
  411. * @throws \app\common\exceptions\AppException
  412. */
  413. protected function lcg()
  414. {
  415. $pay_sn = $this->refundApply->order->hasOneOrderPay->pay_sn;
  416. $amount = $this->refundApply->order->hasOneOrderPay->amount;
  417. $result = PayFactory::create($this->refundApply->order->pay_type_id)->doRefund($pay_sn, $amount, $this->refundApply->price, $this->refundApply->order->order_sn);
  418. if ($result['code'] !== true) {
  419. throw new AdminException($result['msg']);
  420. }
  421. //退款状态设为完成
  422. //RefundOperationService::refundComplete(['id' => $this->refundApply->id]);
  423. //throw new AdminException('退款申请成功,等待商家确认退款中。。。');
  424. return ['action' => $result['data']['action_url'], 'input' => $result['data']['form_data']];
  425. //return $result['code'];
  426. }
  427. /**
  428. * 易宝专业版 微信、支付宝退款
  429. * @return array|bool|mixed|void
  430. * @throws AdminException
  431. * @throws \app\common\exceptions\AppException
  432. */
  433. private function yopPro()
  434. {
  435. $pay_sn = $this->refundApply->order->hasOneOrderPay->pay_sn;
  436. $amount = $this->refundApply->order->hasOneOrderPay->amount;
  437. $result = PayFactory::create($this->refundApply->order->pay_type_id)->doRefund($pay_sn, $amount, $this->refundApply->price, $this->refundApply->order->order_sn);
  438. if ($result !== true) {
  439. throw new AdminException($result);
  440. }
  441. //退款状态设为完成
  442. RefundOperationService::refundComplete(['id' => $this->refundApply->id]);
  443. return $result;
  444. }
  445. /**
  446. * 港版微信退款
  447. * @return array|bool|mixed|void
  448. * @throws AdminException
  449. * @throws \app\common\exceptions\AppException
  450. */
  451. private function hkPay()
  452. {
  453. $pay = PayFactory::create($this->refundApply->order->pay_type_id);
  454. $result = $pay->doRefund($this->refundApply->order->hasOneOrderPay->pay_sn, $this->refundApply->order->hasOneOrderPay->amount, $this->refundApply->price);
  455. if (!$result) {
  456. throw new AdminException('微信退款失败');
  457. }
  458. //港版微信退款 同步改变退款和订单状态
  459. RefundOperationService::refundComplete(['id' => $this->refundApply->id]);
  460. return $result;
  461. }
  462. private function payPal()
  463. {
  464. $pay_sn = $this->refundApply->order->hasOneOrderPay->pay_sn;
  465. $amount = $this->refundApply->order->hasOneOrderPay->amount;
  466. $result = PayFactory::create($this->refundApply->order->pay_type_id)->doRefund($pay_sn, $amount, $this->refundApply->price);
  467. if ($result !== true) {
  468. throw new AdminException('退款失败');
  469. }
  470. //退款状态设为完成
  471. RefundOperationService::refundComplete(['id' => $this->refundApply->id]);
  472. return $result;
  473. }
  474. private function convergeQuickPay()
  475. {
  476. $pay_sn = $this->refundApply->order->hasOneOrderPay->pay_sn;
  477. $amount = $this->refundApply->order->hasOneOrderPay->amount;
  478. $result = PayFactory::create($this->refundApply->order->pay_type_id)->doRefund($pay_sn, $amount, $this->refundApply->price);
  479. if (!$result['code']) {
  480. throw new AdminException($result['msg']);
  481. }
  482. //同步改变退款和订单状态
  483. //RefundOperationService::refundComplete(['id' => $this->refundApply->id]);
  484. return true;
  485. }
  486. /**
  487. * 港版支付宝H5退款
  488. * @return array|bool|mixed|void
  489. * @throws AdminException
  490. * @throws \app\common\exceptions\AppException
  491. */
  492. private function hkAliPay()
  493. {
  494. $pay = PayFactory::create($this->refundApply->order->pay_type_id);
  495. $result = $pay->doRefund($this->refundApply->order->hasOneOrderPay->pay_sn, $this->refundApply->order->hasOneOrderPay->amount, $this->refundApply->price);
  496. if (!$result) {
  497. throw new AdminException('退款失败');
  498. }
  499. //港版微信退款 同步改变退款和订单状态
  500. RefundOperationService::refundComplete(['id' => $this->refundApply->id]);
  501. return $result;
  502. }
  503. private function xfpayPay()
  504. {
  505. $pay = PayFactory::create($this->refundApply->order->pay_type_id);
  506. $result = $pay->doRefund($this->refundApply->order->hasOneOrderPay->pay_sn, $this->refundApply->order->hasOneOrderPay->amount, $this->refundApply->price);
  507. if (!$result) {
  508. throw new AdminException('商云客退款失败');
  509. }
  510. //商云客微信支付宝退款
  511. RefundOperationService::refundComplete(['id' => $this->refundApply->id]);
  512. return $result;
  513. }
  514. private function sandpayPay()
  515. {
  516. $pay = PayFactory::create($this->refundApply->order->pay_type_id);
  517. $result = $pay->doRefund($this->refundApply->order->hasOneOrderPay->pay_sn, $this->refundApply->order->hasOneOrderPay->amount, $this->refundApply->price);
  518. if (!$result) {
  519. throw new AdminException('杉德退款失败');
  520. }
  521. // 杉德支付宝微信退款
  522. RefundOperationService::refundComplete(['id' => $this->refundApply->id]);
  523. return $result;
  524. }
  525. private function lakalaPay()
  526. {
  527. $pay = PayFactory::create($this->refundApply->order->pay_type_id);
  528. $result = $pay->doRefund($this->refundApply->order->hasOneOrderPay->pay_sn, $this->refundApply->order->hasOneOrderPay->amount, $this->refundApply->price);
  529. if (!$result) {
  530. throw new AdminException('拉卡拉支付退款失败');
  531. }
  532. // 拉卡拉支付宝微信退款
  533. RefundOperationService::refundComplete(['id' => $this->refundApply->id]);
  534. return $result;
  535. }
  536. private function leshuaPay()
  537. {
  538. $pay = PayFactory::create($this->refundApply->order->pay_type_id);
  539. $result = $pay->doRefund($this->refundApply->order->hasOneOrderPay->pay_sn, $this->refundApply->order->hasOneOrderPay->amount, $this->refundApply->price);
  540. if (!$result) {
  541. throw new AdminException('乐刷支付退款失败');
  542. }
  543. // 拉卡拉支付宝微信退款
  544. RefundOperationService::refundComplete(['id' => $this->refundApply->id]);
  545. return $result;
  546. }
  547. private function silverPointRefund()
  548. {
  549. $pay = PayFactory::create($this->refundApply->order->pay_type_id);
  550. $result = $pay->doRefund($this->refundApply->order->hasOneOrderPay->pay_sn, $this->refundApply->order->hasOneOrderPay->amount, $this->refundApply->price);
  551. if (!$result) {
  552. throw new AdminException('银典支付退款失败');
  553. }
  554. // 银典支付支付宝微信退款
  555. RefundOperationService::refundComplete(['id' => $this->refundApply->id]);
  556. return $result;
  557. }
  558. private function codeScienceRefund()
  559. {
  560. $pay = PayFactory::create($this->refundApply->order->pay_type_id);
  561. $result = $pay->doRefund($this->refundApply->order->hasOneOrderPay->pay_sn, $this->refundApply->order->hasOneOrderPay->amount, $this->refundApply->price);
  562. if (!$result) {
  563. throw new AdminException('豫章行代金券支付退款失败');
  564. }
  565. // 银典支付支付宝微信退款
  566. RefundOperationService::refundComplete(['id' => $this->refundApply->id]);
  567. return $result;
  568. }
  569. /**
  570. * 确认支付退款操作
  571. * @return bool
  572. * @throws AdminException
  573. */
  574. private function confirmPay()
  575. {
  576. //改变退款和订单状态
  577. RefundOperationService::refundComplete(['id' => $this->refundApply->id]);
  578. return true;
  579. //$pay = PayFactory::create($this->refundApply->order->pay_type_id);
  580. //$pay_sn = $this->refundApply->order->hasOneOrderPay->pay_sn;
  581. //$amount = $this->refundApply->order->hasOneOrderPay->amount;
  582. //$result = $pay->doRefund($pay_sn, $amount, $this->refundApply->price);
  583. }
  584. public function storeAggregatePay()
  585. {
  586. $pay_sn = $this->refundApply->order->hasOneOrderPay->pay_sn;
  587. $amount = $this->refundApply->order->hasOneOrderPay->amount;
  588. $result = PayFactory::create($this->refundApply->order->pay_type_id)->doRefund($pay_sn, $amount, $this->refundApply->price);
  589. //同步改变退款和订单状态
  590. RefundOperationService::refundComplete(['id' => $this->refundApply->id]);
  591. return true;
  592. }
  593. /**
  594. * 汇聚聚合支付统一退款方法
  595. * @return array|bool|mixed|string
  596. * @throws AdminException
  597. * @throws \app\common\exceptions\AppException
  598. */
  599. protected function convergePayRefund()
  600. {
  601. $pay = PayFactory::create($this->refundApply->order->pay_type_id); //修复支付宝无法退款,退款处理统一写在了汇聚微信支付类里了
  602. $result = $pay->doRefund($this->refundApply->order->hasOneOrderPay->pay_sn,
  603. $this->refundApply->order->hasOneOrderPay->amount, $this->refundApply->price);
  604. if ($result['ra_Status'] == '101') {
  605. \Log::debug('汇聚退款失败,失败原因' . $result['rc_CodeMsg'] . '-----失败参数-----' . json_encode($result));
  606. throw new AdminException('汇聚支付退款失败,失败原因' . $result['rc_CodeMsg'] . '-----失败参数-----' . json_encode($result));
  607. }
  608. //汇聚微信退款 同步改变退款和订单状态
  609. RefundOperationService::refundComplete(['id' => $this->refundApply->id]);
  610. return $result;
  611. }
  612. private function jinepayRefund()
  613. {
  614. $pay = PayFactory::create($this->refundApply->order->pay_type_id);
  615. $result = $pay->doRefund($this->refundApply->order->hasOneOrderPay->pay_sn, $this->refundApply->order->hasOneOrderPay->amount, $this->refundApply->price);
  616. if (!$result) {
  617. throw new AdminException('锦银E付退款失败');
  618. }
  619. // 银典支付支付宝微信退款
  620. RefundOperationService::refundComplete(['id' => $this->refundApply->id]);
  621. return $result;
  622. }
  623. private function authPayRefund()
  624. {
  625. $pay = PayFactory::create($this->refundApply->order->pay_type_id);
  626. $result = $pay->doRefund($this->refundApply->order->hasOneOrderPay->pay_sn, $this->refundApply->order->hasOneOrderPay->amount, $this->refundApply->price);
  627. if (!$result) {
  628. throw new AdminException('微信借权支付退款失败');
  629. }
  630. // 银典支付支付宝微信退款
  631. RefundOperationService::refundComplete(['id' => $this->refundApply->id]);
  632. return $result;
  633. }
  634. }