Procházet zdrojové kódy

删除员工操作

shish před 5 roky
rodič
revize
2c69752429

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

@@ -138,15 +138,8 @@ class ShopAdminController extends BaseController
     public function actionDelete()
     {
         $id = Yii::$app->request->get('id');
-        $relation = ShopAdminClass::getInfo($id);
-        if ($relation['super'] == 1) {
-            util::fail("管理员不能删除");
-        }
-        if($id == $this->shopAdminId){
-            util::fail("不能删自己");
-        }
-        ShopAdminClass::valid($relation, $this->shopId);
-        ShopAdminClass::delRelation($relation);
+        $relation = ShopAdminClass::getById($id, true);
+        \biz\shop\classes\ShopAdminClass::deleteShopAdmin($relation, $this->shopAdminId, $this->shopId);
         util::complete();
     }
 

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

@@ -130,15 +130,8 @@ class ShopAdminController extends BaseController
     public function actionDelete()
     {
         $id = Yii::$app->request->get('id');
-        $relation = ShopAdminClass::getInfo($id);
-        if ($relation['super'] == 1) {
-            util::fail("管理员不能删除");
-        }
-        if ($id == $this->shopAdminId) {
-            util::fail("不能删自己");
-        }
-        ShopAdminClass::valid($relation, $this->shopId);
-        ShopAdminClass::delRelation($relation);
+        $relation = ShopAdminClass::getById($id, true);
+        \biz\shop\classes\ShopAdminClass::deleteShopAdmin($relation, $this->shopAdminId, $this->shopId);
         util::complete();
     }
 }

+ 0 - 17
biz-ghs/shop/classes/ShopAdminClass.php

@@ -100,21 +100,4 @@ class ShopAdminClass extends BaseClass
         return $relation;
     }
 
-    //删除员工关系 ssh 2021.3.27
-    public static function delRelation($relation)
-    {
-        $id = $relation['id'];
-        $shopId = $relation['shopId'];
-        $adminId = $relation['adminId'];
-        $admin = AdminClass::getById($adminId);
-        self::updateById($id, ['delStatus' => 1]);
-        if ($admin['currentShopId'] == $shopId) {
-            $shop = self::getByCondition(['shopId' => $shopId, 'adminId' => $adminId, 'delStatus' => 0]);
-            if (!empty($shop)) {
-                $currentId = $shop['id'];
-                AdminClass::updateById($admin, ['currentShopId' => $currentId]);
-            }
-        }
-    }
-
 }

+ 18 - 10
biz-ghs/shop/services/ShopAdminService.php

@@ -50,7 +50,17 @@ class ShopAdminService extends BaseService
         if (empty($bindData)) {
             util::fail('小程序码已失效,请重新创建');
         }
+        $name = isset($bindData['name']) ? $bindData['name'] : '';
+        $password = isset($bindData['password']) ? password_hash($bindData['password'], PASSWORD_BCRYPT) : '';
+        $remark = isset($bindData['remark']) ? $bindData['remark'] : '';
         $merchantId = $bindData['merchantId'] ?? 0;
+        $status = 1;
+        $remind = isset($bindData['remind']) ? $bindData['remind'] : 0;
+
+        $roleId = $bindData['roleId'] ?? 0;
+        $role = AdminRoleClass::getById($roleId);
+        AdminRoleClass::valid($role, $merchantId);
+
         $shop = ShopClass::getById($shopId);
         Yii::info('merchantId:' . $merchantId . ' shopInfo:' . json_encode($shop));
         ShopClass::valid($shop, $merchantId);
@@ -60,16 +70,18 @@ class ShopAdminService extends BaseService
             //员工已经删除的补回
             if (isset($shopAdmin->delStatus) && $shopAdmin->delStatus == 1) {
                 $shopAdmin->delStatus = 0;
+                $shopAdmin->roleId = $roleId;
+                $shopAdmin->remind = $remind;
+                $shopAdmin->status = $status;
                 $shopAdmin->save();
+
+                $update = ['name' => $name, 'mobile' => $mobile, 'password' => $password, 'remark' => $remark, 'currentShopId' => $shopId];
+                AdminClass::updateById($adminId, $update);
+
                 return $shopAdmin->attributes;
             }
             util::fail('您已经是员工');
         }
