修改库存

This commit is contained in:
wucongxing 2023-03-27 15:00:53 +08:00
parent caa92df22e
commit 4a0a162297
9 changed files with 157 additions and 85 deletions

View File

@ -18,22 +18,13 @@ use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface; use Psr\Container\NotFoundExceptionInterface;
/** /**
* 发送短信 * 短信推送
*/ */
#[Consumer(exchange: 'amqp.direct', routingKey: 'SendSmsMessage', queue: 'send.sms.message.queue', nums: 1)] #[Consumer(exchange: 'amqp.direct', routingKey: 'SendSmsMessage', queue: 'send.sms.message.queue', nums: 1)]
class SendSmsMessageConsumer extends ConsumerMessage class SendSmsMessageConsumer extends ConsumerMessage
{ {
/** /**
* @param $data * @param $data
* [
* "template_code" => "SMS_123",
* "template_param" => [
* // 参数不确定,主要看短信模版的不同
* ],
* "scene_desc" => "场景描述",
* "phone" => "手机号",
* "user_id" => "用户id被推送者"
* ]
* @param AMQPMessage $message * @param AMQPMessage $message
* @return string * @return string
* @throws ContainerExceptionInterface * @throws ContainerExceptionInterface
@ -41,17 +32,17 @@ class SendSmsMessageConsumer extends ConsumerMessage
*/ */
public function consumeMessage($data, AMQPMessage $message): string public function consumeMessage($data, AMQPMessage $message): string
{ {
Log::getInstance()->error("开始执行 发送短信 队列:" . json_encode($data, JSON_UNESCAPED_UNICODE)); Log::getInstance()->error("开始执行 短信推送 队列:" . json_encode($data, JSON_UNESCAPED_UNICODE));
if (!isset($data['template_code']) || !isset($data['template_param'])){ if (!isset($data['template_code']) || !isset($data['template_param'])){
Log::getInstance()->error("队列发送短信失败:发送参数错误"); Log::getInstance()->error("短信推送失败:发送参数错误");
return Result::DROP;// 销毁 return Result::DROP;// 销毁
} }
// 验证发送参数 // 验证发送参数
$res = $this->checkTemplateParam($data['template_code'],$data['template_param']); $res = $this->checkTemplateParam($data['template_code'],$data['template_param']);
if (!$res){ if (!$res){
Log::getInstance()->error("队列发送短信失败:发送参数错误"); Log::getInstance()->error("短信推送失败:发送参数错误");
return Result::DROP;// 销毁 return Result::DROP;// 销毁
} }
@ -63,7 +54,7 @@ class SendSmsMessageConsumer extends ConsumerMessage
if (!empty($result)){ if (!empty($result)){
if ( $result > 2){ if ( $result > 2){
// 超出规定时间内最大获取次数 // 超出规定时间内最大获取次数
Log::getInstance()->error("队列发送短信失败:超出最大发送重试次数"); Log::getInstance()->error("短信推送失败:超出最大发送重试次数");
return Result::DROP;// 销毁 return Result::DROP;// 销毁
} }
} }
@ -76,14 +67,14 @@ class SendSmsMessageConsumer extends ConsumerMessage
$redis->del($redis_key); $redis->del($redis_key);
} }
} catch (\Exception $e) { } catch (\Exception $e) {
Log::getInstance()->error("队列发送短信失败:" . $e->getMessage()); Log::getInstance()->error("短信推送失败:" . $e->getMessage());
// 增加发送次数 // 增加发送次数
$redis->incr($redis_key); $redis->incr($redis_key);
return Result::REQUEUE; // 重回队列 return Result::REQUEUE; // 重回队列
} }
Log::getInstance()->info("队列发送短信成功"); Log::getInstance()->info("短信推送成功");
return Result::ACK; return Result::ACK;
} }

View File

