Browse Source

Merge branch 'zhongqi-IntraCityExpress'

shish 11 months ago
parent
commit
a4a7439822

+ 15 - 32
app-hd/controllers/BaseController.php

@@ -6,7 +6,7 @@ use biz\sj\classes\SjClass;
 use bizHd\admin\classes\AdminClass;
 use biz\shop\classes\ShopAdminClass;
 use biz\sj\classes\MerchantExtendClass;
-use bizHd\merchant\services\ShopService;
+use bizHd\merchant\classes\ShopClass;
 use bizHd\shop\classes\MainClass;
 use common\components\dict;
 use common\components\jwt;
@@ -16,11 +16,10 @@ use common\components\util;
 class BaseController extends PublicController
 {
 
-    public $admin, $adminId, $adminAvatar, $account, $customId = 0, $custom;
-    public $sjId = 0, $sj = [], $sjExtend = [], $signPackage, $shopId = 0, $mainId = 0, $main, $shop, $shopAdminId = 0, $shopAdminName, $shopAdmin;
+    public $admin, $adminId, $account, $customId = 0, $custom;
+    public $sjId = 0, $sj = [], $sjExtend = [], $shopId = 0, $mainId = 0, $main, $shop, $shopAdminId = 0, $shopAdminName, $shopAdmin;
     public $appId;
     public $isWx = false;
-    public $isLogin = false;
     //游客可以访问的方法
     public $guestAccess = [];
 
@@ -55,30 +54,33 @@ class BaseController extends PublicController
         if (empty($admin) && in_array($action->id, $this->guestAccess) == false) {
             util::notLogin();
         }
-        $adminId = $admin->id ?? 0;
+        $adminId = $admin ? intval($admin->id) : 0;
         $this->admin = $admin;
         $this->adminId = $adminId;
+
         //后台
-        $currentShopId = $admin->currentShopId ?? 0;
+        $currentShopId = $admin ? intval($admin->currentShopId) : 0;
         if (empty($currentShopId)) {
             if (in_array($action->id, $this->guestAccess) == false) {
                 util::fail('请注册登录');
             }
         } else {
-            $this->shopId = $currentShopId;
-            $shop = ShopService::getById($currentShopId, true);
+            $shop = ShopClass::getById($currentShopId, true);
             if (empty($shop)) {
                 util::fail('没有找到店铺');
             }
+            $this->shopId = $currentShopId;
             $this->shop = $shop;
-            $mainId = $shop->mainId ?? 0;
-            $this->mainId = $mainId;
+
+            $mainId = intval($shop->mainId);
             $main = MainClass::getById($mainId, true);
             if (empty($main)) {
                 util::fail('没有找到main信息');
             }
+            $this->mainId = $mainId;
             $this->main = $main;
-            $shopAdmin = ShopAdminClass::getByCondition(['mainId' => $mainId, 'adminId' => $adminId, 'delStatus' => 0], true);
+
+            $shopAdmin = ShopAdminClass::getByCondition(['mainId' => $mainId, 'adminId' => $adminId, 'delStatus' => 0], true); //xhStaff 表
             if (empty($shopAdmin)) {
                 util::logout('没有找到员工信息');
             }
@@ -91,34 +93,15 @@ class BaseController extends PublicController
             $this->shopAdmin = $shopAdmin;
             $this->shopAdminId = $shopAdmin->id ?? 0;
             $this->shopAdminName = $shopAdmin->name ?? '';
+
             $sjId = $shop->sjId;
-            $this->sjId = $sjId;
             $sj = SjClass::getById($sjId, true);
             $this->sj = $sj;
+            $this->sjId = $sjId;
             $sjExtend = MerchantExtendClass::getBySjId($sjId, true);
             $this->sjExtend = $sjExtend;
         }
 
         return parent::beforeAction($action);
     }
-
-    /**
-     * 把必要参数放 $_POST 或 $_GET 中
-     */
-    private function formParams()
-    {
-        // 将参数放入 $_POST 中(如果是 POST 请求)
-        if (Yii::$app->request->isPost) {
-            $_POST['adminId'] = intval($this->adminId);
-            $_POST['mainId'] = intval($this->mainId);
-            $_POST['shopId'] = intval($this->shopId);
-        }
-        
-        // 将参数放入 $_GET 中(如果是 GET 请求)
-        if (Yii::$app->request->isGet) {
-            $_GET['adminId'] = intval($this->adminId);
-            $_GET['mainId'] = intval($this->mainId);
-            $_GET['shopId'] = intval($this->shopId);
-        }
-    }
 }

+ 40 - 77
app-hd/controllers/IntraCityController.php

