ProductCouponJob.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 app\jobs\product;
  12. use app\services\product\product\StoreProductCouponServices;
  13. use crmeb\basic\BaseJobs;
  14. use crmeb\traits\QueueTrait;
  15. use think\facade\Log;
  16. /**
  17. * 商品关联优惠券
  18. * Class ProductCouponJob
  19. * @package app\jobs\product
  20. */
  21. class ProductCouponJob extends BaseJobs
  22. {
  23. use QueueTrait;
  24. /**
  25. * @param $orderInfo
  26. * @return bool
  27. */
  28. public function doJob($orderInfo)
  29. {
  30. if (!$orderInfo) return true;
  31. try {
  32. /** @var StoreProductCouponServices $storeProductCouponServices */
  33. $storeProductCouponServices = app()->make(StoreProductCouponServices::class);
  34. $storeProductCouponServices->giveOrderProductCoupon((int)$orderInfo['uid'], $orderInfo['id']);
  35. } catch (\Throwable $e) {
  36. Log::error('赠送订单商品关联优惠券发生错误,错误原因:' . $e->getMessage());
  37. }
  38. return true;
  39. }
  40. /**
  41. * 设置保存商品关联优惠券
  42. * @param $id
  43. * @param $coupon_ids
  44. * @return bool|void
  45. */
  46. public function setProductCoupon($id, $coupon_ids)
  47. {
  48. if (!$id) return true;
  49. try {
  50. /** @var StoreProductCouponServices $storeProductCouponServices */
  51. $storeProductCouponServices = app()->make(StoreProductCouponServices::class);
  52. $storeProductCouponServices->setCoupon($id, $coupon_ids);
  53. } catch (\Throwable $e) {
  54. response_log_write([
  55. 'message' => '设置保存商品关联优惠券发生错误,错误原因:' . $e->getMessage(),
  56. 'file' => $e->getFile(),
  57. 'line' => $e->getLine()
  58. ]);
  59. }
  60. return true;
  61. }
  62. }