回退优惠卷

This commit is contained in:
2024-04-16 17:57:24 +08:00
parent 8d74dc33fb
commit 245397dfa7
2 changed files with 25 additions and 42 deletions
+24 -41
View File
@@ -133,20 +133,18 @@ class CouponService extends BaseService
}
// 添加优惠卷过期队列
if (!empty($user_coupon['valid_start_time']) && !empty($user_coupon['valid_end_time'])){
$valid_end_time = strtotime($user_coupon['valid_start_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());
@@ -155,24 +153,22 @@ class CouponService extends BaseService
try {
// 添加优惠卷即将过期提醒队列
if (!empty($user_coupon['valid_start_time']) && !empty($user_coupon['valid_end_time']) && isset($time)){
$time = floor($time * 0.75);
$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());
}
@@ -208,11 +204,9 @@ 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,string $start_time,string $finish_time): bool
public function GrantBuyOrderServicePackageCoupon(string $user_id): bool
{
// 获取购买服务包的用户可领取的优惠卷列表
$coupon = Coupon::getOrderServicePackageCouponList();
@@ -227,17 +221,6 @@ 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;