@@ -7,7 +7,7 @@ use bizHd\express\models\ExpressOrder;
 use bizHd\order\classes\OrderClass;
 use bizHd\order\classes\OrderGoodsClass;
 use bizHd\order\classes\OrderItemClass;
-use bizHd\shop\classes\ShopExtClass;
+use bizHd\shop\classes\MainClass;
 use bizHd\user\classes\UserClass;
 use common\components\noticeUtil;
 use common\components\util;
@@ -15,7 +15,6 @@ use hd\models\IntraCity\StoreFeeForm;
 use Yii;
 use biz\shop\classes\ShopClass;
 use yii\helpers\Json;
-use yii\web\Response;
 use common\components\IntraCityExpress;
 use yii\db\Query;
 
@@ -35,20 +34,19 @@ class IntraCityController extends BaseController
     public function actionCreateStore()
     {
         try {
-            $shopId = $this->shopId;
             $shop = $this->shop;
             $shopName = $shop->shopName ?? '';
             $sjName = $shop->merchantName ?? '';
             $name = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
 
             $storeData = [
-                'out_store_id' => $shop->id,
+                'out_store_id' => $this->mainId, //自定义门店编号 --  从 shopId 改为 dmainId
                 'store_name' => $name,
                 'address_info' => [
                     'province' => $shop->province,
                     'city' => $shop->city,
                     'area' => $shop->dist,
-                    'street' => $shop->address,
+                    'street' => '',
                     'house' => $shop->floor ? $shop->address . $shop->floor : $shop->address,
                     'lat' => $shop->lat,
                     'lng' => $shop->long,
@@ -65,7 +63,9 @@ class IntraCityController extends BaseController
             }
 
             // 创建门店前,检查是否已经 开通门店权限 (有wxStoreId,即说明开通了)
-            $shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], true, false, 'id, wxStoreId');
+            //$shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], true, false, 'id, wxStoreId');
+            $shopExt = MainClass::getById($this->mainId, true, false, 'id, wxStoreId');
+
             // 查询是否存在 wx_store_id,不存在则执行apply
             if ($shopExt->wxStoreId == '') {
                 $re = IntraCityExpress::applyStore();
@@ -102,9 +102,10 @@ class IntraCityController extends BaseController
     {
         $shopId = $this->shopId;
         // 首先从门店扩展表查询是否已经创建
-        $shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], true, false, 'id, wxStoreId');
+        //$shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], true, false, 'id, wxStoreId');
+        $shopExt = MainClass::getById($this->mainId, true, false, 'id, wxStoreId');
         if ($shopExt->wxStoreId == '') { // 不存在,则从微信接口查询
-            $result = IntraCityExpress::getStore($shopId);
+            $result = IntraCityExpress::getStore($this->mainId);
             if ($result['errcode'] === 0) {
                 $store = $result['store_list'][0];
                 // 保存 wx_store_id
@@ -129,9 +130,9 @@ class IntraCityController extends BaseController
      */
     public function actionUpdateStore()
     {
-        $shopId = $this->shopId;
         // 首先从门店扩展表查询是否已经创建
-        $shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], false, false, 'id, wxStoreId');
+        //$shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], false, false, 'id, wxStoreId');
+        $shopExt = MainClass::getById($this->mainId, false, false, 'id, wxStoreId');
         if ($shopExt['wxStoreId'] == '') {
             util::fail('未创建门店,请先创建');
         }
@@ -149,7 +150,7 @@ class IntraCityController extends BaseController
                     'province' => $shop->province,
                     'city' => $shop->city,
                     'area' => $shop->dist,
-                    'street' => $shop->address,
+                    'street' => '',
                     'house' => $shop->floor ? $shop->address . $shop->floor : $shop->address,
                     'lat' => $shop->lat,
                     'lng' => $shop->long,
@@ -187,12 +188,8 @@ class IntraCityController extends BaseController
             util::fail('快递动力ID出错');
         }
 
-        $shopId = intval($this->shopId);
-        if (empty($shopId)) {
-            util::fail("门店不存在");
-        }
-
-        $shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], false, false, 'id, wxStoreId');
+        //$shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], false, false, 'id, wxStoreId');
+        $shopExt = MainClass::getById($this->mainId, false, false, 'id, wxStoreId');
         if ($shopExt['wxStoreId'] == '') {
             util::fail('微信门店编号为空');
         }
