瀏覽代碼

中央化数据迁移

shish 4 年之前
父節點
當前提交
1608741941

+ 2 - 1
app-ghs/controllers/AdminController.php

@@ -224,6 +224,7 @@ class AdminController extends BaseController
         $wxInfo['miniOpenId'] = $admin['miniOpenId'] ?? '';
         //这个接口没有提供unionId,这边补充一下
         $wxInfo['unionId'] = $unionId;
+        $wxInfo['mainId'] = $this->mainId;
         $admin = AdminService::replaceAdmin($wxInfo, $source);
         $adminId = $admin['id'];
         $admin = AdminService::getAdminById($adminId);
@@ -273,7 +274,7 @@ class AdminController extends BaseController
     {
         $admin = $this->admin;
         $currentGhsShopId = $admin->currentGhsShopId ?? 0;
-        $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($this->shopAdmin->attributes);
+        $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($this->shopAdmin);
         $openShop = $admin['openGhsShop'] ?? 1;
         $showDemo = 1;
         $skCustomId = $this->shop->skCustomId ?? 0;

+ 1 - 1
app-ghs/controllers/ApplyController.php

@@ -144,7 +144,7 @@ class ApplyController extends BaseController
             $post['adminId'] = $adminId;
             $currentShopId = $admin['currentGhsShopId'] ?? 0;
             if (!empty($currentShopId)) {
-                util::fail('您已提交过申请');
+                util::fail('您已提交过申请,管理员ID:' . $adminId);
             }
             if (isset($admin['openGhsShop']) && $admin['openGhsShop'] == 2) {
                 util::fail('审核中,无需重复申请');

+ 4 - 4
app-ghs/controllers/AuthController.php

@@ -79,7 +79,7 @@ class AuthController extends PublicController
         $shopAdmin->save();
         $shopAdminId = $shopAdmin->id ?? 0;
         //是否有切换门店的权限
-        $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin->attributes);
+        $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin);
 
         $admin['avatar'] = imgUtil::getPrefix() . '/retail/default-img.png';
         $token = jwt::getNewToken($adminId);
@@ -185,7 +185,7 @@ class AuthController extends PublicController
         $shopAdmin->save();
         $shopAdminId = $shopAdmin->id ?? 0;
         //是否有切换门店的权限
-        $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin->attributes);
+        $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin);
 
         $admin['avatar'] = imgUtil::getPrefix() . '/retail/default-img.png';
         $token = jwt::getNewToken($adminId);
@@ -421,7 +421,7 @@ class AuthController extends PublicController
         $shopAdmin->save();
         $shopAdminId = $shopAdmin->id ?? 0;
         //是否有切换门店的权限
-        $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin->attributes);
+        $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin);
         $admin['avatar'] = imgUtil::getPrefix() . '/retail/default-img.png';
         $token = jwt::getNewToken($adminId);
         $showDemo = 1;
@@ -501,7 +501,7 @@ class AuthController extends PublicController
         $token = jwt::getNewToken($adminId);
         $shopAdminId = $shopAdmin->id ?? 0;
         //是否有切换门店的权限
-        $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin->attributes);
+        $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin);
         //1没有开店 2已申请待审核 3已开店
         $openShop = $admin['openGhsShop'] ?? 1;
         $showDemo = 1;

+ 2 - 2
app-ghs/controllers/BaseController.php

@@ -67,7 +67,7 @@ class BaseController extends PublicController
             $this->mainId = $mainId;
             $main = MainClass::getById($mainId, true);
             if (empty($main)) {
-                util::fail('没有main信息,shopId:'.$this->shopId);
+                util::fail('没有main信息,shopId:' . $this->shopId);
             }
             $this->main = $main;
             $shopExt = ShopExtClass::getByCondition(['shopId' => $currentShopId], true);
@@ -75,7 +75,7 @@ class BaseController extends PublicController
                 util::fail('门店信息有问题,请联系管理员');
             }
             $this->shopExt = $shopExt;
-            $shopAdmin = ShopAdminClass::getByCondition(['shopId' => $currentShopId, 'adminId' => $adminId, 'delStatus' => 0], true);
+            $shopAdmin = ShopAdminClass::getByCondition(['mainId' => $mainId, 'adminId' => $adminId, 'delStatus' => 0], true);
             if (empty($shopAdmin)) {
                 util::logout('没有找到员工');
             }

+ 2 - 0
app-ghs/controllers/ShopAdminController.php

@@ -96,6 +96,7 @@ class ShopAdminController extends BaseController
         $post['shopId'] = $this->shopId;
         $post['sjId'] = $this->sjId;
         $post['adminId'] = $this->adminId;
