新增快递100回调
This commit is contained in:
@@ -6,6 +6,7 @@ use App\Amqp\Producer\AssignDoctorProducer;
|
||||
use App\Constants\DoctorTitleCode;
|
||||
use App\Constants\HttpEnumCode;
|
||||
use App\Exception\BusinessException;
|
||||
use App\Model\BasicLogisticsCompany;
|
||||
use App\Model\Hospital;
|
||||
use App\Model\MessageIm;
|
||||
use App\Model\OrderInquiry;
|
||||
@@ -14,6 +15,7 @@ use App\Model\OrderInquiryRefund;
|
||||
use App\Model\OrderPrescription;
|
||||
use App\Model\OrderProduct;
|
||||
use App\Model\OrderProductItem;
|
||||
use App\Model\OrderProductLogistic;
|
||||
use App\Model\OrderProductRefund;
|
||||
use App\Model\Product;
|
||||
use App\Model\ProductPlatformAmount;
|
||||
@@ -912,18 +914,98 @@ class CallBackController extends AbstractController
|
||||
return $this->LogisticsFailReturn("缺少推送参数:data");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 检测状态
|
||||
if (!isset($request_params['param']['lastResult']['state'])){
|
||||
return $this->LogisticsFailReturn("缺少推送参数:state");
|
||||
}
|
||||
|
||||
// 运单签收状态(0在途 1揽收 2疑难 3签收 4退签 5派件 8清关 14拒签)
|
||||
$logistics_status = [0,1,2,3,4,5,8,14];
|
||||
// if ()
|
||||
if (!in_array($request_params['param']['lastResult']['state'],$logistics_status)){
|
||||
return $this->LogisticsSuccessReturn("非可执行状态");
|
||||
}
|
||||
|
||||
Db::beginTransaction();
|
||||
|
||||
try {
|
||||
// 获取药品订单数据
|
||||
$params = array();
|
||||
$params['logistics_no'] = $request_params['param']['lastResult']['nu'];
|
||||
$params['logistics_company_code'] = $request_params['param']['lastResult']['com'];
|
||||
$order_product = OrderProduct::getOne($params);
|
||||
if (empty($order_product)){
|
||||
Db::rollBack();
|
||||
return $this->LogisticsFailReturn("药品订单数据错误");
|
||||
}
|
||||
|
||||
// 检测药品订单数据
|
||||
if (in_array($order_product['order_product_status'],[1,4,5])){
|
||||
// 订单状态(1:待支付 2:待发货 3:已发货 4:已签收 5:已取消)
|
||||
Db::rollBack();
|
||||
return $this->LogisticsSuccessReturn("无需处理");
|
||||
}
|
||||
|
||||
// 获取快递公司数据
|
||||
$params = array();
|
||||
$params['company_code'] = $request_params['param']['lastResult']['com'];
|
||||
$params['company_type'] = 1;
|
||||
$basic_logistics_company = BasicLogisticsCompany::getOne($params);
|
||||
if (empty($basic_logistics_company)){
|
||||
Db::rollBack();
|
||||
return $this->LogisticsFailReturn("快递公司编码错误");
|
||||
}
|
||||
|
||||
// 获取商品订单-物流数据
|
||||
$params = array();
|
||||
$params['logistics_no'] = $request_params['param']['lastResult']['nu'];
|
||||
$params['company_code'] = $request_params['param']['lastResult']['com'];
|
||||
$order_product_logistics = OrderProductLogistic::getOne($params);
|
||||
if (empty($order_product_logistics)){
|
||||
// 不存在物流数据
|
||||
$data = array();
|
||||
$data['order_product_id'] = $order_product['order_product_id'];
|
||||
$data['logistics_status'] = $request_params['param']['lastResult']['state'];
|
||||
$data['logistics_no'] = $request_params['param']['lastResult']['nu'];
|
||||
$data['company_name'] = $basic_logistics_company['company_name'];
|
||||
$data['company_code'] = $request_params['param']['lastResult']['com'];
|
||||
$data['logistics_content'] = json_encode($request_params['param']['lastResult']['data'],JSON_UNESCAPED_UNICODE);
|
||||
$order_product_logistics = OrderProductLogistic::addOrderProductLogistic($data);
|
||||
if (empty($order_product_logistics)){
|
||||
Db::rollBack();
|
||||
return $this->LogisticsFailReturn("添加物流数据错误");
|
||||
}
|
||||
}else{
|
||||
$params = array();
|
||||
$params['logistics_id'] = $order_product_logistics['logistics_id'];
|
||||
|
||||
$data = array();
|
||||
if ($order_product_logistics['logistics_status'] != $request_params['param']['lastResult']['state']){
|
||||
$data['logistics_status'] = $request_params['param']['lastResult']['state'];
|
||||
}
|
||||
|
||||
$data['logistics_content'] = json_encode($request_params['param']['lastResult']['data'],JSON_UNESCAPED_UNICODE);
|
||||
OrderProductLogistic::edit($params,$data);
|
||||
}
|
||||
|
||||
// 运单签收状态(0在途 1揽收 2疑难 3签收 4退签 5派件 8清关 14拒签)
|
||||
if ($request_params['param']['lastResult']['state'] == 3){
|
||||
// 修改药品订单数据为已签收
|
||||
$params = array();
|
||||
$params['order_product_id'] = $order_product['order_product_id'];
|
||||
|
||||
$data['order_product_status'] = 4;
|
||||
OrderProduct::edit($params,$data);
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
} catch (\Exception $e) {
|
||||
Db::rollBack();
|
||||
return $this->LogisticsFailReturn($e->getMessage());
|
||||
}
|
||||
|
||||
return $this->LogisticsSuccessReturn();
|
||||
} catch (\Exception $e) {
|
||||
|
||||
return $this->LogisticsFailReturn("异常:" . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -948,4 +1030,26 @@ class CallBackController extends AbstractController
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 快递100订阅回调成功
|
||||
* @param string $message
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
protected function LogisticsSuccessReturn(string $message = ""): ResponseInterface
|
||||
{
|
||||
return $this->response
|
||||
->withStatus(200)
|
||||
->withBody(
|
||||
new SwooleStream(
|
||||
strval(
|
||||
json_encode([
|
||||
'result' => true,
|
||||
'returnCode' => "200",
|
||||
'message' => $message,
|
||||
], JSON_UNESCAPED_UNICODE)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user