|
|
|
|
@ -531,4 +531,96 @@ FROM
|
|
|
|
|
];
|
|
|
|
|
return \Yz::Return(true, '查询完成', $planInfo);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 保存占位数量
|
|
|
|
|
public function SaveLockedCount(Request $request)
|
|
|
|
|
{
|
|
|
|
|
$userid = $request->get('userid');
|
|
|
|
|
$roster_detail_id = request('roster_detail_id');
|
|
|
|
|
$locked_counts = request('locked_counts');
|
|
|
|
|
|
|
|
|
|
if (empty($roster_detail_id)) {
|
|
|
|
|
return \Yz::echoError1('计划明细ID不能为空');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (empty($locked_counts) || !is_array($locked_counts)) {
|
|
|
|
|
return \Yz::echoError1('占位数量不能为空');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DB::beginTransaction();
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
$changes = []; // 记录有变更的渠道
|
|
|
|
|
|
|
|
|
|
foreach ($locked_counts as $item) {
|
|
|
|
|
$appointment_type_id = $item['appointment_type_id'];
|
|
|
|
|
$locked_count = $item['locked_count'];
|
|
|
|
|
|
|
|
|
|
// 查询对应的记录
|
|
|
|
|
$countRecord = DB::table('s_source_roster_detail_count')
|
|
|
|
|
->where([
|
|
|
|
|
'roster_detail_id' => $roster_detail_id,
|
|
|
|
|
'appointment_type_id' => $appointment_type_id
|
|
|
|
|
])
|
|
|
|
|
->first();
|
|
|
|
|
|
|
|
|
|
if (!$countRecord) {
|
|
|
|
|
DB::rollBack();
|
|
|
|
|
return \Yz::echoError1('未找到对应的渠道数量记录');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 验证占位数量不能超过剩余可用数量
|
|
|
|
|
$remaining = $countRecord->count - $countRecord->used_count;
|
|
|
|
|
if ($locked_count > $remaining) {
|
|
|
|
|
DB::rollBack();
|
|
|
|
|
return \Yz::echoError1('占位数量不能大于剩余可用数量');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($locked_count < 0) {
|
|
|
|
|
DB::rollBack();
|
|
|
|
|
return \Yz::echoError1('占位数量不能为负数');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 记录变更前的值
|
|
|
|
|
$old_locked_count = $countRecord->locked_count;
|
|
|
|
|
|
|
|
|
|
// 只有值有变化时才记录
|
|
|
|
|
if ($old_locked_count != $locked_count) {
|
|
|
|
|
$changes[] = [
|
|
|
|
|
'appointment_type_id' => $appointment_type_id,
|
|
|
|
|
'old_locked_count' => $old_locked_count,
|
|
|
|
|
'new_locked_count' => $locked_count
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// 更新占位数量
|
|
|
|
|
DB::table('s_source_roster_detail_count')
|
|
|
|
|
->where([
|
|
|
|
|
'roster_detail_id' => $roster_detail_id,
|
|
|
|
|
'appointment_type_id' => $appointment_type_id
|
|
|
|
|
])
|
|
|
|
|
->update([
|
|
|
|
|
'locked_count' => $locked_count,
|
|
|
|
|
'updated_at' => date('Y-m-d H:i:s')
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 有变更时记录日志
|
|
|
|
|
if (!empty($changes)) {
|
|
|
|
|
DB::table('s_source_roster_detail_log')->insert([
|
|
|
|
|
'roster_detail_id' => $roster_detail_id,
|
|
|
|
|
'type' => '修改占位数量',
|
|
|
|
|
'content' => json_encode($changes, JSON_UNESCAPED_UNICODE),
|
|
|
|
|
'userid' => $userid
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DB::commit();
|
|
|
|
|
return \Yz::Return(true, '保存成功', []);
|
|
|
|
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
|
DB::rollBack();
|
|
|
|
|
return \Yz::echoError1('保存失败:' . $e->getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|