This commit is contained in:
wucongxing 2023-04-12 14:38:47 +08:00
parent 189dc54d55
commit 66df9d1548
6 changed files with 85 additions and 44 deletions

View File

@ -5,6 +5,8 @@ declare(strict_types=1);
namespace App\Command; namespace App\Command;
use App\Model\OrderProduct; use App\Model\OrderProduct;
use App\Model\UserPatient;
use App\Services\MessagePush;
use App\Services\OrderPrescriptionService; use App\Services\OrderPrescriptionService;
use App\Services\OrderProductService; use App\Services\OrderProductService;
use Hyperf\Command\Command as HyperfCommand; use Hyperf\Command\Command as HyperfCommand;
@ -68,7 +70,7 @@ class ReportPreProductOrderCommand extends HyperfCommand
$redis_value = $redis->get($redis_key); $redis_value = $redis->get($redis_key);
$redis->incr($redis_key); $redis->incr($redis_key);
if(!empty($redis_value)){ if(!empty($redis_value)){
if ($redis_value >= 2){ if ($redis_value >= 100){
// 存储上报失败 // 存储上报失败
$this->savaReportFail($item['order_product_id'],"超出最大上报次数"); $this->savaReportFail($item['order_product_id'],"超出最大上报次数");
@ -80,6 +82,14 @@ class ReportPreProductOrderCommand extends HyperfCommand
$OrderProductService = new OrderProductService(); $OrderProductService = new OrderProductService();
$OrderProductService->OrderProductRefund($item['order_product_id'],"药品订单退款"); $OrderProductService->OrderProductRefund($item['order_product_id'],"药品订单退款");
// 获取患者用户id
$user_id = $this->getPatientUserId($item['patient_id']);
if (!empty($user_id)){
// 发送站内、订阅、短信消息-药品订单退款成功
$MessagePush = new MessagePush($user_id);
$MessagePush->refundProductSuccess($item['order_product_id']);
}
// 清空缓存 // 清空缓存
$redis->del($redis_key); $redis->del($redis_key);
@ -99,12 +109,7 @@ class ReportPreProductOrderCommand extends HyperfCommand
try { try {
// 上报处方平台 // 上报处方平台
$orderPrescriptionService = new OrderPrescriptionService(); $orderPrescriptionService = new OrderPrescriptionService();
$res = $orderPrescriptionService->reportPrescription($item['order_product_id']); $orderPrescriptionService->reportPrescription($item['order_product_id']);
if (!$res){
// 上报失败
$this->line("上报失败");
continue;
}
// 存储上报成功 // 存储上报成功
$this->savaReportSuccess($item['order_product_id']); $this->savaReportSuccess($item['order_product_id']);
@ -114,7 +119,7 @@ class ReportPreProductOrderCommand extends HyperfCommand
Db::rollBack(); Db::rollBack();
// 记录失败次数 // 记录失败次数
$redis->incr($redis_key); $redis->incr($redis_key);
$this->line("商品订单上报处方平台失败:失败原因" . $e->getMessage()); $this->line("上报失败:失败原因" . $e->getMessage());
} }
// 清空缓存 // 清空缓存
@ -139,6 +144,7 @@ class ReportPreProductOrderCommand extends HyperfCommand
$fields = [ $fields = [
'order_product_id', 'order_product_id',
'patient_id',
]; ];
$order_product = OrderProduct::getList($params,$fields); $order_product = OrderProduct::getList($params,$fields);
@ -202,4 +208,22 @@ class ReportPreProductOrderCommand extends HyperfCommand
$data['cancel_remarks'] = $cancel_remarks; // 订单取消备注(自动添加) $data['cancel_remarks'] = $cancel_remarks; // 订单取消备注(自动添加)
OrderProduct::edit($params,$data); OrderProduct::edit($params,$data);
} }
/**
* 获取患者用户id
* @param string $patient_id
* @return string
*/
protected function getPatientUserId(string $patient_id): string
{
// 获取患者数据
$params = array();
$params['patient_id'] = $patient_id;
$user_patient = UserPatient::getOne($params);
if (empty($user_patient)){
return "";
}
return $user_patient['user_id'];
}
} }

View File

