Sfoglia il codice sorgente

Merge branch 'zhongqi-ghsCallExpress'

shish 10 mesi fa
parent
commit
d1b623dbd0

+ 255 - 119
app-ghs/controllers/IntraCityController.php

@@ -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();
+    }
 }
 }

+ 8 - 20
app-hd/controllers/IntraCityController.php

@@ -333,7 +333,7 @@ class IntraCityController extends BaseController
             $adminId = $this->adminId;
             $adminId = $this->adminId;
             util::checkRepeatCommit($adminId, 4);
             util::checkRepeatCommit($adminId, 4);
 
 
-            $orderId = $post['orderId'];
+            $orderId = intval($post['orderId']);
             $field = 'mainId, status, sendStatus, repeat, forward, orderSn, userId, actPrice, sendNum, salt';
             $field = 'mainId, status, sendStatus, repeat, forward, orderSn, userId, actPrice, sendNum, salt';
             $order = OrderClass::getById($orderId, false, $field);
             $order = OrderClass::getById($orderId, false, $field);
             if (empty($order)) {
             if (empty($order)) {
@@ -371,7 +371,7 @@ class IntraCityController extends BaseController
                     $itemList[] = [
                     $itemList[] = [
                         'item_name' => $itemInfo['name'],
                         'item_name' => $itemInfo['name'],
                         'item_pic_url' => $itemInfo['bigCover'],
                         'item_pic_url' => $itemInfo['bigCover'],
-                        'count' => $itemInfo['num'],
+                        'count' => intval($itemInfo['num']),
                     ];
                     ];
                     $itemCount += $itemInfo['num'];
                     $itemCount += $itemInfo['num'];
                 }
                 }
@@ -382,7 +382,7 @@ class IntraCityController extends BaseController
                     $itemList[] = [
                     $itemList[] = [
                         'item_name' => $itemInfo['name'],
                         'item_name' => $itemInfo['name'],
                         'item_pic_url' => $itemInfo['bigCover'],
                         'item_pic_url' => $itemInfo['bigCover'],
-                        'count' => $itemInfo['num'],
+                        'count' => intval($itemInfo['num']),
                     ];
                     ];
                     $itemCount += $itemInfo['num'];
                     $itemCount += $itemInfo['num'];
                 }
                 }
@@ -429,7 +429,7 @@ class IntraCityController extends BaseController
             //生成 store_order_id,加统一后缀,避免线上线下ID命中
             //生成 store_order_id,加统一后缀,避免线上线下ID命中
             $storeOrderId = $orderId . '_exp';
             $storeOrderId = $orderId . '_exp';
             if ($order['sendStatus'] == 3) { // 如果不是首次用 $orderId 创建快递配送,则要生成新 store_order_id
             if ($order['sendStatus'] == 3) { // 如果不是首次用 $orderId 创建快递配送,则要生成新 store_order_id
-                // store_order_id 门店订单编号, 即 orderId。如果是重新配送的第n次,订单编号的命名规则为:orderId_copy_n
+                // store_order_id 门店订单编号, 即 orderId。如果是重新配送的第n次,订单编号的命名规则为:orderId_cp_n
                 $query = (new Query())
                 $query = (new Query())
                     ->from('xhExpressOrder')
                     ->from('xhExpressOrder')
                     ->where(['orderId' => $orderId]);
                     ->where(['orderId' => $orderId]);
@@ -463,16 +463,6 @@ class IntraCityController extends BaseController
                 'cargo' => $cargo
                 'cargo' => $cargo
             ];
             ];
 
 
