Sfoglia il codice sorgente

客户与供货商关系

shish 5 anni fa
parent
commit
01e4d060fc

+ 1 - 1
app-hd/controllers/GhsController.php

@@ -31,7 +31,7 @@ class GhsController extends BaseController
     public function actionInfo()
     {
         $shopId = Yii::$app->request->get('shopId');
-        $ghs = GhsClass::build($shopId, $this->shopId, $this->sjId);
+        $ghs = GhsClass::build($shopId, $this->shopId);
         util::success($ghs);
     }
 

+ 1 - 1
app-hd/controllers/ProductController.php

@@ -123,7 +123,7 @@ class ProductController extends BaseController
 
             if (empty($id)) {
                 if (!empty($this->shopId)) {
-                    $ghs = GhsClass::build($shopId, $this->shopId, $this->sjId);
+                    $ghs = GhsClass::build($shopId, $this->shopId);
                     $sjId = $ghs['sjId'] ?? 0;
                 } else {
                     $shop = ShopClass::getShopInfo($shopId);

+ 1 - 1
app-pt/controllers/GhsController.php

@@ -49,7 +49,7 @@ class GhsController extends BaseController
         try {
             foreach ($list as $current) {
                 $ownShopId = $current['id'];
-                GhsClass::build($currentShopId, $ownShopId, $ownSjId);
+                GhsClass::build($currentShopId, $ownShopId);
             }
             $transaction->commit();
             util::complete();

+ 3 - 145
biz-ghs/custom/classes/CustomClass.php

@@ -3,14 +3,10 @@
 namespace bizGhs\custom\classes;
 
 use biz\ghs\classes\GhsClass;
-use biz\shop\classes\ShopClass;
 use biz\sj\classes\MerchantClass;
-use biz\sj\classes\SjClass;
 use common\components\business;
 use common\components\imgUtil;
-use common\components\stringUtil;
 use common\components\util;
-use Yii;
 use bizHd\base\classes\BaseClass;
 
 class CustomClass extends BaseClass
@@ -21,148 +17,10 @@ class CustomClass extends BaseClass
     const IS_DEBT_NO = 0;
     const IS_DEBT_YES = 1;
 
-    //申请开店建立客户关系 ssh 2021.2.28
-    //GhsClass::build()也有相似流程
-    public static function buildCustom($applyData, $newSj, $newShop)
+    //建立客户和供货商关系
+    public static function build($ghsShopId, $hdShopId)
     {
-        $sjId = $newSj['id'] ?? 0;
-        $shopId = $newShop['id'] ?? 0;
-        $sjName = $newSj['name'] ?? '';
-        $shopName = $newShop['shopName'] ?? '';
-        $currentName = $sjName . ' ' . $shopName;
-        $currentPy = stringUtil::py($currentName);
-        if ($applyData['style'] == SjClass::STYLE_RETAIL) {
-            if ($applyData['introStyle'] == SjClass::STYLE_SUPPLIER) {
-                $custom = self::getByCondition(['ownShopId' => $applyData['introShopId'], 'shopId' => $shopId]);
-                if (empty($custom)) {
-                    $customData = [
-                        'sjId' => $sjId,//零售商家id
-                        'shopId' => $shopId,//零售门店id
-                        'ownSjId' => $applyData['introSjId'],//供货商id
-                        'name' => $currentName,
-                        'py' => $currentPy,
-                        'mobile' => $applyData['mobile'],
-                        'province' => $applyData['province'] ?? '',
-                        'city' => $applyData['city'] ?? '',
-                        'dist' => $applyData['dist'] ?? '',
-                        'address' => $applyData['address'] ?? '',
-                        'fullAddress' => $applyData['fullAddress'],
-                        'long' => $applyData['long'],
-                        'lat' => $applyData['lat'],
-                    ];
-                    $custom = self::addCustom($customData);
-                }
-                $customId = $custom['id'];
-
-                $introShopId = $applyData['introShopId'] ?? 0;
-                $ghsShop = ShopClass::getShopInfo($introShopId);
-                if (empty($ghsShop)) {
-                    util::fail('没有找到门店');
-                }
-                $introSjId = $applyData['introSjId'] ?? 0;
-                $ghsSj = SjClass::getById($introSjId);
-                if (empty($ghsSj)) {
-                    util::fail('没有找到商家');
-                }
-                $ghs = GhsClass::getByCondition(['ownShopId' => $shopId, 'shopId' => $ghsShop['id']]);
-                if (empty($ghs)) {
-                    $shopName = $ghsShop['shopName'] ?? '';
-                    $ghsSjName = $ghsSj['name'] ?? '';
-                    $name = $ghsSjName . ' ' . $shopName;
-                    $py = stringUtil::py($name);
-                    $mobile = $ghsShop['mobile'] ?? '';
-                    $ghsData = [
-                        'sjId' => $ghsShop['merchantId'],
-                        'customId' => $customId,
-                        'shopId' => $ghsShop['id'],
-                        'ownSjId' => $sjId,
-                        'ownShopId' => $sjId,
-                        'name' => $name,
-                        'py' => $py,
-                        'mobile' => $mobile,
-                        'province' => $ghsShop['province'] ?? '',
-                        'city' => $ghsShop['city'] ?? '',
-                        'dist' => $ghsShop['dist'] ?? '',
-                        'address' => $ghsShop['address'] ?? '',
-                        'floor' => $ghsShop['floor'] ?? '',
-                        'fullAddress' => $ghsShop['fullAddress'] ?? '',
-                        'lat' => $ghsShop['lat'] ?? '',
-                        'long' => $ghsShop['long'] ?? '',
-                    ];
-                    $ghs = GhsClass::addGhs($ghsData);
-                    $ghsId = $ghs['id'] ?? 0;
-                    self::updateById($customId, ['ghsId' => $ghsId]);
-                }
-            }
-        }
-
-        if ($applyData['style'] == SjClass::STYLE_SUPPLIER) {
-            if ($applyData['introStyle'] == SjClass::STYLE_RETAIL) {
-                $has = self::getByCondition(['ownShopId' => $shopId, 'shopId' => $applyData['introShopId']]);
-                $introSjId = $applyData['introSjId'] ?? 0;
-                $introShopId = $applyData['introShopId'] ?? 0;
-                if (empty($has)) {
-                    $shop = ShopClass::getShopInfo($introShopId);
-                    $thisSj = SjClass::getById($introSjId);
-                    if (empty($thisSj)) {
-                        util::fail('没有找到商家');
-                    }
-                    $shopName = $shop['shopName'] ?? '';
-                    $sjName = $thisSj['name'] ?? '';
-                    $name = $sjName . ' ' . $shopName;
-                    $py = stringUtil::py($name);
-                    $super = ShopClass::getSuper($introShopId);
-                    $mobile = $super['mobile'] ?? '';
-                    $customData = [
-                        'sjId' => $introSjId,//零售商id
-                        'shopId' => $introShopId,//零售门店id
-                        'ownSjId' => $sjId,//供货商id
-                        'name' => $name,
-                        'py' => $py,
-                        'mobile' => $mobile,
-                        'isOpen' => 1,
-                        'province' => $applyData['province'] ?? '',
-                        'city' => $applyData['city'] ?? '',
-                        'dist' => $applyData['dist'] ?? '',
-                        'address' => $applyData['address'] ?? '',
-                        'fullAddress' => $applyData['fullAddress'],
-                        'long' => $applyData['long'],
-                        'lat' => $applyData['lat'],
-                    ];
-                    $has = self::addCustom($customData);
-                }
-                $customId = $has['id'] ?? 0;
-                $ghs = GhsClass::getByCondition(['ownShopId' => $introShopId, 'shopId' => $shopId]);
-                if (empty($ghs)) {
-                    $shopName = $newShop['shopName'] ?? '';
-                    $sjName = $newSj['name'] ?? '';
-                    $name = $sjName . ' ' . $shopName;
-                    $py = stringUtil::py($name);
-                    $mobile = $newShop['mobile'] ?? '';
-                    $ghsData = [
-                        'sjId' => $sjId,
-                        'shopId' => $shopId,
-                        'ownSjId' => $introSjId,
-                        'ownShopId' => $introShopId,
-                        'name' => $name,
-                        'customId' => $customId,
-                        'py' => $py,
-                        'mobile' => $mobile,
-                        'province' => $newShop['province'] ?? '',
-                        'city' => $newShop['city'] ?? '',
-                        'dist' => $newShop['dist'] ?? '',
-                        'address' => $newShop['address'] ?? '',
-                        'floor' => $newShop['floor'] ?? '',
-                        'fullAddress' => $newShop['fullAddress'] ?? '',
-                        'lat' => $newShop['lat'] ?? '',
-                        'long' => $newShop['long'] ?? '',
-                    ];
-                    $ghs = GhsClass::addGhs($ghsData);
-                    $ghsId = $ghs['id'] ?? 0;
-                    self::updateById($customId, ['ghsId' => $ghsId]);
-                }
-            }
-        }
+        return GhsClass::build($ghsShopId, $hdShopId);
     }
 
     //添加客户 ssh 2021.2.24

+ 22 - 2
biz-ghs/custom/services/CustomService.php

@@ -2,16 +2,36 @@
 
 namespace bizGhs\custom\services;
 
+use biz\sj\classes\SjClass;
 use bizHd\base\services\BaseService;
 use bizGhs\custom\classes\CustomClass;
-use biz\shop\classes\ShopClass;
-use Yii;
 
 class CustomService extends BaseService
 {
 
     public static $baseFile = '\bizGhs\custom\classes\CustomClass';
 
+    //分享建立客户和供货商关系 ssh 2021.2.28
+    public static function shareBuildTrade($applyData, $newSj, $newShop)
+    {
+        $sjId = $newSj['id'] ?? 0;
+        $shopId = $newShop['id'] ?? 0;
+        $introSjId = $applyData['introSjId'] ?? 0;
+        $introShopId = $applyData['introShopId'] ?? 0;
+        //申请人是花店,介绍人是供货商
+        if ($applyData['style'] == SjClass::STYLE_RETAIL) {
+            if ($applyData['introStyle'] == SjClass::STYLE_SUPPLIER) {
+                CustomClass::buildTrade($introShopId, $introSjId, $shopId, $sjId);
+            }
+        }
+        //申请人是供货商,介绍人是花店
+        if ($applyData['style'] == SjClass::STYLE_SUPPLIER) {
+            if ($applyData['introStyle'] == SjClass::STYLE_RETAIL) {
+                CustomClass::buildTrade($shopId, $sjId, $introShopId, $introSjId);
+            }
+        }
+    }
+
     public static function getCustomList($where)
     {
         $data = CustomClass::getList('*', $where, 'addTime DESC');

+ 51 - 58
biz/ghs/classes/GhsClass.php

@@ -16,71 +16,64 @@ class GhsClass extends BaseClass
 
     public static $baseFile = '\biz\ghs\models\Ghs';
 
-    //新增供货商 shish 2021.4.13
-    //CustomClass::buildCustom()也有相似流程
-    public static function build($thisShopId, $shopId, $sjId)
+    //新增客户和供货商关系 shish 2021.4.13
+    public static function build($ghsShopId, $hdShopId)
     {
-        $ghsShop = ShopClass::getShopInfo($thisShopId);
-        if (empty($ghsShop)) {
-            util::fail('没有找到供货商门店');
-        }
-        $thisSjId = $ghsShop['merchantId'] ?? 0;
-        $ghs = self::getByCondition(['ownShopId' => $shopId, 'shopId' => $thisShopId]);
-        $createGhs = false;
-        if (empty($ghs)) {
-            $name = $ghsShop['merchantName'] . ' ' . $ghsShop['shopName'];
-            $py = stringUtil::py($name);
-            $data = [
-                'sjId' => $thisSjId,
-                'shopId' => $thisShopId,
-                'ownSjId' => $sjId,
-                'ownShopId' => $shopId,
-                'name' => $name,
-                'py' => $py,
-                'mobile' => $ghsShop['mobile'] ?? '',
-                'province' => $ghsShop['province'] ?? '',
-                'city' => $ghsShop['city'] ?? '',
-                'dist' => $ghsShop['dist'] ?? '',
-                'address' => $ghsShop['address'] ?? '',
-                'floor' => $ghsShop['floor'] ?? '',
-                'fullAddress' => $ghsShop['fullAddress'] ?? '',
-                'lat' => $ghsShop['lat'] ?? '',
-                'long' => $ghsShop['long'] ?? '',
-            ];
-            $ghs = self::addGhs($data);
-            $createGhs = true;
+        $ghs = self::getByCondition(['ownShopId' => $hdShopId, 'shopId' => $ghsShopId]);
+        if (!empty($ghs)) {
+            return true;
         }
+        $ghsShop = ShopClass::getShopInfo($ghsShopId);
+        $ghsSjId = $ghsShop['merchantId'] ?? 0;
+        $name = $ghsShop['merchantName'] . ' ' . $ghsShop['shopName'];
+        $py = stringUtil::py($name);
+
+        $ghShop = ShopClass::getShopInfo($hdShopId);
+        $hdSjId = $ghShop['merchantId'] ?? 0;
 
-        $shop = ShopClass::getShopInfo($shopId);
+        $data = [
+            'sjId' => $ghsSjId,
+            'shopId' => $ghsShopId,
+            'ownSjId' => $hdSjId,
+            'ownShopId' => $hdShopId,
+            'name' => $name,
+            'py' => $py,
+            'mobile' => $ghsShop['mobile'] ?? '',
+            'province' => $ghsShop['province'] ?? '',
+            'city' => $ghsShop['city'] ?? '',
+            'dist' => $ghsShop['dist'] ?? '',
+            'address' => $ghsShop['address'] ?? '',
+            'floor' => $ghsShop['floor'] ?? '',
+            'fullAddress' => $ghsShop['fullAddress'] ?? '',
+            'lat' => $ghsShop['lat'] ?? '',
+            'long' => $ghsShop['long'] ?? '',
+        ];
+        $ghs = self::addGhs($data);
+
+        $shop = ShopClass::getShopInfo($hdShopId);
         $name = $shop['merchantName'] . ' ' . $shop['shopName'];
         $py = stringUtil::py($name);
         $mobile = $shop['mobile'] ?? '';
         $ghsId = $ghs['id'] ?? 0;
-
-        $custom = CustomClass::getByCondition(['ownShopId' => $thisShopId, 'shopId' => $shopId]);
-        if (empty($custom)) {
-            $customData = [
-                'sjId' => $sjId,
-                'ghsId' => $ghsId,
-                'shopId' => $shopId,
-                'ownSjId' => $thisSjId,
-                'ownShopId' => $thisShopId,
-                'name' => $name,
-                'py' => $py,
-                'mobile' => $mobile,
-                'city' => $shop['city'] ?? '',
-                'dist' => $shop['dist'] ?? '',
-                'address' => $shop['address'] ?? '',
-                'fullAddress' => $shop['fullAddress'] ?? '',
-                'long' => $shop['long'] ?? '',
-                'lat' => $shop['lat'] ?? '',
-            ];
-            $custom = CustomClass::addCustom($customData);
-        }
-        if ($createGhs) {
-            $customId = $custom['id'] ?? 0;
-            self::updateById($ghsId, ['customId' => $customId]);
-        }
+        $customData = [
+            'sjId' => $hdSjId,
+            'ghsId' => $ghsId,
+            'shopId' => $hdShopId,
+            'ownSjId' => $ghsSjId,
+            'ownShopId' => $ghsShopId,
+            'name' => $name,
+            'py' => $py,
+            'mobile' => $mobile,
+            'city' => $shop['city'] ?? '',
+            'dist' => $shop['dist'] ?? '',
+            'address' => $shop['address'] ?? '',
+            'fullAddress' => $shop['fullAddress'] ?? '',
+            'long' => $shop['long'] ?? '',
+            'lat' => $shop['lat'] ?? '',
+        ];
+        $custom = CustomClass::addCustom($customData);
+        $customId = $custom['id'] ?? 0;
+        self::updateById($ghsId, ['customId' => $customId]);
         return $ghs;
     }
 

+ 3 - 2
biz/sj/services/MerchantService.php

@@ -3,6 +3,7 @@
 namespace biz\sj\services;
 
 use biz\sj\classes\SjClass;
+use bizGhs\custom\services\CustomService;
 use bizHd\agent\classes\AgentAssetClass;
 use bizHd\auth\services\AuthService;
 use bizHd\goods\classes\GoodsSettingClass;
@@ -171,8 +172,8 @@ class MerchantService extends BaseService
         $sjData['status'] = $sjStatus;
         MerchantClass::updateById($sjId, $sjData);
 
-        //建立客户关系
-        CustomClass::buildCustom($applyData, $sj, $shopRespond);
+        //建立供货商和客户关系
+        CustomService::shareBuildTrade($applyData, $sj, $shopRespond);
 
         return $sj;
     }