Order.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Exceptions\AlertException;
  4. use App\Jobs\GrowingIO\ActivateSvipReportJob;
  5. use App\Jobs\OrderCloseJob;
  6. use App\Services\Pay\CouponService;
  7. use App\Services\Pay\OrderService;
  8. use App\Services\User\VipService;
  9. use Illuminate\Support\Facades\DB;
  10. use App\Http\Controllers\Core\Auth;
  11. use App\Http\Controllers\Fpdx\PairController;
  12. use App\Http\Controllers\Miniprogram\Auth as MiniAuth;
  13. use App\Models\OrderModel;
  14. use Illuminate\Http\Request;
  15. use Ixudra\Curl\Facades\Curl;
  16. /**
  17. * 订单及微信支付
  18. * Class Order
  19. * @package App\Http\Controllers
  20. */
  21. class Order extends Controller
  22. {
  23. private $orderModel;
  24. public function __construct()
  25. {
  26. $this->orderModel = new OrderModel();
  27. }
  28. // 商品信息
  29. public const GOODS = [
  30. 1 => [
  31. 'goods_id' => 1,
  32. 'desc' => '金fa充值',
  33. 'total_fee' => 100,
  34. 'gold_flower' => 1,
  35. 'red_flower' => 0,
  36. 'body' => '卖室友充值',
  37. 'notify_url' => "/api/core/pay/notify"
  38. ],
  39. 2 => [
  40. 'goods_id' => 2,
  41. 'desc' => '卖室友表白',
  42. 'total_fee' => 100,
  43. 'gold_flower' => 0,
  44. 'red_flower' => 0,
  45. 'body' => '卖室友表白',
  46. 'notify_url' => "/api/core/pay/notify"
  47. ],
  48. 3 => [
  49. 'goods_id' => 3,
  50. 'desc' => '72小时恋爱体验入场券',
  51. 'total_fee' => 990,
  52. 'gold_flower' => 0,
  53. 'red_flower' => 0,
  54. 'body' => '72小时入场券',
  55. 'notify_url' => "/api/core/pay/notify"
  56. ],
  57. 9 => [
  58. 'goods_id' => 9,
  59. 'desc' => '购买小fa充值',
  60. 'total_fee' => 900,
  61. 'gold_flower' => 10,
  62. 'red_flower' => 0,
  63. 'body' => '卖室友充值',
  64. 'notify_url' => "/api/core/pay/notify"
  65. ],
  66. 10 => [
  67. 'goods_id' => 10,
  68. 'desc' => '购买小fa充值',
  69. 'total_fee' => 8800,
  70. 'gold_flower' => 100,
  71. 'red_flower' => 0,
  72. 'body' => '卖室友充值',
  73. 'notify_url' => "/api/core/pay/notify"
  74. ],
  75. 12 => [
  76. 'goods_id' => 12,
  77. 'desc' => "「1个月」超级会员充值",
  78. 'total_fee' => 2990,
  79. 'gold_flower' => 0,
  80. 'red_flower' => 0,
  81. 'body' => '分配对象「1个月」超级会员充值',
  82. 'notify_url' => "/api/pay/notify/supervip"
  83. ],
  84. 13 => [
  85. 'goods_id' => 13,
  86. 'desc' => "「3个月」超级会员充值",
  87. 'total_fee' => 7200,
  88. 'gold_flower' => 0,
  89. 'red_flower' => 0,
  90. 'body' => '分配对象「3个月」超级会员充值',
  91. 'notify_url' => "/api/pay/notify/supervip"
  92. ],
  93. 14 => [
  94. 'goods_id' => 14,
  95. 'desc' => "「12个月」超级会员充值",
  96. 'total_fee' => 25200,
  97. 'gold_flower' => 0,
  98. 'red_flower' => 0,
  99. 'body' => '分配对象「12个月」超级会员充值',
  100. 'notify_url' => "/api/pay/notify/supervip"
  101. ],
  102. ];
  103. /**
  104. * 超级会员充值
  105. * @param Request $request
  106. * @param int $goods_type
  107. * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
  108. * @throws AlertException
  109. * @throws \App\Exceptions\ApiException
  110. */
  111. public function unifyBySuperVip(Request $request, int $goods_type)
  112. {
  113. $uid = Auth::auth();
  114. if (!in_array($goods_type, [1, 3, 9, 10, 12, 13, 14])) {
  115. throw new AlertException("商品类型不存在", 404001);
  116. }
  117. $agent = $request->header('user-agent');
  118. $os = 'other';
  119. if (
  120. strpos($agent, 'macintosh')
  121. || strpos($agent, 'iPod')
  122. || strpos($agent, 'iPhone')
  123. || strpos($agent, 'iPad')
  124. ) {
  125. $os = "ios";
  126. }
  127. if (strpos($agent, 'Android')) {
  128. $os = 'android';
  129. }
  130. $goods = self::GOODS[$goods_type];
  131. $total_fee = $goods['total_fee'];
  132. $coupon_id = $request->input('coupon_id', 0);
  133. if ($coupon_id) {
  134. $couponService = new CouponService();
  135. $total_fee = $couponService->setUid($uid)
  136. ->setCouponId($coupon_id)
  137. ->setGoodsId($goods['goods_id'])
  138. ->use();
  139. }
  140. $params = [
  141. 'uid' => $uid,
  142. 'body' => $goods['body'],
  143. 'total_fee' => $total_fee,
  144. 'notify_url' => config('api.msy_url') . $goods['notify_url']
  145. ];
  146. $url = config('api.pay_url') . "/payments/unify";
  147. $result = Curl::to($url)->withContentType("application/x-www-form-urlencoded")->withData($params)->asJsonResponse()->post();
  148. if (isset($result->code) && $result->code == 200) {
  149. $fill = [
  150. 'flower' => $goods['gold_flower'],
  151. 'out_trade_no' => $result->data->order_id,
  152. 'total_amount' => $goods['total_fee'],
  153. 'total_fee' => $total_fee,
  154. 'uid' => $uid,
  155. 'type' => $goods['goods_id'],
  156. 'coupon_id' => $coupon_id,
  157. 'device' => $os,
  158. 'create_at' => time(),
  159. ];
  160. $media_id = $request->get('media_id', null);
  161. if (!is_null($media_id)) {
  162. $fill['attach_data'] = json_encode(['media_id' => $media_id]);
  163. }
  164. $order = $this->orderModel->fill($fill);
  165. if ($order->save()) {
  166. OrderCloseJob::dispatch($order->id)->onQueue('{order:close}')->delay(now()->addMinute(5));
  167. return response([
  168. 'code' => 200,
  169. 'message' => 'OK',
  170. 'data' => [
  171. 'order_id' => $order->id
  172. ],
  173. ]);
  174. } else {
  175. throw new AlertException("系统异常", 505);
  176. }
  177. } else {
  178. throw new AlertException("系统异常", 505);
  179. }
  180. }
  181. /**
  182. * 用户充值任意小fa下单
  183. * @param Request $request
  184. * @param float $gold_flower
  185. * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
  186. */
  187. public function unifyByFlower(Request $request, $gold_flower = 1.00)
  188. {
  189. $uid = Auth::auth();
  190. // 支付设备
  191. $agent = $request->header('user-agent');
  192. $os = 'other';
  193. if (
  194. strpos($agent, 'macintosh')
  195. || strpos($agent, 'iPod')
  196. || strpos($agent, 'iPhone')
  197. || strpos($agent, 'iPad')
  198. ) {
  199. $os = "ios";
  200. }
  201. if (strpos($agent, 'Android')) {
  202. $os = 'android';
  203. }
  204. $goods = self::GOODS[1];
  205. $params = [
  206. 'uid' => $uid,
  207. 'body' => $goods['body'],
  208. 'total_fee' => $gold_flower * 100,
  209. 'notify_url' => config('api.msy_url') . "/api/core/pay/notify"
  210. ];
  211. $url = config('api.pay_url') . "/payments/unify";
  212. $result = \Curl::to($url)->withContentType("application/x-www-form-urlencoded")->withData($params)->asJsonResponse()->post();
  213. if (isset($result->code) && $result->code == 200) {
  214. $order = $this->orderModel->fill([
  215. 'flower' => $gold_flower,
  216. 'out_trade_no' => $result->data->order_id,
  217. 'total_amount' => $gold_flower * 100,
  218. 'total_fee' => $gold_flower * 100,
  219. 'uid' => $uid,
  220. 'type' => $goods['goods_id'],
  221. 'device' => $os,
  222. 'create_at' => time(),
  223. ]);
  224. if ($order->save()) {
  225. return response([
  226. 'code' => 200,
  227. 'message' => 'OK',
  228. 'data' => [
  229. 'order_id' => $order->id
  230. ],
  231. ]);
  232. } else {
  233. return response([
  234. 'code' => 505,
  235. 'message' => '数据库异常'
  236. ]);
  237. }
  238. } else {
  239. return response([
  240. 'code' => $result->code ?? 505,
  241. 'message' => $result->message ?? "系统异常"
  242. ]);
  243. }
  244. }
  245. /**
  246. * 分配对象下单
  247. * @param int $total_fee 费用
  248. * @param array $attach 附加数据包
  249. * @param Request $request
  250. * @return int
  251. * @throws AlertException
  252. */
  253. public function unifyByFpdx(int $total_fee, array $attach, Request $request)
  254. {
  255. $uid = Auth::auth();
  256. // 支付设备
  257. $agent = $request->header('user-agent');
  258. $os = 'other';
  259. if (
  260. strpos($agent, 'macintosh')
  261. || strpos($agent, 'iPod')
  262. || strpos($agent, 'iPhone')
  263. || strpos($agent, 'iPad')
  264. ) {
  265. $os = "ios";
  266. }
  267. if (strpos($agent, 'Android')) {
  268. $os = 'android';
  269. }
  270. $goods = self::GOODS[3];
  271. // 使用优惠券
  272. $coupon_id = $request->input('coupon_id', 0);
  273. if ($coupon_id) {
  274. $couponService = new CouponService();
  275. $total_fee = $couponService->setUid($uid)
  276. ->setCouponId($coupon_id)
  277. ->setGoodsId($goods['goods_id'])
  278. ->use();
  279. }
  280. $params = [
  281. 'uid' => $uid,
  282. 'body' => "72小时恋爱体验报名",
  283. 'total_fee' => $total_fee,
  284. 'notify_url' => config('api.msy_url') . "/api/core/pay/notify/fpdx",
  285. 'attach' => json_encode($attach)
  286. ];
  287. $url = config('api.pay_url') . "/payments/unify";
  288. $result = \Curl::to($url)->withData($params)->asJsonResponse()->post();
  289. if (isset($result->code) && $result->code == 200) {
  290. $order = $this->orderModel->fill([
  291. 'out_trade_no' => $result->data->order_id,
  292. 'total_amount' => $goods['total_fee'],
  293. 'total_fee' => $total_fee,
  294. 'uid' => $uid,
  295. 'type' => $goods['goods_id'],
  296. 'type_id' => $attach['stage_id'] ?? 0,
  297. 'coupon_id' => $coupon_id,
  298. 'attach_data' => json_encode($attach),
  299. 'device' => $os,
  300. 'create_at' => time(),
  301. ]);
  302. if ($order->save()) {
  303. OrderCloseJob::dispatch($order->id)->onQueue('{order:close}')->delay(now()->addMinute(5));
  304. if ($total_fee == 0) {
  305. $params = [
  306. 'out_trade_no' => $result->data->order_id,
  307. ];
  308. $url = config('api.pay_url') . "/payments/notify/koudai";
  309. \Curl::to($url)->withContentType("application/x-www-form-urlencoded")->withData($params)->post();
  310. return 0;
  311. }
  312. return $order->id;
  313. } else {
  314. throw new AlertException("数据库异常", 505);
  315. }
  316. } else {
  317. throw new AlertException(isset($result->message) ? $result->message : "发起支付失败", $result->code ?? 505);
  318. }
  319. }
  320. /**
  321. * 表白下单
  322. * @param int $total_fee 表白费用
  323. * @param int $confess_id 表白记录id
  324. * @param Request $request
  325. * @return mixed
  326. * @throws AlertException
  327. */
  328. public function unifyByConfess(int $total_fee, int $confess_id, Request $request)
  329. {
  330. $uid = Auth::auth();
  331. // 支付设备
  332. $agent = $request->header('user-agent');
  333. $os = 'other';
  334. if (
  335. strpos($agent, 'macintosh')
  336. || strpos($agent, 'iPod')
  337. || strpos($agent, 'iPhone')
  338. || strpos($agent, 'iPad')
  339. ) {
  340. $os = "ios";
  341. }
  342. if (strpos($agent, 'Android')) {
  343. $os = 'android';
  344. }
  345. $goods = self::GOODS[2];
  346. $params = [
  347. 'uid' => $uid,
  348. 'body' => '卖室友表白',
  349. 'total_fee' => $total_fee,
  350. 'notify_url' => config('api.msy_url') . "/api/core/pay/notify/confess"
  351. ];
  352. $pay_url = config('api.pay_url') . "/payments/unify";
  353. $result = \Curl::to($pay_url)->withContentType("application/x-www-form-urlencoded")->withData($params)->asJsonResponse()->post();
  354. if (isset($result->code) && $result->code == 200) {
  355. $order = $this->orderModel->fill([
  356. 'out_trade_no' => $result->data->order_id,
  357. 'total_amount' => $total_fee,
  358. 'total_fee' => $total_fee,
  359. 'uid' => $uid,
  360. 'type' => $goods['goods_id'],
  361. 'type_id' => $confess_id,
  362. 'device' => $os,
  363. 'create_at' => time(),
  364. ]);
  365. if ($order->save()) {
  366. OrderCloseJob::dispatch($order->id)->onQueue('{order:close}')->delay(now()->addMinute(5));
  367. return $order->id;
  368. } else {
  369. throw new AlertException("数据库异常", 505);
  370. }
  371. } else {
  372. throw new AlertException($result->message ?? "系统异常", $result->code ?? 505);
  373. }
  374. }
  375. /**
  376. * 小程序支付jssdk
  377. * @param int $order_id
  378. * @return array
  379. * @throws \Tymon\JWTAuth\Exceptions\JWTException
  380. */
  381. public function miniProgram(int $order_id)
  382. {
  383. $uid = MiniAuth::auth();
  384. $order = $this->orderModel->find($order_id);
  385. if (collect($order)->isEmpty()) {
  386. return response([
  387. 'code' => 404,
  388. 'message' => '订单号错误或者不存在'
  389. ]);
  390. }
  391. if ($order->trade_state != 0) {
  392. return response([
  393. 'code' => 102,
  394. 'message' => '订单失效' . json_encode($order->toArray())
  395. ]);
  396. }
  397. if ($uid != $order->uid) {
  398. return response([
  399. 'code' => 403,
  400. 'message' => '用户标识不一致'
  401. ]);
  402. }
  403. $public_id = config('miniprogram.public_id');
  404. $pay_url = config('api.pay_url') . "/payments/miniProgram/{$order->out_trade_no}";
  405. $result = \Curl::to($pay_url)->withHeader("app:{$public_id}")->asJsonResponse()->get();
  406. if (isset($result->code) && $result->code == 200) {
  407. return response([
  408. 'code' => 200,
  409. 'message' => 'Success',
  410. 'data' => $result->data,
  411. ]);
  412. } else {
  413. return response([
  414. 'code' => $result->code ?? 505,
  415. 'message' => $result->message ?? "系统异常",
  416. 'data' => $result
  417. ]);
  418. }
  419. }
  420. /**
  421. * 公众号支付jssdk
  422. * @param int $order_id
  423. * @return array
  424. */
  425. public function jssdk(int $order_id)
  426. {
  427. $uid = Auth::auth();
  428. $order = $this->orderModel->find($order_id);
  429. if (collect($order)->isEmpty()) {
  430. return response([
  431. 'code' => 404,
  432. 'message' => '订单号错误或不存在'
  433. ]);
  434. }
  435. if ($order->trade_state != 0) {
  436. return response([
  437. 'code' => 102,
  438. 'message' => '订单失效'
  439. ]);
  440. }
  441. if ($uid != $order->uid) {
  442. return response([
  443. 'code' => 403,
  444. 'message' => '用户标识不一致'
  445. ]);
  446. }
  447. $url = config('api.pay_url') . "/payments/jssdk/{$order->out_trade_no}";
  448. $result = \Curl::to($url)->asJsonResponse()->get();
  449. if (isset($result->code) && $result->code == 200) {
  450. return response([
  451. 'code' => 200,
  452. 'message' => 'Success',
  453. 'data' => $result->data,
  454. ]);
  455. } else {
  456. return response([
  457. 'code' => $result->code ?? 505,
  458. 'message' => $result->message ?? "系统异常"
  459. ]);
  460. }
  461. }
  462. /**
  463. * app支付jssdk
  464. * @param int $order_id
  465. * @return array
  466. */
  467. public function app(int $order_id)
  468. {
  469. $uid = Auth::auth();
  470. $order = $this->orderModel->find($order_id);
  471. if (collect($order)->isEmpty()) {
  472. return response([
  473. 'code' => 404,
  474. 'message' => '订单号错误或者不存在'
  475. ]);
  476. }
  477. if ($order->trade_state != 0) {
  478. return response([
  479. 'code' => 102,
  480. 'message' => '订单失效' . json_encode($order->toArray())
  481. ]);
  482. }
  483. if ($uid != $order->uid) {
  484. return response([
  485. 'code' => 403,
  486. 'message' => '用户标识不一致'
  487. ]);
  488. }
  489. $pay_url = config('api.pay_url') . "/payments/app/{$order->out_trade_no}";
  490. $result = \Curl::to($pay_url)->asJsonResponse()->get();
  491. if (isset($result->code) && $result->code == 200) {
  492. return response([
  493. 'code' => 200,
  494. 'message' => 'Success',
  495. 'data' => $result->data,
  496. ]);
  497. } else {
  498. return response([
  499. 'code' => $result->code ?? 505,
  500. 'message' => $result->message ?? "系统异常",
  501. 'data' => $result
  502. ]);
  503. }
  504. }
  505. /**
  506. * 订单退款
  507. * @param int $order_id
  508. * @param int $refund_fee 退款金额:分
  509. * @param string $refund_desc
  510. * @param bool $all
  511. * @return array|bool
  512. * @throws AlertException
  513. */
  514. public function refund(int $order_id, int $refund_fee, $refund_desc = "", $all = false)
  515. {
  516. $order = $this->orderModel->find($order_id);
  517. if (collect($order)->isEmpty()) {
  518. throw new AlertException('订单错误或不存在', 101);
  519. }
  520. if (0 == $order->order_state) {
  521. throw new AlertException('订单未支付不可退款', 102);
  522. }
  523. if ($all && $order->create_at < 1533114000) {
  524. throw new AlertException("过期订单,请联系小向导微信:fpdxkf", 103);
  525. $pay_url = config('api.pay_url') . '/payments/transfer';
  526. $data = [
  527. 'uid' => $order->uid,
  528. 'amount' => $refund_fee,
  529. 'app_order_id' => "fpdx_refund_" . uniqid(),
  530. 'desc' => $refund_desc
  531. ];
  532. } else {
  533. $pay_url = config('api.pay_url') . "/payments/order/{$order->out_trade_no}/refund";
  534. $data = [
  535. 'refund_fee' => $refund_fee,
  536. 'refund_desc' => $refund_desc
  537. ];
  538. }
  539. $result = \Curl::to($pay_url)->withContentType("application/x-www-form-urlencoded")->asJsonResponse()->withData($data)->post();
  540. if (isset($result->code) && $result->code == 200) {
  541. // 使用优惠券逻辑
  542. if ($order->coupon_id) {
  543. $couponService = new CouponService();
  544. $couponService->setUid($order->uid)
  545. ->setCouponId($order->coupon_id)
  546. ->unUse();
  547. }
  548. return true;
  549. } else {
  550. throw new AlertException("退款失败", 500);
  551. }
  552. }
  553. /**
  554. * 支付结果核销处理
  555. * @param Request $request
  556. * @param array $callback
  557. * @return string
  558. */
  559. private function handlePaidNotify(Request $request, array $callback)
  560. {
  561. $orderModel = new OrderModel();
  562. /** @var OrderModel|null $order */
  563. $order = $orderModel->where('out_trade_no', $request->input('order_id'))->first();
  564. if (!$order) {
  565. return "fail";
  566. }
  567. if ($order->order_state != 0) {
  568. return "success";
  569. } else {
  570. $order->cash_fee = $request->input('cash_fee', 0);
  571. if ($request->input('trade_state') == 'SUCCESS') {
  572. $order->order_state = 1;
  573. }
  574. if ($order->save()) {
  575. dispatch_now(new ActivateSvipReportJob($order));
  576. call_user_func($callback, $order);
  577. return "success";
  578. } else {
  579. return "fail";
  580. }
  581. }
  582. }
  583. /**
  584. * 普通支付成功业务处理
  585. * @param OrderModel $order
  586. * @return bool
  587. * @throws \Exception
  588. */
  589. protected function payment(OrderModel $order)
  590. {
  591. DB::beginTransaction();
  592. try {
  593. // 增加花
  594. DB::table('kdgx_partner_charge_user')->where('uid', $order->uid)->increment(
  595. 'red_flower',
  596. self::GOODS[$order->type]['red_flower']
  597. );
  598. DB::table('kdgx_partner_charge_user')->where('uid', $order->uid)->increment('gold_flower', $order->flower);
  599. // 日志
  600. DB::table('kdgx_partner_charge_pay_logs')->insert([
  601. 'uid' => $order->uid,
  602. 'create_at' => time(),
  603. 'type' => 3,
  604. 'gold_flower' => $order->flower,
  605. 'red_flower' => self::GOODS[$order->type]['red_flower'],
  606. 'type_id' => $order->total_fee,
  607. 'remark' => "微信充值 {$order->total_fee}"
  608. ]);
  609. DB::commit();
  610. return true;
  611. } catch (\Exception $e) {
  612. DB::rollBack();
  613. return false;
  614. }
  615. }
  616. /**
  617. * 普通支付结果通知
  618. * @param Request $request
  619. * @return string
  620. * @throws \Exception
  621. */
  622. public function notify(Request $request)
  623. {
  624. return $this->handlePaidNotify($request, [$this, 'payment']);
  625. }
  626. // 超级VIP支付结果通知
  627. public function notifyBySuperVip(Request $request)
  628. {
  629. $vs = new VipService();
  630. return $this->handlePaidNotify($request, [$vs, 'payment']);
  631. }
  632. /**
  633. * 表白支付结果通知
  634. * @param Request $request
  635. * @return string
  636. */
  637. public function notifyByconfess(Request $request)
  638. {
  639. $confess = new Confess();
  640. return $this->handlePaidNotify($request, [$confess, 'payment']);
  641. }
  642. /**
  643. * 分配对象报名支付结果通知
  644. * @param Request $request
  645. * @return string
  646. */
  647. public function notifyByfpdx(Request $request)
  648. {
  649. $pairObj = new PairController();
  650. return $this->handlePaidNotify($request, [$pairObj, 'payment']);
  651. }
  652. /**
  653. * 后台退款接口
  654. * @param int $order_id
  655. * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
  656. * @throws AlertException
  657. * @throws \App\Exceptions\ApiException
  658. */
  659. public function requestRefund(int $order_id)
  660. {
  661. $order = $this->orderModel->find($order_id);
  662. $orderService = new OrderService();
  663. $result = $orderService->refund($order_id, $order->cash_fee, '测试退款');
  664. return response([
  665. 'code' => 200,
  666. 'message' => 'OK',
  667. 'data' => $result
  668. ]);
  669. }
  670. /**
  671. * 订单关闭
  672. * @param $id
  673. * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
  674. * @throws \App\Exceptions\ApiException
  675. */
  676. public function closeOrder($id)
  677. {
  678. $orderService = new OrderService();
  679. $orderService->closeOrder($id);
  680. return response([
  681. 'code' => 200,
  682. 'message' => 'OK'
  683. ]);
  684. }
  685. }