Pārlūkot izejas kodu

实现"我已离职"接口

shizhongqi 1 gadu atpakaļ
vecāks
revīzija
1368608069

+ 48 - 0
app-hd/controllers/AdminController.php

@@ -7,7 +7,10 @@ use biz\shop\services\ShopAdminService;
 use bizHd\admin\classes\AdminClass;
 use bizHd\admin\classes\ShopAdminClass;
 use bizHd\admin\services\AdminService;
+use bizHd\staff\classes\StaffClass;
+use bizHd\staff\services\StaffService;
 use bizHd\wx\services\WxOpenService;
+use common\components\dict;
 use common\components\imgUtil;
 use common\components\noticeUtil;
 use common\components\util;
@@ -39,6 +42,51 @@ class AdminController extends BaseController
         util::complete();
     }
 
+    //我已离职(从某门店离职)
+    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('员工信息不存在');
+        }
+        if($staff->founder == 2) {
+           util::fail('店主不执行离职操作');
+        }
+        if($staff->delStatus == 1) {
+           util::fail('帐号已删除');
+        }
+
+         // 使用事务保证数据一致性
+         $connection = Yii::$app->db;
+         $transaction = $connection->beginTransaction();
+
+         try {
+             // 执行离职操作
+             $staffServ = new StaffService();
+             $staffServ->executeStaffResignation($admin, $staff);
+             $transaction->commit();
+             util::complete('离职完成');
+         } catch (\Exception $exception) {
+             $transaction->rollBack();
+             Yii::error("员工离职失败:" . $exception->getMessage());
+             util::fail('离职操作失败');
+         }
+    }
+
     //个人信息 ssh 20230505
     public function actionInfo()
     {

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

@@ -42,7 +42,6 @@ class ShopAdminController extends BaseController
     //添加员工
     public function actionAddStaff()
     {
-
         $shopAdmin = $this->shopAdmin;
         if (isset($shopAdmin->super) == false || $shopAdmin->super != 1) {
             util::fail('没有权限');

+ 33 - 1
biz-hd/staff/services/StaffService.php

@@ -2,12 +2,44 @@
 
 namespace bizHd\staff\services;
 
+use biz\shop\classes\ShopClass;
 use bizHd\base\services\BaseService;
-use Yii;
+use common\components\dict;
+use common\components\util;
+use bizHd\admin\models\Admin;
+use bizHd\staff\models\Staff;
 
 class StaffService extends BaseService
 {
 
     public static $baseFile = '\bizHd\staff\classes\StaffClass';
 
+    /**
+     * 执行员工离职操作
+     * @param Admin $admin 管理员模型
+     * @param Staff $staff 员工模型
+     */
+    public function executeStaffResignation($admin, $staff)
+    {
+        // 标记员工为已删除
+        $staff->delStatus = 1;
+        $staff->save();
+
+        // 检查管理员是否有自己的门店
+        $shops = ShopClass::getAllByCondition(['adminId' => $admin->id], null, '*', 'id');
+        if (empty($shops)) {
+            // 情况1:自己没有店,在别人那边当员工
+            $admin->currentShopId = 0;
+        } else {
+            // 情况2:自己有店,但是在别人那边当员工
+            $ptStyle = dict::getDict('ptStyle', 'hd');
+            $shop = ShopClass::getByCondition(['adminId' => $admin->id, 'ptStyle' => $ptStyle]);
+            if (empty($shop)) {
+                util::fail('没有找到有效的门店信息');
+            }
+            $admin->currentShopId = $shop['id'];
+        }
+        $admin->save();
+    }
+
 }