| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155 |
- <?php
- namespace ghs\controllers;
- use common\components\util;
- use Yii;
- use common\components\delivery\services\adapter\FengniaoAdapter;
- use common\components\delivery\platform\fengniao\Auth;
- /**
- * 蜂鸟配送 API 测试控制器
- *
- * ⚠️ 常见错误诊断:apiCode=B0112 -- 门店不存在
- *
- * 可能的原因:
- * 1. chain_store_id 填写错误或不存在 ← 最可能!
- * 2. chain_store_id 所属的城市不在蜂鸟配送范围内
- * 3. 收货地址超出该门店的配送范围
- * 4. 收货坐标系与接口要求不匹配(建议使用高德地图坐标系 position_source=3)
- * 5. 门店已被禁用或删除
- *
- * 解决步骤:
- * 1. 确认 chain_store_id = '14594092' 是否真实存在
- * 2. 使用 actionCityList() 验证收货城市是否在蜂鸟配送范围内
- * 3. 修改收货地址到该门店的配送范围内
- * 4. 确保使用高德地图坐标系(position_source = 3)
- * 5. 查看运行时日志(runtime/logs/app.log)了解更多错误细节
- */
- class DeliveryFengniaoController extends BaseController
- {
- private const TEST_SHOP_ID = '467788524';
- public function actionGetToken()
- {
- $auth = new Auth();
- $auth->setMerchantId('14594092');
- $accessToken = $auth->getAccessToken('H9IbEc4t5lf4w96KJ7yjQT');
- return $this->asJson($accessToken);
- }
- /**
- * 获取蜂鸟配送覆盖的城市列表
- * 用于诊断:收货地址所在城市是否在蜂鸟配送范围内
- */
- public function actionCityList()
- {
- $fap = new FengniaoAdapter('5e1577dc-487d-4f56-96e0-e4b3aba7326b');
- $fap->setMerchantId('14594092');
-
- Yii::info("=== 获取城市列表 ===");
- $re = $fap->cityList();
-
- Yii::info("=== 城市列表响应 ===");
- Yii::info(json_encode($re, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
-
- return $this->asJson($re);
- }
- /**
- * 门店批量查询接口
- */
- public function actionChainstoreQueryList()
- {
- $fap = new FengniaoAdapter('5e1577dc-487d-4f56-96e0-e4b3aba7326b');
- $ret = $fap->chainstoreQueryList(['merchant_id'=>14594092]);
- util::success($ret, "success");
- }
- public function actionCreateOrder()
- {
- $order = $this->getValidCreateOrderData();
- $fap = new FengniaoAdapter('5e1577dc-487d-4f56-96e0-e4b3aba7326b');
- $fap->setMerchantId('14594092');
- $fap->createOrder($order);
- }
- public function actionPreCreateOrder()
- {
- $order = $this->getValidCreateOrderData();
- $fap = new FengniaoAdapter('5e1577dc-487d-4f56-96e0-e4b3aba7326b');
- $fap->setMerchantId('14594092');
-
- // 添加调试日志
- Yii::info("=== 预下单接口请求 ===");
- Yii::info("门店ID: " . $order['chain_store_id']);
- Yii::info("商户ID: 14594092");
- Yii::info("收货地址: " . $order['receiver_address']);
- Yii::info("收货坐标: {$order['receiver_latitude']}, {$order['receiver_longitude']}");
-
- $re = $fap->getPrice($order);
-
- Yii::info("=== 预下单接口响应 ===");
- Yii::info(json_encode($re, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
-
- return $this->asJson($re);
- }
- public function actionPreCancelOrder()
- {
- $fap = new FengniaoAdapter('5e1577dc-487d-4f56-96e0-e4b3aba7326b');
- $fap->setMerchantId('14594092');
- $cancelOrder = [
- "order_id" => '100000000191491340',
- 'order_cancel_role' => 1,
- "order_cancel_code" => 6,
- 'order_cancel_other_reason' => '订单取消'
- ];
- $re = $fap->cancelOrder($cancelOrder);
- }
- /**
- * 获取有效的创建订单数据
- */
- private function getValidCreateOrderData(): array
- {
- return [
- 'partner_order_code' => 'TEST_ORDER_' . time() . '_' . uniqid(),
- 'receiver_primary_phone' => '13800000000',
- 'receiver_name' => '张三',
- 'receiver_latitude' => 39.9042,
- 'receiver_longitude' => 116.4074,
- 'receiver_address' => '北京市朝阳区建国门外大街1号',
- 'position_source' => 3,
- 'goods_count' => 2,
- 'goods_weight' => 1.5,
- 'goods_total_amount_cent' => 5000,
- 'goods_actual_amount_cent' => 4500,
- 'goods_item_list' => [
- [
- 'item_id' => 'ITEM_001',
- 'item_name' => '玫瑰花束',
- 'item_amount_cent' => 3000,
- 'item_actual_amount_cent' => 2700,
- 'item_quantity' => 1,
- 'item_size' => 2,
- ],
- [
- 'item_id' => 'ITEM_002',
- 'item_name' => '贺卡',
- 'item_amount_cent' => 2000,
- 'item_actual_amount_cent' => 1800,
- 'item_quantity' => 1,
- 'item_size' => 1,
- ],
- ],
- 'order_type' => 1,
- 'chain_store_id' => self::TEST_SHOP_ID,
- 'order_remark' => '请轻拿轻放',
- ];
- }
- }
|