@ -0,0 +1,70 @@
<?php
declare(strict_types=1);
namespace App\Amqp\Consumer;
use App\Model\MessageNotice;
use App\Services\ImService;
use App\Utils\Log;
use Hyperf\Amqp\Result;
use Hyperf\Amqp\Annotation\Consumer;
use Hyperf\Amqp\Message\ConsumerMessage;
use PhpAmqpLib\Message\AMQPMessage;
/**
* 站内消息推送
*/
#[Consumer(exchange: 'amqp.direct', routingKey: 'SendStationMessage', queue: 'send.station.message.queue',nums: 1)]
class SendStationMessageConsumer extends ConsumerMessage
{
public function consumeMessage($data, AMQPMessage $message): string
{
Log::getInstance()->info("开始执行 站内消息推送 队列:" . json_encode($data, JSON_UNESCAPED_UNICODE));
// 验证参数
if (!isset($data['notice_id'])){
Log::getInstance()->info("站内消息推送失败:参数错误");
return Result::DROP;
}
// 获取推送信息数据
$params = array();
$params['notice_id'] = $data['notice_id'];
$message_notice = MessageNotice::getOne($params);
if (empty($message_notice)){
Log::getInstance()->info("站内消息推送失败:无推送表数据");
return Result::DROP;
}
try {
} catch (\Exception $e) {
Log::getInstance()->error("站内消息推送执行失败:" . $e->getMessage());
}
// 处理推送参数
$ImService = new ImService();
// 发送消息
// 自定义消息
$cloud_custom_data = array();
$cloud_custom_data['order_inquiry_id'] = "494837308861095936";
$cloud_custom_data['is_system'] = 1;
$cloud_custom_data['inquiry_type'] = 1;
// 消息内容
$message_content_data = array();
$message_content_data['message_type'] = 1;
$message_content_data['content'] = "--测试--";
$message_content_data['desc'] = "温馨提示:您可继续补充问诊内容,便于更快确认病情,医生均在临床一线工作,还请耐心等待,医生接诊会第一时间短信通知您。";
$message_content = [
'Data' => json_encode($message_content_data,JSON_UNESCAPED_UNICODE),
];
$ImService->sendMessage("491925054435950592", "492404831991414785", $message_content, "TIMCustomElem", $cloud_custom_data);
Log::getInstance()->info("站内消息推送成功");
return Result::ACK;
}
}

View File

