新增快递100回调
This commit is contained in:
parent
81a47d72e0
commit
d5cd0ac053
@ -11,6 +11,7 @@ use App\Services\MessagePush;
|
||||
use App\Services\OrderPrescriptionService;
|
||||
use App\Services\OrderProductService;
|
||||
use App\Utils\Log;
|
||||
use Extend\Kuaidi100\Kuaidi;
|
||||
use Extend\Prescription\Prescription;
|
||||
use Hyperf\Command\Command as HyperfCommand;
|
||||
use Hyperf\Command\Annotation\Command;
|
||||
@ -135,8 +136,17 @@ class getPrescriptionOrderStatusCommand extends HyperfCommand
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isset($result['deliveryTime'])){
|
||||
$result['deliveryTime'] = date('Y-m-d H:i:s',time());
|
||||
}
|
||||
|
||||
// 订阅快递推送
|
||||
$Kuaidi = new Kuaidi();
|
||||
$Kuaidi->subscribe($result['deliveryId'],$logistics_company_code,$item['consignee_tel']);
|
||||
|
||||
// 修改成功时药品订单数据
|
||||
$this->savePreSuccessOrderStatus($item,$result['deliveryId'],$logistics_company_code);
|
||||
$this->savePreSuccessOrderStatus($item,$result['deliveryId'],$logistics_company_code,$result['deliveryTime']);
|
||||
|
||||
}
|
||||
|
||||
$this->line("获取处方平台订单数据结束:处理完毕");
|
||||
@ -191,6 +201,7 @@ class getPrescriptionOrderStatusCommand extends HyperfCommand
|
||||
'order_prescription_id',
|
||||
'patient_id',
|
||||
'order_product_status',
|
||||
'consignee_tel',
|
||||
];
|
||||
|
||||
$order_product = OrderProduct::getStatusList($params,$order_product_status,$fields);
|
||||
@ -282,8 +293,9 @@ class getPrescriptionOrderStatusCommand extends HyperfCommand
|
||||
* @param array|object $order_product
|
||||
* @param string $logistics_no // 物流编号
|
||||
* @param string $logistics_company_code // 快递公司编码
|
||||
* @param string $delivery_time
|
||||
*/
|
||||
protected function savePreSuccessOrderStatus(array|object $order_product,string $logistics_no,string $logistics_company_code)
|
||||
protected function savePreSuccessOrderStatus(array|object $order_product,string $logistics_no,string $logistics_company_code,string $delivery_time = "")
|
||||
{
|
||||
$params = array();
|
||||
$params['order_product_id'] = $order_product['order_product_id'];
|
||||
@ -291,7 +303,8 @@ class getPrescriptionOrderStatusCommand extends HyperfCommand
|
||||
$data['order_product_status'] = 3; // 订单状态(1:待支付 2:待发货 3:已发货 4:已签收 5:已取消)
|
||||
$data['logistics_no'] = $logistics_no; // 物流编号
|
||||
$data['logistics_company_code'] = $logistics_company_code; // 快递公司编码
|
||||
$data['delivery_time'] = date('Y-m-d H:i:s',time()); // 发货时间
|
||||
$data['sub_logistics_status'] = 1; // 快递推送订阅状态(0:未订阅/无需订阅 1:已订阅 2:订阅失败)
|
||||
$data['delivery_time'] = $delivery_time ?: date('Y-m-d H:i:s',time()); // 发货时间
|
||||
OrderProduct::edit($params,$data);
|
||||
}
|
||||
|
||||
|
||||
@ -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)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -67,4 +67,25 @@ class OrderProductLogistic extends Model
|
||||
{
|
||||
return self::where($params)->exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增
|
||||
* @param array $data
|
||||
* @return \Hyperf\Database\Model\Model|OrderProductLogistic
|
||||
*/
|
||||
public static function addOrderProductLogistic(array $data): \Hyperf\Database\Model\Model|OrderProductLogistic
|
||||
{
|
||||
return self::create($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
* @param array $params
|
||||
* @param array $data
|
||||
* @return int
|
||||
*/
|
||||
public static function edit(array $params = [], array $data = []): int
|
||||
{
|
||||
return self::where($params)->update($data);
|
||||
}
|
||||
}
|
||||
|
||||
@ -970,6 +970,12 @@ class InquiryService extends BaseService
|
||||
$inquiry_refund_status = 3;
|
||||
$refund_id = "模拟退款:" . $generator->generate();
|
||||
$success_time = date("Y-m-d H:i:s", time());
|
||||
|
||||
// 模拟退款时手动退还优惠卷
|
||||
if (!empty($order_inquiry['coupon_amount_total']) && $order_inquiry['coupon_amount_total'] > 0) {
|
||||
$InquiryService = new InquiryService();
|
||||
$InquiryService->returnInquiryCoupon($order_inquiry['order_inquiry_id'], $order_inquiry['user_id']);
|
||||
}
|
||||
}
|
||||
|
||||
// 新增退款表
|
||||
|
||||
@ -46,11 +46,9 @@ class Kuaidi
|
||||
|
||||
/**
|
||||
* 订阅快递推送
|
||||
* @param string $logistics_no
|
||||
* @param string $logistics_company_code
|
||||
* @param string $order_product_id
|
||||
* @param string $phone
|
||||
* @return mixed
|
||||
* @param string $logistics_no 快递号
|
||||
* @param string $logistics_company_code 快递公司编码
|
||||
* @param string $phone 手机号
|
||||
* @throws GuzzleException
|
||||
*/
|
||||
public function subscribe(string $logistics_no,string $logistics_company_code,string $phone = ""){
|
||||
@ -61,7 +59,7 @@ class Kuaidi
|
||||
'parameters' => array (
|
||||
'callbackurl' => 'http://dev.hospital.applets.igandanyiyuan.com/callback/logistics', // 回调地址
|
||||
'resultv2' => '1', // 行政区域解析
|
||||
'phone' => $phone, // 手机号
|
||||
'phone' => $phone ?: "", // 手机号
|
||||
'salt' => config('kuaidi100.salt'), // 签名用字符串
|
||||
)
|
||||
];
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user