CancelGroupOrderJob.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 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 crmeb\interfaces\JobInterface;
  17. use think\facade\Db;
  18. use think\facade\Log;
  19. class CancelGroupOrderJob implements JobInterface
  20. {
  21. public function fire($job, $groupOrderId)
  22. {
  23. $groupOrderRepository = app()->make(StoreGroupOrderRepository::class);
  24. $groupOrder = $groupOrderRepository->getCancelDetail($groupOrderId);
  25. if (!$groupOrder) return $job->delete();
  26. Db::transaction(function () use ($groupOrder) {
  27. $couponId = [];
  28. $productRepository = app()->make(ProductRepository::class);
  29. foreach ($groupOrder->orderList as $order) {
  30. if ($order->coupon_id)
  31. $couponId = array_merge($couponId, explode(',', $order->coupon_id));
  32. foreach ($order->orderProduct as $cart) {
  33. $productRepository->orderProductIncStock($cart);
  34. }
  35. }
  36. if (count($couponId)) {
  37. app()->make(StoreCouponUserRepository::class)->updates($couponId, ['status' => 0]);
  38. }
  39. });
  40. return $job->delete();
  41. }
  42. public function failed($data)
  43. {
  44. Log::info('取消订单执行失败:' . var_export($data, true));
  45. }
  46. }