-        $name = isset($bindData['name']) ? $bindData['name'] : '';
-
-        $roleId = $bindData['roleId'] ?? 0;
-        $role = AdminRoleClass::getById($roleId);
-        AdminRoleClass::valid($role, $merchantId);
 
         $admin = AdminClass::getById($adminId);
         if (empty($admin)) {
@@ -78,11 +90,7 @@ class ShopAdminService extends BaseService
         if (isset($admin['subscribe']) == false || $admin['subscribe'] != 1) {
             //util::fail("请关注公众号");
         }
-        $roleId = $bindData['roleId'];
-        $remind = isset($bindData['remind']) ? $bindData['remind'] : 0;
-        $status = 1;
-        $password = isset($bindData['password']) ? password_hash($bindData['password'], PASSWORD_BCRYPT) : '';
-        $remark = isset($bindData['remark']) ? $bindData['remark'] : '';
+
         $update = ['name' => $name, 'mobile' => $mobile, 'password' => $password, 'remark' => $remark, 'currentShopId' => $shopId];
         AdminClass::updateById($adminId, $update);
         $addData = [

+ 23 - 11
biz-hd/admin/services/ShopAdminService.php

@@ -45,25 +45,42 @@ class ShopAdminService extends BaseService
         $shopId = isset($data['shopId']) ? $data['shopId'] : 0;
         $adminId = isset($data['adminId']) ? $data['adminId'] : 0;
         $bindData = ShopAdminClass::getBindAdminData($shopId, $recommendAdminId);
-        $shop = ShopClass::getById($shopId);
-        if (empty($shop)) {
-            util::fail('没有找到门店');
-        }
-        $merchantId = isset($shop['merchantId']) ? $shop['merchantId'] : 0;
         if (empty($bindData)) {
             util::fail('小程序码已失效,请重新创建员工');
         }
+
+        $password = isset($bindData['password']) ? password_hash($bindData['password'], PASSWORD_BCRYPT) : '';
+        $remark = isset($bindData['remark']) ? $bindData['remark'] : '';
+        $name = isset($bindData['name']) ? $bindData['name'] : '';
+        $remind = isset($bindData['remind']) ? $bindData['remind'] : 0;
+        $merchantId = $bindData['merchantId'] ?? 0;
+        $status = 1;
+
+        $roleId = $bindData['roleId'] ?? 0;
+        $role = AdminRoleClass::getById($roleId);
+        AdminRoleClass::valid($role, $merchantId);
+
+        $shop = ShopClass::getById($shopId);
+        Yii::info('merchantId:' . $merchantId . ' shopInfo:' . json_encode($shop));
+        ShopClass::valid($shop, $merchantId);
+
         $shopAdmin = ShopAdminClass::getByCondition(['adminId' => $adminId, 'shopId' => $shopId]);
         if (!empty($shopAdmin)) {
             //员工已经删除的补回
             if (isset($shopAdmin->delStatus) && $shopAdmin->delStatus == 1) {
                 $shopAdmin->delStatus = 0;
+                $shopAdmin->roleId = $roleId;
+                $shopAdmin->remind = $remind;
+                $shopAdmin->status = $status;
                 $shopAdmin->save();
+                $update = ['name' => $name, 'mobile' => $mobile, 'password' => $password, 'remark' => $remark, 'currentShopId' => $shopId];
+                AdminClass::updateById($adminId, $update);
+
                 return $shopAdmin->attributes;
             }
             util::fail('您已经是员工');
         }
-        $name = isset($bindData['name']) ? $bindData['name'] : '';
+
         if (isset($bindData['roleId']) == false || empty($bindData['roleId'])) {
             util::fail('添加管理员时请选择角色');
         }
@@ -74,11 +91,6 @@ class ShopAdminService extends BaseService
         if (isset($admin['subscribe']) == false || $admin['subscribe'] != 1) {
             //util::fail("请关注公众号");
         }
-        $roleId = $bindData['roleId'];
-        $remind = isset($bindData['remind']) ? $bindData['remind'] : 0;
-        $status = 1;
-        $password = isset($bindData['password']) ? password_hash($bindData['password'], PASSWORD_BCRYPT) : '';
-        $remark = isset($bindData['remark']) ? $bindData['remark'] : '';
         $update = ['name' => $name, 'mobile' => $mobile, 'password' => $password, 'remark' => $remark, 'currentShopId' => $shopId];
         AdminClass::updateById($adminId, $update);
         $addData = [

+ 31 - 0
biz/shop/classes/ShopAdminClass.php

@@ -2,6 +2,7 @@
 
 namespace biz\shop\classes;
 
+use biz\admin\classes\AdminClass;
 use biz\admin\classes\AdminRoleClass;
 use bizGhs\ws\services\WsService;
 use bizHd\user\classes\UserClass;
@@ -168,4 +169,34 @@ class ShopAdminClass extends BaseClass
         return $super;
     }
 
+    //删除员工 shish 2021.5.3
+    public static function deleteShopAdmin($relation, $thisShopAdminId, $thisShopId)
+    {
+        $id = $relation->id ?? 0;
+        if ($relation->super == 1) {
+            util::fail("管理员不能删除");
+        }
+        if ($id == $thisShopAdminId) {
+            util::fail("不能删自己");
+        }
+        ShopAdminClass::valid($relation, $thisShopId);
+        $adminId = $relation->adminId ?? 0;
+        $currentShopId = $relation->shopId ?? 0;
+        $admin = AdminClass::getById($adminId, true);
+        if (empty($admin)) {
+            util::fail('删除失败');
+        }
+        if (isset($admin->currentShopId) && $admin->currentShopId == $currentShopId) {
+            $has = self::getByCondition(['adminId' => $adminId, 'delStatus' => 0, 'status' => 1], true);
+            if (!empty($has)) {
+                $hasId = $has->shopId;
+                $admin->currentShopId = $hasId;
+            } else {
+                $admin->currentShopId = 0;
+            }
+            $admin->save();
+        }
+        self::updateById($id, ['delStatus' => 1]);
+    }
+
 }