Ver código fonte

同城配送

shizhongqi 1 ano atrás
pai
commit
f92218bcad

+ 426 - 0
app-hd/controllers/IntraCityController.php

@@ -0,0 +1,426 @@
+<?php
+
+namespace hd\controllers;
+
+use common\components\util;
+use Yii;
+use biz\shop\classes\ShopClass;
+use yii\web\Response;
+use common\components\IntraCityExpress;
+
+/**
+ * 同城配送控制器
+ * 
+ * 提供同城配送相关的API接口
+ */
+class IntraCityController extends BaseController
+{
+    /**
+     * 禁用CSRF验证(用于接收微信回调)
+     */
+    public function beforeAction($action)
+    {
+        if ($action->id === 'callback') {
+            $this->enableCsrfValidation = false;
+        }
+        return parent::beforeAction($action);
+    }
+
+    /**
+     * 创建门店
+     * POST /intra-city/create-store
+     */
+    public function actionCreateStore()
+    {
+        Yii::$app->response->format = Response::FORMAT_JSON;
+        
+        try {
+            $shopId = intval($this->shopId);
+            if (empty($shopId)) {
+                $shopId = $this->shopId;
+            }
+            $shop = ShopClass::getById($shopId, true, 'id, merchantName, address, lat, long, telephone');
+
+            $storeData = [
+                'out_store_id' => $shop->id,
+                'store_name' => $shop->merchantName,
+                'store_address' => $shop->address,
+                'store_longitude' => $shop->long,
+                'store_latitude' => $shop->lat,
+                'store_phone' => $shop->telephone
+            ];
+            
+            // 验证必填参数
+            $requiredFields = ['out_store_id', 'store_name', 'store_address', 'store_longitude', 'store_latitude', 'store_phone'];
+            foreach ($requiredFields as $field) {
+                if (empty($storeData[$field])) {
+                    util::fail("缺少必填参数:{$field}");
+                }
+            }
+            
+            $result = IntraCityExpress::createStore($storeData);
+            
+            if ($result['errcode'] === 0) {
+                util::success("门店创建成功", $result);
+            } else {
+                Yii::error("门店创建失败:" . $result['errmsg']);
+                util::fail($result['errmsg']);
+            }
+        } catch (\Exception $e) {
+            Yii::error("门店创建失败:" . $e->getMessage());
+            util::fail("系统出错");
+        }
+    }
+
+    /**
+     * 查询门店创建情况
+     */
+    public function actionStore()
+    {
+        util::complete();
+    }
+
+    /**
+     * 创建订单
+     * POST /intra-city/create-order
+     */
+    public function actionCreateOrder()
+    {
+        Yii::$app->response->format = Response::FORMAT_JSON;
+        
+        try {
+            $request = Yii::$app->request;
+            $orderData = $request->post();
+            
+            // 验证必填参数
+            $requiredFields = [
+                'out_store_id', 'store_order_id', 'delivery_service_code',
+                'to_user_name', 'to_user_phone', 'to_user_address',
+                'to_user_longitude', 'to_user_latitude', 'goods_value',
+                'goods_weight'
+            ];
+            
+            foreach ($requiredFields as $field) {
+                if (empty($orderData[$field])) {
+                    util::fail("缺少必填参数:{$field}");
+                }
+            }
+            
+            $result = IntraCityExpress::createOrder($orderData);
+            
+            if (isset($result['errcode']) && $result['errcode'] === 0) {
+                util::success('订单创建成功', [
+                    'wx_order_id' => $result['wx_order_id'] ?? null,
+                    'order_status' => $result['order_status'] ?? null,
+                    'fee' => $result['fee'] ?? null,
+                    'delivery_token' => $result['delivery_token'] ?? null,
+                ]);
+            } else {
+                Yii::error("订单创建失败:" . ($result['errmsg'] ?? '未知错误'), 'intracity');
+                util::fail($result['errmsg'] ?? '订单创建失败', $result['errcode'] ?? -1);
+            }
+        } catch (\Exception $e) {
+            Yii::error("订单创建异常:" . $e->getMessage(), 'intracity');
+            util::fail("系统出错");
+        }
+    }
+
+    /**
+     * 查询订单
+     * GET /intra-city/get-order
+     */
+    public function actionGetOrder()
+    {
+        Yii::$app->response->format = Response::FORMAT_JSON;
+        
+        try {
+            $request = Yii::$app->request;
+            $wxOrderId = $request->get('wx_order_id');
+            $outOrderId = $request->get('store_order_id'); // 修正为 store_order_id
+            $outStoreId = $request->get('out_store_id');
+            
+            if (empty($wxOrderId) && (empty($outOrderId) || empty($outStoreId))) {
+                 util::fail("参数不足:wx_order_id 或 (store_order_id + out_store_id) 必须提供一组");
+            }
+            
+            $result = IntraCityExpress::getOrder($wxOrderId, $outOrderId, $outStoreId);
+            
+            if (isset($result['errcode']) && $result['errcode'] === 0) {
+                util::success("查询成功", $result);
+            } else {
+                Yii::error("订单查询失败:" . ($result['errmsg'] ?? '未知错误'), 'intracity');
+                util::fail($result['errmsg'] ?? '订单查询失败', $result['errcode'] ?? -1);
+            }
+        } catch (\Exception $e) {
+            Yii::error("订单查询异常:" . $e->getMessage(), 'intracity');
+            util::fail("系统出错");
+        }
+    }
+
+    /**
+     * 取消订单
+     * POST /intra-city/cancel-order
+     */
+    public function actionCancelOrder()
+    {
+        Yii::$app->response->format = Response::FORMAT_JSON;
+        
+        try {
+            $request = Yii::$app->request;
+            $wxOrderId = $request->post('wx_order_id');
+            $outOrderId = $request->post('store_order_id'); // 修正为 store_order_id
+            $outStoreId = $request->post('out_store_id');
+            
+            if (empty($wxOrderId) && (empty($outOrderId) || empty($outStoreId))) {
+                util::fail("参数不足:wx_order_id 或 (store_order_id + out_store_id) 必须提供一组");
+            }
+            
+            $result = IntraCityExpress::cancelOrder($wxOrderId, $outOrderId, $outStoreId);
+            
+            if (isset($result['errcode']) && $result['errcode'] === 0) {
+                util::success("订单取消成功", $result);
+            } else {
+                Yii::error("订单取消失败:" . ($result['errmsg'] ?? '未知错误'), 'intracity');
+                util::fail($result['errmsg'] ?? '订单取消失败', $result['errcode'] ?? -1);
+            }
+        } catch (\Exception $e) {
+            Yii::error("订单取消异常:" . $e->getMessage(), 'intracity');
+            util::fail("系统出错");
+        }
+    }
+
+    /**
+     * 获取门店列表
+     * GET /intra-city/store-list
+     */
+    public function actionStoreList()
+    {
+        Yii::$app->response->format = Response::FORMAT_JSON;
+        
+        try {
+            $request = Yii::$app->request;
+            $offset = $request->get('offset', 0);
+            $limit = $request->get('limit', 20);
+            
+            $result = IntraCityExpress::getStoreList($offset, $limit);
+            
+            if ($result['errcode'] === 0) {
+                return [
+                    'success' => true,
+                    'message' => '查询成功',
+                    'data' => $result
+                ];
+            } else {
+                return [
+                    'success' => false,
+                    'message' => $result['errmsg'],
+                    'error_code' => $result['errcode']
+                ];
+            }
+        } catch (\Exception $e) {
+            return [
+                'success' => false,
+                'message' => '系统错误:' . $e->getMessage()
+            ];
+        }
+    }
+
+    /**
+     * 获取订单列表
+     * GET /intra-city/order-list
+     */
+    public function actionOrderList()
+    {
+        Yii::$app->response->format = Response::FORMAT_JSON;
+        
+        try {
+            $request = Yii::$app->request;
+            $offset = $request->get('offset', 0);
+            $limit = $request->get('limit', 20);
+            
+            $result = IntraCityExpress::getOrderList($offset, $limit);
+            
+            if ($result['errcode'] === 0) {
+                return [
+                    'success' => true,
+                    'message' => '查询成功',
+                    'data' => $result
+                ];
+            } else {
+                return [
+                    'success' => false,
+                    'message' => $result['errmsg'],
+                    'error_code' => $result['errcode']
+                ];
+            }
+        } catch (\Exception $e) {
+            return [
+                'success' => false,
+                'message' => '系统错误:' . $e->getMessage()
+            ];
+        }
+    }
+
+    /**
+     * 获取运力列表
+     * GET /intra-city/delivery-list
+     */
+    public function actionDeliveryList()
+    {
+        Yii::$app->response->format = Response::FORMAT_JSON;
+        
+        try {
+            $result = IntraCityExpress::getDeliveryList();
+            
+            if ($result['errcode'] === 0) {
+                return [
+                    'success' => true,
+                    'message' => '查询成功',
+                    'data' => $result
+                ];
+            } else {
+                return [
+                    'success' => false,
+                    'message' => $result['errmsg'],
+                    'error_code' => $result['errcode']
+                ];
+            }
+        } catch (\Exception $e) {
+            return [
+                'success' => false,
+                'message' => '系统错误:' . $e->getMessage()
+            ];
+        }
+    }
+
+    /**
+     * 微信回调接口
+     * POST /intra-city/callback
+     */
+    public function actionCallback()
+    {
+        Yii::$app->response->format = Response::FORMAT_JSON;
+        
+        try {
+            $request = Yii::$app->request;
+            $callbackData = $request->post();
+            
+            // 从配置中获取安全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_callback');
+            
+            return $result;
+        } catch (\Exception $e) {
+            Yii::error('同城配送回调处理异常:' . $e->getMessage(), 'intracity_callback');
+            return [
+                'return_code' => 1,
+                'return_msg' => '系统错误'
+            ];
+        }
+    }
+
+    /**
+     * 模拟回调(测试用)
+     * POST /intra-city/mock-notify
+     */
+    public function actionMockNotify()
+    {
+        Yii::$app->response->format = Response::FORMAT_JSON;
+        
+        try {
+            $request = Yii::$app->request;
+            $orderStatus = $request->post('order_status');
+            $wxOrderId = $request->post('wx_order_id');
+            $outStoreId = $request->post('out_store_id');
+            $outOrderId = $request->post('store_order_id'); // 修正为 store_order_id
+            
+            if (empty($orderStatus)) {
+                util::fail("请提供订单状态");
+            }
+
+            if (empty($wxOrderId) && (empty($outStoreId) || empty($outOrderId))) {
+                util::fail("参数不足:wx_order_id 或 (out_store_id + store_order_id) 必须提供一组");
+            }
+            
+            $result = IntraCityExpress::mockNotify($orderStatus, $wxOrderId, $outStoreId, $outOrderId);
+            
+            if (isset($result['errcode']) && $result['errcode'] === 0) {
+                util::success("模拟回调成功", $result);
+            } else {
+                Yii::error("模拟回调失败:" . ($result['errmsg'] ?? '未知错误'), 'intracity');
+                util::fail($result['errmsg'] ?? '模拟回调失败', $result['errcode'] ?? -1);
+            }
+        } catch (\Exception $e) {
+            Yii::error("模拟回调异常:" . $e->getMessage(), 'intracity');
+            util::fail("系统出错");
+        }
+    }
+
+    /**
+     * 获取订单状态常量
+     * GET /intra-city/order-status-list
+     */
+    public function actionOrderStatusList()
+    {
+        Yii::$app->response->format = Response::FORMAT_JSON;
+        
+        $statusList = [
+            IntraCityExpress::ORDER_STATUS_CREATED => '订单创建成功',
+            IntraCityExpress::ORDER_STATUS_CANCELED_BY_MERCHANT => '商家取消订单',
+            IntraCityExpress::ORDER_STATUS_CANCELED_BY_DELIVERY => '配送方取消订单',
+            IntraCityExpress::ORDER_STATUS_ACCEPTED => '配送员接单',
+            IntraCityExpress::ORDER_STATUS_ARRIVED => '配送员到店',
+            IntraCityExpress::ORDER_STATUS_DELIVERING => '配送中',
+            IntraCityExpress::ORDER_STATUS_WITHDRAWN => '配送员撤单',
+            IntraCityExpress::ORDER_STATUS_COMPLETED => '配送完成',
+            IntraCityExpress::ORDER_STATUS_EXCEPTION => '配送异常',
+        ];
+        
+        return [
+            'success' => true,
+            'message' => '查询成功',
+            'data' => $statusList
+        ];
+    }
+
+    /**
+     * 获取物品类型常量
+     * GET /intra-city/goods-type-list
+     */
+    public function actionGoodsTypeList()
+    {
+        Yii::$app->response->format = Response::FORMAT_JSON;
+        
+        $goodsTypeList = [
+            IntraCityExpress::GOODS_TYPE_FAST_FOOD => '快餐',
+            IntraCityExpress::GOODS_TYPE_MEDICINE => '药品',
+            IntraCityExpress::GOODS_TYPE_GENERAL => '百货',
+            IntraCityExpress::GOODS_TYPE_FRESH => '生鲜',
+            IntraCityExpress::GOODS_TYPE_WINE => '酒品',
+            IntraCityExpress::GOODS_TYPE_DOCUMENT => '文件',
+            IntraCityExpress::GOODS_TYPE_CAKE => '蛋糕',
+            IntraCityExpress::GOODS_TYPE_FLOWER => '鲜花',
+            IntraCityExpress::GOODS_TYPE_DIGITAL => '数码',
+            IntraCityExpress::GOODS_TYPE_CLOTHING => '服装',
+            IntraCityExpress::GOODS_TYPE_AUTO_PARTS => '汽配',
+            IntraCityExpress::GOODS_TYPE_JEWELRY => '珠宝',
+            IntraCityExpress::GOODS_TYPE_DRINK => '饮料',
+            IntraCityExpress::GOODS_TYPE_LICENSE => '证照',
+            IntraCityExpress::GOODS_TYPE_PET => '宠物用品',
+            IntraCityExpress::GOODS_TYPE_MATERNITY => '母婴用品',
+            IntraCityExpress::GOODS_TYPE_COSMETICS => '美妆用品',
+            IntraCityExpress::GOODS_TYPE_HOME => '家居建材',
+            IntraCityExpress::GOODS_TYPE_OTHER => '其他',
+        ];
+        
+        return [
+            'success' => true,
+            'message' => '查询成功',
+            'data' => $goodsTypeList
+        ];
+    }
+}

