1
This commit is contained in:
@@ -6,6 +6,8 @@ namespace App\Command;
|
||||
|
||||
use App\Model\OrderPrescription;
|
||||
use App\Model\OrderProduct;
|
||||
use App\Model\UserPatient;
|
||||
use App\Services\MessagePush;
|
||||
use App\Services\OrderPrescriptionService;
|
||||
use App\Services\OrderProductService;
|
||||
use App\Utils\Log;
|
||||
@@ -45,13 +47,17 @@ class getPrescriptionOrderStatusCommand extends HyperfCommand
|
||||
$this->line("获取处方平台订单数据结束,无可执行的商品订单");
|
||||
return;
|
||||
}
|
||||
// dump($order_product_ids);die;
|
||||
|
||||
|
||||
foreach ($order_product_ids as $item) {
|
||||
if ($item['order_product_id'] != "504371738743726081"){
|
||||
if ($item['order_product_id'] != "504656990619947008"){
|
||||
continue;
|
||||
}
|
||||
Db::beginTransaction();
|
||||
|
||||
// 是否执行了退款-预定义变量
|
||||
$is_refund = 0;
|
||||
|
||||
$this->line("本次请求订单号:" . $item['order_product_id']);
|
||||
|
||||
// 获取药品订单处方数据
|
||||
@@ -84,7 +90,7 @@ class getPrescriptionOrderStatusCommand extends HyperfCommand
|
||||
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);
|
||||
@@ -96,13 +102,17 @@ class getPrescriptionOrderStatusCommand extends HyperfCommand
|
||||
// 修改失败时药品订单数据
|
||||
if ($result['status'] == "CFD03"){
|
||||
$this->savePreFailedOrderStatus($order_prescription,"复核失败");
|
||||
}else{
|
||||
}elseif($result['status'] == "CFD04"){
|
||||
$this->savePreFailedOrderStatus($order_prescription,"库存不足");
|
||||
}else{
|
||||
$this->savePreFailedOrderStatus($order_prescription,"订单取消");
|
||||
}
|
||||
|
||||
// 执行退款
|
||||
$OrderProductService = new OrderProductService();
|
||||
$OrderProductService->OrderProductRefund($item['order_product_id'],"订单退款");
|
||||
|
||||
$is_refund = 1;
|
||||
}
|
||||
|
||||
if ($result['status'] == "CFD05"){
|
||||
@@ -132,30 +142,6 @@ class getPrescriptionOrderStatusCommand extends HyperfCommand
|
||||
$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("获取处方平台订单数据结束:处理完毕");
|
||||
|
||||
Db::commit();
|
||||
@@ -164,6 +150,21 @@ class getPrescriptionOrderStatusCommand extends HyperfCommand
|
||||
// 记录失败次数
|
||||
$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("获取处方平台订单数据全部处理结束");
|
||||
@@ -189,6 +190,7 @@ class getPrescriptionOrderStatusCommand extends HyperfCommand
|
||||
'order_product_id',
|
||||
'order_product_no',
|
||||
'order_prescription_id',
|
||||
'patient_id',
|
||||
];
|
||||
|
||||
$order_product = OrderProduct::getStatusList($params,$order_product_status,$fields);
|
||||
@@ -368,4 +370,22 @@ class getPrescriptionOrderStatusCommand extends HyperfCommand
|
||||
|
||||
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'];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user