新增优惠卷即将过期通知

This commit is contained in:
wucongxing 2023-05-04 09:37:17 +08:00
parent 5e35083c64
commit 113f9e34a1
5 changed files with 181 additions and 34 deletions

View File

@ -103,7 +103,7 @@ class AssignPharmacistConsumer extends ConsumerMessage
Log::getInstance()->error("分配药师队列执行失败原因:" . $e->getMessage());
// 分配失败,按照驳回处理
$this->reject($data['order_prescription_id'], $user_doctor['user_id'], $order_prescription['order_inquiry_id']);
$this->reject($data['order_prescription_id'], $user_doctor['user_id'],$user_patient['user_id'], $order_prescription['order_inquiry_id']);
return Result::DROP; // 重回队列
}

View File

@ -0,0 +1,99 @@
<?php
declare(strict_types=1);
namespace App\Amqp\Consumer;
use App\Model\Coupon;
use App\Model\UserCoupon;
use App\Services\MessagePush;
use App\Utils\Log;
use Hyperf\Amqp\Message\ConsumerDelayedMessageTrait;
use Hyperf\Amqp\Message\ProducerDelayedMessageTrait;
use Hyperf\Amqp\Message\Type;
use Hyperf\Amqp\Result;
use Hyperf\Amqp\Annotation\Consumer;
use Hyperf\Amqp\Message\ConsumerMessage;
use Hyperf\DbConnection\Db;
use PhpAmqpLib\Message\AMQPMessage;
/**
* 用户优惠卷即将过期通知
*/
#[Consumer(nums: 1)]
class UserCouponExpiredNoticeDelayDirectConsumer extends ConsumerMessage
{
use ProducerDelayedMessageTrait;
use ConsumerDelayedMessageTrait;
protected string $exchange = 'amqp.delay.direct';
protected ?string $queue = 'user.coupon.expired.notice.delay.queue';
protected string $type = Type::DIRECT; //Type::FANOUT;
protected string|array $routingKey = 'UserCouponExpiredNotice';
public function consumeMessage($data, AMQPMessage $message): string
{
Log::getInstance("queue-UserCouponExpiredNotice")->error("开始:" . json_encode($data, JSON_UNESCAPED_UNICODE));
// 检测参数
if (!isset($data['user_coupon_id'])){
Db::rollBack();
Log::getInstance("queue-UserCouponExpiredNotice")->error("错误:入参错误");
return Result::DROP;
}
// 获取优惠卷数据
$params = array();
$params['user_coupon_id'] = $data['user_coupon_id'];
$user_coupon = UserCoupon::getOne($params);
if (empty($user_coupon)){
Log::getInstance("queue-UserCouponExpiredNotice")->error("错误:无优惠卷数据");
return Result::DROP;
}
// 检测优惠卷是否被使用
if ($user_coupon['user_coupon_status'] == 1){
Log::getInstance("queue-UserCouponExpiredNotice")->info("结束:优惠卷已被使用,无需处理");
return Result::DROP;
}
// 检测优惠卷是否已执行过期处理
if ($user_coupon['user_coupon_status'] == 3){
Log::getInstance("queue-UserCouponExpiredNotice")->info("结束:优惠卷已执行过期处理,无需处理");
return Result::DROP;
}
// 检测优惠卷过期时间
$valid_end_time = strtotime($user_coupon['valid_end_time']);
if ($valid_end_time <= time()){
// 已过期,无需处理
Log::getInstance("queue-UserCouponExpiredNotice")->info("结束:优惠卷过期,无需处理");
return Result::DROP;
}
$params = array();
$params['coupon_id'] = $user_coupon['coupon_id'];
$coupon = Coupon::getOne($params);
if (empty($coupon)){
Log::getInstance("queue-UserCouponExpiredNotice")->error("错误:无优惠卷数据");
return Result::DROP;
}
try {
// 患者-优惠卷即将过期
$MessagePush = new MessagePush($user_coupon['user_id']);
$MessagePush->patientExpireCoupon($coupon['coupon_name']);
}catch (\Exception $e){
Log::getInstance("queue-UserCouponExpiredNotice")->error("错误:" . $e->getMessage());
return Result::DROP;
}
return Result::ACK;
}
}

View File

@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
namespace App\Amqp\Producer;
use Hyperf\Amqp\Annotation\Producer;
use Hyperf\Amqp\Message\ProducerDelayedMessageTrait;
use Hyperf\Amqp\Message\ProducerMessage;
use Hyperf\Amqp\Message\Type;
/**
* 用户优惠卷即将过期通知
*/
#[Producer]
class UserCouponExpiredNoticeDelayDirectProducer extends ProducerMessage
{
use ProducerDelayedMessageTrait;
protected string $exchange = 'amqp.delay.direct';
protected string $type = Type::DIRECT;
protected string|array $routingKey = 'UserCouponExpiredNotice';
public function __construct($data)
{
$this->payload = $data;
}
}

View File

@ -4,6 +4,7 @@ namespace App\Services;
use App\Amqp\Producer\AutoCompleteInquiryDelayDirectProducer;
use App\Amqp\Producer\UserCouponExpiredDelayDirectProducer;
use App\Amqp\Producer\UserCouponExpiredNoticeDelayDirectProducer;
use App\Constants\HttpEnumCode;
use App\Model\Coupon;
use App\Model\Popup;
@ -152,7 +153,7 @@ class CouponService extends BaseService
}
// 添加用户优惠卷自动过期队列
// 添加自动完成队列
// 添加优惠卷过期队列
$valid_end_time = strtotime($user_coupon->valid_end_time);
$data = array();
@ -167,8 +168,24 @@ class CouponService extends BaseService
return false;
}
// 添加优惠卷即将过期提醒队列
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) {
return false;
}
try {
// 患者-发送通知消息-优惠卷发放
// 患者-优惠卷发放
$MessagePush = new MessagePush($user_id);
$MessagePush->patientDistributeCoupon($value['coupon_name']);
} catch (\Exception $e) {

View File

@ -635,13 +635,14 @@ class MessagePush extends BaseService
}
/**
* 患者-优惠劵过期
* 患者-优惠劵即将过期
* 站内
* @param string $coupon_name
* @return void
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function patientExpireCoupon(): void
public function patientExpireCoupon(string $coupon_name): void
{
try {
$data = array();
@ -650,7 +651,7 @@ class MessagePush extends BaseService
$data['notice_system_type'] = 2; // 系统消息类型(患者端系统消息存在 1:服务消息 2:福利消息 3:退款消息 4:物流消息)
$data['from_name'] = "肝胆小秘书";
$data['notice_brief_title'] = "您有一张优惠劵即将过期,点击查看详情。";
$data['notice_title'] = "优惠劵名称】即将过期";
$data['notice_title'] = "{$coupon_name}】即将过期";
$data['notice_content'] = "您有一张优惠劵即将过期,点击查看详情!";
$data['link_type'] = 7;