|
|
@@ -17,6 +17,7 @@ use biz\shop\classes\ShopClass;
|
|
|
use yii\helpers\Json;
|
|
|
use yii\web\Response;
|
|
|
use common\components\IntraCityExpress;
|
|
|
+use yii\db\Query;
|
|
|
|
|
|
/**
|
|
|
* 同城配送控制器
|
|
|
@@ -409,7 +410,12 @@ class IntraCityController extends BaseController
|
|
|
$storeOrderId = $orderId;
|
|
|
if ($post['isNew'] == 0) { // 如果不是首次用 $orderId 创建快递配送,则要生成新 store_order_id
|
|
|
// store_order_id 门店订单编号, 即 orderId。如果是重新配送的第n次,订单编号的命名规则为:orderId_copy_n
|
|
|
- $copyOrderCount = ExpressOrderClass::getCount(['storeOrderId'=>['like', $orderId . '_copy_%']]);
|
|
|
+ $query = (new Query())
|
|
|
+ ->from('xhExpressOrder')
|
|
|
+ ->where(new \yii\db\Expression('storeOrderId LIKE CONCAT(:prefix, "%")', [':prefix' => $orderId.'_copy_%']));
|
|
|
+ // $command = $query->createCommand();
|
|
|
+ // $sql = $command->sql;
|
|
|
+ $copyOrderCount = $query->count();
|
|
|
$copyOrderCount += 1;
|
|
|
$storeOrderId = $orderId . '_copy_' . $copyOrderCount;
|
|
|
}
|
|
|
@@ -479,18 +485,38 @@ class IntraCityController extends BaseController
|
|
|
$shopExt = ShopExtClass::getByCondition(['shopId'=>$shopId], false, false, 'id, wxStoreId');
|
|
|
|
|
|
$post = Yii::$app->request->post();
|
|
|
- $wxOrderId = $post['wx_order_id'];
|
|
|
- $storeOrderId = $post['orderId']; // 即 orderId
|
|
|
+ $wxOrderId = isset($post['wx_order_id']) ? $post['wx_order_id'] : '';
|
|
|
+ $orderId = $post['orderId'];
|
|
|
$wxStoreId = isset($post['wx_store_id']) ? $post['wx_order_id'] : $shopExt['wxStoreId'];
|
|
|
|
|
|
- if (empty($wxOrderId) && (empty($outOrderId) || empty($outStoreId))) {
|
|
|
- util::fail("参数不足:wx_order_id 或 (store_order_id + wx_store_id) 必须提供一组");
|
|
|
+ if (empty($wxOrderId) && (empty($orderId) || empty($wxStoreId))) {
|
|
|
+ util::fail("参数不足:wx_order_id 或 (order_id + wx_store_id) 必须提供一组");
|
|
|
}
|
|
|
- $order = OrderClass::getById($storeOrderId, false, 'id, mainId, sendStatus');
|
|
|
+ $order = OrderClass::getById($orderId, false, 'id, mainId, sendStatus');
|
|
|
if ($order['mainId'] != $this->mainId){
|
|
|
util::fail('订单未找到');
|
|
|
}
|
|
|
|
|
|
+ // 检查是否存在重复的订单:如果存在,则使用最后一个订单的 store_order_id
|
|
|
+ $storeOrderId = $orderId; // ------------------------------------- 注意区分:$storeOrderId , $orderId 。它们有可能不相同
|
|
|
+ $query = (new Query())
|
|
|
+ ->from('xhExpressOrder')
|
|
|
+ ->where(['and',
|
|
|
+ new \yii\db\Expression('storeOrderId LIKE CONCAT(:prefix, "%")', [':prefix' => $orderId.'_copy_']),
|
|
|
+ ['status' => 1]
|
|
|
+ ])->orderBy('addTime DESC');
|
|
|
+ $esDatas = $query->all();
|
|
|
+ $count = count($esDatas);
|
|
|
+ if ($count > 0) {
|
|
|
+ $es = $esDatas[0];
|
|
|
+ $storeOrderId = $es['storeOrderId'];
|
|
|
+
|
|
|
+ if ($count > 1) {
|
|
|
+ noticeUtil::push('同城配送订单重复多于1个. store_order_id:'.$orderId.',wx_store_id:'.$wxStoreId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
$result = IntraCityExpress::queryOrder($wxStoreId, $storeOrderId, $wxOrderId);
|
|
|
if (isset($result['errcode']) && $result['errcode'] === 0) {
|
|
|
util::success("查询成功", $result);
|
|
|
@@ -520,12 +546,12 @@ class IntraCityController extends BaseController
|
|
|
$shopExt = ShopExtClass::getByCondition(['shopId'=>$shopId], false, false, 'id, wxStoreId');
|
|
|
|
|
|
$wxOrderId = isset($post['wx_order_id']) ? $post['wx_order_id'] : '';
|
|
|
- $storeOrderId = $post['orderId']; //配送订单创建成功后,也会返回的 store_order_id。 即 orderId
|
|
|
+ $orderId = $post['orderId']; //配送订单创建成功后,也会返回的 store_order_id。 即 orderId
|
|
|
$wxStoreId = isset($post['wx_store_id']) ? $post['wx_order_id'] : $shopExt['wxStoreId'];
|
|
|
- if (empty($wxOrderId) && (empty($storeOrderId) || empty($wxStoreId))) {
|
|
|
+ if (empty($wxOrderId) && (empty($orderId) || empty($wxStoreId))) {
|
|
|
util::fail("参数不足:wx_order_id 或 (store_order_id + wx_store_id) 必须提供一组");
|
|
|
}
|
|
|
- $order = OrderClass::getById($storeOrderId, false, 'id, mainId, sendStatus');
|
|
|
+ $order = OrderClass::getById($orderId, false, 'id, mainId, sendStatus');
|
|
|
if ($order['mainId'] != $this->mainId){
|
|
|
util::fail('订单未找到');
|
|
|
}
|
|
|
@@ -533,10 +559,32 @@ class IntraCityController extends BaseController
|
|
|
util::fail('配送单状态不是配送中');
|
|
|
}
|
|
|
|
|
|
+ // 检查是否存在重复的订单,如果存在,则使用最后一个订单的 store_order_id
|
|
|
+ $storeOrderId = $orderId; // ------------------------------------- 注意区分:$storeOrderId , $orderId 。它们有可能不相同
|
|
|
+ $query = (new Query())
|
|
|
+ ->from('xhExpressOrder')
|
|
|
+ ->where(['and',
|
|
|
+ new \yii\db\Expression('storeOrderId LIKE CONCAT(:prefix, "%")', [':prefix' => $orderId.'_copy_']),
|
|
|
+ ['status' => 1]
|
|
|
+ ])->orderBy('addTime DESC');
|
|
|
+ // $command = $query->createCommand();
|
|
|
+ // $sql = $command->sql;
|
|
|
+ $esDatas = $query->all();
|
|
|
+
|
|
|
+ $count = count($esDatas);
|
|
|
+ if ($count > 0) {
|
|
|
+ $es = $esDatas[0];
|
|
|
+ $storeOrderId = $es['storeOrderId'];
|
|
|
+
|
|
|
+ if ($count > 1) {
|
|
|
+ noticeUtil::push('同城配送订单重复多于1个. store_order_id:'.$orderId.',wx_store_id:'.$wxStoreId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
$result = IntraCityExpress::cancelOrder($wxOrderId, $storeOrderId, $wxStoreId);
|
|
|
if (isset($result['errcode']) && $result['errcode'] === 0) {
|
|
|
// 更新订单状态
|
|
|
- OrderClass::updateById($storeOrderId, ['sendStatus'=>3]);//设置为取消状态
|
|
|
+ OrderClass::updateById($orderId, ['sendStatus'=>OrderClass::ORDER_STATUS_CANCEL]);//设置为取消状态
|
|
|
$eo = ExpressOrderClass::getByCondition(['storeOrderId'=>$storeOrderId, 'wxStoreId'=>$wxStoreId], true);
|
|
|
if(!empty($eo)) {
|
|
|
$eo->status = ExpressOrder::STATUS_CANCELED;
|
|
|
@@ -547,6 +595,12 @@ class IntraCityController extends BaseController
|
|
|
|
|
|
util::success("订单取消成功", $result);
|
|
|
} else {
|
|
|
+ if ($result['errcode'] == 934018) { // 93401 -- 订单已取消,请勿重复操作
|
|
|
+ // 更新订单状态
|
|
|
+ OrderClass::updateById($orderId, ['sendStatus'=>OrderClass::ORDER_STATUS_CANCEL]);//设置为取消状态
|
|
|
+ util::success("订单取消成功", $result);
|
|
|
+ }
|
|
|
+
|
|
|
Yii::error("订单取消失败:" . ($result['errmsg'] ?? '未知错误'), 'intracity');
|
|
|
util::fail($result['errmsg'] ?? '订单取消失败', $result['errcode'] ?? -1);
|
|
|
}
|