浏览代码

请完善收花地址

shish 10 月之前
父节点
当前提交
df8e781605

+ 2 - 12
app-hd/controllers/GhsController.php

@@ -294,18 +294,8 @@ class GhsController extends BaseController
         $info['buyNotice'] = $shopExt['purchaseGuide'] > 0 ? 1 : 0; //兼容原有设定:购买须知 0.没有 1.有
 
         //判断是否开启同城配送功能
-        $hasMap = dict::getDict('hasMap');
-        if (getenv('YII_ENV') == 'production') {
-            $openIntraCityMainList = [50];
-        } else {
-            $openIntraCityMainList = [644];
-        }
-        //没有开启同城配送
-        $openIntraCity = 0;
-        if ($hasMap == 1 && in_array($info['mainId'], $openIntraCityMainList)) {
-            //有地址功能,并且叫跑腿功能开启
-            $openIntraCity = 1;
-        }
+        $intraCityRet = ShopClass::hasIntraCity($ghsShop);
+        $openIntraCity = $intraCityRet['openIntraCity'] ?? 0;
         $info['openIntraCity'] = $openIntraCity;
 
         util::success($info);

+ 9 - 15
app-hd/controllers/PurchaseController.php

@@ -263,6 +263,10 @@ class PurchaseController extends BaseController
             $post['ghsAvatar'] = $ghsInfo['avatar'] ?? '';
             $post['ghsFullAddress'] = $ghsInfo['fullAddress'] ?? '';
             $customId = $ghsInfo['customId'] ?? 0;
+            $custom = CustomClass::getById($customId, true);
+            if (empty($custom)) {
+                util::fail('用户信息缺失');
+            }
             $post['customId'] = $customId;
             $shopAdmin = $this->shopAdmin ?? null;
             $name = $shopAdmin->name ?? '';
@@ -572,7 +576,7 @@ class PurchaseController extends BaseController
                         $currentWeight = bcmul($thisWeight, $bigNum, 2);
                         $weight = bcadd($currentWeight, $weight, 2);
                     }
-                    $result = PurchaseClass::getDistanceFee($this->shop, $ghsShopInfo, $weight);
+                    $result = PurchaseClass::getDistanceFee($this->shop, $ghsShopInfo, $weight, $custom);
                     $sendCost = $result['fee'] ?? 0;
                 }
                 $post['sendCost'] = $sendCost;
