浏览代码

员工修改绑定团队

yb 1 月之前
父节点
当前提交
71740cca88
共有 1 个文件被更改,包括 21 次插入1 次删除
  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\SysDept;
 use app\model\SysUser;
+use support\Db;
 use support\Request;
 
 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 = [
             'name' => $params['name'],
             'mobile' => $params['mobile'],
@@ -198,12 +204,26 @@ class ConsultantService
             'status' => $params['status'] ?? 1,
             'relation_user_id' => $params['relation_user_id'] ?? null,
             'type' => $type,
+            'dept_id' => $params['dept_id'],
+            'top_dept_id' => $topDeptId,
             'updated_at' => time()
         ];
         if (!empty($params['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) {
             return json_success('更新成功');
         } else {