Browse Source

1. 生成采购单接口根据花材的免费配送设置来判断跑腿费是否免费
2. fix bug

shizhongqi 8 tháng trước cách đây
mục cha
commit
57a51e87d9

+ 35 - 34
app-hd/controllers/GhsController.php

@@ -236,26 +236,26 @@ class GhsController extends BaseController
     public function actionDetail()
     {
         $id = Yii::$app->request->get('id');
-        $info = GhsClass::getGhsInfo($id);
-        $giveLevel = $info['giveLevel'] ?? 0;
+        $ghsInfo = GhsClass::getGhsInfo($id);
+        $giveLevel = $ghsInfo['giveLevel'] ?? 0;
         $levelMap = CustomClass::$nickNameMap;
         $giveLevelName = $levelMap[$giveLevel] ?? '散客';
-        $info['giveLevelName'] = $giveLevelName;
-        GhsClass::valid($info, $this->shopId);
+        $ghsInfo['giveLevelName'] = $giveLevelName;
+        GhsClass::valid($ghsInfo, $this->shopId);
 
         //是否有充值送红包活动
-        $ghsShopId = $info['shopId'] ?? 0;
+        $ghsShopId = $ghsInfo['shopId'] ?? 0;
         $ghsShop = ShopClass::getById($ghsShopId, true);
-        $info['hasRechargeHb'] = $ghsShop->recharge ?? 0;
+        $ghsInfo['hasRechargeHb'] = $ghsShop->recharge ?? 0;
         $hb = RechargeHbClass::getByCondition(['shopId' => $ghsShopId, 'delStatus' => 0], true, 'totalHb DESC');
-        $info['hasRechargeHbAmount'] = $hb->totalHb ?? 0;
-        $info['xrFl'] = $ghsShop->xrFl ?? 0;
-        $info['xrFlAmount'] = $ghsShop->xrFlAmount ?? 0;
-        $info['tjFl'] = $ghsShop->tjFl ?? 0;
-        $info['tjFlAmount'] = $ghsShop->tjFlAmount ?? 0;
-        $info['packCost'] = $ghsShop->packCost ? floatval($ghsShop->packCost) : 0;
+        $ghsInfo['hasRechargeHbAmount'] = $hb->totalHb ?? 0;
+        $ghsInfo['xrFl'] = $ghsShop->xrFl ?? 0;
+        $ghsInfo['xrFlAmount'] = $ghsShop->xrFlAmount ?? 0;
+        $ghsInfo['tjFl'] = $ghsShop->tjFl ?? 0;
+        $ghsInfo['tjFlAmount'] = $ghsShop->tjFlAmount ?? 0;
+        $ghsInfo['packCost'] = $ghsShop->packCost ? floatval($ghsShop->packCost) : 0;
         $lackExpend = $ghsShop->lackExpend ? floatval($ghsShop->lackExpend) : 0;
-        $customId = $info['customId'] ?? 0;
+        $customId = $ghsInfo['customId'] ?? 0;
         $needAdd = \bizHd\shop\classes\ShopClass::needAddPackCost($ghsShop, $customId);
         //昆明批发,需要算打包费和运费
         $needAddPackFreight = 1;
@@ -264,63 +264,64 @@ class GhsController extends BaseController
             //昆明批发,不需要算打包费和运费
             $needAddPackFreight = 0;
         }
-        $info['needAddPackFreight'] = $needAddPackFreight;
-        $info['lackExpend'] = $lackExpend;
-        $info['showSold'] = $ghsShop->showSold ?? 0;
-        $info['lsShopId'] = $ghsShop->lsShopId ?? 0;
+        $ghsInfo['needAddPackFreight'] = $needAddPackFreight;
+        $ghsInfo['lackExpend'] = $lackExpend;
+        $ghsInfo['showSold'] = $ghsShop->showSold ?? 0;
+        $ghsInfo['lsShopId'] = $ghsShop->lsShopId ?? 0;
         //预订单的最低公斤数和每公斤服务费
