DispatchService.php 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074
  1. <?php
  2. namespace common\components\delivery\services;
  3. use biz\shop\classes\ShopClass;
  4. use bizGhs\express\classes\DeliveryAuthTokenClass;
  5. use bizGhs\express\classes\GhsDeliveryOrderClass;
  6. use bizGhs\order\classes\OrderClass;
  7. use bizGhs\order\classes\OrderItemClass;
  8. use bizHd\express\classes\HdDeliveryOrderClass;
  9. use common\components\delivery\helpers\HttpClient;
  10. use common\components\delivery\services\adapter\{DadaAdapter,
  11. DidiAdapter,
  12. Functions,
  13. ShansongAdapter,
  14. HuolalaAdapter,
  15. FengniaoAdapter,
  16. ShunfengAdapter}; // MeituanAdapter, UUAdapter,
  17. use common\components\util;
  18. use Yii;
  19. /**
  20. * 聚合调度逻辑(平台选择/优先级)
  21. * Class DispatchService
  22. * @package App\Services
  23. */
  24. class DispatchService
  25. {
  26. protected $adapters;
  27. protected $platformName = '';
  28. public function __construct($mainId, $platform='')
  29. {
  30. if ($platform == '') {
  31. $authPlatforms = DeliveryAuthTokenClass::getAllByCondition(['mainId'=>$mainId]);
  32. foreach($authPlatforms as $pt) {
  33. switch ($pt['platform']) {
  34. case 'shansong':
  35. $this->adapters['shansong'] = new ShansongAdapter($pt['accessToken'], $pt['shopId']);
  36. break;
  37. case 'huolala':
  38. $this->adapters['huolala'] = new HuolalaAdapter($pt['accessToken']);
  39. break;
  40. case 'fengniao':
  41. $adapter = new FengniaoAdapter($pt['accessToken']);
  42. // 动态设置商户ID与门店ID
  43. $adapter->setMerchantId($pt['merchantId']);
  44. $adapter->setShopId($pt['shopId']);
  45. $this->adapters['fengniao'] = $adapter;
  46. break;
  47. case 'shunfeng':
  48. $this->adapters['shunfeng'] = new ShunfengAdapter($pt, $pt['shopId']);
  49. break;
  50. case 'dada':
  51. $this->adapters['dada'] = new DadaAdapter($pt['accessToken'], $pt['shopId'], $pt['merchantId']);
  52. //$this->adapters['dada']->setShopNo($pt['shopId']);
  53. //$this->adapters['dada']->setSourceId($pt['merchantId']); // 用 merchanId 来保存 sourceId
  54. break;
  55. case 'didi':
  56. $this->adapters['didi'] = new DidiAdapter($pt['accessToken'], $pt['mainId']);
  57. break;
  58. }
  59. //检测 token 是否即将过期
  60. $tokenExpireTime = $pt['expiresAt'];
  61. if ($tokenExpireTime < time() + 86400 * 5) {
  62. Yii::info('刷新 token: ' . $pt['platform'] . ',refreshToken: ' . $pt['refreshToken'] . ',merchantId: ' . $pt['merchantId']);
  63. $this->refreshToken($pt['platform'], $pt['refreshToken'], ['merchantId' => $pt['merchantId']]);
  64. }
  65. }
  66. } else {
  67. $authPlatform = DeliveryAuthTokenClass::getByCondition(['mainId'=>$mainId, 'platform'=>$platform]);
  68. switch ($platform) {
  69. case 'shansong':
  70. $this->adapters['shansong'] = new ShansongAdapter($authPlatform['accessToken'], $authPlatform['shopId']);
  71. break;
  72. case 'huolala':
  73. $this->adapters['huolala'] = new HuolalaAdapter($authPlatform['accessToken']);
  74. break;
  75. case 'fengniao':
  76. //$this->adapters['fengniao'] = new FengniaoAdapter($authPlatform['accessToken']);
  77. $adapter = new FengniaoAdapter($authPlatform['accessToken']);
  78. // 动态设置商户ID与门店ID
  79. $adapter->setMerchantId($authPlatform['merchantId']);
  80. $adapter->setShopId($authPlatform['shopId']);
  81. $this->adapters['fengniao'] = $adapter;
  82. break;
  83. case 'shunfeng':
  84. $this->adapters['shunfeng'] = new ShunfengAdapter($authPlatform, $authPlatform['shopId']);
  85. break;
  86. case 'dada':
  87. $this->adapters['dada'] = new DadaAdapter($authPlatform['accessToken'], $authPlatform['shopId'], $authPlatform['merchantId']);
  88. //$this->adapters['dada']->setShopNo($authPlatform['shopId']);
  89. //$this->adapters['dada']->setSourceId($authPlatform['merchantId']); // 用 merchanId 来保存 sourceId
  90. break;
  91. case 'didi':
  92. $this->adapters['didi'] = new DidiAdapter($authPlatform['accessToken'], $authPlatform['mainId']);
  93. break;
  94. }
  95. $this->platformName = $platform;
  96. if($authPlatform['expiresAt'] < time() + 86400 * 5) {
  97. Yii::info('刷新 token: ' . $platform . ',refreshToken: ' . $authPlatform['refreshToken'] . ',merchantId: ' . $authPlatform['merchantId']);
  98. $this->refreshToken($platform, $authPlatform['refreshToken'], ['merchantId' => $authPlatform['merchantId']]);
  99. }
  100. }
  101. }
  102. public function validateOrder($order)
  103. {
  104. if(empty($order['address'])){
  105. throw new \Exception('客户地址缺失');
  106. }
  107. if(empty($order['long']) || empty($order['lat'])){
  108. throw new \Exception('客户地址信息缺失');
  109. }
  110. if(empty($order['customName'])){
  111. throw new \Exception('客户姓名缺失');
  112. }
  113. if(empty($order['city'])){
  114. throw new \Exception('客户城市信息缺失');
  115. }
  116. if(empty($order['customMobile']) && empty($order['receiveMobile']) && empty($order['bookMobile'])){
  117. throw new \Exception('客户联系电话缺失');
  118. }
  119. }
  120. /**
  121. * @param $order
  122. * @param string $orderType 订单类型:xhOrder 或 xhGhsOrder
  123. * @param $shopId
  124. * @param $params
  125. * @return mixed
  126. */
  127. public function createOrder($order, $orderType, $shopId, $params)
  128. {
  129. $order = $order->toArray();
  130. if(!in_array($orderType, ['xhOrder', 'xhGhsOrder'])){
  131. util::fail('订单类型错误');
  132. }
  133. $shop = ShopClass::getById($shopId, false, 'id,merchantName,shopName,fullAddress,lat,long,city,dist,floor,mobile,merchantName');
  134. $adapter = $this->getAdapter();
  135. $orderData = $adapter->formatOrderData($order, $orderType, $shop, $params);
  136. return $adapter->createOrder($orderData);
  137. }
  138. /**
  139. *
  140. */
  141. public function addTip($data)
  142. {
  143. $adapter = $this->getAdapter();
  144. return $adapter->addTip($data);
  145. }
  146. /**
  147. * @param $orderId 平台订单号
  148. * @param string $thirdOrderNo xhGhsOrder.orderSn
  149. */
  150. public function selectOrder($orderId, $thirdOrderNo='')
  151. {
  152. $adapter = $this->getAdapter();
  153. if ($adapter instanceof ShansongAdapter) {
  154. $deliveryOrder = $this->getDeliveryOrder($orderId, 'shansong');
  155. return $adapter->selectOrder($deliveryOrder['orderId'], $thirdOrderNo);
  156. }
  157. if ($adapter instanceof HuolalaAdapter) {
  158. $deliveryOrder = $this->getDeliveryOrder($orderId, 'huolala');
  159. return $adapter->selectOrder($deliveryOrder['orderId']);
  160. }
  161. if ($adapter instanceof FengniaoAdapter) {
  162. $deliveryOrder = $this->getDeliveryOrder($orderId, 'fengniao');
  163. //order_id 和 partner_order_code 必填一个
  164. return $adapter->selectOrder(['order_id'=>$deliveryOrder['orderId']]);
  165. }
  166. if ($adapter instanceof ShunfengAdapter) {
  167. $deliveryOrder = $this->getDeliveryOrder($orderId, 'shunfeng');
  168. return $adapter->selectOrder($deliveryOrder['orderId']);
  169. }
  170. if ($adapter instanceof DadaAdapter) {
  171. $ghsOrder = OrderClass::getById($orderId, false, 'id,orderSn');
  172. return $adapter->selectOrder($ghsOrder['orderSn']);
  173. }
  174. if ($adapter instanceof DidiAdapter) {
  175. $deliveryOrder = $this->getDeliveryOrder($orderId, 'didi', 'id,orderId,createdAt');
  176. $timeStamp = strtoTime($deliveryOrder['createdAt']);
  177. return $adapter->selectOrder($deliveryOrder['orderId'], $thirdOrderNo, $timeStamp);
  178. }
  179. return $adapter->selectOrder($orderId);
  180. }
  181. /**
  182. * 根据订单号查找配送订单
  183. *
  184. * @param string $orderId
  185. * @return object|null
  186. */
  187. private function getDeliveryOrder($orderId, $deliveryId, $fields=null)
  188. {
  189. $fields = $fields ?? 'id,orderId';
  190. // 查找批发配送订单
  191. $deliveryOrder = GhsDeliveryOrderClass::getByCondition([
  192. 'deliveryId' => $deliveryId,
  193. 'ghsOrderId' => $orderId,
  194. 'orderStatus' => ['not in', [-1, -2]],
  195. ], false, null, $fields);
  196. if ($deliveryOrder) {
  197. return $deliveryOrder;
  198. }
  199. // 查找零售配送订单
  200. $deliveryOrder = HdDeliveryOrderClass::getByCondition([
  201. 'deliveryId' => $deliveryId,
  202. 'hdOrderId' => $orderId,
  203. 'orderStatus' => ['not in', [-1, -2]],
  204. ], false, null, $fields);
  205. if ($deliveryOrder) {
  206. return $deliveryOrder;
  207. }
  208. util::fail('未找到对应的配送订单: ' . $orderId);
  209. }
  210. public function cancelOrder($orderId, $reason)
  211. {
  212. $adapter = $this->getAdapter();
  213. return $adapter->cancelOrder($orderId, $reason);
  214. }
  215. public function getCancelReasonList($orderId)
  216. {
  217. $adapter = $this->getAdapter();
  218. return $adapter->getCancelReasonList($orderId);
  219. }
  220. public function getAdapter()
  221. {
  222. return $this->adapters[$this->platformName];
  223. }
  224. /**
  225. * 获取所有平台的报价(使用 Guzzle 并发请求)
  226. *
  227. * 流程说明:
  228. * 1. 同步准备各平台的前置数据(如城市信息、订单商品等)
  229. * 2. 使用 Guzzle Pool 并发发送各平台的报价请求(5秒超时)
  230. * 3. 某个平台失败/超时不影响其他平台,继续等待结果
  231. *
  232. * @param array $order 订单信息
  233. * @param array $shop 店铺信息
  234. * @param string $pickupTime 取件时间
  235. * @return array 返回所有平台的报价结果
  236. */
  237. public function getAllPlatformPrice($order, $shop, $pickupTime)
  238. {
  239. // 第一步:准备前置数据(同步进行,因为某些平台需要这些数据)
  240. $preparedData = $this->preparePlatformData($order, $shop, $pickupTime);
  241. if (empty($preparedData)) {
  242. return ['error' => '所有平台数据准备失败'];
  243. }
  244. // 第二步:并发调用各平台的报价接口
  245. $results = $this->concurrentGetPrices($preparedData, $pickupTime);
  246. if (empty($results['success']) && empty($results['failed'])) {
  247. return ['error' => '没有可用的物流平台'];
  248. }
  249. // 格式化返回结果
  250. return [
  251. 'quotes' => $results['success'] ?? [],
  252. 'failed' => $results['failed'] ?? [],
  253. ];
  254. }
  255. /**
  256. * 为各平台准备订单数据(前置数据同步获取)
  257. * @param array $order 订单信息
  258. * @param array $shop 店铺信息
  259. * @param string $pickupTime 取件时间
  260. * @return array 各平台的订单数据
  261. */
  262. private function preparePlatformData($order, $shop, $pickupTime)
  263. {
  264. $preparedData = [];
  265. // 准备 Huolala 数据
  266. if (isset($this->adapters['huolala'])) {
  267. try {
  268. $preparedData['huolala'] = $this->prepareHuolalaData($order, $shop);
  269. } catch (\Exception $e) {
  270. Yii::warning("Huolala 数据准备失败: {$e->getMessage()}");
  271. }
  272. }
  273. // 准备 Fengniao 数据
  274. if (isset($this->adapters['fengniao'])) {
  275. try {
  276. /** @var FengniaoAdapter $fengniaoAdapter */
  277. $fengniaoAdapter = $this->adapters['fengniao'];
  278. $platformShopId = $fengniaoAdapter->getShopId();
  279. $preparedData['fengniao'] = $this->prepareFengniaoData($order, $shop, $platformShopId);
  280. } catch (\Exception $e) {
  281. Yii::warning("Fengniao 数据准备失败: {$e->getMessage()}");
  282. }
  283. }
  284. // 准备 Shansong 数据
  285. if (isset($this->adapters['shansong'])) {
  286. try {
  287. $preparedData['shansong'] = $this->prepareShansongData($order, $shop, $pickupTime);
  288. } catch (\Exception $e) {
  289. Yii::warning("Shansong 数据准备失败: {$e->getMessage()}");
  290. }
  291. }
  292. // 准备顺丰订单数据
  293. if (isset($this->adapters['shunfeng'])) {
  294. try {
  295. /** @var ShunfengAdapter $adapter */
  296. $adapter = $this->adapters['shunfeng'];
  297. // is_person_direct -- 店铺是否支持专人直送,0不支持 1支持 2只能发独享专送
  298. $isPersonDirect = $adapter->getIsPersonDirect();
  299. if($isPersonDirect != 2){
  300. $customSettings = [];//自定义用户设置:默认不专人直送
  301. $preparedData['shunfeng'] = $this->prepareShunfengData($order, $shop, $customSettings);
  302. }
  303. //添加专人直送的订单数据
  304. if(in_array($isPersonDirect, [1, 2])){ // 支持专人直送
  305. $customSettings = ['isPersonDirect' => 1];//自定义用户设置:专人直送
  306. $preparedData['shunfeng_1v1'] = $this->prepareShunfengData($order, $shop, $customSettings);
  307. // Yii::info('预创建订单 shunfeng_1v1 request data: ' . json_encode($preparedData['shunfeng_1v1']));
  308. }
  309. // else{
  310. // $customSettings = [];//自定义用户设置:默认不专人直送
  311. // $preparedData['shunfeng'] = $this->prepareShunfengData($order, $shop, $customSettings);
  312. // }
  313. } catch (\Exception $e) {
  314. Yii::warning("Shunfeng 数据准备失败: {$e->getMessage()}");
  315. }
  316. }
  317. // 准备达达订单数据
  318. if (isset($this->adapters['dada'])) {
  319. try {
  320. $dadaAdapter = $this->adapters['dada'];
  321. $shopNo = $dadaAdapter->getShopNo();
  322. // 拼送
  323. $customSettings = ['is_direct_delivery' => 0];
  324. $preparedData['dada'] = $this->prepareDadaData($order, $shopNo, $customSettings);
  325. // 专送
  326. //$customSettings = ['is_direct_delivery' => 1];
  327. //$preparedData['dada_1v1'] = $this->prepareDadaData($order, $shopNo, $customSettings);
  328. } catch (\Exception $e) {
  329. Yii::warning("Dada 数据准备失败: {$e->getMessage()}");
  330. }
  331. }
  332. // 准备滴滴订单数据
  333. if (isset($this->adapters['didi'])) {
  334. try {
  335. $preparedData['didi'] = $this->prepareDidiData($order, $shop);
  336. } catch (\Exception $e) {
  337. Yii::warning("Didi 数据准备失败: {$e->getMessage()}");
  338. }
  339. }
  340. return $preparedData;
  341. }
  342. /**
  343. * 准备货拉拉订单数据
  344. */
  345. private function prepareHuolalaData($order, $shop)
  346. {
  347. $formatCity = rtrim($order['city'], '市');
  348. $cities = include Yii::getAlias('@common/components/delivery/platform/huolala/cities.php');
  349. if (!isset($cities[$formatCity])) {
  350. throw new \Exception('城市编码表中没有找到城市: ' . $formatCity);
  351. }
  352. $cityId = $cities[$formatCity]['city_id'];
  353. $cityVehicleList = $this->adapters['huolala']->getCityVehicleList($cityId); // 产生外部请求
  354. $cityInfoRevision = $cityVehicleList['city_info_revision']; // 城市版本号
  355. $vehicleList = $cityVehicleList['vehicle_list']; // 所有车型列表
  356. if (empty($vehicleList)) {
  357. throw new \Exception('没有找到可选车型');
  358. }
  359. // 解析额外需求
  360. $specReqItem = $cityVehicleList['spec_req_item'] ?? [];
  361. $specReq = [];
  362. foreach ($specReqItem as $item) {
  363. $specReq[] = $item['type'] ?? null;
  364. }
  365. $specReq = array_filter($specReq);
  366. // 构建所需车型数据
  367. $vehicleTypeList = [];
  368. foreach ($vehicleList as $vehicle) {
  369. if(!in_array($vehicle['vehicle_name'], ['跑腿', '小面', '微面'])){ // && !$this->adapters['huolala']->getIsSandbox()
  370. continue;
  371. }
  372. $vehicleStd = [];
  373. $vehicleStd[] = count($vehicle['vehicle_std_item']) > 0 ? $vehicle['vehicle_std_item'][0]['name'] : '';
  374. $vehicleTypeList[$vehicle['order_vehicle_id']] = [
  375. 'order_vehicle_id' => $vehicle['order_vehicle_id'],
  376. 'city_info_revision' => $cityInfoRevision,
  377. 'order_time' => time() + 600,
  378. 'addr_info' => [
  379. [
  380. 'name' => $shop['merchantName'],
  381. 'addr' => $shop['province'] . $shop['city'] . $shop['dist'] . $shop['address'],
  382. 'city_id' => $cityId,
  383. 'city_name' => $shop['city'],
  384. 'district_name' => $shop['dist'],
  385. 'house_number' => $shop['floor'],
  386. 'contacts_name' => $shop['mobile'],
  387. 'contacts_phone_no' => $shop['mobile'],
  388. 'lat_lon' => ['lat' => (float)$shop['lat'], 'lon' => (float)$shop['long']],
  389. ],
  390. [
  391. 'name' => $order['customName'],
  392. 'addr' => $order['fullAddress'],
  393. 'city_id' => $cityId,
  394. 'city_name' => $order['city'],
  395. 'district_name' => $order['dist'],
  396. 'house_number' => $order['floor'],
  397. 'contacts_name' => $order['customName'],
  398. 'contacts_phone_no' => Functions::getMobile($order),
  399. 'lat_lon' => ['lat' => (float)$order['lat'], 'lon' => (float)$order['long']],
  400. ]
  401. ],
  402. 'vehicle_std' => $vehicleStd,
  403. 'spec_req' => array_values($specReq),
  404. 'coupon_id' => 123456, // TODO ??? 添加自动获取 coupon_id
  405. 'invoice_type' => 1,
  406. 'order_service_type' => 1,
  407. '_meta' => [
  408. 'vehicle_type' => $vehicle['vehicle_name'],
  409. 'city_info_revision' => $cityInfoRevision,
  410. ]
  411. ];
  412. }
  413. return [
  414. 'platform' => 'huolala',
  415. 'city_id' => $cityId,
  416. 'vehicle_type_list' => $vehicleTypeList,
  417. ];
  418. }
  419. /**
  420. * 准备蜂鸟订单数据
  421. */
  422. private function prepareFengniaoData($order, $shop, $platformShopId)
  423. {
  424. // $this->adapters['fengniao']->setMerchantId(14594092); // adapter 创建时已经设置了
  425. $goodsItemList = [];
  426. $itemInfos = OrderItemClass::getAllByCondition(['orderSn' => $order['orderSn']], null, 'id, name, unitPrice, num');
  427. foreach ($itemInfos as $item) {
  428. $goodsItemList[] = [
  429. 'item_actual_amount_cent' => (int)($item['unitPrice'] * 100 * $item['num']),
  430. 'item_amount_cent' => (int)($item['unitPrice'] * 100),
  431. 'item_id' => $item['id'],
  432. 'item_name' => $item['name'],
  433. 'item_quantity' => $item['num'],
  434. ];
  435. }
  436. return [
  437. 'platform' => 'fengniao',
  438. 'partner_order_code' => $order['orderSn'],
  439. 'receiver_primary_phone' => Functions::getMobile($order),
  440. 'receiver_name' => $order['customName'],
  441. 'receiver_latitude' => (float)$order['lat'],
  442. 'receiver_longitude' => (float)$order['long'],
  443. 'receiver_address' => $order['fullAddress'],
  444. 'position_source' => 3, //坐标经纬度来源(1:腾讯地图,2:百度地图, 3:高德地图)
  445. 'goods_count' => count($goodsItemList),
  446. 'goods_weight' => (float)$order['weight'],
  447. 'goods_total_amount_cent' => (int)($order['actPrice'] * 100),
  448. 'goods_actual_amount_cent' => (int)($order['prePrice'] * 100),
  449. 'goods_item_list' => $goodsItemList,
  450. //'order_type' => 1,
  451. 'chain_store_id' => $platformShopId, // 蜂鸟平台 shopId
  452. 'order_remark' => $order['remark'] ?? '',
  453. ];
  454. }
  455. /**
  456. * 准备闪送订单数据
  457. */
  458. private function prepareShansongData($order, $shop, $pickupTime)
  459. {
  460. $data = [
  461. 'platform' => 'shansong',
  462. 'cityName' => $shop['city'],
  463. 'sender' => [
  464. 'fromAddress' => $shop['address'],
  465. 'fromAddressDetail' => $shop['floor'],
  466. 'fromSenderName' => $shop['shopName'] == '首店' ? $shop['merchantName'] : $shop['merchantName'].'-'.$shop['shopName'],
  467. 'fromMobile' => $shop['mobile'],
  468. 'fromLatitude' => (string)$shop['lat'],
  469. 'fromLongitude' => (string)$shop['long'],
  470. ],
  471. 'receiverList' => [
  472. [
  473. 'orderNo' => $order['orderSn'],
  474. 'toAddress' => $order['address'],
  475. 'toAddressDetail' => $order['floor'],
  476. 'toReceiverName' => $order['customName'],
  477. 'toMobile' => Functions::getMobile($order),
  478. 'toLatitude' => (string)$order['lat'],
  479. 'toLongitude' => (string)$order['long'],
  480. 'goodType' => 7, //鲜花
  481. 'weight' => (int)round($order['weight']),
  482. 'remarks' => $order['remark'] ?? '',
  483. ]
  484. ],
  485. 'appointType' => 0, //预约类型: 0立即单,1预约单
  486. 'travelWay' => 0,
  487. 'deliveryType' => 1,
  488. //补充额外的订单数据
  489. 'sendNum' => $order['sendNum'],
  490. ];
  491. $timestamp = strtotime($pickupTime);
  492. $currentTime = time() + 3600;
  493. if($timestamp > $currentTime){
  494. $data['appointType'] = 1; // 修改成 1预约单
  495. $data['appointmentDate'] = $pickupTime; // 预约时间, yyyy-MM-dd HH:mm格式(例如:2020-02-02 22:00),指的是预约取件时间,只支持一个小时以后
  496. //两天以内
  497. if($timestamp > time() + 172800){
  498. throw new \Exception('取件时间不能超过两天');
  499. }
  500. // 'expectStartTime' 期望送达时间起始时间 -- 毫秒级时间戳。期望送达时间为时间点时,无需传本参数;期望送达时间为时间段时,期望送达时间为expectStartTime至expectEndTime
  501. // 'expectEndTime' 期望送达时间终止时间 -- 毫秒级时间戳。期望送达时间为时间点时,只需传本参数;期望送达时间为时间段时,期望送达时间为expectStartTime至expectEndTime
  502. $data['receiverList'][0]['expectStartTime'] = ($timestamp + 900) * 1000;
  503. $data['receiverList'][0]['expectEndTime'] = ($timestamp + 1800) * 1000;
  504. }
  505. return $data;
  506. }
  507. /**
  508. * 准备顺丰订单数据
  509. */
  510. private function prepareShunfengData($order, $shop, $customSettings)
  511. {
  512. // 获取订单商品信息
  513. // $itemInfos = OrderItemClass::getAllByCondition(['orderSn' => $order['orderSn']], null, 'id, name, unitPrice, num, unitWeight');
  514. // 计算商品总重量(单位:克)
  515. // $totalWeight = 0;
  516. // foreach ($itemInfos as $item) {
  517. // $totalWeight += (int)($item['unitWeight'] * $item['num']) * 1000;
  518. // }
  519. // 如果没有商品重量,使用订单重量
  520. // if ($totalWeight == 0 && isset($order['weight'])) {
  521. // $totalWeight = (int)$order['weight'] * 1000;
  522. // }
  523. // 默认重量为1000克(1公斤)
  524. // if ($totalWeight == 0) {
  525. // $totalWeight = 1000;
  526. // }
  527. return [
  528. 'platform' => 'shunfeng',
  529. 'user_lng' => (string)$order['long'], // 用户地址经度
  530. 'user_lat' => (string)$order['lat'], // 用户地址纬度
  531. 'user_address' => $order['fullAddress'], // 用户详细地址
  532. 'weight' => $order['weight'] * 1000, // 物品重量(单位:克)
  533. 'product_type' => 14, // 物品类型(14:鲜花)
  534. 'push_time' => time(), // 推单时间(秒级时间戳)
  535. //shop 平台级开发者需要传入
  536. // 'shop' => [ // 发货店铺信息
  537. // 'shop_name' => $shop['merchantName'], // 店铺名称
  538. // 'shop_address' => $shop['fullAddress'], // 店铺地址
  539. // 'shop_lng' => (string)$shop['long'], // 店铺经度
  540. // 'shop_lat' => (string)$shop['lat'], // 店铺纬度
  541. // 'shop_phone' => $shop['mobile'], // 店铺联系电话
  542. // ],
  543. //-------------------------- 非必填 -------------------------------
  544. 'city_name' => $order['city'], // 发单城市
  545. //'order_source' => '6', // 订单接入来源(6:京东秒送,可自定义)
  546. 'source_origin_order_id' => $order['orderSn'], // 商流订单号
  547. 'total_price' => (int)($order['actPrice'] * 100), // 用户订单总金额(单位:分)
  548. 'is_appoint' => 0, // 是否预约单(0:非预约单)
  549. //'appoint_type' => 0, // 预约单的时候传入,1:预约送达单;2:预约上门单
  550. //'expect_pickup_time' => 0, // TODO 用户期望上门时间 -- appoint_type=2时需必传,秒级时间戳
  551. //'expect_time' => 0, // TODO 用户期望送达时间
  552. //'shop_expect_time' => 0, // TODO 商家期望送达时间 -- 格式为:{timestamp},
  553. 'lbs_type' => 2, // 坐标类型(2:高德坐标)
  554. 'is_insured' => 0, // 是否保价(0:非保价)
  555. 'is_person_direct' => $customSettings['isPersonDirect'] ?? 0, // 是否专人直送(0:否 1:是)
  556. 'vehicle' => 0, // 配送交通工具,0:否;1:电动车;2:小轿车
  557. //'four_wheeler_type' => 0, // 车型 -- 只有vehicle = 2,⻋型字段才有效。
  558. //'declared_value' => 0, // 保价金额(单位:分)
  559. //'gratuity_fee' => 0, // 订单小费(单位:分)
  560. 'rider_pick_method' => 1, // 物流流向(1:从门店取件送至用户)
  561. 'return_flag' => 511, // 返回字段控制标志位(511:全部返回)
  562. 'multi_pickup_info' => [], // 多点取货信息(暂不使用)
  563. ];
  564. }
  565. /**
  566. * 准备达达订单数据
  567. */
  568. private function prepareDadaData($order, $shopNo, $customSettings)
  569. {
  570. $productList = [];
  571. $itemInfos = OrderItemClass::getAllByCondition(['orderSn' => $order['orderSn']], null, 'id, name, unitPrice, num, bigNum, smallNum, xhUnitName');
  572. foreach ($itemInfos as $item) {
  573. $productList[] = [
  574. 'sku_name' => $item['name'],
  575. 'src_product_no' => (string)$item['id'],
  576. 'count' => (float)$item['num'],
  577. 'unit' => $item['xhUnitName'],
  578. ];
  579. }
  580. // 回调地址
  581. $callbackUrl = Yii::$app->params['ghsHost'] . '/delivery/dada-callback';
  582. $request = [
  583. 'platform' => 'dada',
  584. 'shop_no' => $shopNo,
  585. 'origin_id' => $order['orderSn'],
  586. 'cargo_price' => (float)$order['actPrice'],
  587. 'is_prepay' => 0, // 是否需要垫付 1:是 0:否 (垫付订单金额,非运费)
  588. 'receiver_name' => $order['customName'],
  589. 'receiver_address' => $order['fullAddress'],
  590. 'receiver_lat' => (float)$order['lat'],
  591. 'receiver_lng' => (float)$order['long'],
  592. 'callback' => $callbackUrl,
  593. 'cargo_weight' => isset($order['weight']) ? (float)$order['weight'] : 1.0,
  594. 'receiver_phone' => Functions::getMobile($order),
  595. //'tips' => 0, //小费(单位:元,精确小数点后一位,小费金额不能高于订单金额。)
  596. 'info' => $order['remark'] ?? '',
  597. 'product_list' => $productList,
  598. ];
  599. if(isset($customSettings['is_direct_delivery']) && $customSettings['is_direct_delivery'] == 1){
  600. // $request['origin_id'] = $order['orderSn'] . '_1v1'; // 根据达达的情况,必然会造成订单号出错
  601. $request['is_direct_delivery'] = 1; //是否选择直拿直送(0:不需要;1:需要。选择直拿直送后,同一时间骑士只能配送此订单至完成,同时,也会相应的增加配送费用)
  602. }
  603. return $request;
  604. }
  605. /**
  606. * 准备滴滴订单数据
  607. */
  608. private function prepareDidiData($order, $shop)
  609. {
  610. return [
  611. 'platform' => 'didi',
  612. 'sender' => [
  613. 'fromSenderName' => $shop['merchantName'],
  614. 'fromMobile' => $shop['mobile'],
  615. 'fromAddress' => $shop['address'],
  616. 'fromAddressDetail' => $shop['floor'],
  617. 'fromLatitude' => (float)$shop['lat'],
  618. 'fromLongitude' => (float)$shop['long'],
  619. ],
  620. 'receiverList' => [
  621. [
  622. 'toReceiverName' => $order['customName'],
  623. 'toMobile' => Functions::getMobile($order),
  624. 'toAddress' => $order['address'],
  625. 'toAddressDetail' => $order['floor'],
  626. 'toLatitude' => (float)$order['lat'],
  627. 'toLongitude' => (float)$order['long'],
  628. 'weight' => isset($order['weight']) ? (float)$order['weight'] : 1.0,
  629. 'goodType' => 8,
  630. ]
  631. ]
  632. ];
  633. }
  634. /**
  635. * 并发获取各平台报价(核心实现)
  636. *
  637. * 使用 HttpClient::postConcurrent 实现真正的并发调用,每个平台请求 10 秒超时。
  638. * 某个平台的超时或失败不会影响其他平台的执行。
  639. *
  640. * @param array $preparedData 准备好的各平台数据
  641. * @param string $orderTime 配送时间
  642. * @return array 包含成功和失败结果
  643. */
  644. private function concurrentGetPrices($preparedData, $orderTime)
  645. {
  646. $results = [
  647. 'success' => [],
  648. 'failed' => [],
  649. ];
  650. // 第一步:收集所有平台的请求信息
  651. $allRequests = [];
  652. $platformMapping = []; // 用于将请求标识映射回平台名称
  653. foreach ($preparedData as $platform => $data) {
  654. try {
  655. $adapterKey = $platform; //由于要支持特殊逻辑处理,把 $this->adapters[xxx] 的 xxx 单独取变量
  656. if (!isset($this->adapters[$platform])) {
  657. if (substr($platform, -4) === '_1v1') { //特殊处理 -- 专人直送的订单,使用对应平台适配器
  658. $adapterKey = substr($platform, 0, -4);
  659. } else {
  660. $results['failed'][$platform] = '平台适配器未初始化';
  661. Yii::warning("[DispatchService] {$platform} 平台适配器未初始化");
  662. continue;
  663. }
  664. }
  665. $adapter = $this->adapters[$adapterKey];
  666. // 根据平台类型调用相应的 buildPriceRequest(s) 方法
  667. if ($platform === 'huolala') {
  668. // 货拉拉返回多个请求(一个请求对应一个车型)
  669. $priceRequests = $adapter->buildPriceRequest($data, $orderTime);
  670. foreach ($priceRequests as $requestKey => $requestInfo) {
  671. $allRequests[$requestKey] = $requestInfo;
  672. $platformMapping[$requestKey] = ['platform' => 'huolala', 'data' => $data];
  673. }
  674. } else {
  675. // 其他平台各返回一个请求
  676. $requestInfo = $adapter->buildPriceRequest($data, $orderTime);
  677. $requestKey = "{$platform}_quote";
  678. $allRequests[$requestKey] = $requestInfo;
  679. $platformMapping[$requestKey] = ['platform' => $platform, 'data' => $data];
  680. }
  681. } catch (\Throwable $e) {
  682. $results['failed'][$platform] = "构建请求失败: {$e->getMessage()}";
  683. Yii::error("[DispatchService] {$platform} 构建请求异常: {$e->getMessage()}");
  684. }
  685. }
  686. if (empty($allRequests)) {
  687. return $results;
  688. }
  689. // 第二步:使用 postConcurrent 并发发送所有请求
  690. $startTime = microtime(true);
  691. $concurrentResults = HttpClient::postConcurrent($allRequests, 3);
  692. $totalDuration = microtime(true) - $startTime;
  693. Yii::info("[DispatchService] 所有报价请求完成 (" . round($totalDuration * 1000) . "ms)");
  694. // 第三步:处理并发请求的结果
  695. foreach ($concurrentResults['success'] as $requestKey => $response) {
  696. if (!isset($platformMapping[$requestKey])) {
  697. continue;
  698. }
  699. $mapping = $platformMapping[$requestKey];
  700. $platform = $mapping['platform'];
  701. $data = $mapping['data'];
  702. try {
  703. $adapterKey = $platform; //由于要支持特殊逻辑处理,把 $this->adapters[xxx] 的 xxx 单独取变量
  704. if (substr($platform, -4) === '_1v1') { //特殊处理 -- 专人直送的订单,使用对应平台适配器
  705. $adapterKey = substr($platform, 0, -4);
  706. }
  707. $adapter = $this->adapters[$adapterKey];
  708. $quote = null;
  709. if ($platform === 'huolala') {
  710. // 货拉拉的响应处理
  711. $quote = $adapter->processPriceResponse($response);
  712. if ($quote && !isset($results['success']['huolala'])) {
  713. // 第一次处理货拉拉的结果,初始化
  714. $results['success']['huolala'] = [
  715. 'platform' => 'huolala',
  716. 'city_id' => $data['city_id'],
  717. 'vehicle_type_list' => $data['vehicle_type_list'],
  718. 'price_info_list' => [],
  719. ];
  720. }
  721. $keyArr = explode('_', $requestKey);
  722. $vehicle_type_list_key = $keyArr[2];
  723. // 将该车型的报价加入到列表中
  724. if ($quote && isset($results['success']['huolala'])) {
  725. $results['success']['huolala']['price_info_list'][] = [
  726. 'calculate_price_info' => isset($quote['calculate_price_info_list']) ? $quote['calculate_price_info_list'][0] : [],
  727. 'vehicle_type' => $data['vehicle_type_list'][$vehicle_type_list_key]
  728. ];
  729. Yii::info("[DispatchService] {$platform} 报价成功");// . json_encode($quote));
  730. } else {
  731. $errorMsg = $quote['error'] ?? '报价返回数据为空';
  732. $results['failed'][$platform] = $errorMsg;
  733. Yii::warning("[DispatchService] {$platform} 报价返回错误: {$errorMsg}");
  734. }
  735. } else {
  736. // 响应处理
  737. $quote = $adapter->processPriceResponse($response);
  738. if ($quote && !isset($quote['error'])) {
  739. $quote['_duration'] = $totalDuration;
  740. $results['success'][$platform] = $quote;
  741. Yii::info("[DispatchService] {$platform} 报价成功");// . json_encode($quote));
  742. } else {
  743. $errorMsg = $quote['error'] ?? '报价返回数据为空';
  744. $results['failed'][$platform] = $errorMsg;
  745. Yii::warning("[DispatchService] {$platform} 报价返回错误: {$errorMsg}");
  746. if(strncmp($platform, 'shunfeng', 8) === 0) {
  747. /** @var ShunfengAdapter $adapter */
  748. if($errorMsg == '暂未开启专人直送服务') {
  749. $adapter->getShopInfo();
  750. }
  751. if($errorMsg == '当前店铺只能发独享专送') {
  752. $adapter->getShopInfo();
  753. }
  754. }
  755. }
  756. }
  757. } catch (\Throwable $e) {
  758. $results['failed'][$platform] = "处理响应失败: {$e->getMessage()}";
  759. Yii::error("[DispatchService] {$platform} 处理响应异常: {$e->getMessage()}");
  760. }
  761. }
  762. // 第四步:处理失败的请求
  763. foreach ($concurrentResults['failed'] as $requestKey => $errorMsg) {
  764. if (!isset($platformMapping[$requestKey])) {
  765. continue;
  766. }
  767. $platform = $platformMapping[$requestKey]['platform'];
  768. // 对于货拉拉,只记录某个车型失败,不影响整体平台状态
  769. if ($platform === 'huolala') {
  770. Yii::warning("[DispatchService] huolala 车型报价失败 ({$requestKey}): {$errorMsg}");
  771. } else {
  772. if (!isset($results['failed'][$platform])) {
  773. $results['failed'][$platform] = $errorMsg;
  774. Yii::error("[DispatchService] {$platform} 报价请求失败: {$errorMsg}");
  775. }
  776. }
  777. }
  778. // 为货拉拉添加元数据
  779. if (isset($results['success']['huolala'])) {
  780. $results['success']['huolala']['_duration'] = $totalDuration;
  781. }
  782. return $results;
  783. }
  784. public function openCitiesLists($platform)
  785. {
  786. $ap = $this->adapters[$platform];
  787. return $ap->cityList();
  788. }
  789. /**
  790. * 刷新 token
  791. */
  792. public function refreshToken($platform, $refreshToken, $data=[])
  793. {
  794. switch($platform) {
  795. case 'shansong':
  796. $auth = new \common\components\delivery\platform\shansong\Auth();
  797. $auth->refreshAccessToken($refreshToken);
  798. break;
  799. case 'huolala':
  800. $auth = new \common\components\delivery\platform\huolala\Auth();
  801. $auth->refreshAccessToken($refreshToken);
  802. break;
  803. case 'fengniao':
  804. $auth = new \common\components\delivery\platform\fengniao\Auth();
  805. $auth->refreshAccessToken($refreshToken, $data['merchantId']);
  806. break;
  807. case 'shunfeng':
  808. $auth = new \common\components\delivery\platform\shunfeng\Auth();
  809. $auth->refreshAccessToken($refreshToken);
  810. break;
  811. }
  812. }
  813. /**
  814. * 格式化各平台报价为前端展示格式
  815. *
  816. * @param array $platformQuotes 各平台报价结果(来自 getAllPlatformPrice)
  817. * @return array 格式化后的配送列表
  818. */
  819. public function formatPlatformQuotesForDisplay($platformQuotes)
  820. {
  821. $deliveryList = [];
  822. if (empty($platformQuotes['quotes'])) {
  823. return $deliveryList;
  824. }
  825. foreach ($platformQuotes['quotes'] as $platformKey => $item) {
  826. if(!isset($item['platform'])){
  827. Yii::error(json_encode($item));
  828. continue;
  829. }
  830. switch ($item['platform']) {
  831. case 'shunfeng':
  832. $deliveryList[] = [
  833. 'name' => '顺丰' . ($platformKey == 'shunfeng_1v1' ? ' (专送)' : ''),
  834. 'en_name' => 'shunfeng',
  835. 'price' => $item['real_pay_money'],
  836. 'distance' => $item['distance'],
  837. 'type' => '' . ($platformKey == 'shunfeng_1v1' ? '专人直送' : ''),
  838. 'isAble' => true
  839. ];
  840. break;
  841. case 'shansong':
  842. $deliveryList[] = [
  843. 'name' => '闪送',
  844. 'en_name' => 'shansong',
  845. 'price' => $item['total_amount'],
  846. 'distance' => $item['total_distance'],
  847. 'type' => '',
  848. 'issOrderNo' => $item['order_number'],
  849. 'isAble' => true
  850. ];
  851. break;
  852. case 'fengniao':
  853. // 循环遍历 goods_infos 数组,提取有效项的信息
  854. $validGoods = [];
  855. if (!empty($item['goods_infos']) && is_array($item['goods_infos'])) {
  856. foreach ($item['goods_infos'] as $good) {
  857. if (!empty($good['is_valid']) && $good['is_valid'] == 1) {
  858. $validGoods[] = [
  859. 'actual_delivery_amount_cent' => $good['actual_delivery_amount_cent'] ?? 0,
  860. 'service_goods_id' => $good['service_goods_id'] ?? ''
  861. ];
  862. $deliveryList[] = [
  863. 'name' => '蜂鸟'. ' (' .$good['base_goods_id'] . ')',
  864. 'base_goods_id' => $good['base_goods_id'],
  865. 'en_name' => 'fengniao',
  866. 'price' => $good['actual_delivery_amount_cent'],
  867. 'distance' => $item['distance'],
  868. 'valid_goods' => $validGoods,
  869. 'type' => $good['slogan'],
  870. 'isAble' => true
  871. ];
  872. } else {
  873. $deliveryList[] = [
  874. 'name' => '蜂鸟'. ' (' .$good['base_goods_id'] . ')',
  875. 'base_goods_id' => $good['base_goods_id'],
  876. 'en_name' => 'fengniao',
  877. 'price' => 0,
  878. 'distance' => $item['distance'],
  879. 'valid_goods' => $good,
  880. 'type' => $good['disable_reason'],
  881. 'isAble' => false
  882. ];
  883. }
  884. }
  885. }
  886. break;
  887. case 'huolala':
  888. foreach($item['price_info_list'] as $key => $arr) {
  889. $priceInfo = $arr['calculate_price_info'];
  890. $priceConditions = $priceInfo['price_conditions'] ?? []; //价格明细
  891. $distanceInfo = $priceInfo['distance_info'] ?? []; //距离信息
  892. $vehicleType = $arr['vehicle_type'];
  893. if(empty($priceConditions)){
  894. Yii::error('货拉拉 报价数据 priceConditions 为空:' . json_encode($item) . ' key: ' . $key);
  895. continue;
  896. }
  897. if(empty($distanceInfo)){
  898. Yii::warning('货拉拉 报价数据 distanceInfo 为空:' . json_encode($item) . ' key: ' . $key);
  899. }
  900. $priceCalculateId = $priceInfo['price_calculate_id'] ?? 0;
  901. if(!isset($priceInfo['price_calculate_id'])){
  902. Yii::warning('货拉拉 报价数据 priceInfo 缺少 price_calculate_id:' . json_encode($priceInfo) . ' key: ' . $key);
  903. }
  904. //车型信息
  905. $vehicleAttr = $priceInfo['vehicle_info']['vehicle_attr'] ?? [];
  906. if(empty($vehicleAttr)){
  907. Yii::info('货拉拉 报价数据 vehicleAttr 为空:' . ' key: ' . $key); //json_encode($priceInfo) .
  908. }
  909. $deliveryList[] = [
  910. 'name' => '货拉拉' . ' (' . $vehicleType['_meta']['vehicle_type'] . ')',
  911. 'vehicle_type' => $vehicleType['_meta']['vehicle_type'],
  912. 'en_name' => 'huolala',
  913. 'price' => !empty($priceConditions) ? $priceConditions[0]['price_info']['total_price'] : 0,
  914. 'distance' => !empty($distanceInfo) ? $distanceInfo['distance_total'] : 0,
  915. 'type' => $vehicleType['_meta']['vehicle_type'],
  916. 'isAble' => true,
  917. // ---------------------------------------------
  918. 'order_vehicle_id' => $vehicleType['order_vehicle_id'],
  919. 'city_id' => $item['city_id'],
  920. 'city_info_revision' => $vehicleType['city_info_revision'],
  921. // 下单需要透传的数据
  922. 'vehicle_std' => $vehicleType['vehicle_std'],
  923. 'spec_req' => $vehicleType['spec_req'],
  924. 'price_calculate_id' => $priceCalculateId,
  925. 'price_item_encryption' => !empty($priceConditions) ? $priceConditions[0]['price_item_encryption'] : '',
  926. 'vehicle_attr' => $vehicleAttr,
  927. 'commodity_info' => !empty($priceConditions) ? $priceConditions[0]['commodity_item'] : [],
  928. ];
  929. }
  930. break;
  931. case 'dada':
  932. $list = [
  933. 'name' => '达达'. ($platformKey == 'dada_1v1' ? ' (专送)' : ''),
  934. 'en_name' => 'dada',
  935. 'price' => $item['fee'],
  936. 'distance' => $item['distance'],
  937. 'type' => '',
  938. 'isAble' => true,
  939. // ---------------------------------------------
  940. 'deliverFee' => $item['deliverFee'],
  941. 'deliveryNo' => $item['deliveryNo'],
  942. ];
  943. if(isset($item['couponName']) && isset($item['couponFee'])){
  944. $list['couponName'] = $item['couponName'];
  945. $list['couponFee'] = $item['couponFee'];
  946. }
  947. $deliveryList[] = $list;
  948. break;
  949. case 'didi':
  950. if(!isset($item['estimateList'])){
  951. Yii::error('didi 报价数据为空:' . json_encode($item));
  952. continue;
  953. }
  954. $serviceType = [0 => '拼送', 1 => '直送'];
  955. foreach($item['estimateList'] as $arr) {
  956. $serType = $arr['serviceType'] ?? null;
  957. $type = empty($serType) ? '' : $serviceType[$serType];
  958. $deliveryList[] = [
  959. 'name' => '滴滴' . ' (' . $this->adapters['didi']->carType($arr['carType']) . $type . ')',
  960. 'en_name' => 'didi',
  961. 'price' => $arr['fee'],
  962. 'distance' => $arr['distance'],
  963. 'type' => $type, //服务商或车型名称
  964. 'isAble' => true,
  965. // ---------------------------------------------
  966. 'estimateId' => $arr['estimateId'],
  967. 'bizType' => $arr['bizType'],
  968. 'discountFee' => $arr['discountFee'],
  969. 'icon' => $arr['icon']
  970. ];
  971. }
  972. break;
  973. }
  974. }
  975. return $deliveryList;
  976. }
  977. }