You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

586 lines
22 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. <?php
  2. namespace App\Service\v3\Implementations;
  3. use App\Commons\Log;
  4. use App\Constants\v3\ErrorCode;
  5. use App\Constants\v3\LogLabel;
  6. use App\Constants\v3\OrderState;
  7. use App\Constants\v3\OrderType;
  8. use App\Constants\v3\Payment;
  9. use App\Constants\v3\SsdbKeys;
  10. use App\Exception\ErrorCodeException;
  11. use App\Model\v3\Coupon;
  12. use App\Model\v3\CouponRec;
  13. use App\Model\v3\Goods;
  14. use App\Model\v3\GoodsActivity;
  15. use App\Model\v3\Order;
  16. use App\Model\v3\OrderGoods;
  17. use App\Model\v3\OrderMain;
  18. use App\Model\v3\OrderSalesStatistic;
  19. use App\Model\v3\ShoppingCart;
  20. use App\Model\v3\Store;
  21. use App\Model\v3\UserAddress;
  22. use App\Service\v3\Interfaces\CouponRecServiceInterface;
  23. use App\Service\v3\Interfaces\CouponServiceInterface;
  24. use App\Service\v3\Interfaces\DeliveryMoneyServiceInterface;
  25. use App\Service\v3\Interfaces\DistributionPriceServiceInterface;
  26. use App\Service\v3\Interfaces\GoodsActivityServiceInterface;
  27. use App\Service\v3\Interfaces\GoodsServiceInterface;
  28. use App\Service\v3\Interfaces\PaymentServiceInterface;
  29. use App\Service\v3\Interfaces\ShopCartUpdateServiceInterface;
  30. use App\TaskWorker\SSDBTask;
  31. use Exception;
  32. use Hyperf\Database\Model\Model;
  33. use Hyperf\DbConnection\Db;
  34. use Hyperf\Di\Annotation\Inject;
  35. use App\Service\v3\Interfaces\OrderOnlineServiceInterface;
  36. use Hyperf\Snowflake\IdGeneratorInterface;
  37. use Hyperf\Utils\ApplicationContext;
  38. class OrderOnlineService implements OrderOnlineServiceInterface
  39. {
  40. /**
  41. * @Inject
  42. * @var Log
  43. */
  44. protected $log;
  45. /**
  46. * @Inject
  47. * @var DistributionPriceServiceInterface
  48. */
  49. protected $deliveryService;
  50. /**
  51. * @Inject
  52. * @var CouponRecServiceInterface
  53. */
  54. protected $couponRecService;
  55. /**
  56. * @Inject
  57. * @var CouponServiceInterface
  58. */
  59. protected $couponService;
  60. /**
  61. * @Inject
  62. * @var GoodsActivityServiceInterface
  63. */
  64. protected $goodsActivityService;
  65. /**
  66. * @Inject
  67. * @var GoodsServiceInterface
  68. */
  69. protected $goodsService;
  70. /**
  71. * @Inject
  72. * @var PaymentServiceInterface
  73. */
  74. protected $paymentService;
  75. /**
  76. * @Inject
  77. * @var ShopCartUpdateServiceInterface
  78. */
  79. protected $shopCartUpdateService;
  80. /**
  81. * 下单
  82. * @param $marketId
  83. * @param $userId
  84. * @param $userAddrId
  85. * @param $storeList
  86. * @param $totalMoney
  87. * @param string $deliveryTimeNote
  88. * @param int $serviceMoney
  89. * @param null $receiveCouponIds
  90. * @param string $plat
  91. * @return array[]
  92. */
  93. public function do($marketId, $userId, $userAddrId, $storeList, $totalMoney, $deliveryTimeNote='尽快送达', $serviceMoney=0, $receiveCouponIds=null, $plat=''){
  94. Db::beginTransaction();
  95. try {
  96. $currentTime = time();
  97. bcscale(6);
  98. // 用户收货地址
  99. $userAddr = UserAddress::query()->find($userAddrId);
  100. // 获取配送费用
  101. $deliveryAmount = $this->deliveryService->do($userAddr->lat, $userAddr->lng);
  102. // 优惠券数据
  103. $couponRec = CouponRec::query()->lockForUpdate()->whereIn('id', $receiveCouponIds)->get()->toArray();
  104. // 处理购物车数据,计算订单金额、子订单数据处理等
  105. $totalAmount = 0; # 实付金额
  106. $orderAmount = 0; # 订单金额
  107. $dataMain = []; # 主订单
  108. $dataChildren = []; # 子订单
  109. $dataOrderGoods = []; # 订单商品
  110. $storeTypeIds = []; # 订单中的商户类型,用于校验红包
  111. foreach ($storeList as $key => &$storeItem) {
  112. $storeId = $storeItem->store_id;
  113. // 子订单金额
  114. $subAmount = 0;
  115. // 店铺分类
  116. $storeType = Store::query()->where(['id' => $storeId])->value('category_id');
  117. $storeTypeIds[] = (string)$storeType;
  118. // 店铺今天的订单数
  119. $count = Order::query()
  120. ->join('lanzu_order_main as main', 'main.id', '=', 'lanzu_order.order_main_id')
  121. ->where(['lanzu_order.store_id' => $storeId, 'main.type' => OrderType::ONLINE])
  122. ->whereBetween('lanzu_order.created_at', [strtotime(date('Y-m-d 00:00:00')), strtotime(date('Y-m-d 23:59:59'))])
  123. ->count();
  124. // 用户购物车数据
  125. $cartIds = explode(',', $storeItem->cart_ids);
  126. $carts = ShoppingCart::query()->whereIn('id', $cartIds)->where(['market_id' => $marketId, 'user_id' => $userId])->get();
  127. foreach ($carts as $k => &$cart) {
  128. // 查个商品
  129. $goods = [];
  130. if ($cart->activity_type == 1) {
  131. $goods = Goods::query()->lockForUpdate()->find($cart->goods_id);
  132. $check = $this->goodsService->check($goods, $cart->num);
  133. if (true !== $check) {
  134. throw new ErrorCodeException($check, '[商品失效1]'.$cart->goods_id);
  135. }
  136. } elseif ($cart->activity_type == 2) {
  137. $goods = GoodsActivity::query()->lockForUpdate()->find($cart->goods_id);
  138. $check = $this->goodsActivityService->check($goods, $cart->num, $userId);
  139. if (true !== $check) {
  140. throw new ErrorCodeException($check, '[商品失效2]'.$cart->goods_id);
  141. }
  142. // 活动商品不可用优惠券
  143. if ($goods->can_use_coupon!=1 && $receiveCouponIds) {
  144. throw new ErrorCodeException(ErrorCode::GOODS_ACTIVITY_CANNOT_USE_COUPON, '[商品失效]'.$cart->goods_id);
  145. }
  146. // 活动商品可用优惠券,再校验这些优惠券是不是可以在当前活动类型可用
  147. // receiveCouponIds中是不是有当前活动不可用的优惠券
  148. $couponIds = array_values(array_column($couponRec, 'coupon_id'));
  149. $couponsActivityAvailable = Coupon::query()
  150. ->select(['id'])
  151. ->whereJsonContains('activity_available', [(string)$goods->type])
  152. ->whereJsonContains('market_ids', [(string)$goods->market_id])
  153. ->whereIn('id', $couponIds)
  154. ->get()->toArray();
  155. $couponsActivityAvailableIds = array_values(array_column($couponsActivityAvailable, 'id'));
  156. if (!empty(array_diff($couponIds, $couponsActivityAvailableIds))) {
  157. throw new ErrorCodeException(ErrorCode::GOODS_ACTIVITY_CANNOT_USE_COUPON, '[商品失效]'.json_encode($couponsActivityAvailableIds));
  158. }
  159. }
  160. if (empty($goods)) {
  161. throw new ErrorCodeException(ErrorCode::ORDER_GOODS_NOT_AVAILABLE);
  162. }
  163. // 库存判断
  164. if ($goods->is_infinite !=1 && $goods->inventory < $cart->num) {
  165. throw new ErrorCodeException(ErrorCode::ORDER_GOODS_INVENTORY_LIMIT);
  166. }
  167. // 算金额
  168. $goodsAmount = bcmul((string)$goods->price, (string)$cart->num); # 当前商品的金额
  169. $subAmount = bcadd((string)$subAmount, (string)$goodsAmount); # 当前店铺子订单的金额
  170. // 订单商品数据
  171. $dataOrderGoods[$storeId][] = [
  172. 'order_id' => 0,
  173. 'goods_id' => $cart->goods_id,
  174. 'activity_type' => $cart->activity_type,
  175. 'number' => $cart->num,
  176. 'price' => $goods->price,
  177. 'original_price' => $goods->original_price,
  178. 'vip_price' => $goods->vip_price,
  179. 'name' => $goods->name,
  180. 'goods_unit' => $goods->goods_unit,
  181. 'cover_img' => $goods->cover_img,
  182. 'spec' => json_encode($goods->spec),
  183. ];
  184. }
  185. // 子订单数据
  186. $dataChildren[] = [
  187. 'order_main_id' => 0,
  188. 'user_id' => $userId,
  189. 'store_id' => $storeId,
  190. 'money' => bcadd((string)$subAmount, '0', 2),
  191. 'oid' => $count + 1,
  192. 'order_num' => date('YmdHis').mt_rand(1000, 9999),
  193. 'note' => $storeItem->note
  194. ];
  195. // 订单金额
  196. $orderAmount = bcadd((string)$orderAmount, (string)$subAmount);
  197. }
  198. // 优惠券的使用
  199. $couponMoney = 0;
  200. if (!empty($couponRec)) {
  201. $couponsCanUse = $this->couponRecService->allForOrderOlAvailable($totalAmount, $userId, $marketId, 2, $storeTypeIds);
  202. $couponCanUseIds = array_column($couponsCanUse, 'id');
  203. $couponCanUseIds = array_intersect($couponCanUseIds, $receiveCouponIds);
  204. $couponCannotUseIds = array_diff($receiveCouponIds, $couponCanUseIds);
  205. if (empty($couponCanUseIds)||!empty($couponCannotUseIds)) {
  206. throw new ErrorCodeException(ErrorCode::COUPON_NOT_AVAILABLE);
  207. }
  208. // 计算红包折扣金额
  209. foreach ($couponsCanUse as $key => $coupon) {
  210. if (!in_array($coupon->id, $receiveCouponIds)) {
  211. continue;
  212. }
  213. if ($coupon->discount_type == Coupon::DISCOUNT_TYPE_CASH) {
  214. $couponMoney = bcadd($couponMoney, $coupon->discounts, 2);
  215. } elseif ($coupon->discount_type == Coupon::DISCOUNT_TYPE_RATE) {
  216. $discountRate = bcdiv($coupon->discounts,10);
  217. $discountRate = bcsub(1,$discountRate);
  218. $discountMoney = bcmul($orderAmount, $discountRate);
  219. $couponMoney = bcadd($couponMoney, $discountMoney, 2);
  220. }
  221. }
  222. }
  223. // 获取分布式全局ID
  224. $generator = ApplicationContext::getContainer()->get(IdGeneratorInterface::class);
  225. $globalOrderId = $generator->generate();
  226. $orderAmount = bcadd((string)$orderAmount, '0', 2);
  227. $totalAmount = bcadd((string)$totalAmount, (string)$orderAmount);
  228. $totalAmount = bcadd((string)$totalAmount, (string)$deliveryAmount);
  229. $totalAmount = bcadd((string)$totalAmount, (string)$serviceMoney);
  230. $totalAmount = bcsub((string)$totalAmount, (string)$couponMoney, 2);
  231. // 校验订单总金额
  232. if ($totalAmount != $totalMoney) {
  233. throw new ErrorCodeException(ErrorCode::ORDER_TOTAL_AMOUNT_ERROR);
  234. }
  235. $dataMain = [
  236. 'market_id' => $marketId,
  237. 'order_num' => $globalOrderId,
  238. 'global_order_id' => $globalOrderId,
  239. 'user_id' => $userId,
  240. 'type' => OrderType::ONLINE,
  241. 'money' => $totalAmount,
  242. 'total_money' => $orderAmount,
  243. 'services_money' => $serviceMoney,
  244. 'coupon_money' => $couponMoney,
  245. 'delivery_money' => $deliveryAmount,
  246. 'state' => OrderState::UNPAID,
  247. 'tel' => $userAddr->tel,
  248. 'address' => $userAddr->address.$userAddr->doorplate,
  249. 'lat' => $userAddr->lat,
  250. 'lng' => $userAddr->lng,
  251. 'name' => $userAddr->user_name,
  252. 'plat' => $plat,
  253. 'delivery_time_note' => $deliveryTimeNote
  254. ];
  255. // 生成主订单
  256. $orderMain = OrderMain::query()->create($dataMain);
  257. // 处理子订单
  258. foreach ($dataChildren as $key => &$child) {
  259. $child['order_main_id'] = $globalOrderId;
  260. $orderChild = Order::query()->create($child);
  261. $orderChildId = $orderChild->id;
  262. foreach ($dataOrderGoods[$child['store_id']] as $k => &$orderGoods) {
  263. $orderGoods['order_id'] = $orderChildId;
  264. $orderGoods['created_at'] = $currentTime;
  265. $orderGoods['updated_at'] = $currentTime;
  266. }
  267. OrderGoods::query()->insert($dataOrderGoods[$child['store_id']]);
  268. }
  269. // 判断是否有购买多个特价商品
  270. $check = $this->goodsActivityService->checkOrderActivityCount($dataOrderGoods);
  271. if(!$check){
  272. throw new ErrorCodeException(ErrorCode::GOODS_ACTIVITY_RESTRICT_LIMIT, '[同一订单同种类型活动商品]'.json_encode($dataOrderGoods));
  273. }
  274. // 订单成功,做一些处理
  275. // 活动商品购买记录
  276. foreach ($dataOrderGoods as $key => &$goods) {
  277. foreach ($goods as $k => &$goodsItem)
  278. if ($goodsItem['activity_type'] == 2) {
  279. $this->goodsActivityService->cacheRecord($goodsItem['goods_id'], $goodsItem['number'], $userId);
  280. }
  281. }
  282. // 优惠券红包使用记录
  283. $this->couponService->orderUseCoupons($globalOrderId, $couponRec);
  284. Db::commit();
  285. // 清除购物车
  286. $this->shopCartUpdateService->doClear($userId, $marketId);
  287. // 记录用户中心的badge
  288. $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
  289. $ssdb->exec('hincr', SsdbKeys::USER_ORDER_BADGE.$userId, 'unpaid', 1);
  290. // 支付
  291. return $this->paymentService->do($globalOrderId, $totalAmount, $userId, config('wechat.notify_url.online'));
  292. } catch (Exception $e) {
  293. Db::rollBack();
  294. $this->log->event(LogLabel::ORDER_ONLINE_LOG, ['exception_msg' => $e->getMessage()]);
  295. throw new ErrorCodeException(ErrorCode::ORDER_ONLINE_FAIL, $e->getMessage());
  296. }
  297. }
  298. public function check($globalOrderId, $userId, $state): Model
  299. {
  300. $builder = OrderMain::query()
  301. ->where(['global_order_id' => $globalOrderId, 'user_id' => $userId]);
  302. if (is_array($state)) {
  303. $builder = $builder->whereIn('state', $state);
  304. } else {
  305. $builder = $builder->where(['state' => $state]);
  306. }
  307. $orderMain = $builder->first();
  308. if (empty($orderMain)) {
  309. throw new ErrorCodeException(ErrorCode::ORDER_NOT_AVAILABLE);
  310. }
  311. return $orderMain;
  312. }
  313. /**
  314. * @inheritDoc
  315. */
  316. public function undo($globalOrderId, $userId)
  317. {
  318. Db::beginTransaction();
  319. try {
  320. // 订单待支付
  321. $orderMain = $this->check($globalOrderId, $userId, OrderState::UNPAID);
  322. $orderMain->state = OrderState::CANCELED;
  323. if (!$orderMain->save()) {
  324. throw new ErrorCodeException(ErrorCode::ORDER_NOT_AVAILABLE);
  325. }
  326. // 退还优惠券
  327. $this->couponService->orderRefundCoupons($globalOrderId);
  328. // 撤销活动商品购买记录
  329. $orders = Order::query()->where(['order_main_id' => $globalOrderId])->get()->toArray();
  330. $orderGoods = OrderGoods::query()
  331. ->where('activity_type', 2)
  332. ->whereIn('order_id', array_values(array_column($orders, 'id')))
  333. ->get();
  334. foreach ($orderGoods as $key => &$goods) {
  335. $this->goodsActivityService->clearCacheRecord($goods->goods_id, $goods->number, $orderMain->user_id);
  336. }
  337. Db::commit();
  338. return true;
  339. } catch (Exception $e) {
  340. Db::rollBack();
  341. throw new ErrorCodeException(ErrorCode::ORDER_CANCEL_FAIL, $e->getMessage());
  342. }
  343. }
  344. public function detailByUser($globalOrderId, $userId)
  345. {
  346. $orderMain = OrderMain::with(['market'])->where(['global_order_id' => $globalOrderId])->first();
  347. $orders = Order::query()
  348. ->where(['order_main_id' => $globalOrderId, 'user_id' => $userId])
  349. ->with([
  350. 'orderGoods',
  351. 'store'
  352. ])
  353. ->get()->toArray();
  354. return ['order_main' => $orderMain, 'orders' => $orders];
  355. }
  356. /**
  357. * @inheritDoc
  358. */
  359. public function doByPaid($globalOrderId)
  360. {
  361. Db::beginTransaction();
  362. try {
  363. $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
  364. // 查询订单
  365. $orderMain = OrderMain::query()
  366. ->where(['global_order_id' => $globalOrderId,'type' => OrderType::ONLINE])
  367. ->first();
  368. // 修改订单、子订单状态
  369. $currentTime = time();
  370. $orderMain->state = OrderState::PAID;
  371. $orderMain->pay_time = $currentTime;
  372. $orderMain->save();;
  373. // 更新商品库存和销量
  374. $orders = Order::query()
  375. ->where(['order_main_id' => $globalOrderId])
  376. ->get()
  377. ->toArray();
  378. // 更新商户销量
  379. $upStoreScore = Store::query()
  380. ->whereIn('id', array_values(array_column($orders, 'store_id')))
  381. ->update(['sales' => Db::raw('sales+1')]);
  382. $orderGoods = OrderGoods::query()
  383. ->whereIn('order_id', array_values(array_column($orders, 'id')))
  384. ->get()
  385. ->toArray();
  386. foreach ($orderGoods as $key => &$goodsItem) {
  387. if ($goodsItem['activity_type'] == 2) { # 活动商品
  388. $goods = GoodsActivity::find($goodsItem['goods_id']);
  389. } else {
  390. $goods = Goods::find($goodsItem['goods_id']);
  391. }
  392. $goods->inventory = $goods->inventory - $goodsItem['number'];
  393. $goods->sales = $goods->sales + $goodsItem['number'];
  394. $goods->save();
  395. // 商品月销
  396. if (!$ssdb->exec('exists', SsdbKeys::GOODS_MONTH_SALES . date('Ym') . '_' . $goodsItem['activity_type'] . '_'.$goods->id)) {
  397. $ssdb->exec('set', SsdbKeys::GOODS_MONTH_SALES . date('Ym') . '_' . $goodsItem['activity_type'] . '_' . $goods->id, $goodsItem['number']);
  398. } else {
  399. $ssdb->exec('incr', SsdbKeys::GOODS_MONTH_SALES . date('Ym') . '_' . $goodsItem['activity_type'] . '_' . $goods->id, $goodsItem['number']);
  400. }
  401. }
  402. // 月销流水
  403. $statistics = [];
  404. foreach ($orders as $key => &$order) {
  405. $statistics[] = [
  406. 'money' => $order['money'],
  407. 'user_id' => $order['user_id'],
  408. 'store_id' => $order['store_id'],
  409. 'market_id' => $orderMain->market_id,
  410. 'order_id' => $order['id'],
  411. 'createtime' => $orderMain->pay_time,
  412. ];
  413. // 商户月销
  414. if (!$ssdb->exec('exists', SsdbKeys::STORE_MONTH_SALES . date('Ym').'_' . $order['store_id'])) {
  415. $ssdb->exec('set', SsdbKeys::STORE_MONTH_SALES . date('Ym') . '_' . $order['store_id'], 1);
  416. } else {
  417. $ssdb->exec('incr', SsdbKeys::STORE_MONTH_SALES . date('Ym') . '_' . $order['store_id'], 1);
  418. }
  419. }
  420. if (is_array($statistics) && !empty($statistics)) {
  421. $inSalesStatistics = OrderSalesStatistic::query()->insert($statistics);
  422. }
  423. Db::commit();
  424. // 记录用户中心的badge
  425. $ssdb->exec('hincr', SsdbKeys::USER_ORDER_BADGE.$orderMain->user_id, 'receiving', 1);
  426. return true;
  427. } catch (Exception $e) {
  428. $this->log->event(LogLabel::ORDER_ONLINE_PAID_LOG, ['exception' => $e->getMessage()]);
  429. Db::rollBack();
  430. return false;
  431. }
  432. }
  433. /**
  434. * @inheritDoc
  435. */
  436. public function doPay($globalOrderId, $userId)
  437. {
  438. // 订单待支付
  439. $orderMain = $this->check($globalOrderId, $userId, OrderState::UNPAID);
  440. return $this->paymentService->do(
  441. $orderMain->global_order_id,
  442. $orderMain->money,
  443. $orderMain->user_id,
  444. config('wechat.notify_url.online')
  445. );
  446. }
  447. /**
  448. * @inheritDoc
  449. * @throws Exception
  450. */
  451. public function doDel($globalOrderId, $userId)
  452. {
  453. // 订单完成
  454. $orderMain = $this->check($globalOrderId, $userId, OrderState::CAN_DEL);
  455. if (!$orderMain->delete()) {
  456. throw new ErrorCodeException(ErrorCode::ORDER_DELETE_FAIL);
  457. }
  458. return true;
  459. }
  460. /**
  461. * @inheritDoc
  462. */
  463. public function doApplyRefund($globalOrderId, $userId)
  464. {
  465. // 未接单
  466. $orderMain = $this->check($globalOrderId, $userId, OrderState::PAID);
  467. $orderMain->state = OrderState::REFUNDING;
  468. if (!$orderMain->save()) {
  469. throw new ErrorCodeException(ErrorCode::ORDER_APPLY_REFUND_FAIL);
  470. }
  471. // 记录badge
  472. $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
  473. $ssdb->exec('hincr', SsdbKeys::USER_ORDER_BADGE.$orderMain->user_id, 'refund', 1);
  474. return true;
  475. }
  476. /**
  477. * @inheritDoc
  478. */
  479. public function doComplete($globalOrderId, $userId)
  480. {
  481. $orderMain = $this->check($globalOrderId, $userId, OrderState::RECEIVING);
  482. $orderMain->state = OrderState::COMPLETED;
  483. if (!$orderMain->save()) {
  484. throw new ErrorCodeException(ErrorCode::ORDER_COMPLETE_FAIL);
  485. }
  486. // 记录badge
  487. $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class);
  488. $ssdb->exec('hincr', SsdbKeys::USER_ORDER_BADGE.$orderMain->user_id, 'completed', 1);
  489. return true;
  490. }
  491. /**
  492. * @inheritDoc
  493. */
  494. public function doRefund($globalOrderId, $userId)
  495. {
  496. $orderMain = $this->check($globalOrderId, $userId, OrderState::REFUNDING);
  497. $orderMain->state = OrderState::REFUNDED;
  498. if (!$orderMain->save()) {
  499. throw new ErrorCodeException(ErrorCode::ORDER_REFUND_FAIL);
  500. }
  501. // 微信退款
  502. if ($orderMain->pay_type == Payment::WECHAT) {
  503. return $this->paymentService->undo($orderMain->global_order_id, $userId);
  504. }
  505. }
  506. }