shish hai 1 ano
pai
achega
b40266e628
Modificáronse 2 ficheiros con 144 adicións e 132 borrados
  1. 91 7
      app-ghs/controllers/ExpressController.php
  2. 53 125
      biz-ghs/express/classes/ExpressClass.php

+ 91 - 7
app-ghs/controllers/ExpressController.php

@@ -13,10 +13,31 @@ class ExpressController extends BaseController
 {
 
     //新建运单 ssh
-    public function actionAddNewWayBill()
+    public function actionCreateWayBill()
     {
-        $get = Yii::$app->request->get();
-        $id = $get['id'] ?? 0;
+        $post = Yii::$app->request->post();
+        $id = $post['id'] ?? 0;
+        $weight = $post['weight'] ?? 0;
+        if (empty($weight) || $weight <= 0) {
+            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('请填写包裹数量');
+        }
+
         $order = OrderClass::getById($id, true);
         if (empty($order)) {
             util::fail('没有找到订单');
@@ -37,12 +58,75 @@ class ExpressController extends BaseController
             '50' => '5925274162',
         ];
         $mainId = $this->mainId;
-        $bizId = $bizIdMap[$mainId] ?? 0;
-        if (empty($bizId)) {
-            util::fail('没有找到月结账号');
+
+        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';
         }
+
+        $admin = $this->admin;
+        $openId = $admin->ghsMiniOpenId ?? '';
+        if (empty($openId)) {
+            util::fail('请用小程序发单');
+        }
+
+        $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('你的门店地址还没有设置');
+        }
+
+        $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,
+            '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,
         ];
         ExpressClass::addWayBill($params);
     }

+ 53 - 125
biz-ghs/express/classes/ExpressClass.php

@@ -22,158 +22,86 @@ class ExpressClass extends BaseClass
 
         $orderId = $params['orderId'];
         $openId = $params['openId'];
-        //暂时只支持顺丰
-        $deliveryId = 'SF';
+        $deliveryId = $params['deliveryId'];
         $bizId = $params['bizId'];
-        $customRemark = '鲜花';
-        $sender = $params['sender'];
-        $receiver = $params['receiver'];
-        $shop = $params['shop'];
-        $cargo = $params['cargo'];
-        $insured = $params['insured'];
-        $service = $params['service'];
-        $expectTime = $params['expectTime'];
-        $sender = $params['sender'];
-        $receiver = $params['receiver'];
-        $shop = $params['shop'];
-        $cargo = $params['cargo'];
-        $insured = $params['insured'];
-        $service = $params['service'];
-        $expectTime = $params['expectTime'];
-
-        $sender = [
-            'name' => $params['sender']['name'],
-            'tel' => $params['sender']['tel'],
-            'mobile' => $params['sender']['mobile'],
-            'company' => $params['sender']['company'],
-            'post_code' => $params['sender']['post_code'],
-        ];
-
-        $receiver = [
-            'name' => $params['receiver']['name'],
-            'tel' => $params['receiver']['tel'],
-            'mobile' => $params['receiver']['mobile'],
-            'company' => $params['receiver']['company'],
-            'post_code' => $params['receiver']['post_code'],
-        ];
-
-        $shop = [
-            'wxa_path' => $params['shop']['wxa_path'],
-            'img_url' => $params['shop']['img_url'],
-            'goods_name' => $params['shop']['goods_name'],
-            'goods_count' => $params['shop']['goods_count'],
-            'goods_price' => $params['shop']['goods_price'],
-        ];  
-
-        $cargo = [
-            'count' => $params['cargo']['count'],
-            'weight' => $params['cargo']['weight'],
-            'space_x' => $params['cargo']['space_x'],
-            'space_y' => $params['cargo']['space_y'],
-            'space_z' => $params['cargo']['space_z'],
-        ];  
-
-        $cargoDetailList = [
-            'name' => $params['cargo']['name'],
-            'count' => $params['cargo']['count'],
-        ];
-
-        $cargo = [
-            'count' => $params['cargo']['count'],
-            'weight' => $params['cargo']['weight'],
-            'space_x' => $params['cargo']['space_x'],
-            'space_y' => $params['cargo']['space_y'],
-            'space_z' => $params['cargo']['space_z'],
-            'detail_list' => $cargoDetailList,
-        ];
-
-        $service = [
-            'service_type' => $params['service']['service_type'],
-            'service_name' => $params['service']['service_name'],
-        ];
-
-        $insured = [
-            'use_insured' => $params['insured']['use_insured'],
-            'insured_value' => $params['insured']['insured_value'],
-        ];
-
+        $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, // 备注【选填】
-        
+            'order_id' => $orderId, // 商家订单ID,需唯一
+            'openid' => $openId, // 用户openid
+            'delivery_id' => $deliveryId, // 快递公司ID
+            'biz_id' => $bizId, // 快递公司客户编码或月结账号
+            'custom_remark' => $customRemark, // 备注
+            //0表示已事先约定取件时间;否则请传预期揽件时间戳,需大于当前时间
+            'expect_time' => 0,
             // 发件人信息
             'sender' => [
-                'name' => '', // 发件人姓名【必填】
-                'tel' => '', // 发件人电话【必填】
-                'mobile' => '', // 发件人手机号【必填】
-                'company' => '', // 发件人公司【选填】
-                'post_code' => '', // 发件人邮编【选填】
-                'country' => '', // 发件人国家【选填】
-                'province' => '', // 发件人省份【必填】
-                'city' => '', // 发件人城市【必填】
-                'area' => '', // 发件人区/县【必填】
-                'address' => '', // 发件人详细地址【必填】
+                'name' => $senderName, // 发件人姓名
+                'mobile' => $senderMobile, // 发件人手机号
+                'province' => $senderProvince, // 发件人省份
+                'city' => $senderCity, // 发件人城市
+                'address' => $senderAddress, // 发件人详细地址
             ],