@@ -212,7 +209,8 @@ class IntraCityController extends BaseController
     public function actionStoreBalance()
     {
         $shopId = $this->shopId;
-        $shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], false, false, 'id, wxStoreId');
+        //$shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], false, false, 'id, wxStoreId');
+        $shopExt = MainClass::getById($this->mainId, false, false, 'id, wxStoreId');
         if ($shopExt['wxStoreId'] == '') {
             util::fail('微信门店编号为空');
         }
@@ -261,7 +259,11 @@ class IntraCityController extends BaseController
         if (empty($shopId)) {
             util::fail("门店不存在");
         }
-        $shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], false, false, 'id, wxStoreId');
+        //$shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], false, false, 'id, wxStoreId');
+        $shopExt = MainClass::getById($this->mainId, false, false, 'id, wxStoreId');
+        if (empty($shopExt)) {
+            util::fail("微信门店不存在");
+        }
 
         $itemInfoList = OrderItemClass::getListBySn($sn);
         $orderType = 2; // 默认是 2。说明:1花束订单 2花材订单 3花束和花材都有
@@ -333,7 +335,7 @@ class IntraCityController extends BaseController
             $itemList = [];
             $orderType = 2; // 默认是 2。说明:1花束订单 2花材订单 3花束和花材都有
             if (empty($itemInfoList)) {
-                $orderType = 1;
+                $orderType = 1; // 花束订单
                 $goodsInfoList = OrderGoodsClass::getListBySn($sn);
                 $itemCount = 0;
                 foreach ($goodsInfoList as $itemInfo) {
@@ -358,11 +360,11 @@ class IntraCityController extends BaseController
                 $post['packageNum'] = $itemCount;
             }
 
-            $shopId = intval($this->shopId);
-            if (empty($shopId)) {
-                util::fail("门店不存在");
+            //$shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], false, false, 'id, wxStoreId');
+            $shopExt = MainClass::getById($this->mainId, false, false, 'id, wxStoreId');
+            if (empty($shopExt)) {
+                util::fail("微信门店不存在");
             }
-            $shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], false, false, 'id, wxStoreId');
 
             $cargoName = '花材'; // 商品名称,默认是花材
             $goodsInfoList = OrderGoodsClass::getListBySn($sn);
@@ -431,8 +433,8 @@ class IntraCityController extends BaseController
 
                 // 保存进 xhExpressOrder 表
                 $orderData = [
-                    'mainId' => intval($this->mainId),
-                    'shopId' => intval($this->shopId),
+                    'mainId' => $this->mainId,
+                    'shopId' => $this->shopId,
                     'deliveryId' => isset($result['service_trans_id']) ? $result['service_trans_id'] : '',
                     'wxOrderId' => isset($result['wx_order_id']) ? $result['wx_order_id'] : '',
                     'wxStoreId' => isset($result['wx_store_id']) ? $result['wx_store_id'] : '',
@@ -447,7 +449,7 @@ class IntraCityController extends BaseController
 
                 util::success('订单创建成功', ['fee' => $result['fee']]);
             } else {
-                noticeUtil::push("门店 -- " . $shopId . ",订单创建失败:" . json_encode($result));
+                noticeUtil::push("门店 -- " . $this->mainId . ",订单创建失败:" . json_encode($result));
                 Yii::error("订单创建失败:" . ($result['errmsg'] ?? '未知错误'), 'intracity');
                 util::fail($result['errmsg'] ?? '订单创建失败', $result['errcode'] ?? -1);
             }
@@ -464,8 +466,11 @@ class IntraCityController extends BaseController
     public function actionGetOrder()
     {
         try {
-            $shopId = $this->shopId;
-            $shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], false, false, 'id, wxStoreId');
+            //$shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], false, false, 'id, wxStoreId');
+            $shopExt = MainClass::getById($this->mainId, false, false, 'id, wxStoreId');
+            if (empty($shopExt)) {
+                util::fail("微信门店不存在");
+            }
 
             $post = Yii::$app->request->post();
             $wxOrderId = isset($post['wx_order_id']) ? $post['wx_order_id'] : '';
@@ -522,11 +527,12 @@ class IntraCityController extends BaseController
         try {
             $post = Yii::$app->request->post();
 
-            $shopId = intval($this->shopId);
-            if (empty($shopId)) {
-                util::fail("门店不存在");
+
+            //$shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], false, false, 'id, wxStoreId');
+            $shopExt = MainClass::getById($this->mainId, false, false, 'id, wxStoreId');
+            if (empty($shopExt)) {
+                util::fail("微信门店不存在");
             }
-            $shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], false, false, 'id, wxStoreId');
 
             $wxOrderId = isset($post['wx_order_id']) ? $post['wx_order_id'] : '';
             $orderId = $post['orderId'];    //配送订单创建成功后,也会返回的 store_order_id。 即 orderId
