(string)$user_coupon->user_coupon_id, // 优惠卷金额 'coupon_price' => $coupon['coupon_price'], // 优惠卷金额 'application_scope' => $coupon['application_scope'], // 适用范围(1:全场通用 2:问诊 3:按品牌适用 4:按类别类别适用 5:单品使用) 'inquiry_type' => $coupon['inquiry_type'], // 关联问诊类型,逗号分隔,适用范围为问诊时存在生效(1:专家问诊 2:快速问诊 3:公益问诊 4:问诊购药 5:检测) 'valid_type' => $coupon['valid_type'], // 有效类型(1:绝对时效,xxx-xxx时间段有效 2:相对时效 n天内有效) 'valid_days' => $coupon['valid_days'], // 自领取之日起有效天数 'valid_start_time' => $coupon['valid_start_time'], // 开始使用时间 'valid_end_time' => $coupon['valid_end_time'], // 结束使用时间 ]; $data['popup_content'] = json_encode($popup_content, JSON_UNESCAPED_UNICODE); $popup = Popup::addPopup($data); if (empty($popup)) { return false; } } // 添加优惠卷过期队列 $valid_end_time = strtotime($user_coupon->valid_end_time); $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; } }catch (\Throwable $e){ Log::getInstance("CouponService-GrantUserCoupon")->error($e->getMessage()); return false; } try { // 添加优惠卷即将过期提醒队列 if ($time > 60 * 60 * 24 * 2) { $time = 60 * 60 * 24 * 2; } else { if ($time > 60 * 60 * 5){ $time = $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']); }catch (\Throwable $e){ Log::getInstance("CouponService-GrantUserCoupon")->error($e->getMessage()); } return true; } /** * 发放注册用户优惠卷 * @param string $user_id 用户id * @return bool */ public function GrantRegisterCoupon(string $user_id): bool { // 获取注册用户可领取的优惠卷列表 $coupon = Coupon::getRegisterCouponList(); if (empty($coupon)) { return true; } foreach ($coupon as $value){ // 发放优惠卷 $res = $this->GrantUserCoupon($value['coupon_id'],$user_id); if (!$res){ // 发放失败 Log::getInstance("CouponService-GrantRegisterCoupon")->error("发放注册用户优惠卷"); } } return true; } }