master
cody 3 days ago
parent 638e164f4e
commit 29d3b949df

@ -834,20 +834,46 @@ class UserController extends BaseController
if (empty($idsArray)) { if (empty($idsArray)) {
return $this->fail([StarterResponseCode::START_ERROR_PARAMETER, '编号不能为空']); return $this->fail([StarterResponseCode::START_ERROR_PARAMETER, '编号不能为空']);
} }
if (isset($all['is_schoolmate'])) { DB::beginTransaction();
if ($all['is_schoolmate'] == 1) { try {
// 仅当 非校友→校友 时写入 schoolmate_time已是校友的不更新避免覆盖 $updatedCount = 0;
$this->model->whereIn('id', $idsArray)
->whereRaw('COALESCE(is_schoolmate, 0) != 1') if (isset($all['is_schoolmate'])) {
->update(['is_schoolmate' => 1, 'schoolmate_time' => now()]); if ($all['is_schoolmate'] == 1) {
} else { // 改为逐条 save(),确保触发审计日志
$this->model->whereIn('id', $idsArray)->update([ $users = $this->model->whereIn('id', $idsArray)
'is_schoolmate' => $all['is_schoolmate'], ->whereRaw('COALESCE(is_schoolmate, 0) != 1')
'schoolmate_time' => null, ->get();
]);
foreach ($users as $user) {
$user->is_schoolmate = 1;
$user->schoolmate_time = now();
if ($user->isDirty()) {
$user->save();
$updatedCount++;
}
}
} else {
// 改为逐条 save(),确保触发审计日志
$users = $this->model->whereIn('id', $idsArray)->get();
foreach ($users as $user) {
$user->is_schoolmate = $all['is_schoolmate'];
$user->schoolmate_time = null;
if ($user->isDirty()) {
$user->save();
$updatedCount++;
}
}
}
} }
DB::commit();
return $this->success('批量更新成功,共更新 ' . $updatedCount . ' 条记录');
} catch (\Exception $exception) {
DB::rollBack();
return $this->fail([$exception->getCode(), $exception->getMessage()]);
} }
return $this->success('批量更新成功');
} }
/** /**
@ -911,9 +937,20 @@ class UserController extends BaseController
DB::beginTransaction(); DB::beginTransaction();
try { try {
$this->model->whereIn('id', $idsArray)->update($data); $users = $this->model->whereIn('id', $idsArray)->get();
$updatedCount = 0;
foreach ($users as $user) {
// 改为逐条 save(),确保触发审计日志
$user->fill($data);
if ($user->isDirty()) {
$user->save();
$updatedCount++;
}
}
DB::commit(); DB::commit();
return $this->success('批量更新成功,共更新 ' . count($idsArray) . ' 条记录'); return $this->success('批量更新成功,共更新 ' . $updatedCount . ' 条记录');
} catch (\Exception $exception) { } catch (\Exception $exception) {
DB::rollBack(); DB::rollBack();
return $this->fail([$exception->getCode(), $exception->getMessage()]); return $this->fail([$exception->getCode(), $exception->getMessage()]);

@ -349,13 +349,22 @@ class User extends Authenticatable implements Auditable
// 将课程开课时间转换为 datetime 格式 // 将课程开课时间转换为 datetime 格式
$schoolmateTime = Carbon::parse($courseStartDate)->format('Y-m-d H:i:s'); $schoolmateTime = Carbon::parse($courseStartDate)->format('Y-m-d H:i:s');
// 批量更新:只更新还不是校友的学员;从 非校友→校友 时使用课程开课时间作为 schoolmate_time // 改为逐条 save(),确保自动任务也能触发审计日志
return self::whereIn('id', $userIds) $users = self::whereIn('id', $userIds)
->whereRaw('COALESCE(is_schoolmate, 0) != 1') ->whereRaw('COALESCE(is_schoolmate, 0) != 1')
->update([ ->get();
'is_schoolmate' => 1,
'schoolmate_time' => $schoolmateTime $updatedCount = 0;
]); foreach ($users as $user) {
$user->is_schoolmate = 1;
$user->schoolmate_time = $schoolmateTime;
if ($user->isDirty()) {
$user->save();
$updatedCount++;
}
}
return $updatedCount;
} }
} }

@ -195,5 +195,5 @@ return [
| |
*/ */
'console' => false, 'console' => true,
]; ];

@ -0,0 +1,20 @@
目前会影响“校友状态”的主要有 3 类操作:
## 1. 后台批量把一批人设为校友
后台支持批量操作,可以一次把多个人加入校友库,也可以一次把多个人从校友库移除。
这种方式的特点:一次会改很多人。过去这类操作没有审计日志,现在追加上了。
## 2. 导入数据时把用户设为校友
如果导入的表格里本身带有“是否校友”这一列,系统在导入时也可能把用户设为校友。
## 3. 系统自动把符合条件的学员加入校友库
系统有一个半小时一次的自动任务,检测课程开启了自动加入校友库设置,并且课程已经开始的审核通过的学员设置成校友。
## 问题排查说明
- 经排查,创业课-企业出海与境外投资法律风险及规划。这里人员被设置成校友来源于后台的批量设置功能。比如沈杰是在2025-11-20 10:56:00被批量设置成校友的一批的还有周炫坊李融。王洋是在2026-01-12 15:33:42被批量设置成校友的同一批的还有杨湾湾王婷。王文岩是在2026-01-23 17:40:02被批量设置成校友的。
- 终身校友的人员进入了校友库是由于3.20日反馈有人员是终身校友,但是没有校友权益的问题时候,我理解错误并且误操作把终身校友课程下人员批量设置成了校友但是没有及时发现导致的。
Loading…
Cancel
Save