@ -6,6 +6,8 @@ namespace App\Command;
use App\Model\OrderPrescription; use App\Model\OrderPrescription;
use App\Model\OrderProduct; use App\Model\OrderProduct;
use App\Model\UserPatient;
use App\Services\MessagePush;
use App\Services\OrderPrescriptionService; use App\Services\OrderPrescriptionService;
use App\Services\OrderProductService; use App\Services\OrderProductService;
use App\Utils\Log; use App\Utils\Log;
@ -45,13 +47,17 @@ class getPrescriptionOrderStatusCommand extends HyperfCommand
$this->line("获取处方平台订单数据结束,无可执行的商品订单"); $this->line("获取处方平台订单数据结束,无可执行的商品订单");
return; return;
} }
// dump($order_product_ids);die;
foreach ($order_product_ids as $item) { foreach ($order_product_ids as $item) {
if ($item['order_product_id'] != "504371738743726081"){ if ($item['order_product_id'] != "504656990619947008"){
continue; continue;
} }
Db::beginTransaction(); Db::beginTransaction();
// 是否执行了退款-预定义变量
$is_refund = 0;
$this->line("本次请求订单号:" . $item['order_product_id']); $this->line("本次请求订单号:" . $item['order_product_id']);
// 获取药品订单处方数据 // 获取药品订单处方数据
@ -84,7 +90,7 @@ class getPrescriptionOrderStatusCommand extends HyperfCommand
continue; continue;
} }
if ($result['status'] == "CFD03" || $result['status'] == "CFD04"){ if ($result['status'] == "CFD03" || $result['status'] == "CFD04" || $result['status'] == "CFD06" || $result['status'] == "CFD07"){
// 药师审核未通过/库存不足 // 药师审核未通过/库存不足
// 检测药品订单数据 // 检测药品订单数据
$res = $this->checkPreFailedOrderStatus($order_prescription); $res = $this->checkPreFailedOrderStatus($order_prescription);
@ -96,13 +102,17 @@ class getPrescriptionOrderStatusCommand extends HyperfCommand
// 修改失败时药品订单数据 // 修改失败时药品订单数据
if ($result['status'] == "CFD03"){ if ($result['status'] == "CFD03"){
$this->savePreFailedOrderStatus($order_prescription,"复核失败"); $this->savePreFailedOrderStatus($order_prescription,"复核失败");
}else{ }elseif($result['status'] == "CFD04"){
$this->savePreFailedOrderStatus($order_prescription,"库存不足"); $this->savePreFailedOrderStatus($order_prescription,"库存不足");
}else{
$this->savePreFailedOrderStatus($order_prescription,"订单取消");
} }
// 执行退款 // 执行退款
$OrderProductService = new OrderProductService(); $OrderProductService = new OrderProductService();
$OrderProductService->OrderProductRefund($item['order_product_id'],"订单退款"); $OrderProductService->OrderProductRefund($item['order_product_id'],"订单退款");
$is_refund = 1;
} }
if ($result['status'] == "CFD05"){ if ($result['status'] == "CFD05"){
@ -132,30 +142,6 @@ class getPrescriptionOrderStatusCommand extends HyperfCommand
$this->savePreSuccessOrderStatus($order_prescription,$result['deliveryId'],$logistics_company_code); $this->savePreSuccessOrderStatus($order_prescription,$result['deliveryId'],$logistics_company_code);
} }
if ($result['status'] == "CFD06"){
// 已取消
// 检测药品订单数据
$res = $this->checkPreFailedOrderStatus($order_prescription);
if (!$res){
Db::rollBack();
continue;
}
// 修改药品订单数据
$this->savePreFailedOrderStatus($order_prescription,"订单取消");
// 执行退款
$OrderProductService = new OrderProductService();
$OrderProductService->OrderProductRefund($item['order_product_id'],"订单退款");
}
if ($result['status'] == "CFD07"){
// 申请退款
$OrderProductService = new OrderProductService();
$OrderProductService->OrderProductRefund($item['order_product_id'],"订单退款");
}
$this->line("获取处方平台订单数据结束:处理完毕"); $this->line("获取处方平台订单数据结束:处理完毕");
Db::commit(); Db::commit();
@ -164,6 +150,21 @@ class getPrescriptionOrderStatusCommand extends HyperfCommand
// 记录失败次数 // 记录失败次数
$this->line("获取处方平台订单数据失败:" . $e->getMessage()); $this->line("获取处方平台订单数据失败:" . $e->getMessage());
} }
// 检测是否需要发送通知
if ($is_refund == 1){
try {
// 获取患者用户id
$user_id = $this->getPatientUserId($item['patient_id']);
if (!empty($user_id)){
// 发送站内、订阅、短信消息-药品订单退款成功
$MessagePush = new MessagePush($user_id);
$MessagePush->refundProductSuccess($item['order_product_id']);
}
}catch(\Exception $e){
$this->line("发送消息推送失败:" . $e->getMessage());
}
}
} }
$this->line("获取处方平台订单数据全部处理结束"); $this->line("获取处方平台订单数据全部处理结束");
@ -189,6 +190,7 @@ class getPrescriptionOrderStatusCommand extends HyperfCommand
'order_product_id', 'order_product_id',
'order_product_no', 'order_product_no',
'order_prescription_id', 'order_prescription_id',
'patient_id',
]; ];
$order_product = OrderProduct::getStatusList($params,$order_product_status,$fields); $order_product = OrderProduct::getStatusList($params,$order_product_status,$fields);
@ -368,4 +370,22 @@ class getPrescriptionOrderStatusCommand extends HyperfCommand
return $company_code; return $company_code;
} }
/**
* 获取患者用户id
* @param string $patient_id
* @return string
*/
protected function getPatientUserId(string $patient_id): string
{
// 获取患者数据
$params = array();
$params['patient_id'] = $patient_id;
$user_patient = UserPatient::getOne($params);
if (empty($user_patient)){
return "";
}
return $user_patient['user_id'];
}
} }

