diff --git a/app/common/repositories/store/coupon/StoreCouponRepository.php b/app/common/repositories/store/coupon/StoreCouponRepository.php index 2accd0a7..7332ca7a 100644 --- a/app/common/repositories/store/coupon/StoreCouponRepository.php +++ b/app/common/repositories/store/coupon/StoreCouponRepository.php @@ -48,8 +48,9 @@ class StoreCouponRepository extends BaseRepository const TYPE_STORE_ALL = 0; //店铺商品券 const TYPE_STORE_PRODUCT = 1; - //店铺现金抵扣券,可结余 + //店铺现金抵扣券,可结余,通过购买商品获得 const TYPE_STORE_COUPON = 2; + //店铺现金抵扣券,可结余,通过销售补贴获得 const TYPE_SALE_SUBSIDY = 3; //平台券 const TYPE_PLATFORM_ALL = 10; @@ -373,6 +374,9 @@ class StoreCouponRepository extends BaseRepository if (!empty($this->isFail)) { $data['is_fail'] = $this->isFail; } + if (!empty($this->status)) { + $data['status'] = $this->status; + } return $data; } diff --git a/crmeb/listens/OrderDeliveryListen.php b/crmeb/listens/OrderDeliveryListen.php index 7dac4b00..5fc94a5c 100644 --- a/crmeb/listens/OrderDeliveryListen.php +++ b/crmeb/listens/OrderDeliveryListen.php @@ -3,10 +3,10 @@ namespace crmeb\listens; use app\common\model\store\coupon\StoreCouponDetail; +use app\common\model\store\coupon\StoreCouponUser; use app\common\repositories\store\coupon\StoreCouponRepository; use app\common\repositories\store\coupon\StoreCouponUserRepository; use crmeb\interfaces\ListenerInterface; -use think\facade\Log; /** * Class OrderDeliveryListen @@ -37,24 +37,18 @@ class OrderDeliveryListen implements ListenerInterface StoreCouponDetail::income($order, $couponUser['coupon_user_id'], $coupon->coupon_price, $coupon['title']); //发放春耕补贴优惠券 - if (!empty($orderProduct->product->give_coupon_ids) && $couponTotal >= 1000) { - $giveCoupons = $repo->getGiveCoupon($orderProduct->product->give_coupon_ids); - foreach ($giveCoupons as $giveCoupon) { - if ($giveCoupon['type'] != StoreCouponRepository::TYPE_STORE_COUPON) { - continue; - } - try { - $rate = $this->getRate($couponTotal); - $giveCoupon->coupon_price = bcmul($couponTotal, $rate, 2); - $repo->startTime = date('Y-m-d H:i:s'); - $repo->endTime = '2025-07-01'; - $repo->status = -1; - $couponUser = $repo->sendCoupon($giveCoupon, $order['uid'], StoreCouponUserRepository::SEND_TYPE_BUY); - StoreCouponDetail::income($order, $couponUser['coupon_user_id'], $giveCoupon->coupon_price, $giveCoupon['title'], 0); - } catch (\Exception $e) { - Log::error('自动发放买赠优惠券出错:' . $e->getMessage()); - } + if ($couponTotal >= 1000) { + $giveCoupon = $repo->validCouponQuery(StoreCouponRepository::TYPE_STORE_COUPON, StoreCouponRepository::GET_COUPON_TYPE_PAY)->find(); + if (empty($giveCoupon)) { + return; } + $rate = $this->getRate($couponTotal); + $giveCoupon->coupon_price = bcmul($couponTotal, $rate, 2); + $repo->startTime = date('Y-m-d H:i:s'); + $repo->endTime = '2025-07-01'; + $repo->status = StoreCouponUser::STATUS_REPEAL; + $couponUser = $repo->sendCoupon($giveCoupon, $order['uid'], StoreCouponUserRepository::SEND_TYPE_BUY); + StoreCouponDetail::income($order, $couponUser['coupon_user_id'], $giveCoupon->coupon_price, $giveCoupon['title'], 0); } } }