+        $post['mainId'] = $this->mainId;
         $merchant = WxOpenClass::getGhsWxInfo();
         $post['merchant'] = $merchant;
         $respond = ShopAdminService::prepareBindAdmin($post);
@@ -108,6 +109,7 @@ class ShopAdminController extends BaseController
     {
         $post = Yii::$app->request->post();
         $post['adminId'] = $this->adminId;
+        $post['mainId'] = $this->mainId;
         $admin = $this->admin->attributes;
         $currentShopId = $admin['currentGhsShopId'] ?? 0;
         if (!empty($currentShopId)) {

+ 6 - 2
app-ghs/controllers/ShopController.php

@@ -228,8 +228,12 @@ class ShopController extends BaseController
     //切换门店 lqh 2021.1.31
     public function actionToggleShop()
     {
-        $shopId = Yii::$app->request->post('shopId', 0);
-        $res = AdminClass::toggleShop($this->admin->attributes, $shopId, $this->sjId, $this->shopAdmin->attributes);
+        $newShopId = Yii::$app->request->post('shopId', 0);
+        $newShop = ShopClass::getById($newShopId, true);
+        if (empty($newShop)) {
+            util::fail('没有找到门店');
+        }
+        $res = AdminClass::toggleShop($this->admin, $newShop, $this->sjId, $this->shopAdmin);
         util::success($res);
     }
 

+ 8 - 6
app-hd/controllers/AdminController.php

@@ -2,6 +2,7 @@
 
 namespace hd\controllers;
 
+use biz\shop\classes\ShopClass;
 use biz\shop\services\ShopAdminService;
 use bizHd\admin\classes\AdminClass;
 use bizHd\admin\services\AdminService;
@@ -31,23 +32,24 @@ class AdminController extends BaseController
             }
             util::fail('请先注册');
         }
+        $currentShop = ShopClass::getById($currentShopId, true);
+        if (empty($currentShop)) {
+            util::fail('没有找到门店');
+        }
+        $mainId = $currentShop->mainId ?? 0;
         $adminId = $admin['id'];
-        $shopAdmin = ShopAdminService::getByCondition(['adminId' => $adminId, 'shopId' => $currentShopId, 'delStatus' => 0], true);
+        $shopAdmin = ShopAdminService::getByCondition(['adminId' => $adminId, 'mainId' => $mainId, 'delStatus' => 0], true);
         if (empty($shopAdmin)) {
             util::fail('没有权限操作');
         }
         if (!empty($shopAdmin) && $shopAdmin->status == 0) {
             util::fail("您的账号已冻结");
         }
-        $shopId = $shopAdmin->shopId ?? 0;
-        if (empty($shopId)) {
-            util::fail('您不是管理员');
-        }
         $shopAdmin->lastLogin = date("Y-m-d H:i:s");
         $shopAdmin->save();
         $shopAdminId = $shopAdmin->id ?? 0;
         //是否有切换门店的权限
-        $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin->attributes);
+        $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin);
         $showDemo = 1;
         $remind = getenv('HD_UPDATE_REMIND') == false ? 0 : getenv('HD_UPDATE_REMIND');
 

+ 9 - 9
app-hd/controllers/ApplyController.php

@@ -151,7 +151,7 @@ class ApplyController extends BaseController
             $adminId = $admin['id'] ?? 0;
             $currentShopId = $admin['currentHdShopId'] ?? 0;
             if (!empty($currentShopId)) {
-                util::fail('您已提交过申请');
+                util::fail('您已提交过申请,管理员ID:' . $adminId);
             }
             if (isset($admin['openHdShop']) && $admin['openHdShop'] == 2) {
                 util::fail('审核中,无需重复申请');
@@ -171,23 +171,23 @@ class ApplyController extends BaseController
                 util::fail('申请失败');
             }
             $passInfo = ApplyService::pass($id);
-            $transaction->commit();
-
             $mobile = $post['mobile'] ?? '';
-            noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 注册", '15280215347');
-
             //输出登录信息
             $newShop = $passInfo['shop'] ?? [];
+            $newMainId = $newShop->mainId ?? 0;
             $newShopId = $newShop->id ?? 0;
             //前端用于判断是否注册
             $admin['currentHdShopId'] = $newShopId;
             $adminId = $admin['id'];