-        $info['kiloFee'] = $ghsShop->kiloFee ?? 0;
-        $info['miniKilo'] = $ghsShop->miniKilo ?? 0;
+        $ghsInfo['kiloFee'] = $ghsShop->kiloFee ?? 0;
+        $ghsInfo['miniKilo'] = $ghsShop->miniKilo ?? 0;
 
-        $info['pfLevel'] = $ghsShop->pfLevel ?? 0;
-        $info['afterSale'] = $ghsShop->afterSale ?? 1;
+        $ghsInfo['pfLevel'] = $ghsShop->pfLevel ?? 0;
+        $ghsInfo['afterSale'] = $ghsShop->afterSale ?? 1;
         //联系电话
-        $info['telephone'] = $ghsShop->telephone ?? '';
+        $ghsInfo['telephone'] = $ghsShop->telephone ?? '';
 
         $shareLogo = imgUtil::groupImg('buy_logo.jpg');
         if (!empty($ghsShop->shareLogo)) {
             $shareLogo = imgUtil::groupImg($ghsShop->shareLogo);
         }
-        $info['shareLogo'] = $shareLogo;
-        $info['superWx'] = '';
+        $ghsInfo['shareLogo'] = $shareLogo;
+        $ghsInfo['superWx'] = '';
         if (!empty($ghsShop->superWx)) {
-            $info['superWx'] = imgUtil::groupImg($ghsShop->superWx) . "?x-oss-process=image/resize,w_150";
+            $ghsInfo['superWx'] = imgUtil::groupImg($ghsShop->superWx) . "?x-oss-process=image/resize,w_150";
         }
 
         $ghsMainId = $ghsShop->mainId ?? 0;
         $kmPackCost = PurchaseClass::getKmPackCost($ghsMainId);
-        $info['kmPackCost'] = $kmPackCost;
+        $ghsInfo['kmPackCost'] = $kmPackCost;
 
-        $info['transCost'] = dict::getDict('transCost', null, null, $ghsShop->mainId);
+        $ghsInfo['transCost'] = dict::getDict('transCost', null, null, $ghsShop->mainId);
 
         //杭州斗南鲜花批发 免运费活动
-        if (isset($info['shopId']) && $info['shopId'] == 4608) {
+        if (isset($ghsInfo['shopId']) && $ghsInfo['shopId'] == 4608) {
             $current = time();
             if ($current < strtotime('2023-4-8 00:00:00')) {
-                $info['hasAct'] = 1;
+                $ghsInfo['hasAct'] = 1;
             }
         }
 
         // 弃用 buyNotice, 使用 xhShopExt 表里的 purchaseGuide
         // $info['buyNotice'] = $ghsShop->buyNotice ?? 0;
         $shopExt = ShopExtClass::getByCondition(['shopId' => $ghsShopId], false, false, 'purchaseGuide,hcFreeKm,hcMap');
-        $info['buyNotice'] = $shopExt['purchaseGuide'] > 0 ? 1 : 0; //兼容原有设定:购买须知 0.没有 1.有
+        $ghsInfo['buyNotice'] = $shopExt['purchaseGuide'] > 0 ? 1 : 0; //兼容原有设定:购买须知 0.没有 1.有
 
         //判断是否开启同城配送功能
         $intraCityRet = ShopClass::hasIntraCity($ghsShop);
         $openIntraCity = $intraCityRet['openIntraCity'] ?? 0;
-        $info['openIntraCity'] = $openIntraCity;
+        $ghsInfo['openIntraCity'] = $openIntraCity;
+
         //花材的免费配送设置
         $hcFreeKm = $shopExt['hcFreeKm'] ?? 0;
-        $info['hcFreeKm'] = $hcFreeKm;
+        $ghsInfo['hcFreeKm'] = $hcFreeKm;
         $hcMapString = $shopExt['hcMap'] ?? '';
         $hcMap = [];
         if (!empty($hcMapString)) {
             $hcMap = json_decode($hcMapString, true);
         }
-        $info['hcMap'] = $hcMap;
+        $ghsInfo['hcMap'] = $hcMap;
 
-        util::success($info);
+        util::success($ghsInfo);
     }
 
     //根据门店获取供货商信息 ssh 2021.4.14

