From 70ef1ae11745cbb11dc6488c385d67c514287a74 Mon Sep 17 00:00:00 2001 From: wucongxing8150 <815046773@qq.com> Date: Tue, 16 Apr 2024 14:42:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=91=E6=94=BE=E8=B4=AD=E4=B9=B0=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E5=8C=85=E7=9A=84=E5=85=B3=E8=81=94=E4=BC=98=E6=83=A0?= =?UTF-8?q?=E5=8D=B7=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Model/UserCoupon.php | 2 +- app/Services/CouponService.php | 81 ++++++++++++++++++------------ app/Services/UserCouponService.php | 11 ++-- app/Services/UserDoctorService.php | 2 +- 4 files changed, 59 insertions(+), 37 deletions(-) diff --git a/app/Model/UserCoupon.php b/app/Model/UserCoupon.php index 7c1cb8d..b3a3b56 100644 --- a/app/Model/UserCoupon.php +++ b/app/Model/UserCoupon.php @@ -146,7 +146,7 @@ class UserCoupon extends Model ->whereIn("application_scope",[1,3,4,5]) ->where(function ($query) use ($coupon_product_datas) { foreach ($coupon_product_datas as $coupon_product_data){ - $query->orwhere("product_id","like",'%' . $coupon_product_data['product_id'] . '%'); + $query->orwhere("product_id","=",$coupon_product_data['product_id']); } }); }) diff --git a/app/Services/CouponService.php b/app/Services/CouponService.php index 22d7e69..d9a0d57 100644 --- a/app/Services/CouponService.php +++ b/app/Services/CouponService.php @@ -68,14 +68,16 @@ class CouponService extends BaseService } // 判断该优惠卷过期时间 - if ($coupon['valid_type'] == 1){ - // 绝对时效 - $valid_end_time = strtotime($coupon['valid_end_time']); + if (!empty($coupon['valid_type'])){ + if ($coupon['valid_type'] == 1){ + // 绝对时效 + $valid_end_time = strtotime($coupon['valid_end_time']); - $date = time() + 60 * 10; - if ($valid_end_time < $date){ - // 超出结束使用时间 - return true; + $date = time() + 60 * 10; + if ($valid_end_time < $date){ + // 超出结束使用时间 + return true; + } } } @@ -131,18 +133,20 @@ class CouponService extends BaseService } // 添加优惠卷过期队列 - $valid_end_time = strtotime($user_coupon->valid_end_time); + if (!empty($user_coupon['valid_start_time']) && !empty($user_coupon['valid_end_time'])){ + $valid_end_time = strtotime($user_coupon['valid_start_time']); - $data = array(); - $data['user_coupon_id'] = $user_coupon['user_coupon_id']; + $data = array(); + $data['user_coupon_id'] = $user_coupon['user_coupon_id']; - $time = $valid_end_time - time(); - $message = new UserCouponExpiredDelayDirectProducer($data); - $message->setDelayMs(1000 * $time); - $producer = $this->container->get(Producer::class); - $res = $producer->produce($message); - if (!$res) { - return false; + $time = $valid_end_time - time(); + $message = new UserCouponExpiredDelayDirectProducer($data); + $message->setDelayMs(1000 * $time); + $producer = $this->container->get(Producer::class); + $res = $producer->produce($message); + if (!$res) { + return false; + } } }catch (\Throwable $e){ Log::getInstance("CouponService-GrantUserCoupon")->error($e->getMessage()); @@ -151,22 +155,24 @@ class CouponService extends BaseService try { // 添加优惠卷即将过期提醒队列 - $time = floor($time * 0.75); + if (!empty($user_coupon['valid_start_time']) && !empty($user_coupon['valid_end_time']) && isset($time)){ + $time = floor($time * 0.75); - // 时间低于5小时,不进行过期提醒 - if ($time > 60 * 60 * 5){ - $message = new UserCouponExpiredNoticeDelayDirectProducer($data); - $message->setDelayMs(1000 * $time); - $producer = $this->container->get(Producer::class); - $res = $producer->produce($message); - if (!$res) { - Log::getInstance("CouponService-GrantUserCoupon")->error("添加优惠卷即将过期提醒队列"); + // 时间低于5小时,不进行过期提醒 + if ($time > 60 * 60 * 5){ + $message = new UserCouponExpiredNoticeDelayDirectProducer($data); + $message->setDelayMs(1000 * $time); + $producer = $this->container->get(Producer::class); + $res = $producer->produce($message); + if (!$res) { + Log::getInstance("CouponService-GrantUserCoupon")->error("添加优惠卷即将过期提醒队列"); + } } - } - // 通知-患者-优惠卷发放 - $MessagePush = new MessagePush($user_id); - $MessagePush->patientDistributeCoupon($coupon['coupon_name']); + // 通知-患者-优惠卷发放 + $MessagePush = new MessagePush($user_id); + $MessagePush->patientDistributeCoupon($coupon['coupon_name']); + } }catch (\Throwable $e){ Log::getInstance("CouponService-GrantUserCoupon")->error($e->getMessage()); } @@ -202,9 +208,11 @@ class CouponService extends BaseService /** * 发放购买服务包的关联优惠卷 * @param string $user_id 用户id + * @param string $start_time 开始使用时间 + * @param string $finish_time 结束有效时间 * @return bool */ - public function GrantBuyOrderServicePackageCoupon(string $user_id): bool + public function GrantBuyOrderServicePackageCoupon(string $user_id,string $start_time,string $finish_time): bool { // 获取购买服务包的用户可领取的优惠卷列表 $coupon = Coupon::getOrderServicePackageCouponList(); @@ -219,6 +227,17 @@ class CouponService extends BaseService // 发放失败 return false; } + + // 增加优惠卷有效期 + $params = array(); + $params['user_id'] = $user_id; + $params['coupon_id'] = $value['coupon_id']; + $params['user_coupon_status'] = 0; + + $data = array(); + $data['valid_start_time'] = $start_time; + $data['valid_end_time'] = $finish_time; + UserCoupon::edit($params,$data); } return true; diff --git a/app/Services/UserCouponService.php b/app/Services/UserCouponService.php index 3f6abe4..dfb77a0 100644 --- a/app/Services/UserCouponService.php +++ b/app/Services/UserCouponService.php @@ -135,6 +135,7 @@ class UserCouponService extends BaseService // 处理优惠卷数量限制问题 foreach ($coupons as $key => $coupon) { + // 处理数量优惠卷 if ($coupon['coupon_type'] == 3 && !empty($coupon['product_id'])){ // 数量是否足够标识字段 $quantity_quantity = 0; @@ -161,15 +162,17 @@ class UserCouponService extends BaseService } } - // 处理满减金额问题 - if ($coupon['coupon_type'] == 2 && !empty($coupon['product_id'])){ + // 处理满减金额优惠卷 + if ($coupon['coupon_type'] == 2){ // 可共用一个优惠卷的商品金额问题 $product_price = 0; foreach ($coupon_product_datas as $coupon_product_data) { // 如该优惠卷不包含此商品,跳过 - if (!str_contains($coupon['product_id'], $coupon_product_data['product_id'])) { - continue; + if (!empty($coupon['product_id'])){ + if (!str_contains($coupon['product_id'], $coupon_product_data['product_id'])) { + continue; + } } $product_price = bcadd($product_price, diff --git a/app/Services/UserDoctorService.php b/app/Services/UserDoctorService.php index cf4fa19..896d2a0 100644 --- a/app/Services/UserDoctorService.php +++ b/app/Services/UserDoctorService.php @@ -1911,7 +1911,7 @@ class UserDoctorService extends BaseService if (count($order_service_package_inquiry) <= 1){ // 发放优惠卷 $CouponService = new CouponService(); - $res = $CouponService->GrantBuyOrderServicePackageCoupon($order_inquiry['user_id']); + $res = $CouponService->GrantBuyOrderServicePackageCoupon($order_inquiry['user_id'],$start_time,$finish_time); if (!$res) { Db::rollBack(); return fail(HttpEnumCode::HTTP_ERROR, "接诊失败");