-            //开发环境只能使用沙箱 ssh
-            if (getenv('YII_ENV') != 'production') {
-                $orderData['use_sandbox'] = 1;
-                $orderData['user_name'] = '顺丰同城';
-                $orderData['user_phone'] = 13881979410;
-                $orderData['user_address'] = '北京市海淀区学清嘉创大厦A座15层';
-                $orderData['user_lng'] = '116.352954';
-                $orderData['user_lat'] = '40.014747';
-            }
-
             $result = IntraCityExpress::createOrder($orderData);
             $result = IntraCityExpress::createOrder($orderData);
 
 
             if (isset($result['errcode']) && $result['errcode'] === 0) {
             if (isset($result['errcode']) && $result['errcode'] === 0) {
@@ -580,16 +570,14 @@ class IntraCityController extends BaseController
             $adminId = $this->adminId;
             $adminId = $this->adminId;
             util::checkRepeatCommit($adminId, 4);
             util::checkRepeatCommit($adminId, 4);
 
 
-            //$shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], false, false, 'id, wxStoreId');
-            $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_order_id'] : $shopExt['wxStoreId'];
-            $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) 必须提供一组");
             }
             }
@@ -638,7 +626,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, "订单取消成功");
                 }
                 }
 
 

+ 9 - 0
biz-ghs/express/classes/GhsExpressOrderClass.php

@@ -0,0 +1,9 @@
+<?php
+namespace bizGhs\express\classes;
+
+use bizGhs\base\classes\BaseClass;
+
+class GhsExpressOrderClass extends BaseClass
+{
+    public static $baseFile = '\bizGhs\express\models\GhsExpressOrder';
+}

+ 13 - 0
biz-ghs/express/models/GhsExpressOrder.php

@@ -0,0 +1,13 @@
+<?php
+namespace bizGhs\express\models;
+use bizGhs\base\models\Base;
+
+class GhsExpressOrder extends Base
+{
+
+    public static function tableName()
+    {
+        return 'xhGhsExpressOrder';
+    }
+
+}

+ 0 - 4
biz-hd/express/classes/ExpressOrderClass.php

@@ -7,8 +7,4 @@ class ExpressOrderClass extends BaseClass
 {
 {
     public static $baseFile = '\bizHd\express\models\ExpressOrder';
     public static $baseFile = '\bizHd\express\models\ExpressOrder';
 
 
-    public static function getOrderList()
-    {
-
-    }
 }
 }

+ 63 - 53
common/components/IntraCityExpress.php

