소스 검색

花材采购

shish 3 년 전
부모
커밋
6ed0184f41

+ 15 - 6
app-hd/controllers/GhsController.php

@@ -36,13 +36,22 @@ class GhsController extends BaseController
         if (stringUtil::getWordNum($name) > 8) {
             util::fail('名称不能超过8个汉字');
         }
-        $shopId = $this->shopId;
-        $has = GhsClass::getByCondition(['ownShopId' => $shopId, 'name' => $name], true);
-        if (!empty($has)) {
-            util::fail($name . ' 已经存在了');
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try {
+            $shopId = $this->shopId;
+            $has = GhsClass::getByCondition(['ownShopId' => $shopId, 'name' => $name], true);
+            if (!empty($has)) {
+                util::fail($name . ' 已经存在了');
+            }
+            \bizHd\ghs\services\GhsService::addVirtualGhs($post, $this->shop);
+            $transaction->commit();
+            util::complete('添加成功');
+        } catch (\Exception $e) {
+            $transaction->rollBack();
+            Yii::error("添加失败原因:" . $e->getMessage());
+            util::fail('添加失败');
         }
-        \bizHd\ghs\services\GhsService::addVirtualGhs($post, $this->shop);
-        util::complete();
     }
 
     //是否屏蔽 ssh 20230226

+ 2 - 1
biz-ghs/apply/services/ApplyService.php

@@ -21,10 +21,11 @@ class ApplyService extends BaseService
             util::fail('没有找到申请记录');
         }
         $applyId = $apply['id'];
+        $live = isset($apply['live']) ? $apply['live'] : 1;
         ApplyClass::updateById($applyId, ['status' => ApplyClass::STATUS_PASS, 'remark' => $remark]);
         $apply['name'] = isset($apply['name']) ? $apply['name'] : '';
         //初始化常用花材
-        $main = \bizGhs\shop\classes\MainClass::addMainInitItem();
+        $main = \bizGhs\shop\classes\MainClass::addMainInitItem($live);
 
         $respond = MerchantService::initGhsBaseInfo($apply, $main, true);
         $shop = $respond['shop'] ?? [];

+ 3 - 0
biz-ghs/merchant/services/MerchantService.php

@@ -34,6 +34,7 @@ class MerchantService extends BaseService
     {
         $applyId = $applyData['id'] ?? 0;
         $adminId = $applyData['adminId'] ?? 0;
+        $live = isset($applyData['live']) ? $applyData['live'] : 1;
         $mainId = $main->id ?? 0;
         unset($applyData['id']);
 
@@ -60,6 +61,7 @@ class MerchantService extends BaseService
 
         $sjData = $applyData;
         $sjData['style'] = dict::getDict('ptStyle', 'ghs');
+        $sjData['live'] = $live;
         $sj = self::add($sjData, true);
         $sjId = $sj->id;
         $sjName = $sj->name ?? 0;
@@ -136,6 +138,7 @@ class MerchantService extends BaseService
             'long' => $applyData['long'] ?? '',
             'img' => ['/example/shop/1.jpg'],
             'ptStyle' => $ptStyle,
+            'live' => $live,
         ];
         $shopRespond = \bizGhs\shop\classes\ShopClass::addShop($shopData);
         $shopId = $shopRespond->id;

+ 5 - 2
biz-ghs/shop/classes/MainClass.php

@@ -17,11 +17,14 @@ class MainClass extends BaseClass
     }
 
     //首次开店时创建main并初始化花材 ssh 20220502
-    public static function addMainInitItem()
+    public static function addMainInitItem($live = 1)
     {
         $main = self::addMain();
         $newMainId = $main->id ?? 0;
-        ItemClass::initItem($newMainId);
+        //活的商家要生成花材,虚拟的商家不需要
+        if ($live == 1) {
+            ItemClass::initItem($newMainId);
+        }
         return $main;
     }
 

+ 49 - 0
biz-hd/ghs/services/GhsService.php

@@ -3,6 +3,10 @@
 namespace bizHd\ghs\services;
 
 use bizHd\base\services\BaseService;
+use bizHd\saas\classes\ApplyClass;
+use bizHd\saas\services\ApplyService;
+use bizHd\shop\classes\ShopClass;
+use common\components\dict;
 use common\components\orderSn;
 use common\components\util;
 use Yii;