View File

@ -543,7 +543,6 @@ class CallBackController extends AbstractController
// 发送站内、订阅、短信消息-药品订单退款成功 // 发送站内、订阅、短信消息-药品订单退款成功
$MessagePush = new MessagePush($user_patient['user_id']); $MessagePush = new MessagePush($user_patient['user_id']);
$MessagePush->refundProductSuccess($order_product['order_product_id']); $MessagePush->refundProductSuccess($order_product['order_product_id']);
}catch (\Exception $e) { }catch (\Exception $e) {
// 验证失败 // 验证失败

View File

@ -738,7 +738,7 @@ class MessagePush extends BaseService
$sub_data = array(); $sub_data = array();
$sub_data['push_user_id'] = $this->user['user_id']; $sub_data['push_user_id'] = $this->user['user_id'];
$sub_data['wx_template_id'] = "gQO5vhPQfdnvXtK0XnGns1XqNhQpOrXTjdl-5HWWMUw";//药品订单取消通知 $sub_data['wx_template_id'] = "gQO5vhPQfdnvXtK0XnGns1XqNhQpOrXTjdl-5HWWMUw";//药品订单取消通知
$sub_data['params']['page'] = "pages/orderDetail/orderDetail?order_inquiry_id={$this->order_inquiry['order_inquiry_id']}"; $sub_data['params']['page'] = "pages/medinceOrderDetail/medinceOrderDetail?order_product_id={$order_product_id}";
$sub_data['params']['data'] = [ $sub_data['params']['data'] = [
"character_string3" => $order_product['order_product_no'],// 订单号 "character_string3" => $order_product['order_product_no'],// 订单号

View File

@ -604,7 +604,7 @@ class OrderPrescriptionService extends BaseService
// 获取商品订单列表数据 // 获取商品订单列表数据
$params = array(); $params = array();
$params['order_inquiry_id'] = $order_prescription['order_inquiry_id']; $params['order_product_id'] = $order_product['order_product_id'];
$order_product_item = OrderProductItem::getList($params); $order_product_item = OrderProductItem::getList($params);
if (empty($order_product_item)) { if (empty($order_product_item)) {
throw new BusinessException("上报处方平台失败:商品订单列表数据错误"); throw new BusinessException("上报处方平台失败:商品订单列表数据错误");
@ -837,12 +837,10 @@ class OrderPrescriptionService extends BaseService
$result = $Prescription->reportPrescription($arg); $result = $Prescription->reportPrescription($arg);
if ($result['resultCode'] != "1000"){ if ($result['resultCode'] != "1000"){
if(!empty($result['resultDesc'])){ if(!empty($result['resultDesc'])){
Log::getInstance()->info("上报处方平台失败:" .$result['resultDesc']); throw new BusinessException("上报处方平台失败:" .$result['resultDesc']);
return false;
} }
Log::getInstance()->info("上报处方平台失败:操作编码:" . $result['resultCode']); throw new BusinessException("上报处方平台失败:操作编码:" . $result['resultCode']);
return false;
} }
return true; return true;

View File

@ -380,7 +380,7 @@ class UserService extends BaseService
return fail(HttpEnumCode::HTTP_ERROR, $e->getMessage()); return fail(HttpEnumCode::HTTP_ERROR, $e->getMessage());
} }
return success(); return success($user_ship_address->toArray());
} }
/** /**