@@ -593,30 +599,7 @@ class IntraCityController extends BaseController
         }
     }
 
-    /**
-     * 获取门店列表
-     * GET /intra-city/store-list
-     */
-    public function actionStoreList()
-    {
-        Yii::$app->response->format = Response::FORMAT_JSON;
-
-        try {
-            $request = Yii::$app->request;
-            $offset = $request->get('offset', 0);
-            $limit = $request->get('limit', 20);
 
-            $list = [];
-
-            if ($list) {
-
-            } else {
-
-            }
-        } catch (\Exception $e) {
-
-        }
-    }
 
     /**
      * 获取订单列表
@@ -624,27 +607,7 @@ class IntraCityController extends BaseController
      */
     public function actionOrderList()
     {
-        Yii::$app->response->format = Response::FORMAT_JSON;
-
-        try {
-            $request = Yii::$app->request;
-            $offset = $request->get('offset', 0);
-            $limit = $request->get('limit', 20);
-
-            $result = ExpressOrderClass::getOrderList($offset, $limit);
-
-            if ($result['errcode'] === 0) {
-                return [
 
-                ];
-            } else {
-                return [
-
-                ];
-            }
-        } catch (\Exception $e) {
-
-        }
     }
 
     /**
@@ -686,7 +649,7 @@ class IntraCityController extends BaseController
                 ]);
                 exit();
             }
-            // 提取 orderId
+            // 从 $storeOrderId 提取 orderId
             $arr = explode('_', $storeOrderId);
             $orderId = intval($arr[0]);
 

+ 42 - 0
app-hd/controllers/ShopController.php

@@ -11,9 +11,11 @@ use bizHd\custom\classes\CustomClass as HdCustomClass;
 use bizHd\merchant\services\ShopService;
 use bizHd\purchase\classes\PurchaseClass;
 use bizHd\saas\services\RegionService;
+use bizHd\shop\classes\MainClass;
 use common\components\dict;
 use common\components\dirUtil;
 use common\components\imgUtil;
+use common\components\IntraCityExpress;
 use common\components\stringUtil;
 use common\components\util;
 use common\components\wxUtil;
@@ -111,6 +113,46 @@ class ShopController extends BaseController
         ShopService::valid($shop, $this->sjId);
         $data['img'] = isset($data['img']) && is_array($data['img']) ? json_encode($data['img']) : '';
         ShopClass::updateShop($shop, $data);
+
+        //同步更新同城配送微信门店
+        // 校验有无经纬度数据,没有不更新(说明地图定位功能不可用了)
+        if($data['lat'] != '' && $data['long'] != '') {
+            $shopExt = MainClass::getById($this->mainId, false, false, 'id, wxStoreId');
+            if ($shopExt['wxStoreId'] == '') {
+                Yii::error(__CLASS__ . __METHOD__ .' - 未创建门店,请先创建');
+                util::complete();
+            }
+
+            $shopName = isset($data['shopName']) ? $data['shopName'] : '';
+            $sjName = $shop['merchantName'] ?? '';
+            $storeName = $shopName == '首店' ? $sjName : $sjName . ' ' . $shopName;
+
+            $storeData = [
+                'keys' => ['wx_store_id' => $shopExt['wxStoreId']],
+                'content' => [
+                    'store_name' => $storeName,
+                    'address_info' => [
+                        'province' => $data['province'],
+                        'city' => $data['city'],
+                        'area' => $data['dist'],
+                        'street' => '',
+                        'house' => $data['floor'] ? $data['address'] . $data['floor'] : $data['address'],
+                        'lat' => $data['lat'],
+                        'lng' => $data['long'],
+                        'phone' => $data['mobile']
+                    ],
+                    //"order_pattern" => 2,
+                    //"service_trans_prefer" => "SFTC" //order_pattern = 2时必填
+                ]
+            ];
+            $result = IntraCityExpress::updateStore($storeData);
+            if ($result['errcode'] == 0) {
+                Yii::info("同步更新同城配送微信门店成功");
+            } else {
+                Yii::error("同步更新同城配送微信门店失败:" . $result['errmsg']);
+            }
+        }
+
         util::complete();
     }
 

+ 1 - 1
biz/shop/classes/ShopClass.php

@@ -170,7 +170,7 @@ class ShopClass extends BaseClass
             //如果是批发店,更新供货商信息
             GhsClass::updateByCondition($where, $shopUpdate);
         }
-        if ($ptStyle == 1) {
+        if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
             //如果是花店,更新客户端信息
             $city = $data['city'] ?? '';
             $dist = $data['dist'] ?? '';