修改我的医生,新增优惠卷过期
This commit is contained in:
parent
dc4f85f3d9
commit
882127a9bb
@ -1,50 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Amqp\Consumer;
|
||||
|
||||
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 CouponExpiredDelayDirectConsumer extends ConsumerMessage
|
||||
{
|
||||
use ProducerDelayedMessageTrait;
|
||||
use ConsumerDelayedMessageTrait;
|
||||
|
||||
protected string $exchange = 'amqp.delay.direct';
|
||||
|
||||
protected ?string $queue = 'coupon.expired.delay.queue';
|
||||
|
||||
protected string $type = Type::DIRECT; //Type::FANOUT;
|
||||
|
||||
protected string|array $routingKey = 'CouponExpired';
|
||||
|
||||
public function consumeMessage($data, AMQPMessage $message): string
|
||||
{
|
||||
Log::getInstance()->error("开始执行 取消过期优惠卷 队列:" . json_encode($data, JSON_UNESCAPED_UNICODE));
|
||||
|
||||
Db::beginTransaction();
|
||||
try {
|
||||
|
||||
Db::commit();
|
||||
Log::getInstance()->info("取消过期优惠卷 队列执行成功");
|
||||
return Result::ACK;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollBack();
|
||||
Log::getInstance()->error("取消过期优惠卷 队列执行失败:" . $e->getMessage());
|
||||
return Result::ACK; // 重回队列
|
||||
}
|
||||
}
|
||||
}
|
||||
117
app/Amqp/Consumer/UserCouponExpiredDelayDirectConsumer.php
Normal file
117
app/Amqp/Consumer/UserCouponExpiredDelayDirectConsumer.php
Normal file
@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Amqp\Consumer;
|
||||
|
||||
use App\Amqp\Producer\AutoCompleteInquiryDelayDirectProducer;
|
||||
use App\Amqp\Producer\UserCouponExpiredDelayDirectProducer;
|
||||
use App\Constants\HttpEnumCode;
|
||||
use App\Model\UserCoupon;
|
||||
use App\Utils\Log;
|
||||
use Hyperf\Amqp\Message\ConsumerDelayedMessageTrait;
|
||||
use Hyperf\Amqp\Message\ProducerDelayedMessageTrait;
|
||||
use Hyperf\Amqp\Message\Type;
|
||||
use Hyperf\Amqp\Producer;
|
||||
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 UserCouponExpiredDelayDirectConsumer extends ConsumerMessage
|
||||
{
|
||||
use ProducerDelayedMessageTrait;
|
||||
use ConsumerDelayedMessageTrait;
|
||||
|
||||
protected string $exchange = 'amqp.delay.direct';
|
||||
|
||||
protected ?string $queue = 'user.coupon.expired.delay.queue';
|
||||
|
||||
protected string $type = Type::DIRECT; //Type::FANOUT;
|
||||
|
||||
protected string|array $routingKey = 'UserCouponExpired';
|
||||
|
||||
public function consumeMessage($data, AMQPMessage $message): string
|
||||
{
|
||||
Log::getInstance()->error("开始执行 处理用户优惠卷过期 队列:" . json_encode($data, JSON_UNESCAPED_UNICODE));
|
||||
|
||||
Db::beginTransaction();
|
||||
try {
|
||||
// 检测参数
|
||||
if (!isset($data['user_coupon_id'])){
|
||||
Db::rollBack();
|
||||
Log::getInstance()->error("处理用户优惠卷过期队列 执行失败:入参错误");
|
||||
return Result::DROP;
|
||||
}
|
||||
|
||||
// 获取优惠卷数据
|
||||
$params = array();
|
||||
$params['user_coupon_id'] = $data['user_coupon_id'];
|
||||
$user_coupon = UserCoupon::getOne($params);
|
||||
if (empty($user_coupon)){
|
||||
Db::rollBack();
|
||||
Log::getInstance()->info("处理用户优惠卷过期队列 执行结束:无优惠卷数据");
|
||||
return Result::DROP;
|
||||
}
|
||||
|
||||
// 检测优惠卷是否被使用
|
||||
if ($user_coupon['user_coupon_status'] == 1){
|
||||
Db::rollBack();
|
||||
Log::getInstance()->info("处理用户优惠卷过期队列 执行结束:优惠卷已被使用,无需处理");
|
||||
return Result::DROP;
|
||||
}
|
||||
|
||||
// 检测优惠卷是否已执行过期处理
|
||||
if ($user_coupon['user_coupon_status'] == 3){
|
||||
Db::rollBack();
|
||||
Log::getInstance()->info("处理用户优惠卷过期队列 执行结束:优惠卷已执行过期处理,无需处理");
|
||||
return Result::DROP;
|
||||
}
|
||||
|
||||
// 检测优惠卷过期时间
|
||||
$valid_end_time = strtotime($user_coupon['valid_end_time']);
|
||||
|
||||
// 处理未过期事件
|
||||
// 先删除-重新添加队列
|
||||
if ($valid_end_time > time()){
|
||||
$time = $valid_end_time - time();
|
||||
|
||||
$queue_data = array();
|
||||
$queue_data['order_inquiry_id'] = $data['order_inquiry_id'];
|
||||
|
||||
$message = new UserCouponExpiredDelayDirectProducer($queue_data);
|
||||
$message->setDelayMs(1000 * $time);
|
||||
$producer = $this->container->get(Producer::class);
|
||||
$res = $producer->produce($message);
|
||||
if (!$res) {
|
||||
Db::rollBack();
|
||||
Log::getInstance()->error("处理用户优惠卷过期队列 执行失败:未到过期时间,重新添加队列失败");
|
||||
return Result::REQUEUE;
|
||||
}
|
||||
|
||||
return Result::DROP;
|
||||
}
|
||||
|
||||
// 处理已过期事件
|
||||
$params = array();
|
||||
$params['user_coupon_id'] = $user_coupon['user_coupon_id'];
|
||||
|
||||
$data = array();
|
||||
$data['user_coupon_status'] = 3;
|
||||
UserCoupon::edit($params, $data);
|
||||
|
||||
Db::commit();
|
||||
Log::getInstance()->info("处理用户优惠卷过期 队列执行成功");
|
||||
return Result::ACK;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollBack();
|
||||
Log::getInstance()->error("处理用户优惠卷过期 队列执行失败:" . $e->getMessage());
|
||||
return Result::REQUEUE; // 重回队列
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -10,10 +10,10 @@ use Hyperf\Amqp\Message\ProducerMessage;
|
||||
use Hyperf\Amqp\Message\Type;
|
||||
|
||||
/**
|
||||
* 优惠卷过期
|
||||
* 处理用户优惠卷过期
|
||||
*/
|
||||
#[Producer]
|
||||
class CouponExpiredDelayDirectProducer extends ProducerMessage
|
||||
class UserCouponExpiredDelayDirectProducer extends ProducerMessage
|
||||
{
|
||||
use ProducerDelayedMessageTrait;
|
||||
|
||||
@ -21,7 +21,7 @@ class CouponExpiredDelayDirectProducer extends ProducerMessage
|
||||
|
||||
protected string $type = Type::DIRECT;
|
||||
|
||||
protected string|array $routingKey = 'CouponExpired';
|
||||
protected string|array $routingKey = 'UserCouponExpired';
|
||||
|
||||
public function __construct($data)
|
||||
{
|
||||
@ -775,15 +775,6 @@ class TestController extends AbstractController
|
||||
|
||||
// 快递订阅
|
||||
public function test_14(){
|
||||
$data = array();
|
||||
$data['order_inquiry_id'] = "505311998932189184";
|
||||
|
||||
$message = new AutoCompleteInquiryDelayDirectProducer($data);
|
||||
$message->setDelayMs(1000 * 10);
|
||||
$producer = $this->container->get(Producer::class);
|
||||
$res = $producer->produce($message);
|
||||
if (!$res) {
|
||||
return fail(HttpEnumCode::SERVER_ERROR, "订单创建失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2,8 +2,15 @@
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Amqp\Producer\AutoCompleteInquiryDelayDirectProducer;
|
||||
use App\Amqp\Producer\UserCouponExpiredDelayDirectProducer;
|
||||
use App\Constants\HttpEnumCode;
|
||||
use App\Model\Coupon;
|
||||
use App\Model\UserCoupon;
|
||||
use Hyperf\Amqp\Producer;
|
||||
use Hyperf\DbConnection\Db;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
/**
|
||||
* 优惠卷
|
||||
@ -76,6 +83,8 @@ class CouponService extends BaseService
|
||||
* @param string $patient_id
|
||||
* @param int $coupon_client 使用平台(1:小程序)
|
||||
* @return bool
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function DistributeCoupon(int $distribution_object,string $user_id,string $patient_id,int $coupon_client = 1): bool
|
||||
{
|
||||
@ -113,8 +122,22 @@ class CouponService extends BaseService
|
||||
return false;
|
||||
}
|
||||
|
||||
$res = UserCoupon::addUserCoupon($data);
|
||||
if (empty($res)){
|
||||
$user_coupon = UserCoupon::addUserCoupon($data);
|
||||
if (empty($user_coupon)){
|
||||
return false;
|
||||
}
|
||||
|
||||
// 添加用户优惠卷自动过期队列
|
||||
// 添加自动完成队列
|
||||
$data = array();
|
||||
$data['user_coupon_id'] = $user_coupon['user_coupon_id'];
|
||||
|
||||
$time = $data['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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1086,24 +1086,8 @@ class InquiryService extends BaseService
|
||||
|
||||
// 处理订单优惠卷
|
||||
if (!empty($order_inquiry['coupon_amount_total']) && $order_inquiry['coupon_amount_total'] > 0) {
|
||||
// 获取用户优惠卷信息
|
||||
$params = array();
|
||||
$params['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||||
$order_inquiry_coupon = OrderInquiryCoupon::getOne($params);
|
||||
if (!empty($order_inquiry_coupon)) {
|
||||
// 恢复优惠卷
|
||||
$data = array();
|
||||
$data['user_coupon_status'] = 0;
|
||||
$data['coupon_use_date'] = date('Y-m-d H:i:s', time());
|
||||
|
||||
$params = array();
|
||||
$params['user_coupon_id'] = $order_inquiry_coupon['user_coupon_id'];
|
||||
UserCoupon::edit($params, $data);
|
||||
|
||||
// 发送站内消息-优惠卷退还
|
||||
$MessagePush = new MessagePush($order_inquiry['user_id'],$order_inquiry['order_inquiry_id']);
|
||||
$MessagePush->patientRefundCoupon();
|
||||
}
|
||||
$InquiryService = new InquiryService();
|
||||
$InquiryService->returnInquiryCoupon($order_inquiry['order_inquiry_id'], $order_inquiry['user_id']);
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
||||
@ -45,14 +45,9 @@ class LoginService extends BaseService
|
||||
if (empty($phone_info) || empty($phone_info['phone_info']) || empty($phone_info['phone_info']['purePhoneNumber'])){
|
||||
return fail(HttpEnumCode::GET_WX_ERROR);
|
||||
}
|
||||
// $phone_info['phone_info']['purePhoneNumber'] = "18221234162";
|
||||
|
||||
// 获取用户openid
|
||||
$wx_info_data = $weChat->codeToSession($wx_code);
|
||||
// $wx_info_data = array(
|
||||
// "session_key" => "SWfpkHtKZRq/G0ONoxigaQ==",
|
||||
// "openid" => "o9gYG441zEAHuYoNX7lwFKiQBzKE",
|
||||
// );
|
||||
if (empty($wx_info_data['session_key']) || empty($wx_info_data['openid'])) {
|
||||
return fail(HttpEnumCode::GET_WX_ERROR);
|
||||
}
|
||||
|
||||
@ -508,7 +508,7 @@ class PatientDoctorService extends BaseService
|
||||
|
||||
// 处理数据
|
||||
if (!empty($result['data'])) {
|
||||
foreach ($result['data'] as $item) {
|
||||
foreach ($result['data'] as &$item) {
|
||||
$data = array();
|
||||
|
||||
// 医生专长
|
||||
@ -531,7 +531,7 @@ class PatientDoctorService extends BaseService
|
||||
// 职称
|
||||
$data['user_doctor']['doctor_title_name'] = empty($data['user_doctor']['doctor_title']) ? "" : DoctorTitleCode::getMessage($data['user_doctor']['doctor_title']);
|
||||
|
||||
$result['data'][] = $data;
|
||||
$item = $data;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user