Browse Source

员工修改绑定团队

yb 1 month ago
parent
commit
71740cca88
1 changed files with 21 additions and 1 deletions
  1. 21 1
      app/admin/service/consultant/ConsultantService.php

+ 21 - 1
app/admin/service/consultant/ConsultantService.php

@@ -8,6 +8,7 @@ use app\model\Consultant;
 use app\model\MarketCustomer;
 use app\model\MarketCustomer;
 use app\model\SysDept;
 use app\model\SysDept;
 use app\model\SysUser;
 use app\model\SysUser;
+use support\Db;
 use support\Request;
 use support\Request;
 
 
 class ConsultantService
 class ConsultantService
@@ -190,6 +191,11 @@ class ConsultantService
                 }
                 }
             }
             }
         }
         }
+        //查询上级团队
+        $topDeptId = SysDept::where('dept_id', $params['dept_id'])->where('dept_category', TeamService::DEPT_CATEGORY)->value('dept_super_id');
+        if (!is_numeric($topDeptId)) {
+            return json_fail('团队不存在');
+        }
         $updateData = [
         $updateData = [
             'name' => $params['name'],
             'name' => $params['name'],
             'mobile' => $params['mobile'],
             'mobile' => $params['mobile'],
@@ -198,12 +204,26 @@ class ConsultantService
             'status' => $params['status'] ?? 1,
             'status' => $params['status'] ?? 1,
             'relation_user_id' => $params['relation_user_id'] ?? null,
             'relation_user_id' => $params['relation_user_id'] ?? null,
             'type' => $type,
             'type' => $type,
+            'dept_id' => $params['dept_id'],
+            'top_dept_id' => $topDeptId,
             'updated_at' => time()
             'updated_at' => time()
         ];
         ];
         if (!empty($params['password'])) {
         if (!empty($params['password'])) {
             $updateData['password'] = $password;
             $updateData['password'] = $password;
         }
         }
-        $result = Consultant::where('id', $params['id'])->update($updateData);
+        Db::beginTransaction();
+        try {
+            $result = Consultant::where('id', $params['id'])->update($updateData);
+            if ($info['dept_id'] != $updateData['dept_id']) {
+                //修改员工下客户所属团队
+                MarketCustomer::where('consultant_id', $params['id'])->update(['dept_id' => $params['dept_id']]);
+            }
+            Db::commit();
+        }catch (\Exception $e) {
+            Db::rollBack();
+            return json_fail($e->getMessage());
+        }
+
         if ($result) {
         if ($result) {
             return json_success('更新成功');
             return json_success('更新成功');
         } else {
         } else {