Browse Source

员工管理

shish 4 years ago
parent
commit
0138b70e02

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

@@ -73,10 +73,10 @@ class BaseController extends PublicController
                 util::logout('没有找到员工');
             }
             if (isset($shopAdmin->delStatus) && $shopAdmin->delStatus == 1) {
-                util::fail('您不是员工');
+                util::fail('您不是本店员工');
             }
             if (isset($shopAdmin->status) && $shopAdmin->status == 0) {
-                util::fail('您的帐号已被禁用');
+                util::fail('您已被平台禁止登录');
             }
             $this->shopAdmin = $shopAdmin;
             $this->shopAdminId = $shopAdmin->id ?? 0;

+ 16 - 3
app-ghs/controllers/ShopAdminController.php

@@ -281,9 +281,22 @@ class ShopAdminController extends BaseController
         if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
             util::fail('没有权限');
         }
-        $relation = ShopAdminClass::getById($id, true);
-        \biz\shop\classes\ShopAdminClass::deleteShopAdmin($relation, $this->shopAdminId, $this->mainId);
-        util::complete();
+
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try {
+
+            $relation = ShopAdminClass::getById($id, true);
+            \biz\shop\classes\ShopAdminClass::deleteShopAdmin($relation, $this->shopAdminId, $this->mainId);
+            $transaction->commit();
+            util::complete();
+
+        } catch (\Exception $exception) {
+            $transaction->rollBack();
+            Yii::info("失败原因:" . $exception->getMessage());
+            util::fail('删除失败');
+        }
+
     }
 
 }

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

@@ -70,10 +70,10 @@ class BaseController extends PublicController
                 util::logout('没有找到员工信息');
             }
             if (isset($shopAdmin->delStatus) == false || $shopAdmin->delStatus == 1) {
-                util::fail('您不是员工哦');
+                util::fail('您不是本店员工哦');
             }
             if (isset($shopAdmin->status) == false || $shopAdmin->status == 0) {
-                util::fail('您的帐号已被禁用');
+                util::fail('您已被平台禁止登录');
             }
             $this->shopAdmin = $shopAdmin;
             $this->shopAdminId = $shopAdmin->id ?? 0;

+ 15 - 3
app-hd/controllers/ShopAdminController.php

@@ -248,9 +248,21 @@ class ShopAdminController extends BaseController
             util::fail('超管才能操作');
         }
 
-        $relation = ShopAdminClass::getById($id, true);
-        \biz\shop\classes\ShopAdminClass::deleteShopAdmin($relation, $this->shopAdminId, $this->mainId);
-        util::complete();
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
+        try {
+
+            $relation = ShopAdminClass::getById($id, true);
+            StaffClass::deleteStaff($relation, $this->shopAdminId, $this->mainId);
+
+            $transaction->commit();
+            util::complete();
+        } catch (\Exception $exception) {
+            $transaction->rollBack();
+            Yii::info("失败原因:" . $exception->getMessage());
+            util::fail('删除失败');
+        }
+
     }
 
     //获取所有在职员工 ssh 20220507

+ 39 - 1
biz-hd/staff/classes/StaffClass.php

@@ -5,7 +5,6 @@ namespace bizHd\staff\classes;
 use bizHd\admin\classes\AdminClass;
 use bizHd\admin\classes\AdminRoleClass;
 use bizHd\shop\classes\ShopClass;
-use common\components\dict;
 use common\components\sms;
 use common\components\util;
 use Yii;
@@ -16,6 +15,45 @@ class StaffClass extends BaseClass
 
     public static $baseFile = '\bizHd\staff\models\Staff';
 
+    //删除员工 ssh 2021.5.3
+    public static function deleteStaff($relation, $thisShopAdminId, $mainId)
+    {
+        $id = $relation->id ?? 0;
+        if ($relation->founder == 2) {
+            util::fail("超管不能删除");
+        }
+        if ($id == $thisShopAdminId) {
+            util::fail("不能删自己");
+        }
+        self::valid($relation, $mainId);
+        $adminId = $relation->adminId ?? 0;
+        $currentShopId = $relation->shopId ?? 0;
+        $admin = AdminClass::getById($adminId, true);
+        if (empty($admin)) {
+            util::fail('没有找到员工信息');
+        }
+        $admin->currentShopId = 0;
+        $admin->save();
+        $relation->delStatus = 1;
+        $relation->save();
+        //删除员工关系后,再找出这个员工还有没其它门店员工身份补上
+        if (!empty($admin) && isset($admin->currentShopId) && $admin->currentShopId == $currentShopId) {
+            $has = self::getByCondition(['adminId' => $adminId, 'delStatus' => 0, 'status' => 1], true);
+            $hasCurrentShopId = $has->shopId ?? 0;
+            $admin->currentShopId = $hasCurrentShopId;
+            $admin->save();
+        }
+        // 员工数-1
+        AdminRoleClass::counters(['num' => -1], ['id' => $relation->roleId]);
+    }
+
+    public static function valid($relation, $mainId)
+    {
+        if (isset($relation->mainId) == false || $relation->mainId != $mainId) {
+            util::fail('没有权限');
+        }
+    }
+
     //创建员工 ssh 2021.5.9
     public static function appGenerateStaff($data, $admin)
     {

+ 6 - 1
biz/shop/classes/ShopAdminClass.php

@@ -181,13 +181,18 @@ class ShopAdminClass extends BaseClass
         $adminId = $relation->adminId ?? 0;
         $currentShopId = $relation->shopId ?? 0;
         $admin = AdminClass::getById($adminId, true);
+        if (empty($admin)) {
+            util::fail('没有找到员工信息');
+        }
+        $admin->currentGhsShopId = 0;
+        $admin->save();
         $relation->delStatus = 1;
         $relation->save();
         //删除员工关系后,再找出这个员工还有没其它门店员工身份补上
         if (!empty($admin) && isset($admin->currentShopId) && $admin->currentShopId == $currentShopId) {
             $has = self::getByCondition(['adminId' => $adminId, 'delStatus' => 0, 'status' => 1], true);
             $hasCurrentShopId = $has->shopId ?? 0;
-            $admin->currentShopId = $hasCurrentShopId;
+            $admin->currentGhsShopId = $hasCurrentShopId;
             $admin->save();
         }
         // 员工数-1