+ 0 - 2
app-hd/controllers/ShopController.php

@@ -3,7 +3,6 @@
 namespace hd\controllers;
 
 use biz\shop\classes\ShopClass;
-use biz\shop\classes\ShopExtClass;
 use biz\sj\services\MerchantExtendService;
 use bizGhs\admin\classes\AdminClass;
 use bizGhs\custom\classes\CustomClass;
@@ -15,7 +14,6 @@ use bizHd\saas\services\RegionService;
 use common\components\dict;
 use common\components\dirUtil;
 use common\components\imgUtil;
-use common\components\noticeUtil;
 use common\components\stringUtil;
 use common\components\util;
 use common\components\wxUtil;

+ 0 - 1
biz-ghs/express/classes/ExpressClass.php

@@ -10,7 +10,6 @@ use bizHd\wx\classes\WxOpenClass;
 use common\components\dict;
 use common\components\expressUtil;
 use common\components\util;
-use Yii;
 
 class ExpressClass extends BaseClass
 {

+ 0 - 1
biz-hd/wx/classes/WxOpenClass.php

@@ -5,7 +5,6 @@ namespace bizHd\wx\classes;
 use biz\sj\classes\MerchantClass;
 use common\components\dict;
 use common\components\util;
-use Yii;
 use bizHd\base\classes\BaseClass;
 
 class WxOpenClass extends BaseClass

+ 0 - 1
common/components/expressUtil.php

@@ -2,7 +2,6 @@
 
 namespace common\components;
 
-use Yii;
 use yii\helpers\Json;
 use linslin\yii2\curl;
 

+ 669 - 0
common/components/intraCityExpress.php

@@ -0,0 +1,669 @@
+<?php
+
+namespace common\components;
+
+use yii\helpers\Json;
+use linslin\yii2\curl;
+use bizHd\wx\classes\WxOpenClass;
+
+class IntraCityExpress
+{
+    /**
+     * 获取 access_token
+     * @param $merchant
+     * @param int $ptStyle
+     * @return string
+     */
+    public static function getAccessToken($merchant, $ptStyle = 0)
+    {
+        if ($ptStyle == 0) {
+            $ptStyle = dict::getDict('ptStyle', 'hd');
+        }
+
+        // 直接复用 miniUtil 的获取小程序 access_token 方法
+        return miniUtil::getMiniProgramAccessToken($merchant, $ptStyle);
+    }
+
+    public static function getMerchant()
+    {
+        $merchant = WxOpenClass::getMallWxInfo();
+        return $merchant;
+    }
+
+    /**
+     * 发送HTTP请求
+     * @param string $url 请求URL
+     * @param array $data 请求数据
+     * @param string $accessToken access_token
+     * @return array
+     */
+    public static function sendRequest($url, $data, $accessToken)
+    {
+        $curl = new curl\Curl();
+
+        // 添加access_token到URL
+        $urlWithToken = $url . (strpos($url, '?') !== false ? '&' : '?') . 'access_token=' . $accessToken;
+
+        $response = $curl->setOption(CURLOPT_POSTFIELDS, Json::encode($data))
+                         ->post($urlWithToken);//->setOption(CURLOPT_HTTPHEADER, ['Content-Type: application/json'])
+
+        return Json::decode($response, true);
+    }
+
+    // ==================== API URL常量 ====================
+    const API_BASE_URL = 'https://api.weixin.qq.com/cgi-bin/express/intracity';
+
+    // 门店管理
+    const API_CREATE_STORE = self::API_BASE_URL . '/createstore';
+    const API_UPDATE_STORE = self::API_BASE_URL . '/updatestore';
+    const API_QUERY_STORE = self::API_BASE_URL . '/querystore';
+
+    // 订单管理
+    const API_ADD_ORDER = self::API_BASE_URL . '/addorder';
+    const API_CANCEL_ORDER = self::API_BASE_URL . '/cancelorder';
+    const API_GET_ORDER = self::API_BASE_URL . '/queryorder';
+
+    // 预下单
+    const API_PRE_ADD_ORDER = self::API_BASE_URL . '/preaddorder';
+
+    // 资金管理
+    const API_GET_BALANCE = self::API_BASE_URL . '/getbalance';
+    const API_CHARGE_STORE = self::API_BASE_URL . '/chargestore';
+    const API_REFUND_STORE = self::API_BASE_URL . '/refundstore';
+    const API_GET_CHARGE_RECORD = self::API_BASE_URL . '/getchargerecord';
+
+    // 测试接口
+    const API_MOCK_NOTIFY = self::API_BASE_URL . '/mocknotify';
+
+
+    // ==================== 门店管理接口 ====================
+    /**
+     * 创建门店
+     * @param array $storeData 门店信息
+     * @param string $merchant 商户信息
+     * @param int $ptStyle
+     * @return array
+     */
+    public static function createStore($storeData, $merchant = null, $ptStyle = 0)
+    {
+        if ($merchant === null) {
+            $merchant = self::getMerchant();
+        }
+        
+        $accessToken = self::getAccessToken($merchant, $ptStyle);
+        
+        $data = [
+            'out_store_id' => $storeData['out_store_id'],
+            'store_name' => $storeData['store_name'],
+            'store_address' => $storeData['store_address'],
+            'store_longitude' => $storeData['store_longitude'],
+            'store_latitude' => $storeData['store_latitude'],
+            'store_phone' => $storeData['store_phone'],
+            'service_type' => $storeData['service_type'] ?? 1, // 默认同城配送
+        ];
+        
+        return self::sendRequest(self::API_CREATE_STORE, $data, $accessToken);
+    }
+
+    /**
+     * 更新门店
+     * @param array $storeData 门店信息
+     * @param string $merchant 商户信息
+     * @param int $ptStyle
+     * @return array
+     */
+    public static function updateStore($storeData, $merchant = null, $ptStyle = 0)
+    {
+        if ($merchant === null) {
+            $merchant = self::getMerchant();
+        }
+        
+        $accessToken = self::getAccessToken($merchant, $ptStyle);
+        $data = [
+            'out_store_id' => $storeData['out_store_id'],
+            'store_name' => $storeData['store_name'] ?? null,
+            'store_address' => $storeData['store_address'] ?? null,
+            'store_longitude' => $storeData['store_longitude'] ?? null,
+            'store_latitude' => $storeData['store_latitude'] ?? null,
+            'store_phone' => $storeData['store_phone'] ?? null,
+        ];
+        
+        return self::sendRequest(self::API_UPDATE_STORE, $data, $accessToken);
+    }
+
+    /**
+     * 查询门店
+     * @param string $outStoreId 门店ID
+     * @param string $merchant 商户信息
+     * @param int $ptStyle
+     * @return array
+     */
+    public static function getStore($outStoreId, $merchant = null, $ptStyle = 0)
+    {
+        if ($merchant === null) {
+            $merchant = self::getMerchant();
+        }
+        
+        $accessToken = self::getAccessToken($merchant, $ptStyle);
+        
+        $data = [
+            'out_store_id' => $outStoreId,
+        ];
+        
+        return self::sendRequest(self::API_QUERY_STORE, $data, $accessToken);
+    }
+
+
+    // ==================== 订单管理接口 ====================
+    /**
+     * 创建订单
+     * @param array $orderData 订单信息
+     * @param string $merchant 商户信息
+     * @param int $ptStyle
+     * @return array
+     */
+    public static function createOrder($orderData, $merchant = null, $ptStyle = 0)
+    {
+        if ($merchant === null) {
+            $merchant = self::getMerchant();
+        }
+        
+        $accessToken = self::getAccessToken($merchant, $ptStyle);
+        
+        $data = [
+            'out_store_id' => $orderData['out_store_id'],
+            'store_order_id' => $orderData['store_order_id'], // 注意:文档是 store_order_id,不是 out_order_id
+            'delivery_service_code' => $orderData['delivery_service_code'],
+            'receiver' => [
+                'name' => $orderData['to_user_name'],
+                'phone' => $orderData['to_user_phone'],
+                'address' => $orderData['to_user_address'],
+                'lng' => $orderData['to_user_longitude'],
+                'lat' => $orderData['to_user_latitude'],
+            ],
+            'cargo' => [
+                'goods_value' => $orderData['goods_value'],
+                'goods_weight' => $orderData['goods_weight'],
+                'goods_pickup_info' => $orderData['goods_pickup_info'],
+                'goods_delivery_info' => $orderData['goods_delivery_info'],
+                'cargo_first_class' => $orderData['cargo_first_class'] ?? '',
+                'cargo_second_class' => $orderData['cargo_second_class'] ?? '',
+                'goods_type' => $orderData['goods_type'] ?? 99,
+            ],
+            'order' => [
+                'order_type' => $orderData['order_type'] ?? 0,
+                'expected_pickup_time' => $orderData['expected_pickup_time'] ?? 0,
+                'expected_delivery_time' => $orderData['expected_delivery_time'] ?? 0,
+                'tips' => $orderData['tips'] ?? 0,
+                'is_insured' => $orderData['is_insured'] ?? 0,
+                'declared_value' => $orderData['declared_value'] ?? 0,
+                'cash_on_delivery' => $orderData['cash_on_delivery'] ?? 0,
+                'cash_on_delivery_value' => $orderData['cash_on_delivery_value'] ?? 0,
+            ],
+            'sub_biz_id' => $orderData['sub_biz_id'] ?? '',
+        ];
+        
+        return self::sendRequest(self::API_ADD_ORDER, $data, $accessToken);
+    }
+
+    /**
+     * 预下单(查询运费)
+     * @param array $orderData
+     * @param null $merchant
+     * @param int $ptStyle
+     * @return array
+     */
+    public static function preAddOrder($orderData, $merchant = null, $ptStyle = 0)
+    {
+        if ($merchant === null) {
+            $merchant = self::getMerchant();
+        }
+        
+        $accessToken = self::getAccessToken($merchant, $ptStyle);
+        
+        // 构建与 createOrder 相同的请求体
+        $data = [
+             'out_store_id' => $orderData['out_store_id'],
+            'store_order_id' => $orderData['store_order_id'], 
+            'delivery_service_code' => $orderData['delivery_service_code'],
+            'receiver' => [
+                'name' => $orderData['to_user_name'],
+                'phone' => $orderData['to_user_phone'],
+                'address' => $orderData['to_user_address'],
+                'lng' => $orderData['to_user_longitude'],
+                'lat' => $orderData['to_user_latitude'],
+            ],
+            'cargo' => [
+                'goods_value' => $orderData['goods_value'],
+                'goods_weight' => $orderData['goods_weight'],
+                'goods_pickup_info' => $orderData['goods_pickup_info'],
+                'goods_delivery_info' => $orderData['goods_delivery_info'],
+                'cargo_first_class' => $orderData['cargo_first_class'] ?? '',
+                'cargo_second_class' => $orderData['cargo_second_class'] ?? '',
+                'goods_type' => $orderData['goods_type'] ?? 99,
+            ],
+            'order' => [
+                'order_type' => $orderData['order_type'] ?? 0,
+                'expected_pickup_time' => $orderData['expected_pickup_time'] ?? 0,
+                'expected_delivery_time' => $orderData['expected_delivery_time'] ?? 0,
+                'tips' => $orderData['tips'] ?? 0,
+                'is_insured' => $orderData['is_insured'] ?? 0,
+                'declared_value' => $orderData['declared_value'] ?? 0,
+                'cash_on_delivery' => $orderData['cash_on_delivery'] ?? 0,
+                'cash_on_delivery_value' => $orderData['cash_on_delivery_value'] ?? 0,
+            ],
+            'sub_biz_id' => $orderData['sub_biz_id'] ?? '',
+        ];
+
+        return self::sendRequest(self::API_PRE_ADD_ORDER, $data, $accessToken);
+    }
+
+    /**
+     * 取消订单
+     * @param string $wxOrderId 微信订单号
+     * @param string $outOrderId 商户订单号
+     * @param string $outStoreId 门店ID
+     * @param string $merchant 商户信息
+     * @param int $ptStyle
+     * @return array
+     */
+    public static function cancelOrder($wxOrderId = '', $outOrderId = '', $outStoreId = '', $merchant = null, $ptStyle = 0)
+    {
+        if ($merchant === null) {
+            $merchant = self::getMerchant();
+        }
+        
+        $accessToken = self::getAccessToken($merchant, $ptStyle);
+        
+        $data = [];
+        if (!empty($wxOrderId)) {
+            $data['wx_order_id'] = $wxOrderId;
+        }
+        if (!empty($outOrderId)) {
+            $data['store_order_id'] = $outOrderId;
+        }
+        if (!empty($outStoreId)) {
+            $data['out_store_id'] = $outStoreId;
+        }
+        
+        return self::sendRequest(self::API_CANCEL_ORDER, $data, $accessToken);
+    }
+
+    /**
+     * 查询订单
+     * @param string $wxOrderId 微信订单号
+     * @param string $outOrderId 商户订单号
+     * @param string $outStoreId 门店ID
+     * @param string $merchant 商户信息
+     * @param int $ptStyle
+     * @return array
+     */
+    public static function getOrder($wxOrderId = '', $outOrderId = '', $outStoreId = '', $merchant = null, $ptStyle = 0)
+    {
+        if ($merchant === null) {
+            $merchant = self::getMerchant();
+        }
+        
+        $accessToken = self::getAccessToken($merchant, $ptStyle);
+        
+        $data = [];
+        if (!empty($wxOrderId)) {
+            $data['wx_order_id'] = $wxOrderId;
+        }
+        if (!empty($outOrderId)) {
+            $data['store_order_id'] = $outOrderId;
+        }
+        if (!empty($outStoreId)) {
+            $data['out_store_id'] = $outStoreId;
+        }
+        
+        return self::sendRequest(self::API_GET_ORDER, $data, $accessToken);
+    }
+
+    /**
+     * 获取订单列表
+     * @param int $offset 偏移量
+     * @param int $limit 限制数量
+     * @param string $merchant 商户信息
+     * @param int $ptStyle
+     * @return array
+     */
+    public static function getOrderList($offset = 0, $limit = 20, $merchant = null, $ptStyle = 0)
+    {
+        if ($merchant === null) {
+            $merchant = self::getMerchant();
+        }
+        
+        $accessToken = self::getAccessToken($merchant, $ptStyle);
+        $url = 'https://api.weixin.qq.com/cgi-bin/express/intracity/order/list';
+        
+        $data = [
+            'offset' => $offset,
+            'limit' => $limit,
+        ];
+        
+        return self::sendRequest($url, $data, $accessToken);
+    }
+
+    // ==================== 运力管理接口 ====================
+    /**
+     * 获取运力列表
+     * @param string $merchant 商户信息
+     * @param int $ptStyle
+     * @return array
+     */
+    public static function getDeliveryList($merchant = null, $ptStyle = 0)
+    {
+        if ($merchant === null) {
+            $merchant = self::getMerchant();
+        }
+        
+        $accessToken = self::getAccessToken($merchant, $ptStyle);
+        $url = 'https://api.weixin.qq.com/cgi-bin/express/intracity/delivery/list';
+        
+        return self::sendRequest($url, [], $accessToken);
+    }
+
+    /**
+     * 获取运力服务范围
+     * @param string $deliveryId 运力ID
+     * @param string $merchant 商户信息
+     * @param int $ptStyle
+     * @return array
+     */
+    public static function getDeliveryServiceArea($deliveryId, $merchant = null, $ptStyle = 0)
+    {
+        if ($merchant === null) {
+            $merchant = self::getMerchant();
+        }
+        
+        $accessToken = self::getAccessToken($merchant, $ptStyle);
+        $url = 'https://api.weixin.qq.com/cgi-bin/express/intracity/delivery/service_area';
+        
+        $data = [
+            'delivery_id' => $deliveryId,
+        ];
+        
+        return self::sendRequest($url, $data, $accessToken);
+    }
+
+    // ==================== 资金管理接口 ====================
+    /**
+     * 查询门店余额
+     * @param string $outStoreId
+     * @param null $merchant
+     * @param int $ptStyle
+     * @return array
+     */
+    public static function getBalance($outStoreId, $merchant = null, $ptStyle = 0)
+    {
+        if ($merchant === null) {
+            $merchant = self::getMerchant();
+        }
+
+        $accessToken = self::getAccessToken($merchant, $ptStyle);
+        $data = ['out_store_id' => $outStoreId];
+
+        return self::sendRequest(self::API_GET_BALANCE, $data, $accessToken);
+    }
+
+    /**
+     * 门店充值
+     * @param string $outStoreId
+     * @param string $outChargeId
+     * @param int $amount
+     * @param null $merchant
+     * @param int $ptStyle
+     * @return array
+     */
+    public static function chargeStore($outStoreId, $outChargeId, $amount, $merchant = null, $ptStyle = 0)
+    {
+        if ($merchant === null) {
+            $merchant = self::getMerchant();
+        }
+
+        $accessToken = self::getAccessToken($merchant, $ptStyle);
+        $data = [
+            'out_store_id' => $outStoreId,
+            'out_charge_id' => $outChargeId,
+            'amount' => $amount,
+        ];
+
+        return self::sendRequest(self::API_CHARGE_STORE, $data, $accessToken);
+    }
+
+    /**
+     * 门店退款
+     * @param string $outStoreId
+     * @param string $outRefundId
+     * @param string $outChargeId
+     * @param null $merchant
+     * @param int $ptStyle
+     * @return array
+     */
+    public static function refundStore($outStoreId, $outRefundId, $outChargeId, $merchant = null, $ptStyle = 0)
+    {
+        if ($merchant === null) {
+            $merchant = self::getMerchant();
+        }
+
+        $accessToken = self::getAccessToken($merchant, $ptStyle);
+        $data = [
+            'out_store_id' => $outStoreId,
+            'out_refund_id' => $outRefundId,
+            'out_charge_id' => $outChargeId,
+        ];
+
+        return self::sendRequest(self::API_REFUND_STORE, $data, $accessToken);
+    }
+
+    /**
+     * 查询充值记录
+     * @param string $outChargeId
+     * @param null $merchant
+     * @param int $ptStyle
+     * @return array
+     */
+    public static function getChargeRecord($outChargeId, $merchant = null, $ptStyle = 0)
+    {
+        if ($merchant === null) {
+            $merchant = self::getMerchant();
+        }
+
+        $accessToken = self::getAccessToken($merchant, $ptStyle);
+        $data = ['out_charge_id' => $outChargeId];
+
+        return self::sendRequest(self::API_GET_CHARGE_RECORD, $data, $accessToken);
+    }
+
+    // ==================== 测试接口 ====================
+    /**
+     * 模拟回调接口
+     * @param string $wxOrderId 微信订单号
+     * @param string $outStoreId 门店ID
+     * @param string $outOrderId 商户订单号
+     * @param int $orderStatus 订单状态
+     * @param string $merchant 商户信息
+     * @param int $ptStyle
+     * @return array
+     */
+    public static function mockNotify($orderStatus, $wxOrderId = '', $outStoreId = '', $outOrderId = '', $merchant = null, $ptStyle = 0)
+    {
+        if ($merchant === null) {
+            $merchant = self::getMerchant();
+        }
+        
+        $accessToken = self::getAccessToken($merchant, $ptStyle);
+        
+        $data = [
+            'order_status' => $orderStatus,
+        ];
+        
+        if (!empty($wxOrderId)) {
+            $data['wx_order_id'] = $wxOrderId;
+        }
+        // 注意:文档中模拟回调使用的是 wx_store_id 和 store_order_id
+        if (!empty($outStoreId) && !empty($outOrderId)) {
+            $data['wx_store_id'] = $outStoreId;
+            $data['store_order_id'] = $outOrderId;
+        }
+        
+        return self::sendRequest(self::API_MOCK_NOTIFY, $data, $accessToken);
+    }
+
+    /**
+     * 生成回调签名
+     * @param array $params 回调参数
+     * @param string $token 安全token
+     * @return string
+     */
+    public static function generateCallbackSignature($params, $token)
+    {
+        // 1. 筛选出参与签名的字段
+        $signParams = [];
+        $fieldsToSign = ['appid', 'order_status', 'service_trans_id', 'status_change_time', 'store_order_id', 'timestamp', 'wx_order_id', 'wx_store_id'];
+        foreach ($fieldsToSign as $field) {
+            if (isset($params[$field])) {
+                $signParams[$field] = $params[$field];
+            }
+        }
+        
+        // 2. 按字典序排序参数
+        ksort($signParams);
+        
+        // 3. 拼接参数字符串
+        $signStr = '';
+        foreach ($signParams as $key => $value) {
+            $signStr .= $key . '=' . $value . '&';
+        }
+        $signStr .= 'token=' . $token;
+        
+        // 4. 计算MD5并转为小写
+        return strtolower(md5($signStr));
+    }
+
+    // ==================== 回调验证接口 ====================
+    /**
+     * 验证回调签名
+     * @param array $params 回调参数
+     * @param string $token 安全token
+     * @return bool
+     */
+    public static function verifyCallback($params, $token)
+    {
+        if (!isset($params['sign'])) {
+            return false;
+        }
+        
+        $receivedSign = $params['sign'];
+        unset($params['sign']);
+        
+        $calculatedSign = self::generateCallbackSignature($params, $token);
+        
+        return $receivedSign === $calculatedSign;
+    }
+
+    /**
+     * 处理订单状态回调
+     * @param array $callbackData 回调数据
+     * @param string $token 安全token
+     * @return array
+     */
+    public static function handleOrderCallback($callbackData, $token)
+    {
+        // 验证签名
+        if (!self::verifyCallback($callbackData, $token)) {
+            return [
+                'return_code' => 1,
+                'return_msg' => '签名验证失败'
+            ];
+        }
+        
+        // 处理订单状态变化
+        $orderStatus = $callbackData['order_status'];
+        $wxOrderId = $callbackData['wx_order_id'];
+        $outOrderId = $callbackData['store_order_id'] ?? '';
+        $outStoreId = $callbackData['wx_store_id'] ?? '';
+        
+        // 这里可以添加具体的业务逻辑处理
+        // 例如:更新数据库中的订单状态、发送通知等
+        
+        // 伪代码示例:
+        /*
+        switch ($orderStatus) {
+            case 10000: // 订单创建成功
+                // 处理订单创建成功逻辑
+                break;
+            case 30000: // 配送员接单
+                // 处理配送员接单逻辑
+                break;
+            case 40000: // 配送员到店
+                // 处理配送员到店逻辑
+                break;
+            case 50000: // 配送中
+                // 处理配送中逻辑
+                break;
+            case 70000: // 配送完成
+                // 处理配送完成逻辑
+                break;
+            case 20000: // 商家取消订单
+            case 20001: // 配送方取消订单
+            case 60000: // 配送员撤单
+                // 处理订单取消逻辑
+                break;
+            case 90000: // 配送异常
+                // 处理配送异常逻辑
+                break;
+        }
+        */
+        
+        return [
+            'return_code' => 0,
+            '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_FAST_FOOD = 1;    // 快餐
+    const GOODS_TYPE_MEDICINE = 2;     // 药品
+    const GOODS_TYPE_GENERAL = 3;      // 百货
+    const GOODS_TYPE_FRESH = 6;        // 生鲜
+    const GOODS_TYPE_WINE = 8;         // 酒品
+    const GOODS_TYPE_DOCUMENT = 12;    // 文件
+    const GOODS_TYPE_CAKE = 13;        // 蛋糕
+    const GOODS_TYPE_FLOWER = 14;      // 鲜花
+    const GOODS_TYPE_DIGITAL = 15;     // 数码
+    const GOODS_TYPE_CLOTHING = 16;    // 服装
+    const GOODS_TYPE_AUTO_PARTS = 17;  // 汽配
+    const GOODS_TYPE_JEWELRY = 18;     // 珠宝
+    const GOODS_TYPE_DRINK = 32;       // 饮料
+    const GOODS_TYPE_LICENSE = 36;     // 证照
+    const GOODS_TYPE_PET = 55;         // 宠物用品
+    const GOODS_TYPE_MATERNITY = 56;   // 母婴用品
+    const GOODS_TYPE_COSMETICS = 57;   // 美妆用品
+    const GOODS_TYPE_HOME = 58;        // 家居建材
+    const GOODS_TYPE_OTHER = 99;       // 其他
+
+    /**
+     * 运力常量
+     */
+    const DELIVERY_DADA = 'DADA';      // 达达
+    const DELIVERY_SFTC = 'SFTC';      // 顺丰同城
+}

+ 289 - 0
common/components/intraCityExpressExample.php

@@ -0,0 +1,289 @@
+<?php
+
+namespace common\components;
+
+/**
+ * 微信小程序同城配送使用示例
+ * 
+ * 本文件展示了如何使用 IntraCityExpress 类的各种功能
+ * 包括门店管理、订单管理、运力管理等
+ */
+class IntraCityExpressExample
+{
+    /**
+     * 门店管理示例
+     */
+    public static function storeManagementExample()
+    {
+        // 1. 创建门店
+        $storeData = [
+            'out_store_id' => 'store_001',
+            'store_name' => '花店总店',
+            'store_address' => '北京市朝阳区建国路88号',
+            'store_longitude' => 116.397128,
+            'store_latitude' => 39.916527,
+            'store_phone' => '010-12345678',
+            'service_type' => 1, // 同城配送
+        ];
+        
+        $result = IntraCityExpress::createStore($storeData);
+        if ($result['errcode'] === 0) {
+            echo "门店创建成功\n";
+        } else {
+            echo "门店创建失败:" . $result['errmsg'] . "\n";
+        }
+        
+        // 2. 查询门店
+        $storeInfo = IntraCityExpress::getStore('store_001');
+        if ($storeInfo['errcode'] === 0) {
+            echo "门店信息:" . json_encode($storeInfo, JSON_UNESCAPED_UNICODE) . "\n";
+        }
+        
+        // 3. 更新门店
+        $updateData = [
+            'out_store_id' => 'store_001',
+            'store_name' => '花店总店(已更新)',
+            'store_address' => '北京市朝阳区建国路88号',
+            'store_longitude' => 116.397128,
+            'store_latitude' => 39.916527,
+            'store_phone' => '010-87654321',
+        ];
+        
+        $updateResult = IntraCityExpress::updateStore($updateData);
+        if ($updateResult['errcode'] === 0) {
+            echo "门店更新成功\n";
+        }
+        
+        // 4. 获取门店列表
+        $storeList = IntraCityExpress::getStoreList(0, 10);
+        if ($storeList['errcode'] === 0) {
+            echo "门店列表:" . json_encode($storeList, JSON_UNESCAPED_UNICODE) . "\n";
+        }
+    }
+    
+    /**
+     * 订单管理示例
+     */
+    public static function orderManagementExample()
+    {
+        // 1. 创建订单
+        $orderData = [
+            'out_store_id' => 'store_001',
+            'out_order_id' => 'order_' . time(),
+            'delivery_service_code' => 'DADA', // 达达配送
+            'to_user_name' => '张三',
+            'to_user_phone' => '13800138000',
+            'to_user_address' => '北京市海淀区中关村大街1号',
+            'to_user_longitude' => 116.307852,
+            'to_user_latitude' => 39.984154,
+            'goods_value' => 10000, // 商品价值(分)
+            'goods_weight' => 1000, // 商品重量(克)
+            'goods_pickup_info' => '鲜花一束',
+            'goods_delivery_info' => '鲜花一束',
+            'goods_type' => IntraCityExpress::GOODS_TYPE_FLOWER, // 鲜花
+            'expected_pickup_time' => date('Y-m-d H:i:s', time() + 1800), // 30分钟后取货
+            'expected_delivery_time' => date('Y-m-d H:i:s', time() + 7200), // 2小时后送达
+        ];
+        
+        $result = IntraCityExpress::createOrder($orderData);
+        if ($result['errcode'] === 0) {
+            echo "订单创建成功,微信订单号:" . $result['wx_order_id'] . "\n";
+            
+            // 保存微信订单号用于后续操作
+            $wxOrderId = $result['wx_order_id'];
+            
+            // 2. 查询订单
+            $orderInfo = IntraCityExpress::getOrder($wxOrderId);
+            if ($orderInfo['errcode'] === 0) {
+                echo "订单信息:" . json_encode($orderInfo, JSON_UNESCAPED_UNICODE) . "\n";
+            }
+            
+            // 3. 模拟订单状态变化(测试用)
+            $mockResult = IntraCityExpress::mockNotify(
+                IntraCityExpress::ORDER_STATUS_ACCEPTED, // 配送员接单
+                $wxOrderId
+            );
+            if ($mockResult['errcode'] === 0) {
+                echo "模拟回调成功\n";
+            }
+            
+            // 4. 取消订单(如果需要)
+            // $cancelResult = IntraCityExpress::cancelOrder($wxOrderId);
+            // if ($cancelResult['errcode'] === 0) {
+            //     echo "订单取消成功\n";
+            // }
+        } else {
+            echo "订单创建失败:" . $result['errmsg'] . "\n";
+        }
+        
+        // 5. 获取订单列表
+        $orderList = IntraCityExpress::getOrderList(0, 10);
+        if ($orderList['errcode'] === 0) {
+            echo "订单列表:" . json_encode($orderList, JSON_UNESCAPED_UNICODE) . "\n";
+        }
+    }
+    
+    /**
+     * 运力管理示例
+     */
+    public static function deliveryManagementExample()
+    {
+        // 1. 获取运力列表
+        $deliveryList = IntraCityExpress::getDeliveryList();
+        if ($deliveryList['errcode'] === 0) {
+            echo "运力列表:" . json_encode($deliveryList, JSON_UNESCAPED_UNICODE) . "\n";
+            
+            // 2. 获取运力服务范围
+            if (!empty($deliveryList['delivery_list'])) {
+                $deliveryId = $deliveryList['delivery_list'][0]['delivery_id'];
+                $serviceArea = IntraCityExpress::getDeliveryServiceArea($deliveryId);
+                if ($serviceArea['errcode'] === 0) {
+                    echo "运力服务范围:" . json_encode($serviceArea, JSON_UNESCAPED_UNICODE) . "\n";
+                }
+            }
+        }
+    }
+    
+    /**
+     * 回调处理示例
+     */
+    public static function callbackExample()
+    {
+        // 模拟接收到的回调数据
+        $callbackData = [
+            'appid' => 'wx539e0b4872f19621',
+            'order_status' => IntraCityExpress::ORDER_STATUS_COMPLETED,
+            'service_trans_id' => 'DADA',
+            'status_change_time' => time(),
+            'store_order_id' => 'order_123456',
+            'timestamp' => time(),
+            'wx_order_id' => '4018734875633256960',
+            'wx_store_id' => '4000000000000042001',
+            'sign' => 'a85489d9444bdd382e0de0ddca67a8ee' // 实际签名值
+        ];
+        
+        // 安全token(需要在小程序管理后台设置)
+        $token = 'abcdefghi';
+        
+        // 处理回调
+        $result = IntraCityExpress::handleOrderCallback($callbackData, $token);
+        echo "回调处理结果:" . json_encode($result, JSON_UNESCAPED_UNICODE) . "\n";
+    }
+    
+    /**
+     * 完整业务流程示例
+     */
+    public static function completeWorkflowExample()
+    {
+        echo "=== 微信小程序同城配送完整业务流程示例 ===\n\n";
+        
+        // 1. 门店管理
+        echo "1. 门店管理\n";
+        self::storeManagementExample();
+        echo "\n";
+        
+        // 2. 运力管理
+        echo "2. 运力管理\n";
+        self::deliveryManagementExample();
+        echo "\n";
+        
+        // 3. 订单管理
+        echo "3. 订单管理\n";
+        self::orderManagementExample();
+        echo "\n";
+        
+        // 4. 回调处理
+        echo "4. 回调处理\n";
+        self::callbackExample();
+        echo "\n";
+        
+        echo "=== 业务流程示例完成 ===\n";
+    }
+    
+    /**
+     * 错误处理示例
+     */
+    public static function errorHandlingExample()
+    {
+        echo "=== 错误处理示例 ===\n";
+        
+        // 1. 处理常见错误码
+        $errorCodes = [
+            934000 => '其他逻辑错误',
+            934001 => '请求参数有误',
+            934002 => '订单已存在,且订单在处理中',
+            934003 => '运力ID错误',
+            934005 => '运力预创建订单错误',
+            934006 => '有在途订单,暂不能退款',
+            934007 => '不是在途订单',
+            934008 => '门店ID和APPID不匹配',
+            934009 => '不支持该门店所在城市',
+            934010 => '重复创建门店',
+            934011 => '请求签名错误',
+            934012 => 'appid和access_token不匹配',
+            934013 => '门店余额不足无法下单',
+            934014 => '运力公司返回了非法金额',
+            934015 => '余额扣减失败',
+            934016 => '订单不存在',
+            934017 => '订单处在不能被取消的状态',
+            934018 => '订单已取消,请勿重复操作',
+            934019 => '超出运力支持的配送范围',
+            934020 => '商品超重',
+            934021 => '门店不存在',
+            934022 => '账号类型不可以为个人账号',
+            934023 => '小程序类型必须为普通小程序',
+            934999 => '内部系统错误',
+        ];
+        
+        foreach ($errorCodes as $code => $message) {
+            echo "错误码 {$code}: {$message}\n";
+        }
+        
+        // 2. 实际错误处理示例
+        try {
+            // 尝试创建无效订单
+            $invalidOrderData = [
+                'out_store_id' => 'invalid_store',
+                'out_order_id' => 'order_' . time(),
+                'delivery_service_code' => 'INVALID_DELIVERY',
+                'to_user_name' => '测试用户',
+                'to_user_phone' => '13800138000',
+                'to_user_address' => '测试地址',
+                'to_user_longitude' => 116.397128,
+                'to_user_latitude' => 39.916527,
+                'goods_value' => 10000,
+                'goods_weight' => 1000,
+                'goods_pickup_info' => '测试商品',
+                'goods_delivery_info' => '测试商品',
+            ];
+            
+            $result = IntraCityExpress::createOrder($invalidOrderData);
+            
+            if ($result['errcode'] !== 0) {
+                echo "订单创建失败,错误码:{$result['errcode']},错误信息:{$result['errmsg']}\n";
+                
+                // 根据错误码进行相应处理
+                switch ($result['errcode']) {
+                    case 934021:
+                        echo "门店不存在,请先创建门店\n";
+                        break;
+                    case 934003:
+                        echo "运力ID错误,请检查运力配置\n";
+                        break;
+                    case 934019:
+                        echo "超出配送范围,请选择其他配送方式\n";
+                        break;
+                    default:
+                        echo "其他错误,请联系技术支持\n";
+                        break;
+                }
+            }
+        } catch (\Exception $e) {
+            echo "异常处理:" . $e->getMessage() . "\n";
+        }
+    }
+}
+
+// 使用示例(取消注释即可运行)
+// IntraCityExpressExample::completeWorkflowExample();
+// IntraCityExpressExample::errorHandlingExample();

+ 0 - 2
common/components/miniUtil.php

@@ -2,10 +2,8 @@
 
 namespace common\components;
 
-use bizHd\wx\classes\WxOpenClass;
 use bizHd\wx\services\WxBaseService;
 use bizHd\wx\services\WxMiniBaseService;
-use bizHd\wx\services\WxOpenService;
 use common\services\xhMerchantExtendService;
 use Yii;
 use yii\helpers\Json;