|
@@ -2,11 +2,14 @@
|
|
|
|
|
|
|
|
namespace ghs\controllers;
|
|
namespace ghs\controllers;
|
|
|
|
|
|
|
|
-use bizHd\express\classes\ExpressOrderClass;
|
|
|
|
|
-use bizHd\express\models\ExpressOrder;
|
|
|
|
|
|
|
+use biz\wx\classes\WxMessageClass;
|
|
|
|
|
+use biz\wx\classes\WxOpenClass;
|
|
|
|
|
+use bizGhs\express\classes\GhsExpressOrderClass as ExpressOrderClass;
|
|
|
use bizHd\order\classes\OrderGoodsClass;
|
|
use bizHd\order\classes\OrderGoodsClass;
|
|
|
use bizHd\user\classes\UserClass;
|
|
use bizHd\user\classes\UserClass;
|
|
|
-use bizHd\order\classes\OrderItemClass;
|
|
|
|
|
|
|
+use bizGhs\order\classes\OrderItemClass;
|
|
|
|
|
+use common\components\dict;
|
|
|
|
|
+use common\components\imgUtil;
|
|
|
use hd\models\IntraCity\StoreFeeForm;
|
|
use hd\models\IntraCity\StoreFeeForm;
|
|
|
// 以上类来自零售端
|
|
// 以上类来自零售端
|
|
|
|
|
|
|
@@ -65,10 +68,10 @@ class IntraCityController extends BaseController
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 创建门店前,检查是否已经 开通门店权限 (有wxStoreId,即说明开通了)
|
|
// 创建门店前,检查是否已经 开通门店权限 (有wxStoreId,即说明开通了)
|
|
|
- $shopExt = MainClass::getById($this->mainId, true, 'id, wxStoreId');
|
|
|
|
|
|
|
+ $main = MainClass::getById($this->mainId, true, 'id, wxStoreId');
|
|
|
|
|
|
|
|
// 查询是否存在 wx_store_id,不存在则执行apply
|
|
// 查询是否存在 wx_store_id,不存在则执行apply
|
|
|
- if ($shopExt->wxStoreId == '') {
|
|
|
|
|
|
|
+ if ($main->wxStoreId == '') {
|
|
|
$re = IntraCityExpress::applyStore();
|
|
$re = IntraCityExpress::applyStore();
|
|
|
if (!is_array($re)) {
|
|
if (!is_array($re)) {
|
|
|
$re = Json::decode($re, true);
|
|
$re = Json::decode($re, true);
|
|
@@ -82,8 +85,8 @@ class IntraCityController extends BaseController
|
|
|
$result = IntraCityExpress::createStore($storeData);
|
|
$result = IntraCityExpress::createStore($storeData);
|
|
|
if ($result['errcode'] === 0) {
|
|
if ($result['errcode'] === 0) {
|
|
|
// 保存微信门店编号(wx_store_id)
|
|
// 保存微信门店编号(wx_store_id)
|
|
|
- $shopExt->wxStoreId = $result['wx_store_id'];
|
|
|
|
|
- $shopExt->save();
|
|
|
|
|
|
|
+ $main->wxStoreId = $result['wx_store_id'];
|
|
|
|
|
+ $main->save();
|
|
|
|
|
|
|
|
util::success($result, "门店创建成功");
|
|
util::success($result, "门店创建成功");
|
|
|
} else {
|
|
} else {
|
|
@@ -103,14 +106,14 @@ class IntraCityController extends BaseController
|
|
|
{
|
|
{
|
|
|
$shopId = $this->shopId;
|
|
$shopId = $this->shopId;
|
|
|
// 首先从门店扩展表查询是否已经创建
|
|
// 首先从门店扩展表查询是否已经创建
|
|
|
- $shopExt = MainClass::getById($this->mainId, true, 'id, wxStoreId');
|
|
|
|
|
- if ($shopExt->wxStoreId == '') { // 不存在,则从微信接口查询
|
|
|
|
|
|
|
+ $main = MainClass::getById($this->mainId, true, 'id, wxStoreId');
|
|
|
|
|
+ if ($main->wxStoreId == '') { // 不存在,则从微信接口查询
|
|
|
$result = IntraCityExpress::getStore($this->mainId);
|
|
$result = IntraCityExpress::getStore($this->mainId);
|
|
|
if ($result['errcode'] === 0) {
|
|
if ($result['errcode'] === 0) {
|
|
|
$store = $result['store_list'][0];
|
|
$store = $result['store_list'][0];
|
|
|
// 保存 wx_store_id
|
|
// 保存 wx_store_id
|
|
|
- $shopExt->wxStoreId = $store['wx_store_id'];
|
|
|
|
|
- $shopExt->save();
|
|
|
|
|
|
|
+ $main->wxStoreId = $store['wx_store_id'];
|
|
|
|
|
+ $main->save();
|
|
|
|
|
|
|
|
util::success($store, "门店查询成功");
|
|
util::success($store, "门店查询成功");
|
|
|
} else {
|
|
} else {
|
|
@@ -120,7 +123,7 @@ class IntraCityController extends BaseController
|
|
|
} else {
|
|
} else {
|
|
|
$field = 'province, city, dist, lat, long, floor, address';
|
|
$field = 'province, city, dist, lat, long, floor, address';
|
|
|
$shop = ShopClass::getById($shopId, false, $field);
|
|
$shop = ShopClass::getById($shopId, false, $field);
|
|
|
- $data = array_merge($shop, $shopExt->toArray());
|
|
|
|
|
|
|
+ $data = array_merge($shop, $main->toArray());
|
|
|
util::success($data, "门店查询成功");
|
|
util::success($data, "门店查询成功");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -131,8 +134,8 @@ class IntraCityController extends BaseController
|
|
|
public function actionUpdateStore()
|
|
public function actionUpdateStore()
|
|
|
{
|
|
{
|
|
|
// 首先从门店扩展表查询是否已经创建
|
|
// 首先从门店扩展表查询是否已经创建
|
|
|
- $shopExt = MainClass::getById($this->mainId, false, 'id, wxStoreId');
|
|
|
|
|
- if ($shopExt['wxStoreId'] == '') {
|
|
|
|
|
|
|
+ $main = MainClass::getById($this->mainId, false, 'id, wxStoreId');
|
|
|
|
|
+ if ($main['wxStoreId'] == '') {
|
|
|
util::fail('未创建门店,请先创建');
|
|
util::fail('未创建门店,请先创建');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -142,7 +145,7 @@ class IntraCityController extends BaseController
|
|
|
$name = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
|
|
$name = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
|
|
|
|
|
|
|
|
$storeData = [
|
|
$storeData = [
|
|
|
- 'keys' => ['wx_store_id' => $shopExt['wxStoreId']],
|
|
|
|
|
|
|
+ 'keys' => ['wx_store_id' => $main['wxStoreId']],
|
|
|
'content' => [
|
|
'content' => [
|
|
|
'store_name' => $name,
|
|
'store_name' => $name,
|
|
|
'address_info' => [
|
|
'address_info' => [
|
|
@@ -259,7 +262,7 @@ class IntraCityController extends BaseController
|
|
|
util::fail("微信门店不存在");
|
|
util::fail("微信门店不存在");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $itemInfoList = OrderItemClass::getListBySn($sn);
|
|
|
|
|
|
|
+ $itemInfoList = OrderItemClass::getAllByCondition(['orderSn'=>$sn], null,'id, name, cover, num');
|
|
|
$orderType = 2; // 默认是 2。说明:1花束订单 2花材订单 3花束和花材都有
|
|
$orderType = 2; // 默认是 2。说明:1花束订单 2花材订单 3花束和花材都有
|
|
|
if (empty($itemInfoList)) {
|
|
if (empty($itemInfoList)) {
|
|
|
$orderType = 1;
|
|
$orderType = 1;
|
|
@@ -315,7 +318,7 @@ class IntraCityController extends BaseController
|
|
|
{
|
|
{
|
|
|
try {
|
|
try {
|
|
|
$post = Yii::$app->request->post();
|
|
$post = Yii::$app->request->post();
|
|
|
- $orderId = $post['orderId'];
|
|
|
|
|
|
|
+ $orderId = intval($post['orderId']);
|
|
|
$order = OrderClass::getById($orderId);
|
|
$order = OrderClass::getById($orderId);
|
|
|
if (empty($order)) {
|
|
if (empty($order)) {
|
|
|
util::fail('订单出错');
|
|
util::fail('订单出错');
|
|
@@ -325,59 +328,33 @@ class IntraCityController extends BaseController
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$sn = $order['orderSn'];
|
|
$sn = $order['orderSn'];
|
|
|
- $itemInfoList = OrderItemClass::getListBySn($sn, 'id, name, cover, num');
|
|
|
|
|
|
|
+ $itemInfoList = OrderItemClass::getAllByCondition(['orderSn'=>$sn], null,'id, name, cover, num');
|
|
|
$itemList = [];
|
|
$itemList = [];
|
|
|
- $orderType = 2; // 默认是 2。说明:1花束订单 2花材订单 3花束和花材都有
|
|
|
|
|
- if (empty($itemInfoList)) {
|
|
|
|
|
- $orderType = 1; // 花束订单
|
|
|
|
|
- $goodsInfoList = OrderGoodsClass::getListBySn($sn);
|
|
|
|
|
- $itemCount = 0;
|
|
|
|
|
- foreach ($goodsInfoList as $itemInfo) {
|
|
|
|
|
- $itemList[] = [
|
|
|
|
|
- 'item_name' => $itemInfo['name'],
|
|
|
|
|
- 'item_pic_url' => $itemInfo['bigCover'],
|
|
|
|
|
- 'count' => $itemInfo['num'],
|
|
|
|
|
- ];
|
|
|
|
|
- $itemCount += $itemInfo['num'];
|
|
|
|
|
- }
|
|
|
|
|
- $post['packageNum'] = $itemCount;
|
|
|
|
|
- } else {
|
|
|
|
|
- $itemCount = 0;
|
|
|
|
|
- foreach ($itemInfoList as $itemInfo) {
|
|
|
|
|
- $itemList[] = [
|
|
|
|
|
- 'item_name' => $itemInfo['name'],
|
|
|
|
|
- 'item_pic_url' => $itemInfo['bigCover'],
|
|
|
|
|
- 'count' => $itemInfo['num'],
|
|
|
|
|
- ];
|
|
|
|
|
- $itemCount += $itemInfo['num'];
|
|
|
|
|
- }
|
|
|
|
|
- $post['packageNum'] = $itemCount;
|
|
|
|
|
|
|
+ $itemCount = 0;
|
|
|
|
|
+ foreach ($itemInfoList as $itemInfo) {
|
|
|
|
|
+ $itemList[] = [
|
|
|
|
|
+ 'item_name' => $itemInfo['name'],
|
|
|
|
|
+ 'item_pic_url' => imgUtil::groupImg($itemInfo['cover']) . "?x-oss-process=image/resize,m_fill,h_130,w_130",
|
|
|
|
|
+ 'count' => intval($itemInfo['num']),
|
|
|
|
|
+ ];
|
|
|
|
|
+ $itemCount += intval($itemInfo['num']);
|
|
|
}
|
|
}
|
|
|
|
|
+ $post['packageNum'] = $itemCount;
|
|
|
|
|
|
|
|
$shopExt = MainClass::getById($this->mainId, false, 'id, wxStoreId');
|
|
$shopExt = MainClass::getById($this->mainId, false, 'id, wxStoreId');
|
|
|
if (empty($shopExt)) {
|
|
if (empty($shopExt)) {
|
|
|
util::fail("微信门店不存在");
|
|
util::fail("微信门店不存在");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $cargoName = '花材'; // 商品名称,默认是花材
|
|
|
|
|
- $goodsInfoList = OrderGoodsClass::getListBySn($sn);
|
|
|
|
|
- if (count($goodsInfoList) == 1) {
|
|
|
|
|
- $goodsInfo = $goodsInfoList[0];
|
|
|
|
|
- $cargoName = $goodsInfo['name'];
|
|
|
|
|
- } else {
|
|
|
|
|
- if ($orderType != 2) {
|
|
|
|
|
- Yii::error('订单商品数量不正确');
|
|
|
|
|
- util::fail("订单商品数量不正确");
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 通过 userId 获取 openid(小程序OpenId)
|
|
|
|
|
- $user = UserClass::getById($order['userId'], false, 'id, miniOpenId');
|
|
|
|
|
|
|
+ // 获取 openid(小程序OpenId)
|
|
|
|
|
+ $user = UserClass::getByCondition(['mobile'=>$order['customMobile']], false, false,'id, miniOpenId');
|
|
|
if (empty($user)) {
|
|
if (empty($user)) {
|
|
|
|
|
+ noticeUtil::push("通过手机号-".$order['customMobile'].",获取小程序OpenId失败");
|
|
|
Yii::error('获取用户openId出错');
|
|
Yii::error('获取用户openId出错');
|
|
|
util::fail('数据出错');
|
|
util::fail('数据出错');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ $cargoName = '花材'; // 商品名称
|
|
|
$cargo = [
|
|
$cargo = [
|
|
|
'cargo_name' => $cargoName,
|
|
'cargo_name' => $cargoName,
|
|
|
'cargo_weight' => intval($post['weight'] * 1000),
|
|
'cargo_weight' => intval($post['weight'] * 1000),
|
|
@@ -388,34 +365,35 @@ class IntraCityController extends BaseController
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
//生成 store_order_id
|
|
//生成 store_order_id
|
|
|
- $storeOrderId = $orderId;
|
|
|
|
|
- if ($post['isNew'] == 0) { // 如果不是首次用 $orderId 创建快递配送,则要生成新 store_order_id
|
|
|
|
|
- // store_order_id 门店订单编号, 即 orderId。如果是重新配送的第n次,订单编号的命名规则为:orderId_copy_n
|
|
|
|
|
|
|
+ $storeOrderId = $orderId . '_ghs';;
|
|
|
|
|
+ if (true) { // 如果不是首次用 $orderId 创建快递配送,则要生成新 store_order_id
|
|
|
|
|
+ // store_order_id 门店订单编号, 即 orderId。如果是重新配送的第n次,订单编号的命名规则为:orderId_cp_n
|
|
|
$query = (new Query())
|
|
$query = (new Query())
|
|
|
- ->from('xhExpressOrder')
|
|
|
|
|
- ->where(new \yii\db\Expression('storeOrderId LIKE CONCAT(:prefix, "%")', [':prefix' => $orderId . '_copy_%']))
|
|
|
|
|
- ->andWhere(['mainId' => $this->mainId]);
|
|
|
|
|
- // $command = $query->createCommand();
|
|
|
|
|
- // $sql = $command->sql;
|
|
|
|
|
|
|
+ ->from('xhGhsExpressOrder')
|
|
|
|
|
+ ->where(['orderId' => $orderId]);
|
|
|
$copyOrderCount = $query->count();
|
|
$copyOrderCount = $query->count();
|
|
|
$copyOrderCount += 1;
|
|
$copyOrderCount += 1;
|
|
|
- $storeOrderId = $orderId . '_copy_' . $copyOrderCount;
|
|
|
|
|
|
|
+ //区分线上线下
|
|
|
|
|
+ if (getenv('YII_ENV') == 'production') {
|
|
|
|
|
+ $storeOrderId = $storeOrderId . '_cp_' . $copyOrderCount;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $storeOrderId = $storeOrderId . '_cs_cp_' . $copyOrderCount;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
- $callbackUrl = Yii::$app->params['hdHost'] . '/intra-city/callback';
|
|
|
|
|
|
|
+ $callbackUrl = Yii::$app->params['ghsHost'] . '/intra-city/callback';
|
|
|
$orderData = [
|
|
$orderData = [
|
|
|
'wx_store_id' => $shopExt['wxStoreId'],
|
|
'wx_store_id' => $shopExt['wxStoreId'],
|
|
|
'store_order_id' => $storeOrderId, //同一个门店订单编号要保证唯一,相同的订单号会重入
|
|
'store_order_id' => $storeOrderId, //同一个门店订单编号要保证唯一,相同的订单号会重入
|
|
|
- 'user_openid' => $user['miniOpenId'],
|
|
|
|
|
- 'user_lng' => $post['user_lng'],
|
|
|
|
|
- 'user_lat' => $post['user_lat'],
|
|
|
|
|
|
|
+ 'user_openid' => $user['miniOpenId'],//'o-hXO4kkdM2nqORdiII42FlcdeL4'
|
|
|
|
|
+ 'user_lng' => (float)$post['user_lng'],
|
|
|
|
|
+ 'user_lat' => (float)$post['user_lat'],
|
|
|
'user_address' => $post['user_address'],
|
|
'user_address' => $post['user_address'],
|
|
|
'user_name' => $post['user_name'],
|
|
'user_name' => $post['user_name'],
|
|
|
- 'user_phone' => $post['user_phone'],
|
|
|
|
|
- //'order_seq' => '', // 用于配送员快速寻找到匹配的商品(非必传)
|
|
|
|
|
|
|
+ 'user_phone' => (string)$post['user_phone'],
|
|
|
|
|
+ 'order_seq' => $order['sendNum'], // 用于配送员快速寻找到匹配的商品(非必传) -- 对应 xhOrder 表的 sendNum
|
|
|
'verify_code_type' => 0,
|
|
'verify_code_type' => 0,
|
|
|
- 'order_detail_path' => '/admin/order/detail?id=' . $orderId, // TODO 使用花掌柜的地址,后期要重新选个地址
|
|
|
|
|
|
|
+ 'order_detail_path' => '/pagesOrder/detail?id=' . $orderId, // TODO 后期要重新选个地址
|
|
|
'callback_url' => $callbackUrl, // 订单状态回调地址(非必传)
|
|
'callback_url' => $callbackUrl, // 订单状态回调地址(非必传)
|
|
|
//'use_sandbox' => getenv('YII_ENV') == 'production' ? 0 : 1, // 是否使用沙箱(非必传)
|
|
//'use_sandbox' => getenv('YII_ENV') == 'production' ? 0 : 1, // 是否使用沙箱(非必传)
|
|
|
'cargo' => $cargo
|
|
'cargo' => $cargo
|
|
@@ -423,32 +401,45 @@ class IntraCityController extends BaseController
|
|
|
$result = IntraCityExpress::createOrder($orderData);
|
|
$result = IntraCityExpress::createOrder($orderData);
|
|
|
|
|
|
|
|
if (isset($result['errcode']) && $result['errcode'] === 0) {
|
|
if (isset($result['errcode']) && $result['errcode'] === 0) {
|
|
|
- OrderClass::updateById($orderId, ['sendStatus' => 1]); // 更新订单状态为配送中
|
|
|
|
|
-
|
|
|
|
|
- // 保存进 xhExpressOrder 表
|
|
|
|
|
- $orderData = [
|
|
|
|
|
- 'mainId' => $this->mainId,
|
|
|
|
|
- 'shopId' => $this->shopId,
|
|
|
|
|
- 'deliveryId' => isset($result['service_trans_id']) ? $result['service_trans_id'] : '',
|
|
|
|
|
- 'wxOrderId' => isset($result['wx_order_id']) ? $result['wx_order_id'] : '',
|
|
|
|
|
- 'wxStoreId' => isset($result['wx_store_id']) ? $result['wx_store_id'] : '',
|
|
|
|
|
- 'storeOrderId' => isset($result['store_order_id']) ? $result['store_order_id'] : '',
|
|
|
|
|
- 'transOrderId' => isset($result['trans_order_id']) ? $result['trans_order_id'] : '',
|
|
|
|
|
- 'distance' => isset($result['distance']) ? $result['distance'] : 0,
|
|
|
|
|
- 'fee' => isset($result['fee']) ? $result['fee'] : 0,
|
|
|
|
|
- 'fetchCode' => isset($result['fetch_code']) ? $result['fetch_code'] : '',
|
|
|
|
|
- 'orderSeq' => isset($result['order_seq']) ? $result['order_seq'] : ''
|
|
|
|
|
- ];
|
|
|
|
|
- ExpressOrderClass::add($orderData);
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 保存进 xhGhsExpressOrder 表
|
|
|
|
|
+ $data = [
|
|
|
|
|
+ 'mainId' => $this->mainId,
|
|
|
|
|
+ 'shopId' => $this->shopId,
|
|
|
|
|
+ 'deliveryId' => isset($result['service_trans_id']) ? $result['service_trans_id'] : '',
|
|
|
|
|
+ 'wxOrderId' => isset($result['wx_order_id']) ? $result['wx_order_id'] : '',
|
|
|
|
|
+ 'wxStoreId' => isset($result['wx_store_id']) ? $result['wx_store_id'] : '',
|
|
|
|
|
+ 'storeOrderId' => isset($result['store_order_id']) ? $result['store_order_id'] : '',
|
|
|
|
|
+ 'orderId' => $orderId,
|
|
|
|
|
+ 'transOrderId' => isset($result['trans_order_id']) ? $result['trans_order_id'] : '',
|
|
|
|
|
+ 'distance' => isset($result['distance']) ? $result['distance'] : 0,
|
|
|
|
|
+ 'fee' => isset($result['fee']) ? $result['fee'] : 0,
|
|
|
|
|
+ 'fetchCode' => isset($result['fetch_code']) ? $result['fetch_code'] : '',
|
|
|
|
|
+ 'orderSeq' => isset($result['order_seq']) ? $result['order_seq'] : ''
|
|
|
|
|
+ ];
|
|
|
|
|
+ ExpressOrderClass::add($data);
|
|
|
|
|
|
|
|
- util::success(['fee' => $result['fee']], '订单创建成功');
|
|
|
|
|
|
|
+ $updateData = [
|
|
|
|
|
+ 'sendDistance' => $data['distance'],
|
|
|
|
|
+ 'sendStatus' => 0,
|
|
|
|
|
+ 'deliveryId' => $data['deliveryId'],
|
|
|
|
|
+ ];
|
|
|
|
|
+ OrderClass::updateById($orderId, $updateData); // 更新订单状态为配送中
|
|
|
|
|
+ util::success(['fee' => $data['fee']], '订单创建成功');
|
|
|
|
|
+ } catch (\Exception $e) {
|
|
|
|
|
+ Yii::error('同城配送创建订单保存数据失败:' . $e->getMessage());
|
|
|
|
|
+ util::fail('订单创建失败');
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if (isset($result['errcode']) && $result['errcode'] === 934002) {
|
|
|
|
|
+ Yii::error("重复创建订单:" . ($result['errmsg'] ?? '未知错误'), 'intraCity');
|
|
|
|
|
+ util::fail( '重复创建订单: ' . $result['errcode']);
|
|
|
} else {
|
|
} else {
|
|
|
- noticeUtil::push("门店 -- " . $this->mainId . ",订单创建失败:" . json_encode($result));
|
|
|
|
|
- Yii::error("订单创建失败:" . ($result['errmsg'] ?? '未知错误'), 'intracity');
|
|
|
|
|
|
|
+ noticeUtil::push("批发 -- " . $this->mainId . ",订单创建失败:" . json_encode($result));
|
|
|
|
|
+ Yii::error("订单创建失败:" . ($result['errmsg'] ?? '未知错误'), 'intraCity');
|
|
|
util::fail( '订单创建失败: ' . $result['errcode']);
|
|
util::fail( '订单创建失败: ' . $result['errcode']);
|
|
|
}
|
|
}
|
|
|
} catch (\Exception $e) {
|
|
} catch (\Exception $e) {
|
|
|
- Yii::error("订单创建异常:" . $e->getMessage(), 'intracity');
|
|
|
|
|
|
|
+ Yii::error("订单创建异常:" . $e->getMessage(), 'intraCity');
|
|
|
util::fail("系统出错");
|
|
util::fail("系统出错");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -481,21 +472,14 @@ class IntraCityController extends BaseController
|
|
|
// 检查是否存在重复的订单:如果存在,则使用最后一个订单的 store_order_id
|
|
// 检查是否存在重复的订单:如果存在,则使用最后一个订单的 store_order_id
|
|
|
$storeOrderId = $orderId; // ------------------------------------- 注意区分:$storeOrderId , $orderId 。它们有可能不相同
|
|
$storeOrderId = $orderId; // ------------------------------------- 注意区分:$storeOrderId , $orderId 。它们有可能不相同
|
|
|
$query = (new Query())
|
|
$query = (new Query())
|
|
|
- ->from('xhExpressOrder')
|
|
|
|
|
- ->where(['and',
|
|
|
|
|
- new \yii\db\Expression('storeOrderId LIKE CONCAT(:prefix, "%")', [':prefix' => $orderId . '_copy_']),
|
|
|
|
|
- ['status' => 1]
|
|
|
|
|
- ])->andWhere(['mainId' => $this->mainId])
|
|
|
|
|
- ->orderBy('addTime DESC');
|
|
|
|
|
|
|
+ ->from('xhGhsExpressOrder')
|
|
|
|
|
+ ->where(['orderId' => $orderId])
|
|
|
|
|
+ ->andWhere(['mainId' => $this->mainId]);
|
|
|
$esDatas = $query->all();
|
|
$esDatas = $query->all();
|
|
|
$count = count($esDatas);
|
|
$count = count($esDatas);
|
|
|
if ($count > 0) {
|
|
if ($count > 0) {
|
|
|
$es = $esDatas[0];
|
|
$es = $esDatas[0];
|
|
|
$storeOrderId = $es['storeOrderId'];
|
|
$storeOrderId = $es['storeOrderId'];
|
|
|
-
|
|
|
|
|
- if ($count > 1) {
|
|
|
|
|
- noticeUtil::push('同城配送订单重复多于1个. store_order_id:' . $orderId . ',wx_store_id:' . $wxStoreId);
|
|
|
|
|
- }
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -521,14 +505,14 @@ class IntraCityController extends BaseController
|
|
|
try {
|
|
try {
|
|
|
$post = Yii::$app->request->post();
|
|
$post = Yii::$app->request->post();
|
|
|
|
|
|
|
|
- $shopExt = MainClass::getById($this->mainId, false, 'id, wxStoreId');
|
|
|
|
|
- if (empty($shopExt)) {
|
|
|
|
|
|
|
+ $main = MainClass::getById($this->mainId, false, 'id, wxStoreId');
|
|
|
|
|
+ if (empty($main)) {
|
|
|
util::fail("微信门店不存在");
|
|
util::fail("微信门店不存在");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$wxOrderId = isset($post['wx_order_id']) ? $post['wx_order_id'] : '';
|
|
$wxOrderId = isset($post['wx_order_id']) ? $post['wx_order_id'] : '';
|
|
|
$orderId = $post['orderId']; //配送订单创建成功后,也会返回的 store_order_id。 即 orderId
|
|
$orderId = $post['orderId']; //配送订单创建成功后,也会返回的 store_order_id。 即 orderId
|
|
|
- $wxStoreId = isset($post['wx_store_id']) ? $post['wx_store_id'] : $shopExt['wxStoreId'];
|
|
|
|
|
|
|
+ $wxStoreId = isset($post['wx_store_id']) ? $post['wx_store_id'] : $main['wxStoreId'];
|
|
|
if (empty($wxOrderId) && (empty($orderId) || empty($wxStoreId))) {
|
|
if (empty($wxOrderId) && (empty($orderId) || empty($wxStoreId))) {
|
|
|
util::fail("参数不足:wx_order_id 或 (store_order_id + wx_store_id) 必须提供一组");
|
|
util::fail("参数不足:wx_order_id 或 (store_order_id + wx_store_id) 必须提供一组");
|
|
|
}
|
|
}
|
|
@@ -536,18 +520,16 @@ class IntraCityController extends BaseController
|
|
|
if ($order['mainId'] != $this->mainId) {
|
|
if ($order['mainId'] != $this->mainId) {
|
|
|
util::fail('订单未找到');
|
|
util::fail('订单未找到');
|
|
|
}
|
|
}
|
|
|
- if ($order['sendStatus'] != 1) {
|
|
|
|
|
- util::fail('配送单状态不是配送中');
|
|
|
|
|
|
|
+ if (!in_array($order['sendStatus'], [0, 1, 4, 5])) {
|
|
|
|
|
+ util::fail('配送单当前状态不能取消');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 检查是否存在重复的订单,如果存在,则使用最后一个订单的 store_order_id
|
|
// 检查是否存在重复的订单,如果存在,则使用最后一个订单的 store_order_id
|
|
|
$storeOrderId = $orderId; // ------------------------------------- 注意区分:$storeOrderId , $orderId 。它们有可能不相同
|
|
$storeOrderId = $orderId; // ------------------------------------- 注意区分:$storeOrderId , $orderId 。它们有可能不相同
|
|
|
$query = (new Query())
|
|
$query = (new Query())
|
|
|
- ->from('xhExpressOrder')
|
|
|
|
|
- ->where(['and',
|
|
|
|
|
- new \yii\db\Expression('storeOrderId LIKE CONCAT(:prefix, "%")', [':prefix' => $orderId . '_copy_']),
|
|
|
|
|
- ['status' => 1]
|
|
|
|
|
- ])->andWhere(['mainId' => $this->mainId])
|
|
|
|
|
|
|
+ ->from('xhGhsExpressOrder')
|
|
|
|
|
+ ->where(['orderId' => $orderId])
|
|
|
|
|
+ ->andWhere(['status' => 1])
|
|
|
->orderBy('addTime DESC');
|
|
->orderBy('addTime DESC');
|
|
|
// $command = $query->createCommand();
|
|
// $command = $query->createCommand();
|
|
|
// $sql = $command->sql;
|
|
// $sql = $command->sql;
|
|
@@ -559,14 +541,14 @@ class IntraCityController extends BaseController
|
|
|
$storeOrderId = $es['storeOrderId'];
|
|
$storeOrderId = $es['storeOrderId'];
|
|
|
|
|
|
|
|
if ($count > 1) {
|
|
if ($count > 1) {
|
|
|
- noticeUtil::push('同城配送订单重复多于1个. store_order_id:' . $orderId . ',wx_store_id:' . $wxStoreId);
|
|
|
|
|
|
|
+ noticeUtil::push('同城配送订单重复多于1个. store_order_id:' . $storeOrderId . ',wx_store_id:' . $wxStoreId);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$result = IntraCityExpress::cancelOrder($wxOrderId, $storeOrderId, $wxStoreId);
|
|
$result = IntraCityExpress::cancelOrder($wxOrderId, $storeOrderId, $wxStoreId);
|
|
|
if (isset($result['errcode']) && $result['errcode'] === 0) {
|
|
if (isset($result['errcode']) && $result['errcode'] === 0) {
|
|
|
// 更新订单状态
|
|
// 更新订单状态
|
|
|
- OrderClass::updateById($orderId, ['sendStatus' => OrderClass::ORDER_STATUS_CANCEL]);//设置为取消状态
|
|
|
|
|
|
|
+ OrderClass::updateById($orderId, ['sendStatus' => 3]);//设置为取消状态
|
|
|
$eo = ExpressOrderClass::getByCondition(['storeOrderId' => $storeOrderId, 'wxStoreId' => $wxStoreId], true);
|
|
$eo = ExpressOrderClass::getByCondition(['storeOrderId' => $storeOrderId, 'wxStoreId' => $wxStoreId], true);
|
|
|
if (!empty($eo)) {
|
|
if (!empty($eo)) {
|
|
|
$eo->status = 3;
|
|
$eo->status = 3;
|
|
@@ -579,7 +561,7 @@ class IntraCityController extends BaseController
|
|
|
} else {
|
|
} else {
|
|
|
if ($result['errcode'] == 934018) { // 93401 -- 订单已取消,请勿重复操作
|
|
if ($result['errcode'] == 934018) { // 93401 -- 订单已取消,请勿重复操作
|
|
|
// 更新订单状态
|
|
// 更新订单状态
|
|
|
- OrderClass::updateById($orderId, ['sendStatus' => OrderClass::ORDER_STATUS_CANCEL]);//设置为取消状态
|
|
|
|
|
|
|
+ OrderClass::updateById($orderId, ['sendStatus' => 3]);//设置为取消状态
|
|
|
util::success($result, "订单取消成功");
|
|
util::success($result, "订单取消成功");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -587,9 +569,163 @@ class IntraCityController extends BaseController
|
|
|
util::fail('订单取消失败: ' . $result['errcode']);
|
|
util::fail('订单取消失败: ' . $result['errcode']);
|
|
|
}
|
|
}
|
|
|
} catch (\Exception $e) {
|
|
} catch (\Exception $e) {
|
|
|
- Yii::error("订单取消异常:" . $e->getMessage(), 'intracity');
|
|
|
|
|
|
|
+ Yii::error("订单取消异常:" . $e->getMessage(), 'intraCity');
|
|
|
util::fail("系统出错");
|
|
util::fail("系统出错");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 微信回调接口
|
|
|
|
|
+ */
|
|
|
|
|
+ public function actionCallback()
|
|
|
|
|
+ {
|
|
|
|
|
+ $callbackData = Yii::$app->request->post();
|
|
|
|
|
+ if (empty($callbackData)) {
|
|
|
|
|
+ $postStr = file_get_contents('php://input');
|
|
|
|
|
+ $callbackData = json_decode($postStr, true);
|
|
|
|
|
+
|
|
|
|
|
+ if (empty($callbackData)) {
|
|
|
|
|
+ util::fail('回调请求的数据为空');
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 从配置中获取安全token
|
|
|
|
|
+ // $token = Yii::$app->params['wx_intracity_token'] ?? 'your_token_here';
|
|
|
|
|
+ // $result = IntraCityExpress::handleOrderCallback($callbackData, $token);
|
|
|
|
|
+ // 记录回调日志
|
|
|
|
|
+ Yii::info('同城配送回调:' . json_encode($callbackData, JSON_UNESCAPED_UNICODE), 'intraCity');
|
|
|
|
|
+
|
|
|
|
|
+ $storeOrderId = $callbackData['store_order_id'] ?? 0;
|
|
|
|
|
+ $wxStoreId = $callbackData['wx_store_id'] ?? ''; //微信门店编号
|
|
|
|
|
+ if (empty($storeOrderId) || empty($wxStoreId)) {
|
|
|
|
|
+ Yii::error("配送单回调接口的请求参数出错,storeOrderId = $storeOrderId, wxStoreId = $wxStoreId");
|
|
|
|
|
+ return $this->asJson(['return_code' => 1, 'return_msg' => '请求参数不正确']);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 使用 storeOrderId 与 wxStoreId 去查询 xhExpressOrder 表
|
|
|
|
|
+ $eo = ExpressOrderClass::getByCondition(['storeOrderId' => $storeOrderId, 'wxStoreId' => $wxStoreId], true, false);
|
|
|
|
|
+ if (empty($eo)) {
|
|
|
|
|
+ Yii::error('订单不存在. store_order_id: ' . $storeOrderId . ',wx_store_id: ' . $wxStoreId);
|
|
|
|
|
+ return $this->asJson(['return_code' => 1, 'return_msg' => '系统错误']);
|
|
|
|
|
+ }
|
|
|
|
|
+ // 从 $storeOrderId 提取 orderId
|
|
|
|
|
+ $arr = explode('_', $storeOrderId);
|
|
|
|
|
+ $orderId = intval($arr[0]);
|
|
|
|
|
+ if ($orderId == 0) {
|
|
|
|
|
+ Yii::error('订单号为0. store_order_id: ' . $storeOrderId . ',wx_store_id: ' . $wxStoreId);
|
|
|
|
|
+ return $this->asJson(['return_code' => 1, 'return_msg' => '系统错误']);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $tx = Yii::$app->db->beginTransaction(); // ====================== 开启事务
|
|
|
|
|
+ $msg = ''; // 发通知的内容(默认为空,根据情况生成。没有内容则不会发通知)
|
|
|
|
|
+ $orderStatus = intval($callbackData['order_status']);
|
|
|
|
|
+ switch ($orderStatus) {
|
|
|
|
|
+ // 订单创建成功
|
|
|
|
|
+ case IntraCityExpress::ORDER_STATUS_CREATED:
|
|
|
|
|
+ $eo->orderStatus = 1;
|
|
|
|
|
+ // 更新 xhOrder 表的订单状态与配送状态 -- 配送中|已发货
|
|
|
|
|
+ OrderClass::updateById($orderId, ['status' => 3, 'sendStatus' => 0]);
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ // 商家取消订单
|
|
|
|
|
+ case IntraCityExpress::ORDER_STATUS_CANCELED_BY_MERCHANT:
|
|
|
|
|
+ $eo->orderStatus = 2;
|
|
|
|
|
+ // 更新 xhOrder 表的订单状态与配送状态 -- 待配送|取消
|
|
|
|
|
+ OrderClass::updateById($orderId, ['status' => 2, 'sendStatus' => 3]);
|
|
|
|
|
+ $msg = '取消配送,订单编号 ';
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ // 配送方取消订单
|
|
|
|
|
+ case IntraCityExpress::ORDER_STATUS_CANCELED_BY_DELIVERY:
|
|
|
|
|
+ $eo->orderStatus = 3;
|
|
|
|
|
+ $eo->status = 0;
|
|
|
|
|
+ // 更新 xhOrder 表的订单状态与配送状态 -- 待配送|取消
|
|
|
|
|
+ OrderClass::updateById($orderId, ['status' => 2, 'sendStatus' => 3]);
|
|
|
|
|
+ $msg = '配送方取消配送,订单编号 ';
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ // 配送员接单
|
|
|
|
|
+ case IntraCityExpress::ORDER_STATUS_ACCEPTED:
|
|
|
|
|
+ $eo->orderStatus = 4;
|
|
|
|
|
+ // 更新 xhOrder 表的订单状态与配送状态 -- 配送中|已发货
|
|
|
|
|
+ OrderClass::updateById($orderId, ['status' => 3, 'sendStatus' => 1]); //订单创建时已执行了,这儿重复更新
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ // 配送员到店
|
|
|
|
|
+ case IntraCityExpress::ORDER_STATUS_ARRIVED:
|
|
|
|
|
+ $eo->orderStatus = 5;
|
|
|
|
|
+ // 更新 xhOrder 表的订单状态与配送状态 -- 配送中|已发货
|
|
|
|
|
+ OrderClass::updateById($orderId, ['status' => 3, 'sendStatus' => 4]); //订单创建时已执行了,这儿重复更新
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ // 配送中
|
|
|
|
|
+ case IntraCityExpress::ORDER_STATUS_DELIVERING:
|
|
|
|
|
+ $eo->orderStatus = 6;
|
|
|
|
|
+ OrderClass::updateById($orderId, ['sendStatus' => 5]);
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ // 配送员撤单
|
|
|
|
|
+ case IntraCityExpress::ORDER_STATUS_WITHDRAWN:
|
|
|
|
|
+ $eo->orderStatus = 7;
|
|
|
|
|
+ $eo->status = 0;
|
|
|
|
|
+ // 更新 xhOrder 表的订单状态与配送状态 -- 待配送|未发货
|
|
|
|
|
+ OrderClass::updateById($orderId, ['status' => 2, 'sendStatus' => 3]);
|
|
|
|
|
+ $msg = '跑腿取消配送,订单编号 ';
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ // 配送完成
|
|
|
|
|
+ case IntraCityExpress::ORDER_STATUS_COMPLETED:
|
|
|
|
|
+ $eo->orderStatus = 8;
|
|
|
|
|
+ // 更新 xhOrder 表的订单状态与配送状态 -- 已完成|已送达
|
|
|
|
|
+ OrderClass::updateById($orderId, ['status' => 4, 'sendStatus' => 2]);
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ // 配送异常
|
|
|
|
|
+ case IntraCityExpress::ORDER_STATUS_EXCEPTION:
|
|
|
|
|
+ $eo->orderStatus = 9;
|
|
|
|
|
+ $eo->status = 0;
|
|
|
|
|
+ noticeUtil::push('同城配送异常 --- store_order_id(orderId):' . $storeOrderId . ',wx_store_id:' . $wxStoreId);
|
|
|
|
|
+ // 更新 xhOrder 表的订单状态与配送状态 -- 待配送|未发货
|
|
|
|
|
+ OrderClass::updateById($orderId, ['status' => 2, 'sendStatus' => 3]);
|
|
|
|
|
+ $msg = '订单配送异常,订单编号 ';
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if ($msg != '') { // $msg 不为空,则发通知
|
|
|
|
|
+ $order = OrderClass::getById($orderId, true, 'id, shopId, customName, sendNum');
|
|
|
|
|
+ $shop = ShopClass::getById($order->shopId, true, 'id, ptStyle, mainId');
|
|
|
|
|
+ $result = $msg . $order->sendNum;
|
|
|
|
|
+ WxMessageClass::expressErrorInform($shop, $order->customName, $orderId, $result);
|
|
|
|
|
+ }
|
|
|
|
|
+ $re = $eo->save();
|
|
|
|
|
+ if (!$re) {
|
|
|
|
|
+ noticeUtil::push('同城配送回调更新订单状态失败. store_order_id:' . $storeOrderId . ',wx_store_id:' . $wxStoreId . ',status:' . $eo->status);
|
|
|
|
|
+ Yii::error('更新订单状态失败. store_order_id:' . $storeOrderId . ',wx_store_id:' . $wxStoreId . ',status:' . $eo->status);
|
|
|
|
|
+ $tx->rollBack(); // ====================== 事务回滚
|
|
|
|
|
+ return $this->asJson(['return_code' => 1, 'return_msg' => '系统错误']);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $tx->commit(); // ====================== 事务提交
|
|
|
|
|
+ return $this->asJson(['return_code' => 0, 'return_msg' => 'OK']); // 成功状态的返回数据
|
|
|
|
|
+ } catch (\Exception $e) {
|
|
|
|
|
+ Yii::error('同城配送回调处理异常:' . $e->getMessage());
|
|
|
|
|
+ return $this->asJson(['return_code' => 1, 'return_msg' => '系统错误']);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ //模拟接口回调 ssh 20250826
|
|
|
|
|
+ public function actionMockNotify()
|
|
|
|
|
+ {
|
|
|
|
|
+ if (getenv('YII_ENV') != 'production') {
|
|
|
|
|
+ $post = Yii::$app->request->post();
|
|
|
|
|
+ $orderStatus = $post['orderStatus'] ?? 0;
|
|
|
|
|
+ $wxOrderId = $post['wxOrderId'] ?? '';
|
|
|
|
|
+ $ptStyle = dict::getDict('ptStyle', 'hd');
|
|
|
|
|
+ $merchant = WxOpenClass::getWxInfo();
|
|
|
|
|
+ $ret = IntraCityExpress::mockNotify($orderStatus, $wxOrderId, '', '', $merchant, $ptStyle);
|
|
|
|
|
+ util::success($ret);
|
|
|
|
|
+ }
|
|
|
|
|
+ util::complete();
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|