shish hace 11 meses
padre
commit
8efca56287
Se han modificado 1 ficheros con 76 adiciones y 10 borrados
  1. 76 10
      app-ghs/controllers/IntraCityController.php

+ 76 - 10
app-ghs/controllers/IntraCityController.php

@@ -11,6 +11,7 @@ use bizGhs\order\classes\OrderItemClass;
 use common\components\dict;
 use common\components\imgUtil;
 use hd\models\IntraCity\StoreFeeForm;
+
 // 以上类来自零售端
 
 use bizGhs\order\classes\OrderClass;
@@ -117,7 +118,7 @@ class IntraCityController extends BaseController
                 util::success($store, "门店查询成功");
             } else {
                 Yii::error("门店查询失败:" . $result['errmsg']);
-                util::error(-1,'门店查询失败');
+                util::error(-1, '门店查询失败');
             }
         } else {
             $field = 'province, city, dist, lat, long, floor, address';
@@ -209,7 +210,7 @@ class IntraCityController extends BaseController
     {
         $shopExt = MainClass::getById($this->mainId, false, 'id, wxStoreId');
         if ($shopExt['wxStoreId'] == '') {
-            util::error(-1,'微信门店编号为空');
+            util::error(-1, '微信门店编号为空');
         }
         $wxStoreId = $shopExt['wxStoreId'];
         $result = IntraCityExpress::getBalance($wxStoreId);
@@ -261,7 +262,7 @@ class IntraCityController extends BaseController
             util::fail("微信门店不存在");
         }
 
-        $itemInfoList = OrderItemClass::getAllByCondition(['orderSn'=>$sn], null,'id, name, cover, num');
+        $itemInfoList = OrderItemClass::getAllByCondition(['orderSn' => $sn], null, 'id, name, cover, num');
         $orderType = 2; // 默认是 2。说明:1花束订单 2花材订单 3花束和花材都有
         if (empty($itemInfoList)) {
             $orderType = 1;
@@ -309,6 +310,71 @@ class IntraCityController extends BaseController
         }
     }
 
+    //根据订单查询运费 ssh
+    public function actionGetOrderFee()
+    {
+        $post = Yii::$app->request->post();
+        $orderId = $post['id'];
+        $order = OrderClass::getById($orderId, true);
+        if (empty($order)) {
+            util::fail('没有找到订单');
+        }
+        if ($order->mainId != $this->mainId) {
+            util::fail('不是你的订单');
+        }
+        $main = $this->main;
+        $wxStoreId = $main->wxStoreId ?? '';
+        if (empty($wxStoreId)) {
+            util::fail('你还没有开通跑腿');
+        }
+        $weight = $post['weight'] ?? 0;
+        if ($weight <= 0) {
+            util::fail('请填写重量');
+        }
+        $packageNum = $post['packageNum'] ?? 1;
+        $price = $order->actPrice ?? 0;
+        $cargo = [
+            'cargo_name' => '鲜花花材', // 商品名称 -- $order 中没有,要在 goodsInfo 中取
+            'cargo_weight' => intval($weight * 1000), // 单位:克 -- 把千克转换为克
+            'cargo_price' => intval($price * 100), // 单位:分 -- 把元转换为分
+            'cargo_type' => IntraCityExpress::GOODS_TYPE_FLOWER,
+            'cargo_num' => intval($packageNum)
+        ];
+        $originalLng = $order->long;
+        $originalLat = $order->lat;
+        if (empty($originalLng) || empty($originalLat)) {
+            util::fail('客户地址不完整');
+        }
+        $customName = $order->customName ?? '';
+        $customMobile = $order->customMobile ?? '';
+        if (empty($customMobile)) {
+            util::fail('客户手机缺失');
+        }
+        $address = $order->address ?? '';
+        if (empty($address)) {
+            util::fail('客户地址缺失');
+        }
+        $orderData = [
+            'wx_store_id' => $wxStoreId,
+            'user_name' => $customName,
+            'user_phone' => $customMobile,
+            'user_lng' => $originalLng,
+            'user_lat' => $originalLat,
+            'user_address' => $address,
+            'cargo' => $cargo,
+            //'use_sandbox' => 1 // 如果不需要沙箱,use_sandbox就不传就好了 -- 踩坑人的经验
+            //'use_sandbox' => getenv('YII_ENV') == 'production' ? 0 : 1 // 根据环境变量判断是否使用沙盒环境 -- 没用,不生效
+        ];
+        //多处有用到这个方法,需修改请同步修改,搜索关键词 intra_city_express_pre_add
+        $result = IntraCityExpress::preAddOrder($orderData);
+        if ($result['errcode'] === 0) {
+            util::success($result, "查询成功");
+        } else {
+            Yii::error("运费查询失败:" . json_encode($result));
+            util::fail('查询失败');
+        }
+    }
+
     /**
      * 创建订单
      * POST /intra-city/create-order
@@ -327,7 +393,7 @@ class IntraCityController extends BaseController
             }
 
             $sn = $order['orderSn'];
-            $itemInfoList = OrderItemClass::getAllByCondition(['orderSn'=>$sn], null,'id, name, cover, num');
+            $itemInfoList = OrderItemClass::getAllByCondition(['orderSn' => $sn], null, 'id, name, cover, num');
             $itemList = [];
             $itemCount = 0;
             foreach ($itemInfoList as $itemInfo) {
@@ -346,9 +412,9 @@ class IntraCityController extends BaseController
             }
 
             // 获取 openid(小程序OpenId)
-            $user = UserClass::getByCondition(['mobile'=>$order['customMobile']], false, false,'id, miniOpenId');
+            $user = UserClass::getByCondition(['mobile' => $order['customMobile']], false, false, 'id, miniOpenId');
             if (empty($user)) {
-                noticeUtil::push("通过手机号-".$order['customMobile'].",获取小程序OpenId失败");
+                noticeUtil::push("通过手机号-" . $order['customMobile'] . ",获取小程序OpenId失败");
                 Yii::error('获取用户openId出错');
                 util::fail('数据出错');
             }
@@ -429,13 +495,13 @@ class IntraCityController extends BaseController
                     Yii::error('同城配送创建订单保存数据失败:' . $e->getMessage());
                     util::fail('订单创建失败');
                 }
-            } else if (isset($result['errcode']) && $result['errcode'] ===  934002) {
+            } else if (isset($result['errcode']) && $result['errcode'] === 934002) {
                 Yii::error("重复创建订单:" . ($result['errmsg'] ?? '未知错误'), 'intraCity');
-                util::fail( '重复创建订单: ' . $result['errcode']);
+                util::fail('重复创建订单: ' . $result['errcode']);
             } else {
                 noticeUtil::push("批发 -- " . $this->mainId . ",订单创建失败:" . json_encode($result));
                 Yii::error("订单创建失败:" . ($result['errmsg'] ?? '未知错误'), 'intraCity');
-                util::fail( '订单创建失败: ' . $result['errcode']);
+                util::fail('订单创建失败: ' . $result['errcode']);
             }
         } catch (\Exception $e) {
             Yii::error("订单创建异常:" . $e->getMessage(), 'intraCity');
@@ -487,7 +553,7 @@ class IntraCityController extends BaseController
                 util::success($result, "查询成功");
             } else {
                 Yii::error("订单查询失败:" . ($result['errmsg'] ?? '未知错误'), 'intracity');
-                util::fail( '订单查询失败: ' . $result['errcode']);
+                util::fail('订单查询失败: ' . $result['errcode']);
             }
         } catch (\Exception $e) {
             Yii::error("订单查询异常:" . $e->getMessage(), 'intracity');