@ -30,7 +30,7 @@ use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
/** /**
* 发送订阅消息 * 订阅消息推送
* 每条消息都需携带发送短信参数,用户可能拒绝接受订阅消息 * 每条消息都需携带发送短信参数,用户可能拒绝接受订阅消息
*/ */
#[Consumer(exchange: 'amqp.direct', routingKey: 'SendSubMessage', queue: 'send.sub.message.queue', nums: 1)] #[Consumer(exchange: 'amqp.direct', routingKey: 'SendSubMessage', queue: 'send.sub.message.queue', nums: 1)]
@ -38,33 +38,6 @@ class SendSubMessageConsumer extends ConsumerMessage
{ {
/** /**
* @param $data * @param $data
* [
* "sub_data" => [
* "push_user_id" // 用户id被推送者
* "template_title" // 推送的模版名称
* "send_reason" // 发送原因
* "params" => [ // 推送所需的参数
* "page" // 跳转页面
* "data" => [
* "key1" => "value1" // 入参数据结构
// * "thing1" => [ // 发送时处理的数据结构
// * "value" => [
// * "参数1"
// * ]
// * ]
* ]
* ],
* ]
* "sms_data" => [ // 短信所需的参数,如订阅发送失败需发送短信
* "template_code" => "SMS_123",
* "template_param" => [
* // 参数不确定,主要看短信模版的不同
* ],
* "scene_desc" => "场景描述",
* "phone" => "手机号",
* "user_id" => "用户id被推送者"
* ]
* ]
* @param AMQPMessage $message * @param AMQPMessage $message
* @return string * @return string
* @throws ContainerExceptionInterface * @throws ContainerExceptionInterface
@ -77,7 +50,7 @@ class SendSubMessageConsumer extends ConsumerMessage
*/ */
public function consumeMessage($data, AMQPMessage $message): string public function consumeMessage($data, AMQPMessage $message): string
{ {
Log::getInstance()->info("开始执行 发送订阅消息 队列:" . json_encode($data, JSON_UNESCAPED_UNICODE)); Log::getInstance()->info("开始执行 订阅消息推送 队列:" . json_encode($data, JSON_UNESCAPED_UNICODE));
try { try {
// 获取被推送用户信息 // 获取被推送用户信息
@ -85,13 +58,13 @@ class SendSubMessageConsumer extends ConsumerMessage
$params['user_id'] = $data['push_user_id']; $params['user_id'] = $data['push_user_id'];
$user = User::getOne($params); $user = User::getOne($params);
if (empty($user)){ if (empty($user)){
Log::getInstance()->error("队列发送订阅消息执行失败:未查询到被推送用户信息"); Log::getInstance()->error("订阅消息推送执行失败:未查询到被推送用户信息");
return Result::ACK; return Result::ACK;
} }
// 验证发送参数 // 验证发送参数
if (empty($data['sub_data']['params']['data'])){ if (empty($data['sub_data']['params']['data'])){
Log::getInstance()->error("队列发送订阅消息执行失败:无推送数据"); Log::getInstance()->error("订阅消息推送执行失败:无推送数据");
$this->saveErrorPushLog($user['user_type'],$data['sub_data'],"无推送数据"); $this->saveErrorPushLog($user['user_type'],$data['sub_data'],"无推送数据");
return Result::DROP; return Result::DROP;
@ -108,7 +81,7 @@ class SendSubMessageConsumer extends ConsumerMessage
} }
if (empty($send_data)){ if (empty($send_data)){
Log::getInstance()->error("队列发送订阅消息执行失败:发送参数处理失败"); Log::getInstance()->error("订阅消息推送执行失败:发送参数处理失败");
$this->saveErrorPushLog($user['user_type'],$data['sub_data'],"发送参数处理失败"); $this->saveErrorPushLog($user['user_type'],$data['sub_data'],"发送参数处理失败");
return Result::DROP; return Result::DROP;
@ -119,7 +92,7 @@ class SendSubMessageConsumer extends ConsumerMessage
$UserService = new UserService(); $UserService = new UserService();
$open_id = $UserService->getOpenIdWithUserId($user['user_id'],$user['user_type']); $open_id = $UserService->getOpenIdWithUserId($user['user_id'],$user['user_type']);
if (empty($open_id)){ if (empty($open_id)){
Log::getInstance()->error("队列发送订阅消息执行失败未获取到被推送用户open_id"); Log::getInstance()->error("订阅消息推送执行失败未获取到被推送用户open_id");
$this->saveErrorPushLog($user['user_type'],$data['sub_data'],"未获取到被推送用户open_id"); $this->saveErrorPushLog($user['user_type'],$data['sub_data'],"未获取到被推送用户open_id");
// 执行发送短信步骤 // 执行发送短信步骤
@ -131,7 +104,7 @@ class SendSubMessageConsumer extends ConsumerMessage
// 获取消息模版 // 获取消息模版
$sub_template = $this->getSubTemplate($user['user_type'],$data['sub_data']['template_title']); $sub_template = $this->getSubTemplate($user['user_type'],$data['sub_data']['template_title']);
if (empty($template_title)){ if (empty($template_title)){
Log::getInstance()->error("队列发送订阅消息执行失败:未获取到需要发送的消息模版数据"); Log::getInstance()->error("订阅消息推送执行失败:未获取到需要发送的消息模版数据");
$this->saveErrorPushLog($user['user_type'],$data['sub_data'],"未获取到需要发送的消息模版数据"); $this->saveErrorPushLog($user['user_type'],$data['sub_data'],"未获取到需要发送的消息模版数据");
// 执行发送短信步骤 // 执行发送短信步骤
@ -159,17 +132,17 @@ class SendSubMessageConsumer extends ConsumerMessage
$Wechat = new Wechat($user['user_type']); $Wechat = new Wechat($user['user_type']);
$result = $Wechat->sendSubscribeMessage($options); $result = $Wechat->sendSubscribeMessage($options);
if (empty($result)){ if (empty($result)){
Log::getInstance()->error("队列发送订阅消息执行失败:推送失败"); Log::getInstance()->error("订阅消息推送执行失败:推送失败");
$this->saveErrorPushLog($user['user_type'],$data['sub_data'],"推送失败"); $this->saveErrorPushLog($user['user_type'],$data['sub_data'],"推送失败");
} }
if (!isset($result['errcode'])){ if (!isset($result['errcode'])){
Log::getInstance()->error("队列发送订阅消息执行失败:推送失败,返回值错误" . json_encode($result,JSON_UNESCAPED_UNICODE)); Log::getInstance()->error("订阅消息推送执行失败:推送失败,返回值错误" . json_encode($result,JSON_UNESCAPED_UNICODE));
$this->saveErrorPushLog($user['user_type'],$data['sub_data'],"推送失败,返回值错误"); $this->saveErrorPushLog($user['user_type'],$data['sub_data'],"推送失败,返回值错误");
} }
if ($result['errcode'] == 43101){ if ($result['errcode'] == 43101){
Log::getInstance()->error("队列发送订阅消息执行失败:用户拒绝接收消息"); Log::getInstance()->error("订阅消息推送执行失败:用户拒绝接收消息");
$this->saveErrorPushLog($user['user_type'],$data['sub_data'],"用户拒绝接收消息"); $this->saveErrorPushLog($user['user_type'],$data['sub_data'],"用户拒绝接收消息");
// 执行发送短信步骤 // 执行发送短信步骤
@ -178,11 +151,11 @@ class SendSubMessageConsumer extends ConsumerMessage
return Result::ACK; return Result::ACK;
} }
Log::getInstance()->info("队列发送订阅消息执行成功"); Log::getInstance()->info("订阅消息推送执行成功");
$this->saveSuccessPushLog($user['user_type'],$data['sub_data']); $this->saveSuccessPushLog($user['user_type'],$data['sub_data']);
} catch (\Exception $e) { } catch (\Exception $e) {
Log::getInstance()->error("队列发送订阅消息执行失败:" . $e->getMessage()); Log::getInstance()->error("订阅消息推送执行失败:" . $e->getMessage());
$this->saveErrorPushLog($user['user_type'],$data['sub_data'],$e->getMessage()); $this->saveErrorPushLog($user['user_type'],$data['sub_data'],$e->getMessage());
} }
@ -206,7 +179,7 @@ class SendSubMessageConsumer extends ConsumerMessage
$data['content'] = json_encode($sub_data['params'],JSON_UNESCAPED_UNICODE); $data['content'] = json_encode($sub_data['params'],JSON_UNESCAPED_UNICODE);
$log_message_push = LogMessagePush::addLogMessagePush($data); $log_message_push = LogMessagePush::addLogMessagePush($data);
if (empty($log_message_push)){ if (empty($log_message_push)){
Log::getInstance()->error("队列发送订阅消息成功,增加推送日志失败:" . json_encode($data,JSON_UNESCAPED_UNICODE)); Log::getInstance()->error("订阅消息推送成功,增加推送日志失败:" . json_encode($data,JSON_UNESCAPED_UNICODE));
} }
} }
@ -229,7 +202,7 @@ class SendSubMessageConsumer extends ConsumerMessage
$data['content'] = json_encode($sub_data['params'],JSON_UNESCAPED_UNICODE); $data['content'] = json_encode($sub_data['params'],JSON_UNESCAPED_UNICODE);
$log_message_push = LogMessagePush::addLogMessagePush($data); $log_message_push = LogMessagePush::addLogMessagePush($data);
if (empty($log_message_push)){ if (empty($log_message_push)){
Log::getInstance()->error("队列发送订阅消息成功,增加推送日志失败:" . json_encode($data,JSON_UNESCAPED_UNICODE)); Log::getInstance()->error("订阅消息推送成功,增加推送日志失败:" . json_encode($data,JSON_UNESCAPED_UNICODE));
} }
} }
@ -247,25 +220,25 @@ class SendSubMessageConsumer extends ConsumerMessage
try { try {
if (empty($sms_data)){ if (empty($sms_data)){
// 无需发送短信 // 无需发送短信
Log::getInstance()->info("无数据需添加短信队列"); Log::getInstance()->info("无数据需添加短信推送队列");
return true; return true;
} }
Log::getInstance()->info("添加短信队列"); Log::getInstance()->info("添加短信推送队列");
// 增加至发送短信队列 // 增加至发送短信队列
$message = new SendSmsMessageProducer($sms_data); $message = new SendSmsMessageProducer($sms_data);
$producer = $this->container->get(Producer::class); $producer = $this->container->get(Producer::class);
$res = $producer->produce($message); $res = $producer->produce($message);
if (!$res) { if (!$res) {
Log::getInstance()->error("添加短信队列失败" . json_encode($sms_data,JSON_UNESCAPED_UNICODE)); Log::getInstance()->error("添加短信推送队列失败" . json_encode($sms_data,JSON_UNESCAPED_UNICODE));
} }
} catch (\Exception $e) { } catch (\Exception $e) {
Log::getInstance()->error("添加短信队列失败" . $e->getMessage()); Log::getInstance()->error("添加短信推送队列失败" . $e->getMessage());
} }
Log::getInstance()->info("添加短信队列成功"); Log::getInstance()->info("添加短信推送队列成功");
return true; return true;
} }

View File

@ -8,11 +8,23 @@ use Hyperf\Amqp\Annotation\Producer;
use Hyperf\Amqp\Message\ProducerMessage; use Hyperf\Amqp\Message\ProducerMessage;
/** /**
* 发送短信 * 短信推送
*/ */
#[Producer(exchange: 'amqp.direct', routingKey: 'SendSmsMessage')] #[Producer(exchange: 'amqp.direct', routingKey: 'SendSmsMessage')]
class SendSmsMessageProducer extends ProducerMessage class SendSmsMessageProducer extends ProducerMessage
{ {
/**
* @param $data
* [
* "template_code" => "SMS_123",
* "template_param" => [
* // 参数不确定,主要看短信模版的不同
* ],
* "scene_desc" => "场景描述",
* "phone" => "手机号",
* "user_id" => "用户id被推送者"
* ]
*/
public function __construct($data) public function __construct($data)
{ {
$this->payload = $data; $this->payload = $data;

View File

@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
namespace App\Amqp\Producer;
use Hyperf\Amqp\Annotation\Producer;
use Hyperf\Amqp\Message\ProducerMessage;
#[Producer(exchange: 'amqp.direct', routingKey: 'SendStationMessage')]
class SendStationMessageProducer extends ProducerMessage
{
/**
* @param $data
* [
* "notice_id":"通知消息表主键id"
* ]
*/
public function __construct($data)
{
$this->payload = $data;
}
}

View File

@ -9,7 +9,7 @@ use Hyperf\Amqp\Annotation\Producer;
use Hyperf\Amqp\Message\ProducerMessage; use Hyperf\Amqp\Message\ProducerMessage;
/** /**
* 发送订阅消息 * 订阅消息推送
*/ */
#[Producer(exchange: 'amqp.direct', routingKey: 'SendSubMessage')] #[Producer(exchange: 'amqp.direct', routingKey: 'SendSubMessage')]
class SendSubMessageProducer extends ProducerMessage class SendSubMessageProducer extends ProducerMessage
@ -17,18 +17,25 @@ class SendSubMessageProducer extends ProducerMessage
/** /**
* @param array $data * @param array $data
* [ * [
* "push_user_id" // 用户id被推送者 * "sub_data" => [
* "template_title" // 推送的模版名称 * "push_user_id" // 用户id被推送者
* "params" => [ // 推送所需的参数 * "template_title" // 推送的模版名称
* "page" // 跳转页面 * "send_reason" // 发送原因
* "data" => [ * "params" => [ // 推送所需的参数
* "thing1" => [ * "page" // 跳转页面
* "value" => [ * "data" => [
* "参数1" * "key1" => "value1" // 入参数据结构
* ]
* ] * ]
* ] * ],
* * ]
* "sms_data" => [ // 短信所需的参数,如订阅发送失败需发送短信
* "template_code" => "SMS_123",
* "template_param" => [
* // 参数不确定,主要看短信模版的不同
* ],
* "scene_desc" => "场景描述",
* "phone" => "手机号",
* "user_id" => "用户id被推送者"
* ] * ]
* ] * ]
*/ */

View File

@ -131,7 +131,7 @@ class OrderPrescriptionProduct extends Model
* @param array $data * @param array $data
* @return Model|OrderPrescriptionProduct * @return Model|OrderPrescriptionProduct
*/ */
public static function addOrderPrescriptionProduct(array $data): \Hyperf\Database\Model\Model|OrderPrescriptionProduct public static function addOrderPrescriptionProduct(array $data): Model|OrderPrescriptionProduct
{ {
return self::create($data); return self::create($data);
} }

View File

@ -1154,13 +1154,8 @@ class UserDoctorService extends BaseService
$params = array(); $params = array();
$params['doctor_id'] = $user_info['client_user_id']; $params['doctor_id'] = $user_info['client_user_id'];
$fields = [
'doctor_id', $user_doctor = UserDoctor::getOne($params);
'iden_auth_status',
'idcard_status',
'multi_point_status',
];
$user_doctor = UserDoctor::getOne($params, $fields);
if (empty($user_doctor)) { if (empty($user_doctor)) {
return fail(HttpEnumCode::HTTP_ERROR, "非法医生"); return fail(HttpEnumCode::HTTP_ERROR, "非法医生");
} }
@ -1201,6 +1196,8 @@ class UserDoctorService extends BaseService
$data = array(); $data = array();
$data['order_inquiry_id'] = $order_inquiry_id; $data['order_inquiry_id'] = $order_inquiry_id;
$data['doctor_id'] = $user_info['client_user_id']; $data['doctor_id'] = $user_info['client_user_id'];
$data['patient_id'] = $order_inquiry['patient_id'];
$data['family_id'] = $order_inquiry['family_id'];
$data['prescription_status'] = 1; $data['prescription_status'] = 1;
$data['prescription_code'] = $generator->generate(); // 处方编号 $data['prescription_code'] = $generator->generate(); // 处方编号
$data['doctor_name'] = $user_doctor['user_name']; // 医生名称 $data['doctor_name'] = $user_doctor['user_name']; // 医生名称
@ -1246,7 +1243,7 @@ class UserDoctorService extends BaseService
$product = Product::getWithAmountOne($params); $product = Product::getWithAmountOne($params);
if (empty($product)) { if (empty($product)) {
Db::rollBack(); Db::rollBack();
return fail(); return fail(HttpEnumCode::HTTP_ERROR,"商品库存不足");
} }
if (empty($product['ProductPlatformAmount'])) { if (empty($product['ProductPlatformAmount'])) {

View File

@ -401,7 +401,6 @@ Router::addGroup('/patient', function () {
// 获取患者服务、福利、退款、物流消息通知列表-分页 // 获取患者服务、福利、退款、物流消息通知列表-分页
Router::get('/system', [MessageNoticeController::class, 'getPatientMessageSystem']); Router::get('/system', [MessageNoticeController::class, 'getPatientMessageSystem']);
}); });
}); });
// 药师端api // 药师端api