-        
+
             // 收件人信息
             'receiver' => [
-                'name' => '', // 收件人姓名【必填】
-                'tel' => '', // 收件人电话【必填】
-                'mobile' => '', // 收件人手机号【必填】
-                'company' => '', // 收件人公司【选填】
-                'post_code' => '', // 收件人邮编【选填】
-                'country' => '', // 收件人国家【选填】
-                'province' => '', // 收件人省份【必填】
-                'city' => '', // 收件人城市【必填】
-                'area' => '', // 收件人区/县【必填】
-                'address' => '', // 收件人详细地址【必填】
+                'name' => $receiverName, // 收件人姓名
+                'mobile' => $receiverMobile, // 收件人手机号
+                'province' => $receiverProvince, // 收件人省份
+                'city' => $receiverCity, // 收件人城市
+                'address' => $receiverAddress, // 收件人详细地址
             ],
-        
             // 商品信息
             'shop' => [
-                'wxa_path' => '', // 小程序商品路径【选填】
-                'img_url' => '', // 商品缩略图【选填】
-                'goods_name' => '', // 商品名称【选填】
-                'goods_count' => 1, // 商品数量【选填】
-                'goods_price' => 0, // 商品单价,单位分【选填】
-                'goods_desc' => '', // 商品描述【选填】
+                'goods_name' => $goodsName, // 商品名称
+                'goods_count' => $goodsCount, // 商品数量
             ],
-        
             // 货物信息
             'cargo' => [
-                'count' => 1, // 货物数量【必填】
-                'weight' => 0, // 货物总重量,单位kg【必填】
-                'space_x' => 0, // 货物长度,单位cm【必填】
-                'space_y' => 0, // 货物宽度,单位cm【必填】
-                'space_z' => 0, // 货物高度,单位cm【必填】
+                'count' => $packageNum, // 货物数量
+                'weight' => $weight, // 货物总重量,单位kg
+                'space_x' => $length, // 货物长度,单位cm
+                'space_y' => $width, // 货物宽度,单位cm
+                'space_z' => $height, // 货物高度,单位cm
                 'detail_list' => [
                     [
-                        'name' => '', // 货物名称【必填】
-                        'count' => 1, // 货物数量【必填】
+                        'name' => '鲜花花材', // 货物名称
+                        'count' => $packageNum, // 货物数量
                     ],
-                    // ...可添加多个
                 ],
             ],
-        
             // 保价信息
             'insured' => [
-                'use_insured' => 0, // 是否保价,0-否,1-是【必填】
-                'insured_value' => 0, // 保价金额,单位分【选填,use_insured=1时必填】
+                'use_insured' => 0, // 是否保价,0-否,1-是
             ],
-        
             // 服务类型
             'service' => [
-                'service_type' => 0, // 服务类型,0-标准快递【必填】
-                'service_name' => '', // 服务名称【选填】
+                'service_type' => $serviceType, // 服务类型,0-标准快递
+                'service_name' => $serviceName, // 服务名称
             ],
         ];
-
-        expressUtil::addOrder($merchant, $data, $ptStyle);
+        $ret = expressUtil::addOrder($merchant, $data, $ptStyle);
+        print_r($ret);
     }
 
 }