新增物流状态推送,物流消息推送
This commit is contained in:
parent
2523d50e6c
commit
18a57fc781
@ -10,6 +10,7 @@ use App\Amqp\Producer\UserCouponExpiredDelayDirectProducer;
|
||||
use App\Constants\HttpEnumCode;
|
||||
use App\Model\OrderInquiry;
|
||||
use App\Services\InquiryService;
|
||||
use App\Services\MessagePush;
|
||||
use App\Services\UserDoctorService;
|
||||
use App\Utils\Log;
|
||||
use Hyperf\Amqp\Message\ConsumerDelayedMessageTrait;
|
||||
@ -69,69 +70,6 @@ class AssignDoctorDelayDirectConsumer extends ConsumerMessage
|
||||
|
||||
Db::beginTransaction();
|
||||
try {
|
||||
// 检测分配时间
|
||||
if ($diff_time > 300) {
|
||||
Log::getInstance("queue-AssignDoctor")->info("信息:超出5分钟,执行退款");
|
||||
|
||||
$InquiryService = new InquiryService();
|
||||
|
||||
// 检测问诊订单执行退款次数
|
||||
Log::getInstance("queue-AssignDoctor")->info("信息:检测执行退款次数");
|
||||
$res = $InquiryService->checkInquiryRefundCount($order_inquiry['order_inquiry_id']);
|
||||
if (!$res){
|
||||
Db::rollBack();
|
||||
Log::getInstance("queue-AssignDoctor")->error("错误:超出最大退款次数");
|
||||
return Result::ACK;
|
||||
}
|
||||
|
||||
Log::getInstance("queue-AssignDoctor")->info("信息:订单退款");
|
||||
$InquiryService->inquiryRefund($order_inquiry['order_inquiry_id'], "未分配到合适的医生");
|
||||
|
||||
Log::getInstance("queue-AssignDoctor")->info("信息:取消问诊订单");
|
||||
$save_data = array();
|
||||
$save_data['inquiry_status'] = 7;
|
||||
$save_data['cancel_time'] = date("Y-m-d H:i:s", time());
|
||||
$save_data['cancel_reason'] = 3; // 取消订单原因(1:医生未接诊 2:主动取消 3:无可分配医生 4:客服取消 5:支付超时)
|
||||
$save_data['cancel_remarks'] = "未分配到合适的医生"; // 取消订单备注
|
||||
$save_data['updated_at'] = date("Y-m-d H:i:s", time());
|
||||
|
||||
$params = array();
|
||||
$params['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||||
OrderInquiry::edit($params, $save_data);
|
||||
|
||||
Log::getInstance("queue-AssignDoctor")->info("结束");
|
||||
Db::commit();
|
||||
return Result::ACK;
|
||||
}
|
||||
|
||||
// 检测执行次数
|
||||
$res = $this->checkHandleNumber($data['order_inquiry_id']);
|
||||
if (!$res) {
|
||||
// 超出执行次数后,不再进行分配,按照结束分配时间,重新加入队列。
|
||||
Log::getInstance("queue-AssignDoctor")->info("信息:超出最大执行次数或检测错误");
|
||||
|
||||
Log::getInstance("queue-AssignDoctor")->info("信息:重新加入延迟队列");
|
||||
|
||||
$queue_data = array();
|
||||
$queue_data['order_inquiry_id'] = $data['order_inquiry_id'];
|
||||
|
||||
// 5分钟-支付时间-1s:10:00支付 此时10:04 5-(10:04-10:00)
|
||||
$time = 1000 * (300- (time() - $pay_time) - 1);
|
||||
|
||||
$message = new AssignDoctorDelayDirectProducer($queue_data);
|
||||
$message->setDelayMs($time);
|
||||
$producer = $this->container->get(Producer::class);
|
||||
$res = $producer->produce($message);
|
||||
if (!$res) {
|
||||
Db::rollBack();
|
||||
Log::getInstance("queue-AssignDoctor")->error("错误:重新加入分配医生队列失败,重回队列");
|
||||
return Result::REQUEUE;
|
||||
}
|
||||
|
||||
Log::getInstance("queue-AssignDoctor")->info("结束");
|
||||
return Result::ACK;
|
||||
}
|
||||
|
||||
// 检测当前是否符合系统问诊时间
|
||||
$inquiryService = new InquiryService();
|
||||
$is_system_time_pass = $inquiryService->checkSystemInquiryTime($order_inquiry['inquiry_type']);
|
||||
@ -165,8 +103,91 @@ class AssignDoctorDelayDirectConsumer extends ConsumerMessage
|
||||
$params['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||||
OrderInquiry::edit($params, $save_data);
|
||||
|
||||
Log::getInstance("queue-AssignDoctor")->info("结束:已退款");
|
||||
Log::getInstance("queue-AssignDoctor")->info("成功:已退款");
|
||||
|
||||
Db::commit();
|
||||
|
||||
try {
|
||||
// 患者-分配医生失败-订阅
|
||||
$MessagePush = new MessagePush($order_inquiry['user_id'],$order_inquiry['order_inquiry_id']);
|
||||
$MessagePush->assignDoctorFail();
|
||||
}catch (\Exception $e){
|
||||
Log::getInstance("queue-AssignDoctor")->error("错误:" . $e->getMessage());
|
||||
}
|
||||
|
||||
return Result::ACK;
|
||||
}
|
||||
|
||||
// 检测分配时间
|
||||
if ($diff_time > 300) {
|
||||
Log::getInstance("queue-AssignDoctor")->info("信息:超出5分钟,执行退款");
|
||||
|
||||
$InquiryService = new InquiryService();
|
||||
|
||||
// 检测问诊订单执行退款次数
|
||||
Log::getInstance("queue-AssignDoctor")->info("信息:检测执行退款次数");
|
||||
$res = $InquiryService->checkInquiryRefundCount($order_inquiry['order_inquiry_id']);
|
||||
if (!$res){
|
||||
Db::rollBack();
|
||||
Log::getInstance("queue-AssignDoctor")->error("错误:超出最大退款次数");
|
||||
return Result::ACK;
|
||||
}
|
||||
|
||||
Log::getInstance("queue-AssignDoctor")->info("信息:订单退款");
|
||||
$InquiryService->inquiryRefund($order_inquiry['order_inquiry_id'], "未分配到合适的医生");
|
||||
|
||||
Log::getInstance("queue-AssignDoctor")->info("信息:取消问诊订单");
|
||||
$save_data = array();
|
||||
$save_data['inquiry_status'] = 7;
|
||||
$save_data['cancel_time'] = date("Y-m-d H:i:s", time());
|
||||
$save_data['cancel_reason'] = 3; // 取消订单原因(1:医生未接诊 2:主动取消 3:无可分配医生 4:客服取消 5:支付超时)
|
||||
$save_data['cancel_remarks'] = "未分配到合适的医生"; // 取消订单备注
|
||||
$save_data['updated_at'] = date("Y-m-d H:i:s", time());
|
||||
|
||||
$params = array();
|
||||
$params['order_inquiry_id'] = $order_inquiry['order_inquiry_id'];
|
||||
OrderInquiry::edit($params, $save_data);
|
||||
|
||||
Log::getInstance("queue-AssignDoctor")->info("成功:已退款");
|
||||
|
||||
Db::commit();
|
||||
|
||||
try {
|
||||
// 患者-分配医生失败-订阅
|
||||
$MessagePush = new MessagePush($order_inquiry['user_id'],$order_inquiry['order_inquiry_id']);
|
||||
$MessagePush->assignDoctorFail();
|
||||
}catch (\Exception $e){
|
||||
Log::getInstance("queue-AssignDoctor")->error("错误:" . $e->getMessage());
|
||||
}
|
||||
|
||||
return Result::ACK;
|
||||
}
|
||||
|
||||
// 检测执行次数
|
||||
$res = $this->checkHandleNumber($data['order_inquiry_id']);
|
||||
if (!$res) {
|
||||
// 超出执行次数后,不再进行分配,按照结束分配时间,重新加入队列。
|
||||
Log::getInstance("queue-AssignDoctor")->info("信息:超出最大执行次数或检测错误");
|
||||
|
||||
Log::getInstance("queue-AssignDoctor")->info("信息:重新加入延迟队列");
|
||||
|
||||
$queue_data = array();
|
||||
$queue_data['order_inquiry_id'] = $data['order_inquiry_id'];
|
||||
|
||||
// 5分钟-支付时间-1s:10:00支付 此时10:04 5-(10:04-10:00)
|
||||
$time = 1000 * (300- (time() - $pay_time) - 1);
|
||||
|
||||
$message = new AssignDoctorDelayDirectProducer($queue_data);
|
||||
$message->setDelayMs($time);
|
||||
$producer = $this->container->get(Producer::class);
|
||||
$res = $producer->produce($message);
|
||||
if (!$res) {
|
||||
Db::rollBack();
|
||||
Log::getInstance("queue-AssignDoctor")->error("错误:重新加入分配医生队列失败,重回队列");
|
||||
return Result::REQUEUE;
|
||||
}
|
||||
|
||||
Log::getInstance("queue-AssignDoctor")->info("结束");
|
||||
return Result::ACK;
|
||||
}
|
||||
|
||||
|
||||
@ -134,13 +134,31 @@ class getPrescriptionOrderStatusCommand extends HyperfCommand
|
||||
$result['deliveryTime'] = date('Y-m-d H:i:s',time());
|
||||
}
|
||||
|
||||
// 订阅快递推送
|
||||
$Kuaidi = new Kuaidi();
|
||||
$Kuaidi->subscribe($result['deliveryId'],$logistics_company_code,$item['consignee_tel']);
|
||||
// 检测物流编号是否已经存在并订阅
|
||||
if (empty($order_prescription['logistics_no']) || $order_prescription['logistics_no'] != $result['deliveryId']){
|
||||
// 订阅快递推送
|
||||
$Kuaidi = new Kuaidi();
|
||||
$Kuaidi->subscribe($result['deliveryId'],$logistics_company_code,$item['consignee_tel']);
|
||||
}
|
||||
|
||||
// 修改成功时药品订单数据
|
||||
$this->savePreSuccessOrderStatus($item,$result['deliveryId'],$logistics_company_code,$result['deliveryTime']);
|
||||
|
||||
try {
|
||||
// 获取患者数据
|
||||
$params = array();
|
||||
$params['patient_id'] = $order_prescription['patient_id'];
|
||||
$user_patient = UserPatient::getOne($params);
|
||||
if (empty($user_patient)){
|
||||
$this->line("推送消息错误:用户数据错误");
|
||||
}
|
||||
|
||||
// 患者-药品已发货-订阅失败发送短信
|
||||
$MessagePush = new MessagePush($user_patient['user_id']);
|
||||
$MessagePush->productDelivery($item['order_product_id']);
|
||||
}catch (\Exception $e){
|
||||
$this->line("推送消息错误:" . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
$this->line("获取处方平台订单数据结束:处理完毕");
|
||||
|
||||
@ -1008,6 +1008,47 @@ class CallBackController extends AbstractController
|
||||
return $this->LogisticsFailReturn($e->getMessage());
|
||||
}
|
||||
|
||||
// 推送消息
|
||||
try {
|
||||
// 获取患者数据
|
||||
$params = array();
|
||||
$params['patient_id'] = $order_product['patient_id'];
|
||||
$user_patient = UserPatient::getOne($params);
|
||||
if (empty($user_patient)){
|
||||
return $this->LogisticsSuccessReturn("推送消息错误:用户数据错误");
|
||||
}
|
||||
|
||||
// 检测是否推送过
|
||||
$redis = $this->container->get(Redis::class);
|
||||
|
||||
$redis_key = "logistics_" . $request_params['param']['lastResult']['nu'] . $request_params['param']['lastResult']['state'];
|
||||
$redis_value = $redis->get($redis_key);
|
||||
if (empty($redis_value)){
|
||||
// 未推送过
|
||||
$status = "";
|
||||
if ($request_params['param']['lastResult']['state'] == 1){
|
||||
// 1揽收
|
||||
$status = "已揽收";
|
||||
|
||||
}elseif ($request_params['param']['lastResult']['state'] == 0){
|
||||
// 0在途
|
||||
$status = "已发货";
|
||||
}elseif ($request_params['param']['lastResult']['state'] == 3){
|
||||
// 3签收
|
||||
$status = "已签收";
|
||||
}
|
||||
|
||||
if (!empty($status)){
|
||||
// 患者-药品已发货-订阅失败发送短信
|
||||
$MessagePush = new MessagePush($user_patient['user_id']);
|
||||
$MessagePush->logistics($status,$order_product['patient_id']);
|
||||
$redis->set($redis_key, 1, 60 * 10);
|
||||
}
|
||||
}
|
||||
}catch (\Exception $e){
|
||||
return $this->LogisticsSuccessReturn("推送消息错误:" . $e->getMessage());
|
||||
}
|
||||
|
||||
return $this->LogisticsSuccessReturn();
|
||||
} catch (\Exception $e) {
|
||||
return $this->LogisticsFailReturn("异常:" . $e->getMessage());
|
||||
|
||||
@ -144,6 +144,53 @@ class MessagePush extends BaseService
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 患者-分配医生失败
|
||||
* 订阅
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function assignDoctorFail(): void
|
||||
{
|
||||
try {
|
||||
// 订阅
|
||||
// 获取医生数据
|
||||
$params = array();
|
||||
$params['doctor_id'] = $this->order_inquiry['doctor_id'];
|
||||
$user_doctor = UserDoctor::getOne($params);
|
||||
if (empty($user_doctor)){
|
||||
Log::getInstance("MessagePush")->error("错误:医生数据为空");
|
||||
return;
|
||||
}
|
||||
|
||||
$sub_data = array();
|
||||
$sub_data['push_user_id'] = $this->user['user_id'];
|
||||
$sub_data['wx_template_id'] = "UOMww1S30Oq7rErJrqO8wN6lNEVKRo2fgcXnb0tBwHI";//问诊异常通知
|
||||
$sub_data['params']['page'] = "pages/orderDetail/orderDetail?order_inquiry_id={$this->order_inquiry['order_inquiry_id']}";
|
||||
$sub_data['params']['data'] = [
|
||||
"character_string1" => (string)$this->order_inquiry['inquiry_no'],// 订单ID
|
||||
"name2" => (string)$user_doctor['user_name'],// 问诊医生
|
||||
"date3" => $this->order_inquiry['created_at'],// 问诊时间
|
||||
"thing4" => inquiryCancelReasonToPushString($this->order_inquiry['cancel_reason']),// 取消原因
|
||||
"thing5" => "已进行退款处理,请注意查看账户信息",// 提示说明
|
||||
];
|
||||
|
||||
$data = array();
|
||||
$data['sub_data'] = $sub_data;
|
||||
$data['sms_data'] = array();
|
||||
|
||||
$message = new SendSubMessageProducer($data);
|
||||
$producer = ApplicationContext::getContainer()->get(Producer::class);
|
||||
$result = $producer->produce($message);
|
||||
if (!$result) {
|
||||
Log::getInstance("MessagePush")->error("错误:" . json_encode($data,JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::getInstance("MessagePush")->error("错误:" . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 医生-通知患者回复
|
||||
* 订阅
|
||||
@ -558,7 +605,7 @@ class MessagePush extends BaseService
|
||||
}
|
||||
|
||||
/**
|
||||
* 优惠劵退还
|
||||
* 患者-优惠劵退还
|
||||
* 站内
|
||||
* @param string $coupon_name
|
||||
* @return void
|
||||
@ -590,7 +637,7 @@ class MessagePush extends BaseService
|
||||
}
|
||||
|
||||
/**
|
||||
* 优惠劵过期
|
||||
* 患者-优惠劵过期
|
||||
* 站内
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
@ -841,32 +888,55 @@ class MessagePush extends BaseService
|
||||
}
|
||||
|
||||
/**
|
||||
* 物流信息-暂时无法开发,无物流信息表
|
||||
* 患者-物流信息
|
||||
* 已揽收、已发货、自动收货
|
||||
* 站内
|
||||
* @param string $status 已揽收、已发货、已签收
|
||||
* @param string $order_product_id
|
||||
* @return bool
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function logistics(string $order_product_id): bool
|
||||
public function logistics(string $status,string $order_product_id): void
|
||||
{
|
||||
try {
|
||||
// 站内
|
||||
// 服务消息
|
||||
$data = array();
|
||||
$data['user_id'] = $this->user['user_id'];
|
||||
$data['notice_type'] = 3;
|
||||
$data['notice_system_type'] = 4;// 系统消息类型(患者端系统消息存在 1:服务消息 2:福利消息 3:退款消息 4:物流消息)
|
||||
$data['from_name'] = "肝胆小秘书";
|
||||
$data['notice_brief_title'] = "您购买的药品【{$status}】,点击查看物流详情。";
|
||||
$data['notice_title'] = "您购买的药品【{$status}】,点击查看物流详情。";
|
||||
$data['notice_content'] = "您购买的药品【{$status}】,点击查看物流详情。";
|
||||
|
||||
$data['link_type'] = 9;// 物流详情
|
||||
|
||||
$link_params = array();
|
||||
$link_params['order_product_id'] = $order_product_id;
|
||||
$data['link_params'] = json_encode($link_params,JSON_UNESCAPED_UNICODE);// 跳转参数
|
||||
|
||||
$message = new SendStationMessageProducer($data);
|
||||
$producer = ApplicationContext::getContainer()->get(Producer::class);
|
||||
$result = $producer->produce($message);
|
||||
if (!$result) {
|
||||
Log::getInstance("MessagePush")->error("错误:加入推送队列失败" . json_encode($data,JSON_UNESCAPED_UNICODE));
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
throw new BusinessException("加入推送队列失败" . $e->getMessage());
|
||||
Log::getInstance("MessagePush")->error("错误:加入推送队列失败" . $e->getMessage());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 药品已发货
|
||||
* 患者-药品已发货
|
||||
* 订阅失败发送短信
|
||||
* @param string $order_product_id
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function ProductDelivery(string $order_product_id): void
|
||||
public function productDelivery(string $order_product_id): void
|
||||
{
|
||||
try {
|
||||
// 获取药品订单数据
|
||||
@ -924,9 +994,9 @@ class MessagePush extends BaseService
|
||||
|
||||
"thing3" => $order_product['province'] . $order_product['city'] . $order_product['county'],// 收货地址
|
||||
|
||||
"thing6" => $order_product['consignee_name'],// 收货人
|
||||
"thing6" => (string)$order_product['consignee_name'],// 收货人
|
||||
|
||||
"thing5" => "您的药品已发货,点击可以查看订单详情。",// 备注
|
||||
"thing5" => "您的药品已发货,点击可以查看订单详情",// 备注
|
||||
];
|
||||
|
||||
// 短信
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user