DeliveryController.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. class DeliveryController extends BaseController
  11. {
  12. // 获取多个平台报价
  13. public function actionAllDeliveryQuotes()
  14. {
  15. $post = Yii::$app->request->post();
  16. $orderTime = date('Y-m-d H:i:s');
  17. // --------- $ghsShopId ----------
  18. $ghsId = $post['ghsId'] ?? 0;
  19. $ghs = GhsClass::getById($ghsId, true);
  20. if (empty($ghs)) {
  21. util::fail('获取批发商失败');
  22. }
  23. $ghsShopId = $ghs->shopId ?? 0;
  24. //$ghsShopId = $post['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. //$orderId = intval($post['orderId']);
  33. //$order = OrderClass::getById($orderId);
  34. //构建出 Order 数据
  35. $order = [
  36. 'orderSn' => '',
  37. 'customName' => $custom['name'],
  38. 'customMobile' => $custom['mobile'],
  39. 'fullAddress' => $custom['fullAddress'],
  40. 'floor' => $custom['floor'],
  41. 'dist' => $custom['dist'],
  42. 'lat' => $custom['lat'],
  43. 'long' => $custom['long'],
  44. 'address' => $custom['address'], //'toAddress' => $order['address'],
  45. 'city' => $custom['city'],
  46. 'weight' => $weight,
  47. 'remark' => '',
  48. 'prePrice' => 10,
  49. 'actPrice' => 10,
  50. ];
  51. $arr2 = [
  52. //'goods_count' => count($goodsItemList), // 这个应该是通过 orderSn 查询出来的,如果 orderSn 是假的怎么办? -- 提供临时的
  53. ];
  54. $ghsShop = ShopClass::getById($ghsShopId);
  55. $ghsMainId = $ghs->mainId;
  56. $ds = new DispatchService($ghsMainId);
  57. $platformQuotes = $ds->getAllPlatformPrice($order, $ghsShop, $orderTime);
  58. $deliveryList = [];
  59. foreach ($platformQuotes['quotes'] as $item) {
  60. switch ($item['platform']) {
  61. case 'shunfeng':
  62. $deliveryList[] = [
  63. 'name' => '顺丰',
  64. 'en_name' => 'shunfeng',
  65. 'price' => $item['real_pay_money'],
  66. 'distance' => $item['distance'],
  67. 'type' => '',
  68. 'isAble' => true
  69. ];
  70. break;
  71. case 'shansong':
  72. $deliveryList[] = [
  73. 'name' => '闪送',
  74. 'en_name' => 'shansong',
  75. 'price' => $item['total_amount'],
  76. 'distance' => $item['total_distance'],
  77. 'type' => '',
  78. 'issOrderNo' => $item['order_number'],
  79. 'isAble' => true
  80. ];
  81. break;
  82. case 'fengniao':
  83. // 循环遍历 goods_infos 数组,提取有效项的信息
  84. $validGoods = [];
  85. if (!empty($item['goods_infos']) && is_array($item['goods_infos'])) {
  86. foreach ($item['goods_infos'] as $good) {
  87. if (!empty($good['is_valid']) && $good['is_valid'] == 1) {
  88. $validGoods[] = [
  89. 'actual_delivery_amount_cent' => $good['actual_delivery_amount_cent'] ?? 0,
  90. 'service_goods_id' => $good['service_goods_id'] ?? ''
  91. ];
  92. $deliveryList[] = [
  93. 'name' => '蜂鸟'. ' (' .$good['base_goods_id'] . ')',
  94. 'en_name' => 'fengniao',
  95. 'price' => $good['actual_delivery_amount_cent'],
  96. 'distance' => $item['distance'],
  97. 'valid_goods' => $validGoods,
  98. 'type' => $good['slogan'],
  99. 'isAble' => true
  100. ];
  101. } else {
  102. $deliveryList[] = [
  103. 'name' => '蜂鸟'. ' (' .$good['base_goods_id'] . ')',
  104. 'en_name' => 'fengniao',
  105. 'price' => 0,
  106. 'distance' => $item['distance'],
  107. 'valid_goods' => $good,
  108. 'type' => $good['disable_reason'],
  109. 'isAble' => false
  110. ];
  111. }
  112. }
  113. }
  114. break;
  115. case 'huolala':
  116. foreach($item['price_info_list'] as $arr) {
  117. $priceInfo = $arr['calculate_price_info'];
  118. $vehicleType = $arr['vehicle_type'];
  119. $deliveryList[] = [
  120. 'name' => '货拉拉' . ' (' . $vehicleType['_meta']['vehicle_type'] . ')',
  121. 'en_name' => 'huolala',
  122. 'price' => $priceInfo['price_conditions'][0]['price_info']['total_price'],
  123. 'distance' => $priceInfo['distance_info']['distance_total'],
  124. 'type' => $vehicleType['_meta']['vehicle_type'],
  125. 'isAble' => true,
  126. // ---------------------------------------------
  127. 'order_vehicle_id' => $vehicleType['order_vehicle_id'],
  128. 'city_id' => $item['city_id'],
  129. 'city_info_revision' => $vehicleType['city_info_revision'],
  130. // // 下单需要透传的数据
  131. 'vehicle_std' => $vehicleType['vehicle_std'],
  132. 'spec_req' => $vehicleType['spec_req'],
  133. 'price_calculate_id' => $priceInfo['price_calculate_id'],
  134. 'price_item_encryption' => $priceInfo['price_conditions'][0]['price_item_encryption'],
  135. 'vehicle_attr' => $priceInfo['vehicle_info']['vehicle_attr'],
  136. 'commodity_info' => $priceInfo['price_conditions'][0]['commodity_item'],
  137. ];
  138. }
  139. break;
  140. }
  141. }
  142. $ret['deliveryList'] = $deliveryList;
  143. util::success($ret, "success");
  144. }
  145. }