|
|
@@ -208,6 +208,12 @@ class DeliveryController extends BaseController
|
|
|
'fee' => $ret['data']['fee'],
|
|
|
'orderStatus' => 0
|
|
|
];
|
|
|
+
|
|
|
+ // createdAt 中保存了滴滴跑腿订单的后半截数据
|
|
|
+ if($platform == 'didi'){
|
|
|
+ $data['createdAt'] = date('Y-m-d H:i:s', $ret['data']['timeStamp']);
|
|
|
+ }
|
|
|
+
|
|
|
HdDeliveryOrderClass::add($data);
|
|
|
} else {
|
|
|
Yii::info('重复创建订单');
|
|
|
@@ -215,7 +221,7 @@ class DeliveryController extends BaseController
|
|
|
//更新订单
|
|
|
$Order->sendDistance = $ret['data']['distance'];
|
|
|
$Order->sendStatus = 0;
|
|
|
- $Order->deliveryId = $ret['platform'];
|
|
|
+ $Order->deliveryId = $platform;
|
|
|
$Order->sendType = 2;// 2指跑腿
|
|
|
$Order->status = 3;// 3配送中
|
|
|
$save = $Order->save();
|
|
|
@@ -238,19 +244,20 @@ class DeliveryController extends BaseController
|
|
|
$form = new CancelOrderForm();
|
|
|
$form->loadAndValidate();
|
|
|
$post = $form->getAttributes();
|
|
|
- $orderId = $post['orderId'] ?? 0; // 平台的orderId,
|
|
|
+ $deliveryOrderId = $post['orderId'] ?? 0; // 平台的orderId,
|
|
|
$platform = $post['platform'] ?? '';
|
|
|
$hdOrderId = $post['hdOrderId'];
|
|
|
|
|
|
// 先获取配送订单,确保 $gdo 始终可用
|
|
|
- $hdo = HdDeliveryOrderClass::getByCondition(['mainId' => $this->mainId, 'hdOrderId' => $hdOrderId, 'orderStatus!=' => -1], true);
|
|
|
+ $hdo = HdDeliveryOrderClass::getByCondition(['mainId' => $this->mainId, 'hdOrderId' => $hdOrderId, 'orderStatus' => ['not in', [-1, -2]]], true, 'id DESC');
|
|
|
if (empty($hdo)) {
|
|
|
util::fail('未找到对应订单: ' . $hdOrderId);
|
|
|
}
|
|
|
|
|
|
+ $orderId = $hdo->hdOrderId;
|
|
|
// 如果没有提供平台和订单ID,从配送订单中获取
|
|
|
- if ($platform == '' || $orderId == 0) {
|
|
|
- $orderId = $hdo->orderId;
|
|
|
+ if ($platform == '' || $deliveryOrderId == 0) {
|
|
|
+ $deliveryOrderId = $hdo->orderId;
|
|
|
$platform = $hdo->deliveryId;
|
|
|
}
|
|
|
|
|
|
@@ -259,7 +266,7 @@ class DeliveryController extends BaseController
|
|
|
$cancelCostCent = 0;
|
|
|
if ($platform == 'fengniao') {
|
|
|
//请求订单预取消接口,获取是否可取消。如果运单状态不允许取消,则直接返回
|
|
|
- $cancelParams = ['order_id' => $orderId, 'order_cancel_code' => $post['order_cancel_code']];
|
|
|
+ $cancelParams = ['order_id' => $deliveryOrderId, 'order_cancel_code' => $post['order_cancel_code']];
|
|
|
$res = $ds->getAdapter()->preCancelOrder($cancelParams);
|
|
|
if ($res['code'] != 0) {
|
|
|
util::fail('运单状态不允许取消');
|
|
|
@@ -268,16 +275,26 @@ class DeliveryController extends BaseController
|
|
|
}
|
|
|
if ($platform == 'shunfeng') {
|
|
|
//请求订单预取消接口,获取是否可取消。如果运单状态不允许取消,则直接返回
|
|
|
- $cancelParams = ['order_id' => $orderId, 'order_cancel_code' => $post['order_cancel_code']];
|
|
|
+ $cancelParams = ['order_id' => $deliveryOrderId, 'order_cancel_code' => $post['order_cancel_code']];
|
|
|
$res = $ds->getAdapter()->preCancelOrder($cancelParams);
|
|
|
if ($res['code'] != 0) {
|
|
|
util::fail('运单状态不允许取消');
|
|
|
}
|
|
|
$post['order_type'] = 1; //查询订单ID类型 1、顺丰订单号 2、商家订单号
|
|
|
}
|
|
|
+ if ($platform == 'dada') {
|
|
|
+ $order = OrderClass::getById($orderId, false, 'id,orderSn');
|
|
|
+ $deliveryOrderId = $order['orderSn'];
|
|
|
+ }
|
|
|
+ if ($platform == 'didi') {
|
|
|
+ $order = OrderClass::getById($orderId, false, 'id,orderSn');
|
|
|
+ $timeStamp = strtotime($hdo->createdAt);
|
|
|
+ $post['outOrderNo'] = \common\components\delivery\platform\didi\Didi::generateUniOroder($order['orderSn'], $timeStamp);
|
|
|
+ $post['cancelSource'] = 1; // TODO 要增加取消码判断
|
|
|
+ }
|
|
|
|
|
|
$post['order_cancel_role'] = 1; //1:商户取消, 2:用户取消
|
|
|
- $ret = $ds->cancelOrder($orderId, $post);
|
|
|
+ $ret = $ds->cancelOrder($deliveryOrderId, $post);
|
|
|
if ($ret['code'] == 0) {
|
|
|
$Order = OrderClass::getById($hdOrderId, true, 'id, sendDistance, sendStatus, deliveryId');
|
|
|
$Order->sendDistance = 0;
|
|
|
@@ -304,7 +321,7 @@ class DeliveryController extends BaseController
|
|
|
util::success($ret['data'], "success");
|
|
|
}
|
|
|
|
|
|
- util::fail('取消失败');
|
|
|
+ util::fail('失败:'.$ret['msg']);
|
|
|
}
|
|
|
|
|
|
/**
|