PayGiveCouponJob.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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\StoreCouponRepository;
  13. use app\common\repositories\store\coupon\StoreCouponUserRepository;
  14. use crmeb\interfaces\JobInterface;
  15. use think\facade\Log;
  16. class PayGiveCouponJob implements JobInterface
  17. {
  18. public function fire($job, $data)
  19. {
  20. $storeCouponRepository = app()->make(StoreCouponRepository::class);
  21. $coupons = $storeCouponRepository->getGiveCoupon($data['ids']);
  22. foreach ($coupons as $coupon) {
  23. if ($coupon->is_limited && 0 == $coupon->remain_count)
  24. continue;
  25. try {
  26. $storeCouponRepository->sendCoupon($coupon, $data['uid'], StoreCouponUserRepository::SEND_TYPE_BUY);
  27. } catch (\Exception $e) {
  28. Log::info('自动发放买赠优惠券:' . $e->getMessage());
  29. }
  30. }
  31. $job->delete();
  32. }
  33. public function failed($data)
  34. {
  35. // TODO: Implement failed() method.
  36. }
  37. }