CancelGroupOrderJob.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace crmeb\jobs;
  12. use app\common\repositories\store\coupon\StoreCouponUserRepository;
  13. use app\common\repositories\store\order\StoreGroupOrderRepository;
  14. use app\common\repositories\store\product\ProductAttrValueRepository;
  15. use app\common\repositories\store\product\ProductRepository;
  16. use app\common\repositories\store\product\StoreDiscountRepository;
  17. use crmeb\interfaces\JobInterface;
  18. use think\facade\Db;
  19. use think\facade\Log;
  20. class CancelGroupOrderJob implements JobInterface
  21. {
  22. public function fire($job, $groupOrderId)
  23. {
  24. $groupOrderRepository = app()->make(StoreGroupOrderRepository::class);
  25. $groupOrder = $groupOrderRepository->getCancelDetail($groupOrderId);
  26. if (!$groupOrder) return $job->delete();
  27. Db::transaction(function () use ($groupOrder) {
  28. $couponId = $groupOrder->coupon_id ? [$groupOrder->coupon_id] : [];
  29. $productRepository = app()->make(ProductRepository::class);
  30. foreach ($groupOrder->orderList as $order) {
  31. if ($order->coupon_id)
  32. $couponId = array_merge($couponId, explode(',', $order->coupon_id));
  33. foreach ($order->orderProduct as $cart) {
  34. $productRepository->orderProductIncStock($order, $cart);
  35. }
  36. if ($order->activity_type == 10) {
  37. app()->make(StoreDiscountRepository::class)->incStock($order->orderProduct[0]['activity_id']);
  38. }
  39. }
  40. if (count($couponId)) {
  41. app()->make(StoreCouponUserRepository::class)->updates($couponId, ['status' => 0]);
  42. }
  43. });
  44. return $job->delete();
  45. }
  46. public function failed($data)
  47. {
  48. Log::info('取消订单执行失败:' . var_export($data, true));
  49. }
  50. }