-            $shopAdmin = ShopAdminService::getByCondition(['adminId' => $adminId, 'shopId' => $newShopId, 'delStatus' => 0], true);
+            $shopAdmin = ShopAdminService::getByCondition(['adminId' => $adminId, 'mainId' => $newMainId], true);
+            if (empty($shopAdmin)) {
+                util::fail('没有找到管理员');
+            }
             $shopAdmin->lastLogin = date("Y-m-d H:i:s");
             $shopAdmin->save();
             $shopAdminId = $shopAdmin->id ?? 0;
             //是否有切换门店的权限
-            $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin->attributes);
+            $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin);
             $showDemo = 1;
             $token = jwt::getNewToken($adminId);
             $remind = getenv('HD_UPDATE_REMIND') == false ? 0 : getenv('HD_UPDATE_REMIND');
@@ -196,10 +196,10 @@ class ApplyController extends BaseController
             if ($hdUpgrading == 1) {
                 util::fail('系统升级中,稍后再试');
             }
-
+            $transaction->commit();
+            noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 注册", '15280215347');
             $apiHost = Yii::$app->params['hdHost'];
             $imgUploadApi = $apiHost . '/upload/save-file';
-
             //涉及几个登录的地方,需要同步修改,请搜索关键词uni_login_info
             util::success([
                 'token' => $token,

+ 11 - 5
app-hd/controllers/AuthController.php

@@ -87,7 +87,7 @@ class AuthController extends PublicController
         $shopAdmin->save();
         $shopAdminId = $shopAdmin->id ?? 0;
         //是否有切换门店的权限
-        $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin->attributes);
+        $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin);
         $prefix = imgUtil::getPrefix();
         $avatar = isset($admin['avatar']) && !empty($admin['avatar']) ? $prefix . $admin['avatar'] : $prefix . '/retail/default-img.png';
         $admin['avatar'] = $avatar;
@@ -157,7 +157,7 @@ class AuthController extends PublicController
         $shopAdmin->save();
         $shopAdminId = $shopAdmin->id ?? 0;
         //是否有切换门店的权限
-        $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin->attributes);
+        $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin);
         $prefix = imgUtil::getPrefix();
         $avatar = isset($admin['avatar']) && !empty($admin['avatar']) ? $prefix . $admin['avatar'] : $prefix . '/retail/default-img.png';
         $admin['avatar'] = $avatar;
@@ -245,7 +245,7 @@ class AuthController extends PublicController
         $shopAdmin->save();
         $shopAdminId = $shopAdmin->id ?? 0;
         //是否有切换门店的权限
-        $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin->attributes);
+        $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin);
         $prefix = imgUtil::getPrefix();
         $avatar = isset($admin['avatar']) && !empty($admin['avatar']) ? $prefix . $admin['avatar'] : $prefix . '/retail/default-img.png';
         $admin['avatar'] = $avatar;
@@ -454,7 +454,13 @@ class AuthController extends PublicController
             //没有管理店铺不允许登录
             util::success(['token' => '', 'currentMiniOpenId' => $openid]);
         }
-        $shopAdmin = ShopAdminClass::getByCondition(['shopId' => $currentShopId, 'adminId' => $adminId], true);
+        $currentShop = ShopClass::getById($currentShopId, true);
+        if (empty($currentShop)) {
+            //没有管理店铺不允许登录
+            util::success(['token' => '', 'currentMiniOpenId' => $openid]);
+        }
+        $mainId = $currentShop->mainId ?? 0;
+        $shopAdmin = ShopAdminClass::getByCondition(['mainId' => $mainId, 'adminId' => $adminId], true);
         if (empty($shopAdmin)) {
             //没有管理店铺不允许登录
             util::success(['token' => '', 'currentMiniOpenId' => $openid]);
@@ -467,7 +473,7 @@ class AuthController extends PublicController
         $shopAdmin->save();
         $shopAdminId = $shopAdmin->id ?? 0;
         //是否有切换门店的权限
-        $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin->attributes);
+        $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin);
         $prefix = imgUtil::getPrefix();
         $avatar = isset($admin['avatar']) && !empty($admin['avatar']) ? $prefix . $admin['avatar'] : $prefix . '/retail/default-img.png';
         $admin['avatar'] = $avatar;

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

@@ -70,7 +70,7 @@ class BaseController extends PublicController
                 util::fail('没有找到main信息');
             }
             $this->main = $main;
-            $shopAdmin = ShopAdminClass::getByCondition(['shopId' => $currentShopId, 'adminId' => $adminId], true);
+            $shopAdmin = ShopAdminClass::getByCondition(['mainId' => $mainId, 'adminId' => $adminId, 'delStatus' => 0], true);
             if (empty($shopAdmin)) {
                 util::logout('没有找到员工信息');
             }