+ 39 - 13
app-hd/controllers/PurchaseController.php

@@ -302,6 +302,7 @@ class PurchaseController extends BaseController
 
             //收集客户要下单的花材数量
             $orderNum = [];
+            $productCount = 0;
             foreach ($productList as $key => $product) {
                 $bigNum = $product['bigNum'] ?? 0;
                 $smallNum = $product['smallNum'] ?? 0;
@@ -311,6 +312,7 @@ class PurchaseController extends BaseController
                 }
                 $productId = $product['productId'] ?? 0;
                 $orderNum[$productId] = ['num' => $bigNum];
+                $productCount += $bigNum;
             }
             $lackList = [];
             $changeList = [];
@@ -462,6 +464,13 @@ class PurchaseController extends BaseController
 
             $sendType = $post['sendType'] ?? 0;
             $transType = $post['transType'] ?? 0;
+            $shopExt = null;
+            if ($sendType == dict::getDict('sendType', 'thirdSend')) {
+                $shopExt = ShopExtClass::getByCondition(['shopId' => $ghsShopId], true, null, 'id,shopId,thirdSend,hcMap,hcFreeKm');
+                if ($shopExt->thirdSend == 1) {
+                    util::fail('本店暂不能使用跑腿哦');
+                }
+            }
 
             if (isset($ghsShopInfo->pfLevel) && $ghsShopInfo->pfLevel == 1) {
                 //昆明发货包装费和运费的计算
@@ -597,8 +606,8 @@ class PurchaseController extends BaseController
                         'city' => $custom->city,
                         'weight' => $weight,
                         'remark' => $post['remark'] ?? '',
-                        'prePrice' => 100 * ($post['itemTotalAmount'] ?? 0), // 花材总价
-                        'actPrice' => 100 * ($post['itemTotalAmount'] ?? 0),
+                        'prePrice' => $post['itemTotalAmount'] ?? 0, // 花材总价
+                        'actPrice' => $post['itemTotalAmount'] ?? 0,
                     ];
                     $ghsShop = ShopClass::getById($ghsShopId);
                     $orderTime = date('Y-m-d H:i:s');
@@ -611,13 +620,35 @@ class PurchaseController extends BaseController
                         $deliveryList = [];
                         // 格式化各平台报价为前端展示格式
                         $deliveryList = $ds->formatPlatformQuotesForDisplay($platformQuotes);
-                        $result = $deliveryList[0];
-                        $sendCost = ($result['price'] ?? 0)/100;
-                        $sendDistance = $result['distance'] ?? 0;
+                        if(is_array($deliveryList) && !empty($deliveryList)){
+                            $result = $deliveryList[0];
+                            $sendCost = ($result['price'] ?? 0)/100;
+                            $sendDistance = $result['distance'] ?? 0;
+
+                            //获取花材的免费配送设置
+                            $hcFreeKm = $shopExt['hcFreeKm'] * 1000;
+                            $hcMapString = $shopExt['hcMap'] ?? '';
+                            if (!empty($hcMapString)) {
+                                $hcMap = json_decode($hcMapString, true);
+                            }
 
-                        //Yii::error('获取跑腿估价失败-' .  json_encode($platformQuotes));
-                        //util::fail('获取跑腿估价失败');
+                            // 判断是否免跑腿费
+                            if($sendDistance > $hcFreeKm){
+                                if(count($hcMap)>0){
+                                    foreach($hcMap as $rule){
+                                        if($productCount >= $rule['num'] && $post['itemTotalAmount'] >= $rule['price'] && $sendDistance <= $rule['distance']*1000){
+                                            $sendCost = 0;
+                                            noticeUtil::push("orderSn=" . $orderSn . " 免跑腿费,满足条件:".json_encode($rule));
+                                            break;
+                                        }
+                                    }
+                                }
+                            }else{
+                                $sendCost = 0;
+                            }
+                        }else{
 
+                        }
                     }
                 }
                 $post['sendCost'] = $sendCost;
