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.

591 lines
22 KiB

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