@@ -1272,15 +1276,7 @@ class PurchaseController extends BaseController
     public function actionFreight()
     {
         $get = Yii::$app->request->get();
-
         $shop = $this->shop;
-        $shopLat = $shop->lat ?? '';
-        $shopLong = $shop->long ?? '';
-
-        if (empty($shopLat) || empty($shopLong)) {
-            util::success(['distance' => 0, 'showDistance' => 0, 'fee' => 0]);
-        }
-
         $ghsId = $get['ghsId'] ?? 0;
         $ghs = GhsClass::getById($ghsId, true);
         if (empty($ghs)) {
@@ -1291,18 +1287,16 @@ class PurchaseController extends BaseController
         if (empty($ghsShop)) {
             util::success(['distance' => 0, 'showDistance' => 0, 'fee' => 0]);
         }
-
-        $ghsShopLat = isset($ghsShop->lat) ? $ghsShop->lat : '';
-        $ghsShopLong = isset($ghsShop->long) ? $ghsShop->long : '';
-        if (empty($ghsShopLat) || empty($ghsShopLong)) {
+        $customId = $ghs->customId ?? 0;
+        $custom = CustomClass::getById($customId, true);
+        if (empty($custom)) {
             util::success(['distance' => 0, 'showDistance' => 0, 'fee' => 0]);
         }
-
         $weight = $get['weight'] ?? 0;
         if (empty($weight)) {
             util::success(['distance' => 0, 'showDistance' => 0, 'fee' => 0]);
         }
-        $respond = PurchaseClass::getDistanceFee($this->shop, $ghsShop, $weight);
+        $respond = PurchaseClass::getDistanceFee($shop, $ghsShop, $weight, $custom);
         util::success($respond);
     }
 

+ 47 - 68
biz-hd/purchase/classes/PurchaseClass.php

@@ -29,6 +29,7 @@ use bizHd\stat\classes\StatIncomeClass;
 use bizHd\wx\classes\WxOpenClass;
 use common\components\dict;
 use common\components\imgUtil;
+use common\components\IntraCityExpress;
 use common\components\mapUtil;
 use common\components\noticeUtil;
 use common\components\orderSn;
@@ -416,87 +417,65 @@ class PurchaseClass extends BaseClass
     }
 
     //计算距离和运费【另外还有个地方要同步修改,关键词calc_freight_distance】 ssh 20221003
-    public static function getDistanceFee($shop, $ghsShop, $weight, $mustHasFee = false)
+    public static function getDistanceFee($shop, $ghsShop, $weight, $custom)
     {
-
-        //万丽花行 跑腿不算运费
-        if ($ghsShop->id == 12003) {
-            return ['distance' => 0, 'showDistance' => 0, 'fee' => 0];
+        $ability = ShopClass::hasIntraCity($ghsShop);
+        $openIntraCity = $ability['openIntraCity'] ?? 0;
+        if ($openIntraCity == 0) {
+            //没有开启同城配送能力,不计算运费和距离
+            util::success(['distance' => 0, 'showDistance' => 0, 'fee' => 0]);
         }
-
         $shopLat = $shop->lat ?? '';
         $shopLong = $shop->long ?? '';
-
         if (empty($shopLat) || empty($shopLong)) {
-            util::fail('请完善门店地址哦');
+            util::fail('请完善你的收花地址');
         }
-
-        $ghsShopLat = $ghsShop->lat ?? '';
-        $ghsShopLong = $ghsShop->long ?? '';
-        if (empty($ghsShopLat) || empty($ghsShopLong)) {
-            util::fail('商家地址有问题');
+        $address = $shop->address ?? '';
+        if (empty($address)) {
+            util::fail('请完善收花地址');
         }
-
-        //基础配送费8元,0-5公里,每公里+1元,5-100公里,6元起,每公里+2元
-        //5-10公斤,2元起,每公斤+2元,10-15公斤,+12元,超过15公斤,+20元
-        //00:00 - 06:00 +6元,22:00-24:00 +4元
-        //恶劣天气,下单高峰期会临时调整价格
-
-        //起步价
-        $baseFee = 10;
-        $distance = mapUtil::calculateDistance($shopLong, $shopLat, $ghsShopLong, $ghsShopLat);
-
-        //0-5公里,每公里+1元,5-100公里,6元起,每公里+2元
-        $formatDistance = ceil($distance / 1000);
-        $startKiloFee = 6;
-        if ($formatDistance < 5) {
-            $addDistanceFee = bcmul($formatDistance, 2);
-        } elseif ($formatDistance == 5) {
-            $addDistanceFee = $startKiloFee;
-        } else {
-            $overKilo = bcsub($formatDistance, 5);
-            $overFee = bcmul($overKilo, 3);
-            $addDistanceFee = bcadd($startKiloFee, $overFee);
+        if ($weight <= 0) {
+            util::fail('花材没有重量');
         }
 
-        //5-10公斤,2元起,每公斤+2元,10-15公斤,+12元,超过15公斤,+20元
-        $formatWeight = ceil($weight);
-        if ($formatWeight > 15) {
-            $addWeightFee = 20;
-        } elseif ($formatWeight >= 10 && $formatWeight <= 15) {
-            $addWeightFee = 12;
-        } elseif ($formatWeight >= 5 && $formatWeight < 10) {
-            $overWeight = bcsub($formatWeight, 4);
-            $addWeightFee = bcmul($overWeight, 2);
-        } else {
-            $addWeightFee = 0;
-        }
-
-        $addFee = bcadd($addDistanceFee, $addWeightFee, 2);
-        $totalFee = bcadd($baseFee, $addFee, 2);
+        $wxStoreId = $ability['wxStoreId'] ?? '';
+        $packageNum = 1;
+        $price = 300;
+        $cargo = [
+            'cargo_name' => '鲜花花材', // 商品名称 -- $order 中没有,要在 goodsInfo 中取
+            'cargo_weight' => intval($weight * 1000), // 单位:克 -- 把千克转换为克
+            'cargo_price' => intval($price * 100), // 单位:分 -- 把元转换为分
+            'cargo_type' => IntraCityExpress::GOODS_TYPE_FLOWER,
+            'cargo_num' => $packageNum
+        ];
 
-        //特殊时段费
-        $timeFee = 0;
-        $hour = date("G");
-        //22:00 - 24:00 +4元
-        if (in_array($hour, [22, 23])) {
-            $timeFee = 4;
-        }
-        //00:00 - 06:00 +6元
-        if (in_array($hour, [0, 1, 2, 3, 4, 5])) {
-            $timeFee = 6;
+        $customName = $custom->customName ?? '';
+        $customMobile = $custom->customMobile ?? '';
+        if (empty($customMobile)) {
+            util::fail('客户手机缺失');
         }
-        $totalFee = bcadd($totalFee, $timeFee, 2);
-
-        //恶劣天气和下单高峰费用
-        $weatherFee = 0;
-        $totalFee = bcadd($totalFee, $weatherFee, 2);
 
+        //根据环境变量判断是否使用沙盒环境
+        $useSandBox = getenv('YII_ENV') == 'production' ? 0 : 1;
+        $orderData = [
+            'wx_store_id' => $wxStoreId,
+            'user_name' => $customName,
+            'user_phone' => $customMobile,
+            'user_lng' => $shopLong,
+            'user_lat' => $shopLat,
+            'user_address' => $address,
+            'cargo' => $cargo,
+            'use_sandbox' => $useSandBox,
+        ];
+        //多处有用到这个方法,需修改请同步修改,搜索关键词 intra_city_express_pre_add
+        $result = IntraCityExpress::preAddOrder($orderData);
+        if ($result['errcode'] !== 0) {
+            util::fail('运费查询失败');
+        }
+        $distance = $result['distance'] ?? 0;
         $showDistance = sprintf("%.1f", ($distance / 1000));
-
-        //noticeUtil::push("距离:{$distance} {$showDistance} 重量:{$weight} 费用:{$totalFee}", '15280215347');
-
-
+        $fee = $result['est_fee'] ?? 0;
+        $totalFee = sprintf("%.1f", ($fee / 100));
         return ['distance' => $distance, 'showDistance' => $showDistance, 'fee' => $totalFee];
     }
 

+ 34 - 0
biz/shop/classes/ShopClass.php

@@ -22,6 +22,40 @@ class ShopClass extends BaseClass
 
     public static $baseFile = '\biz\shop\models\Shop';
 
+    //商家是否有同城配送能力
+    public static function hasIntraCity($shop)
+    {
+        //万丽花行 跑腿不算运费
+        if ($shop->id == 12003) {
+            return ['openIntraCity' => 0, 'wxStoreId' => ''];
+        }
+        $mainId = $shop->mainId ?? 0;
+        $main = MainClass::getById($mainId, true);
+        $wxStoreId = $main->wxStoreId ?? '';
+        $lat = $shop->lat ?? '';
+        $long = $shop->long ?? '';
+        $address = $shop->address ?? '';
+        $hasMap = dict::getDict('hasMap');
+        if (getenv('YII_ENV') == 'production') {
+            $openIntraCityMainList = [50];
+        } else {
+            $openIntraCityMainList = [644];
+        }
+        $openIntraCity = 0;
+        //有地图功能
+        if ($hasMap == 1) {
+            //有地址功能,并且叫跑腿功能开启
+            if (in_array($mainId, $openIntraCityMainList)) {
+                if (!empty($lat) && !empty($long) && !empty($address)) {
+                    if (!empty($wxStoreId)) {
+                        $openIntraCity = 1;
+                    }
+                }
+            }
+        }
+        return ['openIntraCity' => $openIntraCity, 'wxStoreId' => $wxStoreId];
+    }
+
     //营业状态
     public static function isOpen($shop)
     {