林琦海 пре 5 година
родитељ
комит
43cdc01394
1 измењених фајлова са 91 додато и 0 уклоњено
  1. 91 0
      app-hd/controllers/PurchaseController.php

+ 91 - 0
app-hd/controllers/PurchaseController.php

@@ -5,6 +5,10 @@ namespace hd\controllers;
 use biz\admin\classes\AdminClass;
 use biz\ghs\classes\GhsClass;
 use bizGhs\custom\classes\CustomClass;
+use bizGhs\custom\services\CustomService;
+use bizGhs\express\services\DadaExpressServices;
+use bizGhs\order\classes\OrderSnClass;
+use bizGhs\order\models\OrderSn;
 use bizHd\purchase\classes\PurchaseClass;
 use bizHd\purchase\services\PurchaseService;
 use bizGhs\product\classes\ProductClass;
@@ -246,6 +250,93 @@ class PurchaseController extends BaseController
     //运费计算  linqh 2021.4.12  暂时返回固定值
     public function actionFreight()
     {
+        $post = Yii::$app->request->post();
+        $ghsId = $post['ghsId'] ?? 0;
+        $ghsId = 31;
+        //供货商
+        $ghsInfo = GhsClass::getById($ghsId);
+        if (empty($ghsInfo)) {
+            util::fail('没有找到供货商');
+        }
+        //花材信息
+        $productJson = $post['product'] ?? '';
+        $productJson = '[{"productId":31993,"bigNum":1,"smallNum":0}]';
+        if (empty($productJson)) {
+            util::fail('请选择花材');
+        }
+        $productList = json_decode($productJson, true);
+        if (empty($productList)) {
+            util::fail('请选择花材');
+        }
+
+        $productList = PurchaseClass::mergeItemInfo($productList);
+        $weight = 0;
+        $price = 0;
+        $productData = ProductClass::getProductMapData($productList);
+        $bigNum = 0;
+        foreach ($productList as $key => $val) {
+            $productId = $val['productId'];
+            $w = ProductClass::getWeight($val['productId'], $val['bigNum'], $val['smallNum']);
+            $bigNum += $val['bigNum'];
+            $weight = bcadd($w, $weight, 2);
+            $ratio = $productData[$productId]['ratio'] ?? 0;
+            //大小数量合并多少扎
+            $itemNum = ProductClass::mergeItemNum($val['bigNum'], $val['smallNum'], $ratio);
+            //售卖价格
+            $itemPrice = $productData[$productId]['price'] ?? 0;
+            //合计价格
+            $price = bcadd($price,bcmul($itemNum, $itemPrice, 2),2);
+        }
+        $ghsShopId = $ghsInfo['shopId']??0;
+        $ghsSjId = $ghsInfo['sjId']??0;
+
+        $sendTime = $post['sendTime']??'';
+        if (!empty($sendTime)) {
+            //配送时间不为空
+            // 预约发单时间(预约时间unix时间戳(10位),精确到分;整分钟为间隔,并且需要至少提前5分钟预约
+            $sendTimeInt = strtotime($sendTime);
+            $now = time();
+            $diff = $sendTimeInt - $now;
+            //因服务器写入时间,改为至少提前6分钟
+            if ($diff <= 360) {
+                util::fail('配送时间至少提前6分钟');
+            }
+            $sendTime = date('Y-m-d H:i', strtotime($sendTime));
+        }else{
+            $sendTime = date('Y-m-d H:i',strtotime("+30 minute"));
+        }
+
+        //找供货商的客户信息,用里面的配送相关地址信息
+        $customId = $ghsInfo['customId'] ?? 0;
+        $customInfo = CustomClass::getById($customId);
+        if (empty($customInfo)) {
+            util::fail('没有找到客户');
+        }
+        //组装订单信息
+        $info = [];
+        //发送放的商家信息,即供货商的相关信息
+        $info['merchantId'] =$ghsSjId;
+        $info['shopId'] =$ghsShopId;
+        $info['actPrice'] = $price;//价格
+        $info['weight'] = $weight;
+        $info['orderSn'] = \common\components\orderSn::getGhsOrderSn();
+        $info['bigNum'] =$bigNum;
+
+        //配送地址,当前零售端的门店地址
+        $info['customName'] = $customInfo['name']??'';
+        $info['customMobile'] = $customInfo['mobile']??'';
+        $info['province'] = $customInfo['province']??'';
+        $info['city'] = $customInfo['city']??'';;
+        $info['address'] = $customInfo['address']??'';;
+        $info['floor'] = $customInfo['floor']??'';;
+        $info['fullAddress'] = $customInfo['fullAddress']??'';;
+        $info['lat'] = $customInfo['lat']??'';;
+        $info['long'] = $customInfo['long']??'';;
+        $info['sendTime'] = $sendTime;
+        
+        $res = DadaExpressServices::queryDeliverFee($info);
+        util::success(['sedCost' => $res['fee']]);
+
         util::success(['sedCost' => 10]);
     }