@@ -645,6 +676,7 @@ class PurchaseController extends BaseController
 
             $respond = PurchaseService::createPurchase($post, $ghsInfo);
 
+
             if ($sendType == 0) {
                 if (getenv('YII_ENV') == 'production') {
                     //杭州斗南鲜花批发部,满500,10公里内免费配送,满1000,20公里免费配送
@@ -707,12 +739,6 @@ class PurchaseController extends BaseController
                 }
 
             }
-            if ($sendType == 2) {
-                $ext = ShopExtClass::getByCondition(['shopId' => $ghsShopId], true, null, 'id,shopId,thirdSend');
-                if ($ext->thirdSend == 1) {
-                    util::fail('本店暂不能使用跑腿哦');
-                }
-            }
 
             if (getenv('YII_ENV') == 'production') {
                 //昆明花落谁家

+ 5 - 11
biz/shop/classes/ShopClass.php

@@ -25,28 +25,22 @@ class ShopClass extends BaseClass
     //商家是否有同城配送能力
     public static function hasIntraCity($shop)
     {
-        $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');
-        $shopId = $shop->id;
-        $ext = ShopExtClass::getByCondition(['shopId' => $shopId], true, null, 'id,shopId,thirdSendFee');
+        $ext = ShopExtClass::getByCondition(['shopId' => $shop->id], true, null, 'id,shopId,thirdSendFee');
         $openIntraCity = 0;
         //有地图功能
         if ($hasMap == 1) {
-            //有地址功能,并且叫跑腿功能开启
-            if ($ext->thirdSendFee == 1) {
+            //有地址功能
+            if ($ext->thirdSend == 0 && $ext->thirdSendFee == 1) {
                 if (!empty($lat) && !empty($long) && !empty($address)) {
-                    if (!empty($wxStoreId)) {
-                        $openIntraCity = 1;
-                    }
+                    $openIntraCity = 1;
                 }
             }
         }
-        return ['openIntraCity' => $openIntraCity, 'wxStoreId' => $wxStoreId];
+        return ['openIntraCity' => $openIntraCity];
     }
 
     //营业状态

+ 1 - 1
common/components/delivery/services/DispatchService.php

@@ -407,7 +407,7 @@ class DispatchService
             'user_lng' => (string)$order['long'],                    // 用户地址经度
             'user_lat' => (string)$order['lat'],                     // 用户地址纬度
             'user_address' => $order['fullAddress'],                 // 用户详细地址
-            'weight' => $order['weight'],                            // 物品重量(单位:克)
+            'weight' => $order['weight'] * 1000,                            // 物品重量(单位:克)
             'product_type' => 4,                                     // 物品类型(4:鲜花绿植)
             'push_time' => time(),                                   // 推单时间(秒级时间戳)
             'shop' => [                                              // 发货店铺信息

+ 5 - 1
common/components/delivery/services/adapter/ShunfengAdapter.php

@@ -357,8 +357,12 @@ class ShunfengAdapter extends Shunfeng implements Adapter
                 'real_pay_money' => $result['real_pay_money'], //实际支付金额,当return_flag中包含64时返回,单位分(实际支付金额=总支付费用-优惠券总金额)
                 // 还有其它返回值没加进来,TODO
             ];
+        } else {
+            return [
+                'platform' => 'shunfeng',
+                'error' => $resp['error_msg'],
+            ];
         }
-        return null;
     }
 
     /**