SendNewPeopleCouponJob.php 1.7 KB

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