+ 2 - 0
app-hd/controllers/ShopAdminController.php

@@ -95,6 +95,7 @@ class ShopAdminController extends BaseController
         unset($post['status']);
         $post['shopId'] = $this->shopId;
         $post['adminId'] = $this->adminId;
+        $post['mainId'] = $this->mainId;
         $merchant = WxOpenService::getWxInfo();
         $post['merchant'] = $merchant;
         $respond = ShopAdminService::prepareBindAdmin($post);
@@ -107,6 +108,7 @@ class ShopAdminController extends BaseController
     {
         $post = Yii::$app->request->post();
         $post['adminId'] = $this->adminId;
+        $post['mainId'] = $this->mainId;
         $admin = $this->admin->attributes;
         $currentShopId = $admin['currentHdShopId'] ?? 0;
         if (!empty($currentShopId)) {

+ 6 - 2
app-hd/controllers/ShopController.php

@@ -80,8 +80,12 @@ class ShopController extends BaseController
     //切换门店 lqh 2021.1.31
     public function actionToggleShop()
     {
-        $shopId = Yii::$app->request->post('shopId', 0);
-        $res = AdminClass::toggleShop($this->admin->attributes, $shopId, $this->sjId, $this->shopAdmin->attributes);
+        $newShopId = Yii::$app->request->post('shopId', 0);
+        $newShop = ShopClass::getById($newShopId, true);
+        if (empty($newShop)) {
+            util::fail('没有找到门店');
+        }
+        $res = AdminClass::toggleShop($this->admin, $newShop, $this->sjId, $this->shopAdmin);
         util::success($res);
     }
 

+ 12 - 5
biz-ghs/admin/classes/AdminClass.php

@@ -413,20 +413,27 @@ class AdminClass extends BaseClass
     }
 
     //切换门店 lqh 2021.1.31
-    public static function toggleShop($admin, $toggleShopId, $sjId, $originShopAdmin)
+    public static function toggleShop($admin, $newShop, $sjId, $originShopAdmin)
     {
         $right = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($originShopAdmin);
         if (empty($right)) {
             util::fail("没有权限");
         }
-        $adminId = $admin['id'];
+        $adminId = $admin->id ?? 0;
+        $newShopId = $newShop->id ?? 0;
         $sjShopList = ShopClass::getSjShopList($sjId);
         $sjShopIds = array_column($sjShopList, 'id');
-        if (in_array($toggleShopId, $sjShopIds) == false) {
+        if (in_array($newShopId, $sjShopIds) == false) {
             util::fail('不是您的门店');
         }
-        $shopAdmin = \biz\shop\classes\ShopAdminClass::changeShopAddRelate($originShopAdmin, $toggleShopId);
-        self::updateById($adminId, ['currentShopId' => $toggleShopId]);
+        $shopAdmin = \biz\shop\classes\ShopAdminClass::changeShopAddRelate($originShopAdmin, $newShop);
+        $ptStyle = Yii::$app->params['ptStyle'];
+        if ($ptStyle == dict::getDict('ptStyle', 'hd')) {
+            self::updateById($adminId, ['currentHdShopId' => $newShopId]);
+        }
+        if ($ptStyle == dict::getDict('ptStyle', 'ghs')) {
+            self::updateById($adminId, ['currentGhsShopId' => $newShopId]);
+        }
         return $shopAdmin;
     }
 

+ 8 - 8
biz-ghs/shop/classes/ShopAdminClass.php

@@ -16,17 +16,17 @@ class ShopAdminClass extends BaseClass
     const GENERATE_ADMIN_DATA = 'generate_ghs_admin_data_';//创建管理员需要的数据
 
     //创建管理准备数据key ssh 2020.4.17
-    public static function getGenerateAdminDataKey($shopId, $adminId)
+    public static function getGenerateAdminDataKey($mainId, $adminId)
     {
-        return self::GENERATE_ADMIN_DATA . $shopId . '_' . $adminId;
+        return self::GENERATE_ADMIN_DATA . $mainId . '_' . $adminId;
     }
 
     //创建管理员数据准备 ssh 2020.4.17
     public static function prepareBindAdmin($data)
     {
         $adminId = $data['adminId'];
-        $shopId = $data['shopId'];
-        $cacheKey = self::getGenerateAdminDataKey($shopId, $adminId);
+        $mainId = $data['mainId'];
+        $cacheKey = self::getGenerateAdminDataKey($mainId, $adminId);
         $params = [$cacheKey];
         if (!empty($data)) {
             foreach ($data as $key => $val) {
@@ -40,9 +40,9 @@ class ShopAdminClass extends BaseClass
     }
 
     //获取创建管理员需要的信息 ssh 2020.4.20
-    public static function getBindAdminData($shopId, $adminId)
+    public static function getBindAdminData($mainId, $adminId)
     {
-        $cacheKey = self::getGenerateAdminDataKey($shopId, $adminId);
+        $cacheKey = self::getGenerateAdminDataKey($mainId, $adminId);
         $cacheData = Yii::$app->redis->executeCommand('HGETALL', [$cacheKey]);
         $data = [];
         if (!empty($cacheData)) {
@@ -65,9 +65,9 @@ class ShopAdminClass extends BaseClass
     }
 
     //删除创建管理员需要的信息 ssh 2020.4.20
-    public static function delBindAdminData($shopId, $adminId)
+    public static function delBindAdminData($mainId, $adminId)
     {
-        $cacheKey = self::getGenerateAdminDataKey($shopId, $adminId);
+        $cacheKey = self::getGenerateAdminDataKey($mainId, $adminId);
         $keyNameList = Yii::$app->redis->executeCommand('HKEYS', [$cacheKey]);
         if (!empty($keyNameList)) {
             $data = array_merge([$cacheKey], $keyNameList);

+ 8 - 8
biz-hd/admin/classes/ShopAdminClass.php

@@ -15,17 +15,17 @@ class ShopAdminClass extends BaseClass
     const GENERATE_ADMIN_DATA = 'generate_admin_data_';//创建管理员需要的数据
 
     //创建管理准备数据key ssh 2020.4.17
-    public static function getGenerateAdminDataKey($shopId, $adminId)
+    public static function getGenerateAdminDataKey($mainId, $adminId)
     {
-        return self::GENERATE_ADMIN_DATA . $shopId . '_' . $adminId;
+        return self::GENERATE_ADMIN_DATA . $mainId . '_' . $adminId;
     }
 
     //创建管理员数据准备 ssh 2020.4.17
     public static function prepareBindAdmin($data)
     {
         $adminId = $data['adminId'];
-        $shopId = $data['shopId'];
-        $cacheKey = self::getGenerateAdminDataKey($shopId, $adminId);
+        $mainId = $data['mainId'];
+        $cacheKey = self::getGenerateAdminDataKey($mainId, $adminId);
         $params = [$cacheKey];
         if (!empty($data)) {
             foreach ($data as $key => $val) {
@@ -39,9 +39,9 @@ class ShopAdminClass extends BaseClass
     }
 
     //获取创建管理员需要的信息 ssh 2020.4.20
-    public static function getBindAdminData($shopId, $adminId)
+    public static function getBindAdminData($mainId, $adminId)
     {
-        $cacheKey = self::getGenerateAdminDataKey($shopId, $adminId);
+        $cacheKey = self::getGenerateAdminDataKey($mainId, $adminId);
         $cacheData = Yii::$app->redis->executeCommand('HGETALL', [$cacheKey]);
         $data = [];
         if (!empty($cacheData)) {
@@ -64,9 +64,9 @@ class ShopAdminClass extends BaseClass
     }
 
     //删除创建管理员需要的信息 ssh 2020.4.20
-    public static function delBindAdminData($shopId, $adminId)
+    public static function delBindAdminData($mainId, $adminId)
     {
-        $cacheKey = self::getGenerateAdminDataKey($shopId, $adminId);
+        $cacheKey = self::getGenerateAdminDataKey($mainId, $adminId);
         $keyNameList = Yii::$app->redis->executeCommand('HKEYS', [$cacheKey]);
         if (!empty($keyNameList)) {
             $data = array_merge([$cacheKey], $keyNameList);

+ 36 - 45
biz-hd/admin/services/ShopAdminService.php

@@ -45,14 +45,12 @@ class ShopAdminService extends BaseService
         $shopId = isset($data['shopId']) ? $data['shopId'] : 0;
         $adminId = isset($data['adminId']) ? $data['adminId'] : 0;
         $name = $data['name'] ?? '未命名';
+        $mainId = $data['mainId'] ?? 0;
 
         $bindData = ShopAdminClass::getBindAdminData($shopId, $recommendAdminId);
         if (empty($bindData)) {
             util::fail('小程序码已失效,请重新创建员工');
         }
-        if (isset($admin['subscribe']) == false || $admin['subscribe'] != 1) {
-            //util::fail("请关注公众号");
-        }
         $avatar = $admin['avatar'] ?? '';
 
         $password = isset($bindData['password']) ? password_hash($bindData['password'], PASSWORD_BCRYPT) : '';
@@ -70,23 +68,10 @@ class ShopAdminService extends BaseService
             util::fail('没有找到门店');
         }
 
-        // 添加员工方法
-        $addShopAdminFunc = function () use ($name, $mobile, $password, $remark, $shopId, $adminId, $roleId) {
-            $update = [
-                'currentShopId' => $shopId
-            ];
-            if (!empty($password)) {
-                $update['password'] = $password;
-            }
-            AdminClass::updateById($adminId, $update);
-            // 员工数+1
-            AdminRoleClass::counters(['num' => 1], ['id' => $roleId]);
-        };
-
         $sjId = $shop['sjId'] ?? 0;
-        $shopAdmin = ShopAdminClass::getByCondition(['adminId' => $adminId, 'shopId' => $shopId], true);
+        $shopAdmin = ShopAdminClass::getByCondition(['adminId' => $adminId, 'mainId' => $mainId], true);
         if (!empty($shopAdmin)) {
-            //员工已经删除的补回
+            //删除员工补回
             if ($shopAdmin->delStatus == 1) {
                 $shopAdmin->delStatus = 0;
                 $shopAdmin->roleId = $roleId;
@@ -96,38 +81,44 @@ class ShopAdminService extends BaseService
                 $shopAdmin->remark = $remark;
                 $shopAdmin->name = $name;
                 $shopAdmin->save();
-                // 添加员工方法
-                $addShopAdminFunc();
+
+                $update = ['currentShopId' => $shopId];
+                if (!empty($password)) {
+                    $update['password'] = $password;
+                }
+                AdminClass::updateById($adminId, $update);
+                AdminRoleClass::counters(['num' => 1], ['id' => $roleId]);
 
                 return $shopAdmin->attributes;
             }
             util::fail('您已经是员工');
+        } else {
+            if (isset($bindData['roleId']) == false || empty($bindData['roleId'])) {
+                util::fail('选择角色');
+            }
+            $addData = [
+                'adminId' => $adminId,
+                'shopId' => $shopId,
+                'roleId' => $roleId,
+                'remind' => $remind,
+                'status' => $status,
+                'sjId' => $sjId,
+                'mainId' => $mainId,
+                'name' => $name,
+                'mobile' => $mobile,
+                'avatar' => $avatar,
+                'remark' => $remark,
+            ];
+            ShopAdminClass::delBindAdminData($shopId, $recommendAdminId);
+            $result = ShopAdminClass::add($addData);
+            $update = ['currentShopId' => $shopId];
+            if (!empty($password)) {
+                $update['password'] = $password;
+            }
+            AdminClass::updateById($adminId, $update);
+            AdminRoleClass::counters(['num' => 1], ['id' => $roleId]);
+            return $result;
         }
-
-        if (isset($bindData['roleId']) == false || empty($bindData['roleId'])) {
-            util::fail('添加管理员时请选择角色');
-        }
-
-        $addData = [
-            'adminId' => $adminId,
-            'shopId' => $shopId,
-            'roleId' => $roleId,
-            'remind' => $remind,
-            'status' => $status,
-            'sjId' => $sjId,
-            'name' => $name,
-            'mobile' => $mobile,
-            'avatar' => $avatar,
-            'remark' => $remark,
-        ];
-        ShopAdminClass::delBindAdminData($shopId, $recommendAdminId);
-
-        $result = ShopAdminClass::add($addData);
-
-        // 添加员工方法
-        $addShopAdminFunc();
-
-        return $result;
     }
 
     //获取管理员 ssh 2020.4.21

+ 8 - 8
biz-mall/admin/classes/ShopAdminClass.php

@@ -15,17 +15,17 @@ class ShopAdminClass extends BaseClass
 	const GENERATE_ADMIN_DATA = 'generate_admin_data_';//创建管理员需要的数据
 	
 	//创建管理准备数据key ssh 2020.4.17
-	public static function getGenerateAdminDataKey($shopId, $adminId)
+	public static function getGenerateAdminDataKey($mainId, $adminId)
 	{
-		return self::GENERATE_ADMIN_DATA . $shopId . '_' . $adminId;
+		return self::GENERATE_ADMIN_DATA . $mainId . '_' . $adminId;
 	}
 	
 	//创建管理员数据准备 ssh 2020.4.17
 	public static function prepareBindAdmin($data)
 	{
 		$adminId = $data['adminId'];
-		$shopId = $data['shopId'];
-		$cacheKey = self::getGenerateAdminDataKey($shopId, $adminId);
+		$mainId = $data['mainId'];
+		$cacheKey = self::getGenerateAdminDataKey($mainId, $adminId);
 		$params = [$cacheKey];
 		if (!empty($data)) {
 			foreach ($data as $key => $val) {
@@ -39,9 +39,9 @@ class ShopAdminClass extends BaseClass
 	}
 	
 	//获取创建管理员需要的信息 ssh 2020.4.20
-	public static function getBindAdminData($shopId, $adminId)
+	public static function getBindAdminData($mainId, $adminId)
 	{
-		$cacheKey = self::getGenerateAdminDataKey($shopId, $adminId);
+		$cacheKey = self::getGenerateAdminDataKey($mainId, $adminId);
 		$cacheData = Yii::$app->redis->executeCommand('HGETALL', [$cacheKey]);
 		$data = [];
 		if (!empty($cacheData)) {
@@ -64,9 +64,9 @@ class ShopAdminClass extends BaseClass
 	}
 
 	//删除创建管理员需要的信息 ssh 2020.4.20
-	public static function delBindAdminData($shopId, $adminId)
+	public static function delBindAdminData($mainId, $adminId)
 	{
-		$cacheKey = self::getGenerateAdminDataKey($shopId, $adminId);
+		$cacheKey = self::getGenerateAdminDataKey($mainId, $adminId);
 		$keyNameList = Yii::$app->redis->executeCommand('HKEYS', [$cacheKey]);
 		if (!empty($keyNameList)) {
 			$data = array_merge([$cacheKey], $keyNameList);

+ 24 - 21
biz/shop/classes/ShopAdminClass.php

@@ -24,17 +24,17 @@ class ShopAdminClass extends BaseClass
     }
 
     //创建管理准备数据key ssh 2020.4.17
-    public static function getGenerateAdminDataKey($shopId, $adminId)
+    public static function getGenerateAdminDataKey($mainId, $adminId)
     {
-        return self::GENERATE_ADMIN_DATA . $shopId . '_' . $adminId;
+        return self::GENERATE_ADMIN_DATA . $mainId . '_' . $adminId;
     }
 
     //创建管理员数据准备 ssh 2020.4.17
     public static function prepareBindAdmin($data)
     {
         $adminId = $data['adminId'];
-        $shopId = $data['shopId'];
-        $cacheKey = self::getGenerateAdminDataKey($shopId, $adminId);
+        $mainId = $data['mainId'];
+        $cacheKey = self::getGenerateAdminDataKey($mainId, $adminId);
         $params = [$cacheKey];
         if (!empty($data)) {
             foreach ($data as $key => $val) {
@@ -48,9 +48,9 @@ class ShopAdminClass extends BaseClass
     }
 
     //获取创建管理员需要的信息 ssh 2020.4.20
-    public static function getBindAdminData($shopId, $adminId)
+    public static function getBindAdminData($mainId, $adminId)
     {
-        $cacheKey = self::getGenerateAdminDataKey($shopId, $adminId);
+        $cacheKey = self::getGenerateAdminDataKey($mainId, $adminId);
         $cacheData = Yii::$app->redis->executeCommand('HGETALL', [$cacheKey]);
         $data = [];
         if (!empty($cacheData)) {
@@ -73,9 +73,9 @@ class ShopAdminClass extends BaseClass
     }
 
     //删除创建管理员需要的信息 ssh 2020.4.20
-    public static function delBindAdminData($shopId, $adminId)
+    public static function delBindAdminData($mainId, $adminId)
     {
-        $cacheKey = self::getGenerateAdminDataKey($shopId, $adminId);
+        $cacheKey = self::getGenerateAdminDataKey($mainId, $adminId);
         $keyNameList = Yii::$app->redis->executeCommand('HKEYS', [$cacheKey]);
         if (!empty($keyNameList)) {
             $data = array_merge([$cacheKey], $keyNameList);
@@ -104,17 +104,20 @@ class ShopAdminClass extends BaseClass
     }
 
     //切换门店时增加员工关系 ssh 2021.3.1
-    public static function changeShopAddRelate($originShopAdmin, $toggleShopId)
+    public static function changeShopAddRelate($originShopAdmin, $newShop)
     {
-        $name = $originShopAdmin['name'];
-        $mobile = $originShopAdmin['mobile'];
-        $avatar = $originShopAdmin['avatar'];
-        $adminId = $originShopAdmin['adminId'];
-        $roleId = $originShopAdmin['roleId'];
-        $sjId = $originShopAdmin['sjId'];
-        $super = $originShopAdmin['super'] ?? 0;
-        $has = self::getByCondition(['shopId' => $toggleShopId, 'adminId' => $adminId, 'delStatus' => 0]);
-        if ($has) {
+        $newMainId = $newShop->mainId ?? 0;
+        $name = $originShopAdmin->name ?? '';
+        $mobile = $originShopAdmin->mobile ?? 0;
+        $avatar = $originShopAdmin->avatar ?? '';
+        $adminId = $originShopAdmin->adminId ?? 0;
+        $roleId = $originShopAdmin->roleId ?? 0;
+        $sjId = $originShopAdmin->sjId ?? 0;
+        $super = $originShopAdmin->super ?? 0;
+        $has = self::getByCondition(['mainId' => $newMainId, 'adminId' => $adminId], true);
+        if (!empty($has)) {
+            $has->delStatus = 0;
+            $has->save();
             return $has;
         }
         $data = [
@@ -123,9 +126,9 @@ class ShopAdminClass extends BaseClass
             'avatar' => $avatar,
             'roleId' => $roleId,
             'adminId' => $adminId,
-            'shopId' => $toggleShopId,
             'sjId' => $sjId,
-            'super' => $super
+            'super' => $super,
+            'mainId' => $newMainId,
         ];
         $return = self::addShopAdmin($data, true);
         return $return;
@@ -160,7 +163,7 @@ class ShopAdminClass extends BaseClass
     //是否有切换门店权限 0不是 1是
     public static function hasSwitchShopRight($shopAdmin)
     {
-        $super = isset($shopAdmin['super']) && $shopAdmin['super'] == 1 ? 1 : 0;
+        $super = isset($shopAdmin->super) && $shopAdmin->super == 1 ? 1 : 0;
         return $super;
     }
 

+ 3 - 4
biz/shop/services/ShopAdminService.php

@@ -43,6 +43,7 @@ class ShopAdminService extends BaseService
         $mobile = isset($data['mobile']) ? $data['mobile'] : '';
         $shopId = isset($data['shopId']) ? $data['shopId'] : 0;
         $adminId = isset($data['adminId']) ? $data['adminId'] : 0;
+        $mainId = $data['mainId'] ?? 0;
         $bindData = ShopAdminClass::getBindAdminData($shopId, $recommendAdminId);
         $shop = ShopClass::getById($shopId);
         if (empty($shop)) {
@@ -52,7 +53,7 @@ class ShopAdminService extends BaseService
         if (empty($bindData)) {
             util::fail('小程序码已经失效,请重新创建员工');
         }
-        $shopAdmin = ShopAdminClass::getByCondition(['adminId' => $adminId, 'shopId' => $shopId]);
+        $shopAdmin = ShopAdminClass::getByCondition(['adminId' => $adminId, 'mainId' => $mainId]);
         if (!empty($shopAdmin)) {
             util::fail('您已经是管理员了');
         }
@@ -64,9 +65,6 @@ class ShopAdminService extends BaseService
         if (empty($admin)) {
             util::fail('没有找到管理员信息');
         }
-        if (isset($admin['subscribe']) == false || $admin['subscribe'] != 1) {
-            //util::fail("请关注公众号({$admin['id']})");
-        }
         $roleId = $bindData['roleId'];
         $remind = isset($bindData['remind']) ? $bindData['remind'] : 0;
         $status = isset($bindData['status']) ? $bindData['status'] : 0;
@@ -82,6 +80,7 @@ class ShopAdminService extends BaseService
             'status' => $status,
             'sjId' => $sjId,
             'name' => $name,
+            'mainId' => $mainId,
         ];
         ShopAdminClass::delBindAdminData($shopId, $recommendAdminId);
         return ShopAdminClass::add($addData);

+ 2 - 0
sql.sql

@@ -967,4 +967,6 @@ ALTER TABLE xhAdmin ADD `openHdShop` TINYINT(4) NOT NULL DEFAULT '1' COMMENT '
 ALTER TABLE xhAdmin ADD `currentGhsShopId` INT(11) NOT NULL DEFAULT '0' COMMENT '当前管理的门店' AFTER `openHdShop`;
 ALTER TABLE xhAdmin ADD `openGhsShop` TINYINT(4) NOT NULL DEFAULT '1' COMMENT '申请开店 1没有 2有申请,待审核 3有申请,已审核通过' AFTER `currentGhsShopId`;
 
+ALTER TABLE xhGoodsSetting DROP INDEX `merchantId`;
+
 -- ssh 20220424