Kaynağa Gözat

Merge branch 'shish-cb' into dev

shish 1 yıl önce
ebeveyn
işleme
1725e1d378

+ 110 - 95
app-ghs/controllers/ExpressController.php

@@ -1,119 +1,134 @@
 <?php
-/**
- * User: admin
- * Date Time: 2021/2/21 19:55
- */
 
 namespace ghs\controllers;
 
-
-use biz\shop\classes\ShopExpressClass;
 use bizGhs\custom\classes\CustomClass;
-use bizGhs\custom\services\CustomService;
-use bizGhs\express\services\MiniExpressService;
-use bizGhs\merchant\services\ShopService;
-use bizGhs\product\services\ProductService;
+use bizGhs\express\classes\ExpressClass;
+use bizGhs\order\classes\OrderClass;
 use common\components\util;
 use Yii;
 
+//用于物流服务
 class ExpressController extends BaseController
 {
 
-
-    //获取即时配送快递列表
-    public function actionList()
-    {
-        $data = MiniExpressService::getAllImmeDelivery("id,deliveryId,deliveryName", ['status' => 1]);
-        util::success($data);
-    }
-
-    //配送费预估
-    public function actionPreAddOrder()
+    //新建运单 ssh
+    public function actionCreateWayBill()
     {
-        // util::success(['fee' => 16.5]);
-
         $post = Yii::$app->request->post();
-        $expressId = $post['expressId'] ?? 0;
-        $ghsItemInfo = $post['itemInfo'] ?? '';
-        if (empty($ghsItemInfo)) {
-            util::fail('请选择花材5');
+        $id = $post['id'] ?? 0;
+        $weight = $post['weight'] ?? 0;
+        if (empty($weight) || $weight <= 0) {
+            util::fail('请填写重量');
         }
-        $ghsItemInfo = json_decode($ghsItemInfo, true); // [{productId:0,itemPrice:1,bigNum:1,smallNum:0}]
-
-        //计算总价格,总重量
-        $cargoInfo = ProductService::groupCargo($ghsItemInfo);
-
-        $shop_order_id = time();
-        $expressData = MiniExpressService::getExpressInfo($expressId);
-        if(empty($expressData)){
-            util::fail("暂不支持");
+        $length = $post['length'] ? trim($post['length']) : 0;
+        if (!is_numeric($length) || $length <= 0) {
+            util::fail('请填写长度');
+        }
+        $width = $post['width'] ? trim($post['width']) : 0;
+        if (!is_numeric($width) || $width <= 0) {
+            util::fail('请填写宽度');
+        }
+        $height = $post['height'] ? trim($post['height']) : 0;
+        if (!is_numeric($height) || $height <= 0) {
+            util::fail('请填写高度');
+        }
+        $packageNum = $post['packageNum'] ? trim($post['packageNum']) : 0;
+        if (!is_numeric($packageNum) || $packageNum <= 0) {
+            util::fail('请填写包裹数量');
         }
 
-        $shop_no = ShopExpressClass::getShopNo($this->sjId,$this->shopId,strtolower( $expressData['deliveryId'])); //与快递签约时的门店ID
+        $order = OrderClass::getById($id, true);
+        if (empty($order)) {
+            util::fail('没有找到订单');
+        }
+        if ($order->mainId != $this->mainId) {
+            util::fail('不是你的订单');
+        }
+        $customId = $order->customId ?? 0;
+        $custom = CustomClass::getById($customId, true);
+        if (empty($custom)) {
+            util::fail('没有找到客户');
+        }
+        //要先去后台绑定,这里填写才有用,mainId对应月结账号
+        $bizIdMap = [
+            //长春花路鲜花,
+            '36707' => '4212960899',
+            //龙岩花掌柜
+            '50' => '5925274162',
+        ];
+        $mainId = $this->mainId;
+
+        if (getenv('YII_ENV') == 'production') {
+            $bizId = $bizIdMap[$mainId] ?? 0;
+            if (empty($bizId)) {
+                util::fail('没有找到月结账号');
+            }
+            //暂时只支持顺丰
+            $deliveryId = 'SF';
+            $serviceType = 0;
+            $serviceName = '标准快递';
+        } else {
+            $deliveryId = 'TEST';
+            $bizId = 'test_biz_id';
+            $serviceType = 1;
+            $serviceName = 'test_service_name';
+        }
 
-        $openid = isset($this->admin) && !empty($this->admin) ? $this->admin->miniOpenId : '';
+        $admin = $this->admin;
+        $openId = $admin->ghsMiniOpenId ?? '';
         if (empty($openId)) {
-            util::fail('没有找到openId');
+            util::fail('请用小程序发单');
         }
 
-        //客户id
-        $customId = $post['customId'] ?? 0;
-        //获取客户name
-        $customInfo = CustomService::getCustomInfo($customId);
-        CustomClass::valid($customInfo, $this->shopId);
-
-        //当前门店的地址信息
-        $shopInfo = ShopService::getById($this->shopId);
-        $sender = [
-            'name' => $shopInfo['shopName'],
-            'city' => $shopInfo['city'] ?? '',
-            'address' => $shopInfo['address'] ?? '',
-            'address_detail' => $shopInfo['floor'] ?? '',
-            'phone' => $shopInfo['telephone'] ?? '',
-            'lng' => (float)$shopInfo['long'] ?? '',
-            'lat' => (float)$shopInfo['lat'] ?? '',
-            'coordinate_type' => 0,
-        ];
+        $shop = $this->shop;
+        $shopName = $shop->shopName;
+        $sjName = $shop->merchantName;
+        $senderName = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
+        $senderMobile = !empty($shop->telephone) ? $shop->telephone : $shop->mobile;
+        $senderProvince = $shop->province;
+        $senderCity = $shop->city;
+        $senderAddress = $shop->address;
+        if (empty($senderAddress)) {
+            util::fail('你的门店地址还没有设置');
+        }
 
-        $receiver = [
-            'name' => $customInfo['name'],
-            'city' => $post['city'] ?? '',
-            'address' => $post['address'] ?? '',
-            'address_detail' => $post['floor'] ?? '',
-            //'phone'=>$customInfo['mobile']??'199121223333',
-            'phone' => '18030142050',
-            'lng' => (float)$post['long'] ?? '118.134343',
-            'lat' => (float)$post['lat'] ?? '24.491566',
-            'coordinate_type' => 0,
-        ];
-        $cargo = [
-            'goods_value' => $cargoInfo['totalPrice'], //总价格  元
-            'goods_weight' => $cargoInfo['totalWeight'], //总重量 kg
-            'cargo_first_class' => '鲜花',
-            'cargo_second_class' => '鲜花',
-        ];
-        $orderInfo = [
-            'is_direct_delivery' => 0,//闪送只能为1,只能直拿直送
-        ];
-        $shop = [
-            'wxa_path' => '/shop',
-            'img_url' => 'http://www.baidu.com/test.png',
-            'goods_name' => '鲜花',
-            'goods_count' => count($ghsItemInfo),
+        $receiverName = $custom->name;
+        $receiverMobile = $custom->mobile;
+        $receiverProvince = $custom->province;
+        $receiverCity = $custom->city;
+        $receiverAddress = $custom->address;
+        $goodsName = '鲜花花材';
+        $customRemark = '鲜花花材,编号:' . $order->sendNum;
+        $goodsCount = ceil($order->itemNum);;
+
+
+        $params = [
+            'bizId' => $bizId,// 快递公司客户编码或月结账号
+            'openId' => $openId,
+            'senderName' => $senderName,
+            'senderMobile' => $senderMobile,
+            'senderProvince' => $senderProvince,
+            'senderCity' => $senderCity,
+            'senderAddress' => $senderAddress,
+            'receiverName' => $receiverName,
+            'receiverMobile' => $receiverMobile,
+            'receiverProvince' => $receiverProvince,
+            'receiverCity' => $receiverCity,
+            'receiverAddress' => $receiverAddress,
+            'goodsCount' => $goodsCount,
+            'goodsName' => $goodsName,
+            'customRemark' => $customRemark,
+            'weight' => $weight,
+            'length' => $length,
+            'width' => $width,
+            'height' => $height,
+            'packageNum' => $packageNum,
+            'deliveryId' => $deliveryId,
+            'serviceType' => $serviceType,
+            'serviceName' => $serviceName,
         ];
-        $res = MiniExpressService::preAddOrder($expressId, $shop_no, $shop_order_id, $openid, $sender, $receiver, $cargo, $orderInfo, $shop);
-        util::success(['fee' => $res['fee']]);
+        ExpressClass::addWayBill($params);
     }
 
-    //根据订单号发货
-    public function actionAddOrder()
-    {
-        $post = Yii::$app->request->post();
-        $expressId = $post['expressId'] ?? 0;// 快递ID
-        $orderSn = $post['orderSn'] ?? '';
-
-
-    }
-
-
-}
+}

+ 107 - 0
biz-ghs/express/classes/ExpressClass.php

@@ -0,0 +1,107 @@
+<?php
+
+namespace bizGhs\express\classes;
+
+
+use bizHd\base\classes\BaseClass;
+use bizHd\wx\classes\WxOpenClass;
+use common\components\dict;
+use common\components\expressUtil;
+use Yii;
+
+class ExpressClass extends BaseClass
+{
+
+    public static $baseFile = '\bizGhs\express\models\DeliveryOrder';
+
+    //新增运单 ssh 20250703
+    public static function addWayBill($params)
+    {
+        $merchant = WxOpenClass::getGhsWxInfo();
+        $ptStyle = dict::getDict('ptStyle', 'ghs');
+
+        $orderId = $params['orderId'];
+        $openId = $params['openId'];
+        $deliveryId = $params['deliveryId'];
+        $bizId = $params['bizId'];
+        $customRemark = $params['customRemark'];
+        $senderName = $params['senderName'];
+        $senderMobile = $params['senderMobile'];
+        $senderProvince = $params['senderProvince'];
+        $senderCity = $params['senderCity'];
+        $senderAddress = $params['senderAddress'];
+        $receiverName = $params['receiverName'];
+        $receiverMobile = $params['receiverMobile'];
+        $receiverProvince = $params['receiverProvince'];
+        $receiverCity = $params['receiverCity'];
+        $receiverAddress = $params['receiverAddress'];
+        $goodsCount = $params['goodsCount'];
+        $goodsName = $params['goodsName'];
+        $weight = $params['weight'];
+        $height = $params['height'];
+        $length = $params['length'];
+        $width = $params['width'];
+        $packageNum = $params['packageNum'];
+        $serviceType = $params['serviceType'];
+        $serviceName = $params['serviceName'];
+
+        $data = [
+            // 订单信息
+            'order_id' => $orderId, // 商家订单ID,需唯一
+            'openid' => $openId, // 用户openid
+            'delivery_id' => $deliveryId, // 快递公司ID
+            'biz_id' => $bizId, // 快递公司客户编码或月结账号
+            'custom_remark' => $customRemark, // 备注
+            //0表示已事先约定取件时间;否则请传预期揽件时间戳,需大于当前时间
+            'expect_time' => 0,
+            // 发件人信息
+            'sender' => [
+                'name' => $senderName, // 发件人姓名
+                'mobile' => $senderMobile, // 发件人手机号
+                'province' => $senderProvince, // 发件人省份
+                'city' => $senderCity, // 发件人城市
+                'address' => $senderAddress, // 发件人详细地址
+            ],
+
+            // 收件人信息
+            'receiver' => [
+                'name' => $receiverName, // 收件人姓名
+                'mobile' => $receiverMobile, // 收件人手机号
+                'province' => $receiverProvince, // 收件人省份
+                'city' => $receiverCity, // 收件人城市
+                'address' => $receiverAddress, // 收件人详细地址
+            ],
+            // 商品信息
+            'shop' => [
+                'goods_name' => $goodsName, // 商品名称
+                'goods_count' => $goodsCount, // 商品数量
+            ],
+            // 货物信息
+            'cargo' => [
+                'count' => $packageNum, // 货物数量
+                'weight' => $weight, // 货物总重量,单位kg
+                'space_x' => $length, // 货物长度,单位cm
+                'space_y' => $width, // 货物宽度,单位cm
+                'space_z' => $height, // 货物高度,单位cm
+                'detail_list' => [
+                    [
+                        'name' => '鲜花花材', // 货物名称
+                        'count' => $packageNum, // 货物数量
+                    ],
+                ],
+            ],
+            // 保价信息
+            'insured' => [
+                'use_insured' => 0, // 是否保价,0-否,1-是
+            ],
+            // 服务类型
+            'service' => [
+                'service_type' => $serviceType, // 服务类型,0-标准快递
+                'service_name' => $serviceName, // 服务名称
+            ],
+        ];
+        $ret = expressUtil::addOrder($merchant, $data, $ptStyle);
+        print_r($ret);
+    }
+
+}

+ 2 - 5
biz-ghs/express/models/DeliveryOrder.php

@@ -1,12 +1,9 @@
 <?php
-/**
- * User: admin
- * Date Time: 2022/7/24 21:53
- */
 
 namespace bizGhs\express\models;
 
-use bizHd\base\models\Base;
+use bizGhs\base\models\Base;
+
 class DeliveryOrder extends Base
 {
     public static function tableName()

+ 13 - 0
biz-ghs/express/models/Express.php

@@ -0,0 +1,13 @@
+<?php
+namespace bizGhs\express\models;
+use bizGhs\base\models\Base;
+
+class Express extends Base
+{
+
+    public static function tableName()
+    {
+        return 'xhExpress';
+    }
+
+}