|
@@ -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 {
|