@@ -11,6 +11,22 @@ use phpseclib\Crypt\RSA;
 
 
 class IntraCityExpress
 class IntraCityExpress
 {
 {
+    /**
+     * 订单状态常量
+     */
+    const ORDER_STATUS_CREATED = 10000;        // 订单创建成功
+    const ORDER_STATUS_CANCELED_BY_MERCHANT = 20000;  // 商家取消订单
+    const ORDER_STATUS_CANCELED_BY_DELIVERY = 20001;  // 配送方取消订单
+    const ORDER_STATUS_ACCEPTED = 30000;       // 配送员接单
+    const ORDER_STATUS_ARRIVED = 40000;        // 配送员到店
+    const ORDER_STATUS_DELIVERING = 50000;     // 配送中
+    const ORDER_STATUS_WITHDRAWN = 60000;      // 配送员撤单
+    const ORDER_STATUS_COMPLETED = 70000;      // 配送完成
+    const ORDER_STATUS_EXCEPTION = 90000;      // 配送异常
+
+    // 物品类型
+    const GOODS_TYPE_FLOWER = 14;      // 鲜花
+
     /**
     /**
      * 获取 access_token
      * 获取 access_token
      * @param $merchant
      * @param $merchant
@@ -46,11 +62,11 @@ class IntraCityExpress
         // 获取私钥
         // 获取私钥
         $env = getenv('YII_ENV') == 'production' ? 'production' : 'dev';
         $env = getenv('YII_ENV') == 'production' ? 'production' : 'dev';
         $privateKeyPath = __DIR__ . '/wxapi/' . $env . '/rsa-private-key.txt';
         $privateKeyPath = __DIR__ . '/wxapi/' . $env . '/rsa-private-key.txt';
-        
+
         if (!file_exists($privateKeyPath)) {
         if (!file_exists($privateKeyPath)) {
             throw new \Exception("私钥文件不存在: {$privateKeyPath}");
             throw new \Exception("私钥文件不存在: {$privateKeyPath}");
         }
         }
-        
+
         $privateKey = file_get_contents($privateKeyPath);
         $privateKey = file_get_contents($privateKeyPath);
         if (!$privateKey) {
         if (!$privateKey) {
             throw new \Exception('无法获取私钥文件');
             throw new \Exception('无法获取私钥文件');
@@ -69,9 +85,8 @@ class IntraCityExpress
         // $base64Signature = base64_encode($signature);
         // $base64Signature = base64_encode($signature);
         // \Yii::info("生成的签名: " . $base64Signature, 'intracity_signature');
         // \Yii::info("生成的签名: " . $base64Signature, 'intracity_signature');
         // return $base64Signature;
         // return $base64Signature;
-            
 
 
-            
+
         // 方案二:使用 RSA SHA256签名
         // 方案二:使用 RSA SHA256签名
         try {
         try {
             // 使用RSA SHA256签名
             // 使用RSA SHA256签名
@@ -80,17 +95,17 @@ class IntraCityExpress
             $rsa->setHash("sha256");
             $rsa->setHash("sha256");
             $rsa->setMGFHash("sha256");
             $rsa->setMGFHash("sha256");
             $signature = $rsa->sign($payload);
             $signature = $rsa->sign($payload);
-            
+
             // $rsa = new RSA();
             // $rsa = new RSA();
             // $rsa->loadKey($privateKey);
             // $rsa->loadKey($privateKey);
             // $rsa->setSignatureMode(RSA::SIGNATURE_PKCS1); // 明确使用PKCS#1 v1.5
             // $rsa->setSignatureMode(RSA::SIGNATURE_PKCS1); // 明确使用PKCS#1 v1.5
             // $rsa->setHash("sha256");
             // $rsa->setHash("sha256");
             // 不要设置MGF,PKCS#1 v1.5不使用MGF
             // 不要设置MGF,PKCS#1 v1.5不使用MGF
             // $signature = $rsa->sign($payload);
             // $signature = $rsa->sign($payload);
-            
+
             $base64Signature = base64_encode($signature);
             $base64Signature = base64_encode($signature);
             \Yii::info("phpseclib生成的签名: " . $base64Signature, 'intracity_signature');
             \Yii::info("phpseclib生成的签名: " . $base64Signature, 'intracity_signature');
-            
+
             return $base64Signature;
             return $base64Signature;
         } catch (\Exception $e) {
         } catch (\Exception $e) {
             \Yii::error("所有签名方法都失败 - OpenSSL: " . $e->getMessage() . " phpseclib: " . $e->getMessage(), 'intracity_signature');
             \Yii::error("所有签名方法都失败 - OpenSSL: " . $e->getMessage() . " phpseclib: " . $e->getMessage(), 'intracity_signature');
@@ -164,7 +179,6 @@ class IntraCityExpress
     }
     }
 
 
 
 
-
     // ==================== API URL常量 ====================
     // ==================== API URL常量 ====================
     const API_BASE_URL = 'https://api.weixin.qq.com/cgi-bin/express/intracity';
     const API_BASE_URL = 'https://api.weixin.qq.com/cgi-bin/express/intracity';
 
 
@@ -195,6 +209,7 @@ class IntraCityExpress
 
 
 
 
     // ==================== 门店管理接口 ====================
     // ==================== 门店管理接口 ====================
+
     /**
     /**
      * 创建门店
      * 创建门店
      * @param array $storeData 门店信息
      * @param array $storeData 门店信息
@@ -215,7 +230,7 @@ class IntraCityExpress
             'order_pattern' => 1,
             'order_pattern' => 1,
             "address_info" => $storeData['address_info']
             "address_info" => $storeData['address_info']
         ];
         ];
-        
+
         return self::sendRequest(self::API_CREATE_STORE, $data, $accessToken);
         return self::sendRequest(self::API_CREATE_STORE, $data, $accessToken);
     }
     }
 
 
@@ -231,10 +246,10 @@ class IntraCityExpress
         if ($merchant === null) {
         if ($merchant === null) {
             $merchant = self::getMerchant();
             $merchant = self::getMerchant();
         }
         }
-        
+
         $accessToken = self::getAccessToken($merchant, $ptStyle);
         $accessToken = self::getAccessToken($merchant, $ptStyle);
         $data = $storeData;
         $data = $storeData;
-        
+
         return self::sendRequest(self::API_UPDATE_STORE, $data, $accessToken);
         return self::sendRequest(self::API_UPDATE_STORE, $data, $accessToken);
     }
     }
 
 
@@ -250,12 +265,12 @@ class IntraCityExpress
         if ($merchant === null) {
         if ($merchant === null) {
             $merchant = self::getMerchant();
             $merchant = self::getMerchant();
         }
         }
-        
+
         $accessToken = self::getAccessToken($merchant, $ptStyle);
         $accessToken = self::getAccessToken($merchant, $ptStyle);
         $data = [
         $data = [
             'out_store_id' => $outStoreId,
             'out_store_id' => $outStoreId,
         ];
         ];
-        
+
         return self::sendRequest(self::API_QUERY_STORE, $data, $accessToken);
         return self::sendRequest(self::API_QUERY_STORE, $data, $accessToken);
     }
     }
 
 
@@ -277,6 +292,7 @@ class IntraCityExpress
 
 
 
 
     // ==================== 订单管理接口 ====================
     // ==================== 订单管理接口 ====================
+
     /**
     /**
      * 创建订单
      * 创建订单
      * @param array $orderData 订单信息
      * @param array $orderData 订单信息
@@ -289,10 +305,19 @@ class IntraCityExpress
         if ($merchant === null) {
         if ($merchant === null) {
             $merchant = self::getMerchant();
             $merchant = self::getMerchant();
         }
         }
-        
+
         $accessToken = self::getAccessToken($merchant, $ptStyle);
         $accessToken = self::getAccessToken($merchant, $ptStyle);
+        //开发环境只能使用沙箱 ssh
+        if (getenv('YII_ENV') != 'production') {
+            $orderData['use_sandbox'] = 1;
+            $orderData['user_name'] = '顺丰同城';
+            $orderData['user_phone'] = (string)13881979410;
+            $orderData['user_address'] = '北京市海淀区学清嘉创大厦A座15层';
+            $orderData['user_lng'] = (double)116.352954;
+            $orderData['user_lat'] = (double)40.014747;
+        }
         $data = $orderData;
         $data = $orderData;
-        
+
         return self::sendRequest(self::API_ADD_ORDER, $data, $accessToken);
         return self::sendRequest(self::API_ADD_ORDER, $data, $accessToken);
     }
     }
 
 
@@ -315,9 +340,9 @@ class IntraCityExpress
         if ($merchant === null) {
         if ($merchant === null) {
             $merchant = self::getMerchant();
             $merchant = self::getMerchant();
         }
         }
-        
+
         $accessToken = self::getAccessToken($merchant, $ptStyle);
         $accessToken = self::getAccessToken($merchant, $ptStyle);
-        
+
         // 请求体
         // 请求体
         $data = $orderData;
         $data = $orderData;
 
 
@@ -339,7 +364,7 @@ class IntraCityExpress
             $merchant = self::getMerchant();
             $merchant = self::getMerchant();
         }
         }
         $accessToken = self::getAccessToken($merchant, $ptStyle);
         $accessToken = self::getAccessToken($merchant, $ptStyle);
-        
+
         $data = [];
         $data = [];
         if (!empty($wxOrderId)) {
         if (!empty($wxOrderId)) {
             $data['wx_order_id'] = $wxOrderId;
             $data['wx_order_id'] = $wxOrderId;
@@ -365,7 +390,7 @@ class IntraCityExpress
      * @param int $ptStyle
      * @param int $ptStyle
      * @return array
      * @return array
      */
      */
-    public static function queryOrder($wxStoreId, $storeOrderId='', $wxOrderId='', $merchant = null, $ptStyle = 0)
+    public static function queryOrder($wxStoreId, $storeOrderId = '', $wxOrderId = '', $merchant = null, $ptStyle = 0)
     {
     {
         if ($merchant === null) {
         if ($merchant === null) {
             $merchant = self::getMerchant();
             $merchant = self::getMerchant();
@@ -375,19 +400,20 @@ class IntraCityExpress
         if (empty($wxOrderId) && (empty($storeOrderId) || empty($wxStoreId))) {
         if (empty($wxOrderId) && (empty($storeOrderId) || empty($wxStoreId))) {
             util::fail("参数不足:wx_order_id 或 (store_order_id + wx_store_id) 必须提供一组");
             util::fail("参数不足:wx_order_id 或 (store_order_id + wx_store_id) 必须提供一组");
         }
         }
-        
+
         $data = [];
         $data = [];
         if ($wxStoreId != '') {
         if ($wxStoreId != '') {
             $data['wx_order_id'] = $wxOrderId;
             $data['wx_order_id'] = $wxOrderId;
         }
         }
         $data['store_order_id'] = $storeOrderId;
         $data['store_order_id'] = $storeOrderId;
         $data['wx_store_id'] = $wxStoreId;
         $data['wx_store_id'] = $wxStoreId;
-        
+
         return self::sendRequest(self::API_GET_ORDER, $data, $accessToken);
         return self::sendRequest(self::API_GET_ORDER, $data, $accessToken);
     }
     }
 
 
 
 
     // ==================== 资金管理接口 ====================
     // ==================== 资金管理接口 ====================
+
     /**
     /**
      * 查询门店余额
      * 查询门店余额
      * @param string $wxStoreId
      * @param string $wxStoreId
@@ -477,6 +503,7 @@ class IntraCityExpress
     }
     }
 
 
     // ==================== 测试接口 ====================
     // ==================== 测试接口 ====================
+
     /**
     /**
      * 模拟回调接口
      * 模拟回调接口
      * @param string $wxOrderId 微信订单号
      * @param string $wxOrderId 微信订单号
@@ -492,13 +519,13 @@ class IntraCityExpress
         if ($merchant === null) {
         if ($merchant === null) {
             $merchant = self::getMerchant();
             $merchant = self::getMerchant();
         }
         }
-        
+
         $accessToken = self::getAccessToken($merchant, $ptStyle);
         $accessToken = self::getAccessToken($merchant, $ptStyle);
-        
+
         $data = [
         $data = [
             'order_status' => $orderStatus,
             'order_status' => $orderStatus,
         ];
         ];
-        
+
         if (!empty($wxOrderId)) {
         if (!empty($wxOrderId)) {
             $data['wx_order_id'] = $wxOrderId;
             $data['wx_order_id'] = $wxOrderId;
         }
         }
@@ -507,7 +534,7 @@ class IntraCityExpress
             $data['wx_store_id'] = $outStoreId;
             $data['wx_store_id'] = $outStoreId;
             $data['store_order_id'] = $outOrderId;
             $data['store_order_id'] = $outOrderId;
         }
         }
-        
+
         return self::sendRequest(self::API_MOCK_NOTIFY, $data, $accessToken);
         return self::sendRequest(self::API_MOCK_NOTIFY, $data, $accessToken);
     }
     }
 
 
@@ -527,22 +554,23 @@ class IntraCityExpress
                 $signParams[$field] = $params[$field];
                 $signParams[$field] = $params[$field];
             }
             }
         }
         }
-        
+
         // 2. 按字典序排序参数
         // 2. 按字典序排序参数
         ksort($signParams);
         ksort($signParams);
-        
+
         // 3. 拼接参数字符串
         // 3. 拼接参数字符串
         $signStr = '';
         $signStr = '';
         foreach ($signParams as $key => $value) {
         foreach ($signParams as $key => $value) {
             $signStr .= $key . '=' . $value . '&';
             $signStr .= $key . '=' . $value . '&';
         }
         }
         $signStr .= 'token=' . $token;
         $signStr .= 'token=' . $token;
-        
+
         // 4. 计算MD5并转为小写
         // 4. 计算MD5并转为小写
         return strtolower(md5($signStr));
         return strtolower(md5($signStr));
     }
     }
 
 
     // ==================== 回调验证接口 ====================
     // ==================== 回调验证接口 ====================
+
     /**
     /**
      * 验证回调签名
      * 验证回调签名
      * @param array $params 回调参数
      * @param array $params 回调参数
@@ -554,12 +582,12 @@ class IntraCityExpress
         if (!isset($params['sign'])) {
         if (!isset($params['sign'])) {
             return false;
             return false;
         }
         }
-        
+
         $receivedSign = $params['sign'];
         $receivedSign = $params['sign'];
         unset($params['sign']);
         unset($params['sign']);
-        
+
         $calculatedSign = self::generateCallbackSignature($params, $token);
         $calculatedSign = self::generateCallbackSignature($params, $token);
-        
+
         return $receivedSign === $calculatedSign;
         return $receivedSign === $calculatedSign;
     }
     }
 
 
@@ -578,16 +606,16 @@ class IntraCityExpress
                 'return_msg' => '签名验证失败'
                 'return_msg' => '签名验证失败'
             ];
             ];
         }
         }
-        
+
         // 处理订单状态变化
         // 处理订单状态变化
         $orderStatus = $callbackData['order_status'];
         $orderStatus = $callbackData['order_status'];
         $wxOrderId = $callbackData['wx_order_id'];
         $wxOrderId = $callbackData['wx_order_id'];
         $outOrderId = $callbackData['store_order_id'] ?? '';
         $outOrderId = $callbackData['store_order_id'] ?? '';
         $outStoreId = $callbackData['wx_store_id'] ?? '';
         $outStoreId = $callbackData['wx_store_id'] ?? '';
-        
+
         // 这里可以添加具体的业务逻辑处理
         // 这里可以添加具体的业务逻辑处理
         // 例如:更新数据库中的订单状态、发送通知等
         // 例如:更新数据库中的订单状态、发送通知等
-        
+
         // 伪代码示例:
         // 伪代码示例:
         /*
         /*
         switch ($orderStatus) {
         switch ($orderStatus) {
@@ -616,28 +644,10 @@ class IntraCityExpress
                 break;
                 break;
         }
         }
         */
         */
-        
+
         return [
         return [
             'return_code' => 0,
             'return_code' => 0,
             'return_msg' => 'OK'
             'return_msg' => 'OK'
         ];
         ];
     }
     }
-
-    // ==================== 常量定义 ====================
-
-    /**
-     * 订单状态常量
-     */
-    const ORDER_STATUS_CREATED = 10000;        // 订单创建成功
-    const ORDER_STATUS_CANCELED_BY_MERCHANT = 20000;  // 商家取消订单
-    const ORDER_STATUS_CANCELED_BY_DELIVERY = 20001;  // 配送方取消订单
-    const ORDER_STATUS_ACCEPTED = 30000;       // 配送员接单
-    const ORDER_STATUS_ARRIVED = 40000;        // 配送员到店
-    const ORDER_STATUS_DELIVERING = 50000;     // 配送中
-    const ORDER_STATUS_WITHDRAWN = 60000;      // 配送员撤单
-    const ORDER_STATUS_COMPLETED = 70000;      // 配送完成
-    const ORDER_STATUS_EXCEPTION = 90000;      // 配送异常
-
-    const GOODS_TYPE_FLOWER = 14;      // 鲜花
-
 }
 }

+ 7 - 0
common/components/dict/GhsExpressOrderDict.php

@@ -0,0 +1,7 @@
+<?php
+namespace common\components\dict;
+
+class GhsExpressOrderDict
+{
+
+}