Эх сурвалжийг харах

Merge branch 'shizhongqi-createShop' into dev

shish 1 жил өмнө
parent
commit
f5a2af7de5

+ 23 - 34
app-hd/controllers/AdminController.php

@@ -45,45 +45,34 @@ class AdminController extends BaseController
     //我已离职(从某门店离职)
     public function actionDelStaff()
     {
-        $post = Yii::$app->request->post();
-        $adminId = intval($post['adminId']);
-        $staffId = intval($post['staffId']);
-        if (empty($adminId) || empty($staffId)) {
-            util::fail('参数错误');
-        }
-        if($this->admin->id != $adminId) {
-           util::fail('错误请求');
-        }
-
-        $admin = AdminClass::getById($adminId, true);
-        if (empty($admin)) {
-            util::fail('管理员信息不存在');
-        }
-        $staff = StaffClass::getById($staffId, true);
-        if (empty($staff)) {
-            util::fail('员工信息不存在');
+        $admin = $this->admin;
+        $staff = $this->shopAdmin;
+        if ($staff->founder == 2) {
+            util::fail('老板不能离职');
         }
-        if($staff->founder == 2) {
-           util::fail('店主不执行离职操作');
+        if ($staff->delStatus == 1) {
+            util::fail('您已离职');
         }
-        if($staff->delStatus == 1) {
-           util::fail('帐号已删除');
+        $adminId = $this->adminId;
+        $shop = $this->shop;
+        if ($shop->adminId == $adminId) {
+            util::fail('老板不能离职哦');
         }
 
-         // 使用事务保证数据一致性
-         $connection = Yii::$app->db;
-         $transaction = $connection->beginTransaction();
+        // 使用事务保证数据一致性
+        $connection = Yii::$app->db;
+        $transaction = $connection->beginTransaction();
 
-         try {
-             // 执行离职操作
-             StaffClass::executeStaffResignation($admin, $staff);
-             $transaction->commit();
-             util::complete('离职完成');
-         } catch (\Exception $exception) {
-             $transaction->rollBack();
-             Yii::error("员工离职失败:" . $exception->getMessage());
-             util::fail('离职操作失败');
-         }
+        try {
+            // 执行离职操作
+            StaffClass::executeStaffResignation($admin, $staff);
+            $transaction->commit();
+            util::complete('离职完成');
+        } catch (\Exception $exception) {
+            $transaction->rollBack();
+            Yii::error("员工离职失败:" . $exception->getMessage());
+            util::fail('离职操作失败');
+        }
     }
 
     //个人信息 ssh 20230505

+ 66 - 11
biz-hd/staff/classes/StaffClass.php

@@ -120,26 +120,81 @@ class StaffClass extends BaseClass
      * @param Admin $admin 管理员模型
      * @param Staff $staff 员工模型
      */
-    public function executeStaffResignation($admin, $staff)
+    public static function executeStaffResignation($admin, $staff)
     {
         // 标记员工为已删除
         $staff->delStatus = 1;
         $staff->save();
 
+        $mobile = $admin->mobile;
+
         // 检查管理员是否有自己的门店
-        $shops = ShopClass::getAllByCondition(['adminId' => $admin->id], null, 'id', 'id');
-        if (empty($shops)) {
-            // 情况1:自己没有店,在别人那边当员工
+        $shopList = ShopClass::getAllByCondition(['mobile' => $mobile], null, '*', null, true);
+        if (empty($shopList)) {
+            // 情况1:自己没有店,在别人那边当员工,直接退出
             $admin->currentShopId = 0;
+            $admin->save();
         } else {
-            // 情况2:自己有店,也在其他店当员工
-            $ptStyle = dict::getDict('ptStyle', 'hd');
-            $shop = ShopClass::getByCondition(['adminId' => $admin->id, 'ptStyle' => $ptStyle], 'id');
-            if (empty($shop)) {
-                util::fail('没有找到有效的门店信息');
+            // 情况2:自己有店,自己可能开批零店,也可能只开零售店,也在其他店当员工
+            $hdMainId = 0;
+            $ghsMainId = 0;
+            if (count($shopList) == 1) {
+                foreach ($shopList as $shop) {
+                    if ($shop->ptStyle == 1) {
+                        $admin->currentShopId = $shop->id;
+                        $admin->save();
+                    } else {
+                        util::fail('账号异常,请联系管理员,编号266389');
+                    }
+                }
+            } else {
+                foreach ($shopList as $shop) {
+                    if ($shop->ptStyle == 2) {
+                        $ghsMainId = $shop->mainId;
+                        $admin->currentGhsShopId = $shop->id;
+                    }
+                    if ($shop->ptStyle == 1) {
+                        $hdMainId = $shop->mainId;
+                        $admin->currentShopId = $shop->id;
+                    }
+                }
+                if ($ghsMainId != $hdMainId) {
+                    util::fail('账号异常,请联系管理,编号0068');
+                }
+                if ($ghsMainId == 0) {
+                    util::fail('账号异常,请联系管理,编号006835');
+                }
+            }
+            $adminId = $admin->id;
+            $staffList = StaffClass::getAllByCondition(['mainId' => $hdMainId, 'adminId' => $adminId], null, '*', null, true);
+            if (empty($staffList)) {
+                $role = AdminRoleClass::getByCondition(['mainId' => $hdMainId], true);
+                $roleId = $role->id;
+                $avatar = $admin->avatar;
+                $name = $admin->name;
+                $staffData = [
+                    'adminId' => $adminId,
+                    'mainId' => $hdMainId,
+                    'remind' => 0,
+                    'roleId' => $roleId,
+                    'avatar' => $avatar,
+                    'name' => $name,
+                    'super' => 1,
+                    'finance' => 0,
+                    'switchShop' => 0,
+                    'founder' => 1,
+                    'mobile' => $mobile,
+                ];
+                self::add($staffData);
+            } else {
+                foreach ($staffList as $myStaff) {
+                    $myStaff->delStatus = 0;
+                    $myStaff->save();
+                }
+            }
+            if (count($staffList) > 1) {
+                util::fail('账号异常,请联系管理员56988');
             }
-            $admin->currentShopId = $shop['id'];
         }
-        $admin->save();
     }
 }