@@ -17,6 +21,51 @@ class GhsService extends BaseService
     {
         $mobile = orderSn::getMobileSn();
         $name = $data['name'] ?? '';
+
+        $hasApply = ApplyClass::getByCondition(['mobile' => $mobile], true);
+        if (!empty($hasApply)) {
+            util::fail('手机号已存在,请和管理员联系');
+        }
+        $has = ShopClass::getByCondition(['mobile' => $mobile], true);
+        if (!empty($has)) {
+            util::fail('手机号已经存在,请跟管理联系');
+        }
+
+        //将下面的环境定义为批发环境,后继代码可能要用到,不确定,避免风险 ssh 20230306
+        Yii::$app->params['ptStyle'] = 2;
+
+        $adminInfo = ['name' => $name, 'mobile' => $mobile, 'style' => 2, 'ghsMiniOpenId' => ''];
+        $fromApp = dict::getDict('userSourceGetId', 'app', 'id');
+        $admin = \bizGhs\admin\classes\AdminClass::replaceAdmin($adminInfo, $fromApp);
+        $adminId = $admin['id'] ?? 0;
+        $applyData = [
+            'mobile' => $mobile,
+            'name' => $name,
+            'from' => ApplyClass::FROM_GHS,
+            'lat' => '40.023916',
+            'long' => '116.298875',
+            'live' => 0,
+            'adminId' => $adminId,
+            'province' => '北京市',
+            'city' => '北京市',
+            'address' => '上地',
+            'showAddress' => '上地',
+            'style' => 0,
+        ];
+        $apply = ApplyService::replaceGhs($applyData);
+        $applyId = $apply['id'] ?? 0;
+        if (empty($applyId)) {
+            util::fail('没有找到申请记录');
+        }
+        \bizGhs\apply\services\ApplyService::pass($applyId);
+
+        $ghsShop = ShopClass::getByCondition(['mobile' => $mobile, 'ptStyle' => dict::getDict('ptStyle', 'ghs')], true);
+        if (empty($ghsShop)) {
+            util::fail('供货商没有生成,请联系管理员');
+        }
+        $ghsShopId = $ghsShop->id ?? 0;
+        $hdShopId = $hdShop->id ?? 0;
+        \bizGhs\custom\classes\CustomClass::build($ghsShopId, $hdShopId);
     }
 
 }

+ 9 - 4
biz-hd/merchant/services/SjService.php

@@ -26,6 +26,7 @@ class SjService extends BaseService
     {
         $applyId = $applyData['id'] ?? 0;
         $adminId = $applyData['adminId'] ?? 0;
+        $live = isset($applyData['live']) ? $applyData['live'] : 1;
         $mainId = $main->id ?? 0;
         unset($applyData['id']);
         $ptStyle = dict::getDict('ptStyle', 'hd');
@@ -52,6 +53,7 @@ class SjService extends BaseService
 
         $jsData = $applyData;
         $sjData['style'] = $ptStyle;
+        $sjData['live'] = $live;
         $sj = self::add($jsData, true);
         $sjId = $sj->id;
         $sjName = $sj->name ?? 0;
@@ -126,7 +128,8 @@ class SjService extends BaseService
             'lat' => $applyData['lat'] ?? '',
             'long' => $applyData['long'] ?? '',
             'img' => ['/example/shop/1.jpg'],
-            'ptStyle' => $ptStyle
+            'ptStyle' => $ptStyle,
+            'live' => $live,
         ];
         $shopInfo = ShopClass::addShop($shopData);
         $shopId = $shopInfo->id;
@@ -151,9 +154,11 @@ class SjService extends BaseService
         $shopInfo->defaultCustomId = $customId;
         $shopInfo->save();
 
-        //初始化种类
-        $initKindData = ['mainId' => $mainId, 'sjId' => $sjId];
-        KindClass::initKind($initKindData);
+        if ($live == 1) {
+            //初始化种类
+            $initKindData = ['mainId' => $mainId, 'sjId' => $sjId];
+            KindClass::initKind($initKindData);
+        }
 
         return ['sj' => $sj, 'shop' => $shopInfo];
     }

+ 3 - 1
biz/ghs/classes/GhsClass.php

@@ -51,6 +51,7 @@ class GhsClass extends BaseClass
         $ghsAvatar = $ghsShop['shortAvatar'] ?? '';
         $ghsDefault = $ghsShop['default'] ?? 0;
         $allowDebt = $ghsShop['allowDebt'] ?? 0;
+        $live = isset($ghsShop['live']) ? $ghsShop['live'] : 1;
         $allowDebtAmount = $ghsShop['allowDebtAmount'] ?? 5000;
 
         $name = $ghsDefault == 1 && $ghsShop['shopName'] == '首店' ? $ghsShop['merchantName'] : $ghsShop['merchantName'] . ' ' . $ghsShop['shopName'];
@@ -78,6 +79,7 @@ class GhsClass extends BaseClass
             'fullAddress' => $ghsShop['fullAddress'] ?? '',
             'lat' => $ghsShop['lat'] ?? '',
             'long' => $ghsShop['long'] ?? '',
+            'live' => $live,
         ];
         $ghs = self::addGhs($data);
         $ghsId = $ghs['id'] ?? 0;
@@ -125,6 +127,7 @@ class GhsClass extends BaseClass
             'debtLimit' => $debtLimit,
             'debt' => $allowDebt,
             'debtLimit' => $allowDebtAmount,
+            'live' => $live,
         ];
         $custom = CustomClass::addCustom($customData);
         $customId = $custom['id'] ?? 0;
@@ -150,7 +153,6 @@ class GhsClass extends BaseClass
     }
 
 
-
     //增加供货商 ssh 2021.3.29
     public static function addGhs($data)
     {

+ 2 - 1
console/controllers/CustomController.php

@@ -203,7 +203,8 @@ class CustomController extends Controller
                 //增加或更新申请
                 $respond = ApplyService::replaceRetail($post);
                 $id = $respond['id'] ?? 0;
-                Yii::$app->params['ptStyle'] = 2; // 后继代码,要用到此参数
+                //后继代码,要用到此参数
+                Yii::$app->params['ptStyle'] = 2;
                 ApplyService::pass($id, '批发商手动添加');
                 $transaction->commit();
                 noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 由批发商添加成功");