DeliveryController.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. namespace hd\controllers;
  3. use biz\ghs\classes\GhsClass;
  4. use bizGhs\custom\classes\CustomClass;
  5. use Yii;
  6. use biz\shop\classes\ShopClass;
  7. use common\components\delivery\services\DispatchService;
  8. use common\components\util;
  9. use ghs\controllers\BaseController;
  10. use yii\helpers\ArrayHelper;
  11. class DeliveryController extends BaseController
  12. {
  13. // 获取多个平台报价
  14. public function actionAllDeliveryQuotes()
  15. {
  16. $post = Yii::$app->request->post();
  17. $orderTime = date('Y-m-d H:i:s');
  18. // --------- $ghsShopId ----------
  19. $ghsId = $post['ghsId'] ?? 0;
  20. $ghs = GhsClass::getById($ghsId, true);
  21. if (empty($ghs)) {
  22. util::fail('获取批发商失败');
  23. }
  24. $ghsShopId = $ghs->shopId;
  25. // --------- $customId
  26. $customId = $ghs->customId ?? 0;
  27. $custom = CustomClass::getById($customId, true);
  28. if (empty($custom)) {
  29. util::fail('获取custom数据失败');
  30. }
  31. $weight = $post['weight'] ?? 1;
  32. // 生成随机订单号
  33. //$snData = ['shopId' => $ghsShopId, 'mainId' => $ghs->mainId, 'ghsId' => $ghsId, 'customId' => $customId];
  34. //$orderSn = orderSn::getGhsOrderSn($snData);
  35. $prefix = 'XSD_CS-';
  36. $orderSn = $prefix . round(microtime(true) * 1000);
  37. //构建出 Order 数据
  38. $order = [
  39. 'orderSn' => $orderSn,
  40. 'customName' => $custom['name'],
  41. 'customMobile' => $custom['mobile'],
  42. 'fullAddress' => $custom['fullAddress'],
  43. 'floor' => $custom['floor'],
  44. 'dist' => $custom['dist'],
  45. 'lat' => $custom['lat'],
  46. 'long' => $custom['long'],
  47. 'address' => $custom['address'], //'toAddress' => $order['address'],
  48. 'city' => $custom['city'],
  49. 'weight' => $weight,
  50. 'remark' => $post['remark'] ?? '',
  51. 'prePrice' => 10,
  52. 'actPrice' => 10,
  53. ];
  54. $ghsShop = ShopClass::getById($ghsShopId);
  55. $ds = new DispatchService($ghs->mainId);
  56. $platformQuotes = $ds->getAllPlatformPrice($order, $ghsShop, $orderTime);
  57. if(isset($platformQuotes['error'])){
  58. util::fail($platformQuotes['error']);
  59. }
  60. $deliveryList = [];
  61. foreach ($platformQuotes['quotes'] as $item) {
  62. switch ($item['platform']) {
  63. case 'shunfeng':
  64. $deliveryList[] = [
  65. 'name' => '顺丰',
  66. 'en_name' => 'shunfeng',
  67. 'price' => $item['real_pay_money'],
  68. 'distance' => $item['distance'],
  69. 'type' => '',
  70. 'isAble' => true
  71. ];
  72. break;
  73. case 'shansong':
  74. $deliveryList[] = [
  75. 'name' => '闪送',
  76. 'en_name' => 'shansong',
  77. 'price' => $item['total_amount'],
  78. 'distance' => $item['total_distance'],
  79. 'type' => '',
  80. 'issOrderNo' => $item['order_number'],
  81. 'isAble' => true
  82. ];
  83. break;
  84. case 'fengniao':
  85. // 循环遍历 goods_infos 数组,提取有效项的信息
  86. $validGoods = [];
  87. if (!empty($item['goods_infos']) && is_array($item['goods_infos'])) {
  88. foreach ($item['goods_infos'] as $good) {
  89. if (!empty($good['is_valid']) && $good['is_valid'] == 1) {
  90. $validGoods[] = [
  91. 'actual_delivery_amount_cent' => $good['actual_delivery_amount_cent'] ?? 0,
  92. 'service_goods_id' => $good['service_goods_id'] ?? ''
  93. ];
  94. $deliveryList[] = [
  95. 'name' => '蜂鸟'. ' (' .$good['base_goods_id'] . ')',
  96. 'en_name' => 'fengniao',
  97. 'price' => $good['actual_delivery_amount_cent'],
  98. 'distance' => $item['distance'],
  99. 'valid_goods' => $validGoods,
  100. 'type' => $good['slogan'],
  101. 'isAble' => true
  102. ];
  103. } else {
  104. $deliveryList[] = [
  105. 'name' => '蜂鸟'. ' (' .$good['base_goods_id'] . ')',
  106. 'en_name' => 'fengniao',
  107. 'price' => 0,
  108. 'distance' => $item['distance'],
  109. 'valid_goods' => $good,
  110. 'type' => $good['disable_reason'],
  111. 'isAble' => false
  112. ];
  113. }
  114. }
  115. }
  116. break;
  117. case 'huolala':
  118. foreach($item['price_info_list'] as $arr) {
  119. $priceInfo = $arr['calculate_price_info'];
  120. $vehicleType = $arr['vehicle_type'];
  121. $deliveryList[] = [
  122. 'name' => '货拉拉' . ' (' . $vehicleType['_meta']['vehicle_type'] . ')',
  123. 'en_name' => 'huolala',
  124. 'price' => $priceInfo['price_conditions'][0]['price_info']['total_price'],
  125. 'distance' => $priceInfo['distance_info']['distance_total'],
  126. 'type' => $vehicleType['_meta']['vehicle_type'],
  127. 'isAble' => true,
  128. // ---------------------------------------------
  129. 'order_vehicle_id' => $vehicleType['order_vehicle_id'],
  130. 'city_id' => $item['city_id'],
  131. 'city_info_revision' => $vehicleType['city_info_revision'],
  132. // // 下单需要透传的数据
  133. 'vehicle_std' => $vehicleType['vehicle_std'],
  134. 'spec_req' => $vehicleType['spec_req'],
  135. 'price_calculate_id' => $priceInfo['price_calculate_id'],
  136. 'price_item_encryption' => $priceInfo['price_conditions'][0]['price_item_encryption'],
  137. 'vehicle_attr' => $priceInfo['vehicle_info']['vehicle_attr'],
  138. 'commodity_info' => $priceInfo['price_conditions'][0]['commodity_item'],
  139. ];
  140. }
  141. break;
  142. }
  143. }
  144. // 按 price 从低到高排序
  145. ArrayHelper::multisort($deliveryList, 'price', SORT_ASC);
  146. $ret['deliveryList'] = $deliveryList;
  147. util::success($ret, "success");
  148. }
  149. }