Browse Source

查询运费

shish 10 months ago
parent
commit
d712535daa
2 changed files with 319 additions and 271 deletions
  1. 158 117
      app-ghs/controllers/IntraCityController.php
  2. 161 154
      app-hd/controllers/IntraCityController.php

+ 158 - 117
app-ghs/controllers/IntraCityController.php

@@ -4,10 +4,12 @@ namespace ghs\controllers;
 
 use biz\wx\classes\WxMessageClass;
 use biz\wx\classes\WxOpenClass;
+use bizGhs\admin\classes\AdminClass;
 use bizGhs\express\classes\GhsExpressOrderClass as ExpressOrderClass;
 use bizHd\order\classes\OrderGoodsClass;
-use bizHd\user\classes\UserClass;
 use bizGhs\order\classes\OrderItemClass;
+use bizHd\purchase\classes\PurchaseClass;
+use bizHd\saas\classes\StaffClass;
 use common\components\dict;
 use common\components\imgUtil;
 use hd\models\IntraCity\StoreFeeForm;
@@ -381,131 +383,170 @@ class IntraCityController extends BaseController
      */
     public function actionCreateOrder()
     {
-        try {
-            $post = Yii::$app->request->post();
-            $orderId = intval($post['orderId']);
-            $order = OrderClass::getById($orderId);
-            if (empty($order)) {
-                util::fail('订单出错');
-            }
-            if ($order['mainId'] != $this->mainId) {
-                util::fail('订单出错');
-            }
+        $post = Yii::$app->request->post();
+        $orderId = intval($post['orderId']);
+        $order = OrderClass::getById($orderId);
+        if (empty($order)) {
+            util::fail('没有找到订单');
+        }
+        if ($order['mainId'] != $this->mainId) {
+            util::fail('不是你的订单');
+        }
+        $packageNum = $post['packageNum'] ?? 0;
+        if ($packageNum <= 0) {
+            util::fail('请填写包裹数量');
+        }
+        $weight = $post['weight'] ?? 0;
+        if ($weight <= 0) {
+            util::fail('请填写重量');
+        }
+        $actPrice = $order['actPrice'] ?? 0;
+        if ($actPrice <= 0) {
+            util::fail('订单没有价格,不需要发跑腿');
+        }
+        $sn = $order['orderSn'];
+        $itemInfo = OrderItemClass::getByCondition(['orderSn' => $sn], null, 'id, name, cover, num');
+        $num = intval($order['itemNum']);
+        $itemList[] = [
+            'item_name' => '花材',
+            'item_pic_url' => imgUtil::groupImg($itemInfo['cover']) . "?x-oss-process=image/resize,m_fill,h_130,w_130",
+            'count' => $num,
+        ];
 
-            $sn = $order['orderSn'];
-            $itemInfoList = OrderItemClass::getAllByCondition(['orderSn' => $sn], null, 'id, name, cover, num');
-            $itemList = [];
-            $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;
+        $main = $this->main;
+        $wxStoreId = $main->wxStoreId ?? '';
+        if (empty($wxStoreId)) {
+            util::fail('你还没有开通跑腿功能');
+        }
 
-            $shopExt = MainClass::getById($this->mainId, false, 'id, wxStoreId');
-            if (empty($shopExt)) {
-                util::fail("微信门店不存在");
-            }
+        $cgId = $order['purchaseId'] ?? 0;
+        if (empty($cgId)) {
+            util::fail('没有找到采购信息');
+        }
 
-            // 获取 openid(小程序OpenId)
-            $user = UserClass::getByCondition(['mobile' => $order['customMobile']], false, false, 'id, miniOpenId');
-            if (empty($user)) {
-                noticeUtil::push("通过手机号-" . $order['customMobile'] . ",获取小程序OpenId失败");
-                Yii::error('获取用户openId出错');
-                util::fail('数据出错');
+        $miniOpenId = '';
+        $customShopAdminId = $order['customShopAdminId'] ?? 0;
+        if (!empty($customShopAdminId)) {
+            $customStaff = StaffClass::getById($customShopAdminId, true);
+            $customStaffAdminId = $customStaff->adminId ?? '';
+            if (!empty($customStaffAdminId)) {
+                $customAdmin = AdminClass::getById($customStaffAdminId, true);
+                $miniOpenId = $customAdmin->miniOpenId ?? '';
             }
+        }
+        if (empty($miniOpenId)) {
+            $admin = $this->admin;
+            $miniOpenId = $admin->miniOpenId ?? '';
+        }
+        if (empty($miniOpenId)) {
+            util::fail('没有找到微信登录信息,无法呼叫跑腿');
+        }
 
-            $cargoName = '花材'; // 商品名称
-            $cargo = [
-                'cargo_name' => $cargoName,
-                'cargo_weight' => intval($post['weight'] * 1000),
-                'cargo_type' => IntraCityExpress::GOODS_TYPE_FLOWER,
-                'cargo_num' => intval($post['packageNum']),
-                'cargo_price' => intval($order['actPrice'] * 100), // $order 中有各个价格,请注意
-                'item_list' => $itemList,
-            ];
+        $cargoName = '鲜花花材';//商品名称
+        $cargo = [
+            'cargo_name' => $cargoName,
+            'cargo_weight' => intval($weight * 1000),
+            'cargo_type' => IntraCityExpress::GOODS_TYPE_FLOWER,
+            'cargo_num' => intval($packageNum),
+            'cargo_price' => intval($actPrice * 100), // $order 中有各个价格,请注意
+            'item_list' => $itemList,
+        ];
 
-            //生成 store_order_id
-            $storeOrderId = $orderId . '_ghs';;
-            if (true) { // 如果不是首次用 $orderId 创建快递配送,则要生成新 store_order_id
-                // store_order_id 门店订单编号, 即 orderId。如果是重新配送的第n次,订单编号的命名规则为:orderId_cp_n
-                $query = (new Query())
-                    ->from('xhGhsExpressOrder')
-                    ->where(['orderId' => $orderId]);
-                $copyOrderCount = $query->count();
-                $copyOrderCount += 1;
-                //区分线上线下
-                if (getenv('YII_ENV') == 'production') {
-                    $storeOrderId = $storeOrderId . '_cp_' . $copyOrderCount;
-                } else {
-                    $storeOrderId = $storeOrderId . '_cs_cp_' . $copyOrderCount;
-                }
+        //生成 store_order_id
+        $storeOrderId = $orderId . '_ghs';;
+        if ($order['sendStatus'] == 3) {
+            // 如果不是首次用 $orderId 创建快递配送,则要生成新 store_order_id
+            // store_order_id 门店订单编号, 即 orderId。如果是重新配送的第n次,订单编号的命名规则为:orderId_cp_n
+            $query = (new Query())
+                ->from('xhGhsExpressOrder')
+                ->where(['orderId' => $orderId]);
+            $copyOrderCount = $query->count();
+            $copyOrderCount += 1;
+            //区分线上线下
+            if (getenv('YII_ENV') == 'production') {
+                $storeOrderId = $storeOrderId . '_cp_' . $copyOrderCount;
+            } else {
+                $storeOrderId = $storeOrderId . '_cs_cp_' . $copyOrderCount;
             }
+        }
+        $sendNum = $order['sendNum'] ?? '';
+        $customName = $order['customName'] ?? '';
+        if (empty($customName)) {
+            util::fail('客户名称无效');
+        }
+        $customMobile = $order['customMobile'] ?? '';
+        if (empty($customMobile)) {
+            util::fail('客户手机号无效');
+        }
+        $long = $order['long'] ?? '';
+        $lat = $order['lat'] ?? '';
+        if (empty($long) || empty($lat)) {
+            util::fail('客户地址无效');
+        }
+        $address = $order['address'] ?? '';
+        if (empty($address)) {
+            util::fail('客户地址无效呢');
+        }
+        $callbackUrl = Yii::$app->params['ghsHost'] . '/intra-city/callback';
+        $orderData = [
+            'wx_store_id' => $wxStoreId,
+            'store_order_id' => $storeOrderId, //同一个门店订单编号要保证唯一,相同的订单号会重入
+            'user_openid' => $miniOpenId,
+            'user_lng' => (float)$long,
+            'user_lat' => (float)$lat,
+            'user_address' => $address,
+            'user_name' => $customName,
+            'user_phone' => $customMobile,
+            'order_seq' => $sendNum, // 用于配送员快速寻找到匹配的商品(非必传) -- 对应 xhOrder 表的 sendNum
+            'verify_code_type' => 0,
+            'order_detail_path' => '/admin/order/detail?id=' . $cgId,
+            'callback_url' => $callbackUrl, // 订单状态回调地址(非必传)
+            'use_sandbox' => getenv('YII_ENV') == 'production' ? 0 : 1, // 开发环境默认使用沙箱
+            'cargo' => $cargo
+        ];
 
-            $callbackUrl = Yii::$app->params['ghsHost'] . '/intra-city/callback';
-            $orderData = [
-                'wx_store_id' => $shopExt['wxStoreId'],
-                'store_order_id' => $storeOrderId, //同一个门店订单编号要保证唯一,相同的订单号会重入
-                'user_openid' => $user['miniOpenId'],//'o-hXO4kkdM2nqORdiII42FlcdeL4'
-                'user_lng' => (float)$post['user_lng'],
-                'user_lat' => (float)$post['user_lat'],
-                'user_address' => $post['user_address'],
-                'user_name' => $post['user_name'],
-                'user_phone' => (string)$post['user_phone'],
-                'order_seq' => $order['sendNum'], // 用于配送员快速寻找到匹配的商品(非必传) -- 对应 xhOrder 表的 sendNum
-                'verify_code_type' => 0,
-                'order_detail_path' => '/pagesOrder/detail?id=' . $orderId, // TODO 后期要重新选个地址
-                'callback_url' => $callbackUrl, // 订单状态回调地址(非必传)
-                //'use_sandbox' => getenv('YII_ENV') == 'production' ? 0 : 1, // 是否使用沙箱(非必传)
-                '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);
+
+        if (isset($result['errcode']) && $result['errcode'] === 0) {
+
+            // 保存进 xhGhsExpressOrder 表
+            $data = [
+                'mainId' => $this->mainId,
+                'shopId' => $this->shopId,
+                'deliveryId' => $result['service_trans_id'] ?? '',
+                'wxOrderId' => $result['wx_order_id'] ?? '',
+                'wxStoreId' => $result['wx_store_id'] ?? '',
+                'storeOrderId' => $result['store_order_id'] ?? '',
+                'orderId' => $orderId,
+                'transOrderId' => $result['trans_order_id'] ?? '',
+                'distance' => $result['distance'] ?? 0,
+                'fee' => $result['fee'] ?? 0,
+                'fetchCode' => $result['fetch_code'] ?? '',
+                'orderSeq' => $result['order_seq'] ?? ''
             ];
-            $result = IntraCityExpress::createOrder($orderData);
-
-            if (isset($result['errcode']) && $result['errcode'] === 0) {
-                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);
-
-                    $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 {
-                noticeUtil::push("批发 -- " . $this->mainId . ",订单创建失败:" . json_encode($result));
-                Yii::error("订单创建失败:" . ($result['errmsg'] ?? '未知错误'), 'intraCity');
-                util::fail('订单创建失败: ' . $result['errcode']);
-            }
-        } catch (\Exception $e) {
-            Yii::error("订单创建异常:" . $e->getMessage(), 'intraCity');
-            util::fail("系统出错");
+            ExpressOrderClass::add($data);
+            $updateData = [
+                'sendDistance' => $data['distance'],
+                'sendStatus' => 0,
+                'deliveryId' => $data['deliveryId'],
+            ];
+            //更新订单状态为配送中
+            OrderClass::updateById($orderId, $updateData);
+            util::success(['fee' => $data['fee']], '订单创建成功');
+        } else {
+            noticeUtil::push("批发 -- " . $this->mainId . ",订单创建失败:" . json_encode($result));
+            Yii::error("订单创建失败:" . ($result['errmsg'] ?? '未知错误'), 'intraCity');
+            util::fail('提交失败,请确认余额是否充足');
         }
     }
 

+ 161 - 154
app-hd/controllers/IntraCityController.php

@@ -327,178 +327,185 @@ class IntraCityController extends BaseController
      */
     public function actionCreateOrder()
     {
-        try {
-            $post = Yii::$app->request->post();
 
-            $adminId = $this->adminId;
-            util::checkRepeatCommit($adminId, 4);
+        $post = Yii::$app->request->post();
 
-            $orderId = intval($post['orderId']);
-            $field = 'mainId, status, sendStatus, repeat, forward, orderSn, userId, actPrice, sendNum, salt';
-            $order = OrderClass::getById($orderId, false, $field);
-            if (empty($order)) {
-                util::fail('没有找到订单');
-            }
-            if ($order['mainId'] != $this->mainId) {
-                util::fail('不是你的订单');
-            }
-            // 不能创建配送的几种订单状态
-            if ($order['status'] != 2) {
-                util::fail('已不能叫跑腿,请刷新页面哈');
-            }
-            // 不能创建配送的几种配送状态
-            $notCanCreateSendStatus = [-1, 3];
-            if (!in_array($order['sendStatus'], $notCanCreateSendStatus)) {
-                util::fail('已不能叫跑腿,请刷新页面');
-            }
-            if ($order['repeat'] == 1) {
-                util::fail('收款码订单不支持跑腿');
+        $adminId = $this->adminId;
+        util::checkRepeatCommit($adminId, 4);
+
+        $orderId = intval($post['orderId']);
+        $field = 'mainId, status, sendStatus, repeat, forward, orderSn, userId, actPrice, sendNum, salt';
+        $order = OrderClass::getById($orderId, false, $field);
+        if (empty($order)) {
+            util::fail('没有找到订单');
+        }
+        if ($order['mainId'] != $this->mainId) {
+            util::fail('不是你的订单');
+        }
+        // 不能创建配送的几种订单状态
+        if ($order['status'] != 2) {
+            util::fail('已不能叫跑腿,请刷新页面哈');
+        }
+        // 不能创建配送的几种配送状态
+        $notCanCreateSendStatus = [-1, 3];
+        if (!in_array($order['sendStatus'], $notCanCreateSendStatus)) {
+            util::fail('已不能叫跑腿,请刷新页面');
+        }
+        if ($order['repeat'] == 1) {
+            util::fail('收款码订单不支持跑腿');
+        }
+        if ($order['forward'] == 1) {
+            util::fail('售后付款单不支持跑腿');
+        }
+
+        $sn = $order['orderSn'];
+        $salt = $order['salt'] ?? "";
+        $itemInfoList = OrderItemClass::getListBySn($sn, 'id, name, cover, num');
+        $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' => intval($itemInfo['num']),
+                ];
+                $itemCount += $itemInfo['num'];
             }
-            if ($order['forward'] == 1) {
-                util::fail('售后付款单不支持跑腿');
+            $post['packageNum'] = $itemCount;
+        } else {
+            $itemCount = 0;
+            foreach ($itemInfoList as $itemInfo) {
+                $itemList[] = [
+                    'item_name' => $itemInfo['name'],
+                    'item_pic_url' => $itemInfo['bigCover'],
+                    'count' => intval($itemInfo['num']),
+                ];
+                $itemCount += $itemInfo['num'];
             }
+            $post['packageNum'] = $itemCount;
+        }
 
-            $sn = $order['orderSn'];
-            $salt = $order['salt'] ?? "";
-            $itemInfoList = OrderItemClass::getListBySn($sn, 'id, name, cover, num');
-            $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' => intval($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' => intval($itemInfo['num']),
-                    ];
-                    $itemCount += $itemInfo['num'];
-                }
-                $post['packageNum'] = $itemCount;
-            }
+        //$shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], false, false, 'id, wxStoreId');
+        $shopExt = MainClass::getById($this->mainId, false, 'id, wxStoreId');
+        if (empty($shopExt)) {
+            util::fail("微信门店不存在");
+        }
 
-            //$shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], false, false, 'id, wxStoreId');
-            $shopExt = MainClass::getById($this->mainId, false, 'id, wxStoreId');
-            if (empty($shopExt)) {
-                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("订单商品数量不正确");
             }
+        }
 
-            $cargoName = '花材'; // 商品名称,默认是花材
-            $goodsInfoList = OrderGoodsClass::getListBySn($sn);
-            if (count($goodsInfoList) == 1) {
-                $goodsInfo = $goodsInfoList[0];
-                $cargoName = $goodsInfo['name'];
+        // 通过 userId 获取 openid(小程序OpenId)
+        $user = UserClass::getById($order['userId'], false, 'id, miniOpenId');
+        if (empty($user)) {
+            util::fail('用户信息缺失');
+        }
+        $miniOpenId = $user['miniOpenId'] ?? '';
+        if (empty($miniOpenId)) {
+            util::fail('没有找到用户的微信数据');
+        }
+
+        $cargo = [
+            'cargo_name' => $cargoName,
+            'cargo_weight' => intval($post['weight'] * 1000),
+            'cargo_type' => IntraCityExpress::GOODS_TYPE_FLOWER,
+            'cargo_num' => intval($post['packageNum']),
+            'cargo_price' => intval($order['actPrice'] * 100), // $order 中有各个价格,请注意
+            'item_list' => $itemList,
+        ];
+
+        //生成 store_order_id,加统一后缀,避免线上线下ID命中
+        $storeOrderId = $orderId . '_exp';
+        if ($order['sendStatus'] == 3) { // 如果不是首次用 $orderId 创建快递配送,则要生成新 store_order_id
+            // store_order_id 门店订单编号, 即 orderId。如果是重新配送的第n次,订单编号的命名规则为:orderId_cp_n
+            $query = (new Query())
+                ->from('xhExpressOrder')
+                ->where(['orderId' => $orderId]);
+            // $command = $query->createCommand();
+            // $sql = $command->sql;
+            $copyOrderCount = $query->count();
+            $copyOrderCount += 1;
+            //区分线上线下
+            if (getenv('YII_ENV') == 'production') {
+                $storeOrderId = $storeOrderId . '_cp_' . $copyOrderCount;
             } else {
-                if ($orderType != 2) {
-                    Yii::error('订单商品数量不正确');
-                    util::fail("订单商品数量不正确");
-                }
+                $storeOrderId = $storeOrderId . '_cs_cp_' . $copyOrderCount;
             }
+        }
 
-            // 通过 userId 获取 openid(小程序OpenId)
-            $user = UserClass::getById($order['userId'], false, 'id, miniOpenId');
-            if (empty($user)) {
-                util::fail('用户信息缺失');
-            }
-            $miniOpenId = $user['miniOpenId'] ?? '';
-            if (empty($miniOpenId)) {
-                util::fail('没有找到用户的微信数据');
-            }
+        $callbackUrl = Yii::$app->params['hdHost'] . '/intra-city/callback';
+        $orderData = [
+            'wx_store_id' => $shopExt['wxStoreId'],
+            'store_order_id' => $storeOrderId, //同一个门店订单编号要保证唯一,相同的订单号会重入
+            'user_openid' => $miniOpenId,
+            'user_lng' => $post['user_lng'],
+            'user_lat' => $post['user_lat'],
+            'user_address' => $post['user_address'],
+            'user_name' => $post['user_name'],
+            'user_phone' => $post['user_phone'],
+            'order_seq' => $order['sendNum'], // 用于配送员快速寻找到匹配的商品(非必传) -- 对应 xhOrder 表的 sendNum
+            'verify_code_type' => 0,
+            'order_detail_path' => '/admin/order/info?id=' . $orderId . '&salt=' . $salt,
+            'callback_url' => $callbackUrl, // 订单状态回调地址(非必传)
+            'use_sandbox' => getenv('YII_ENV') == 'production' ? 0 : 1, // 开发环境默认使用沙箱
+            'cargo' => $cargo
+        ];
 
-            $cargo = [
-                'cargo_name' => $cargoName,
-                'cargo_weight' => intval($post['weight'] * 1000),
-                'cargo_type' => IntraCityExpress::GOODS_TYPE_FLOWER,
-                'cargo_num' => intval($post['packageNum']),
-                'cargo_price' => intval($order['actPrice'] * 100), // $order 中有各个价格,请注意
-                'item_list' => $itemList,
-            ];
+        //开发环境只能使用沙箱 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';
+        }
 
-            //生成 store_order_id,加统一后缀,避免线上线下ID命中
-            $storeOrderId = $orderId . '_exp';
-            if ($order['sendStatus'] == 3) { // 如果不是首次用 $orderId 创建快递配送,则要生成新 store_order_id
-                // store_order_id 门店订单编号, 即 orderId。如果是重新配送的第n次,订单编号的命名规则为:orderId_cp_n
-                $query = (new Query())
-                    ->from('xhExpressOrder')
-                    ->where(['orderId' => $orderId]);
-                // $command = $query->createCommand();
-                // $sql = $command->sql;
-                $copyOrderCount = $query->count();
-                $copyOrderCount += 1;
-                //区分线上线下
-                if (getenv('YII_ENV') == 'production') {
-                    $storeOrderId = $storeOrderId . '_cp_' . $copyOrderCount;
-                } else {
-                    $storeOrderId = $storeOrderId . '_cs_cp_' . $copyOrderCount;
-                }
-            }
+        $result = IntraCityExpress::createOrder($orderData);
 
-            $callbackUrl = Yii::$app->params['hdHost'] . '/intra-city/callback';
+        if (isset($result['errcode']) && $result['errcode'] === 0) {
+            $deliveryId = $result['service_trans_id'] ?? '';
+            // 更新订单状态为配送中,已呼叫小哥,等小哥接单;有可能到店自取的转跑腿,sendType要变化
+            OrderClass::updateById($orderId, ['sendStatus' => 0, 'status' => 3, 'deliveryId' => $deliveryId, 'sendType' => 2]);
+
+            // 保存进 xhExpressOrder 表
             $orderData = [
-                'wx_store_id' => $shopExt['wxStoreId'],
-                'store_order_id' => $storeOrderId, //同一个门店订单编号要保证唯一,相同的订单号会重入
-                'user_openid' => $miniOpenId,
-                'user_lng' => $post['user_lng'],
-                'user_lat' => $post['user_lat'],
-                'user_address' => $post['user_address'],
-                'user_name' => $post['user_name'],
-                'user_phone' => $post['user_phone'],
-                'order_seq' => $order['sendNum'], // 用于配送员快速寻找到匹配的商品(非必传) -- 对应 xhOrder 表的 sendNum
-                'verify_code_type' => 0,
-                'order_detail_path' => '/admin/order/info?id=' . $orderId . '&salt=' . $salt,
-                'callback_url' => $callbackUrl, // 订单状态回调地址(非必传)
-                //'use_sandbox' => getenv('YII_ENV') == 'production' ? 0 : 1, // 是否使用沙箱(非必传)
-                'cargo' => $cargo
+                'mainId' => $this->mainId,
+                'shopId' => $this->shopId,
+                'deliveryId' => $deliveryId,
+                'wxOrderId' => $result['wx_order_id'] ?? '',
+                'wxStoreId' => $result['wx_store_id'] ?? '',
+                'storeOrderId' => $result['store_order_id'] ?? '',
+                'orderId' => $orderId,
+                'transOrderId' => $result['trans_order_id'] ?? '',
+                'distance' => $result['distance'] ?? 0,
+                'fee' => $result['fee'] ?? 0,
+                'fetchCode' => $result['fetch_code'] ?? '',
+                'orderSeq' => $result['order_seq'] ?? ''
             ];
+            ExpressOrderClass::add($orderData);
 
-            $result = IntraCityExpress::createOrder($orderData);
-
-            if (isset($result['errcode']) && $result['errcode'] === 0) {
-                $deliveryId = $result['service_trans_id'] ?? '';
-                // 更新订单状态为配送中,已呼叫小哥,等小哥接单;有可能到店自取的转跑腿,sendType要变化
-                OrderClass::updateById($orderId, ['sendStatus' => 0, 'status' => 3, 'deliveryId' => $deliveryId, 'sendType' => 2]);
-
-                // 保存进 xhExpressOrder 表
-                $orderData = [
-                    'mainId' => $this->mainId,
-                    'shopId' => $this->shopId,
-                    'deliveryId' => $deliveryId,
-                    'wxOrderId' => $result['wx_order_id'] ?? '',
-                    'wxStoreId' => $result['wx_store_id'] ?? '',
-                    'storeOrderId' => $result['store_order_id'] ?? '',
-                    'orderId' => $orderId,
-                    'transOrderId' => $result['trans_order_id'] ?? '',
-                    'distance' => $result['distance'] ?? 0,
-                    'fee' => $result['fee'] ?? 0,
-                    'fetchCode' => $result['fetch_code'] ?? '',
-                    'orderSeq' => $result['order_seq'] ?? ''
-                ];
-                ExpressOrderClass::add($orderData);
-
-                util::success(['fee' => $result['fee']], '订单创建成功');
-            } else {
-                noticeUtil::push("门店 -- " . $this->mainId . ",订单创建失败:" . json_encode($result));
-                Yii::error("订单创建失败:" . ($result['errmsg'] ?? '未知错误'), 'intracity');
-                $errorMsg = $result['errmsg'] ?? '';
-                noticeUtil::push("跑腿单创建失败:" . $errorMsg, '15280215347');
-                util::fail('提交失败,请确认余额是否充足');
-            }
-        } catch (\Exception $e) {
-            Yii::error("订单创建异常:" . $e->getMessage(), 'intracity');
-            util::fail("系统出错");
+            util::success(['fee' => $result['fee']], '订单创建成功');
+        } else {
+            noticeUtil::push("门店 -- " . $this->mainId . ",订单创建失败:" . json_encode($result));
+            Yii::error("订单创建失败:" . ($result['errmsg'] ?? '未知错误'), 'intracity');
+            $errorMsg = $result['errmsg'] ?? '';
+            noticeUtil::push("跑腿单创建失败:" . $errorMsg, '15280215347');
+            util::fail('提交失败,请确认余额是否充足');
         }
+
     }
 
     /**