占位接口

main
岩仔88 2 days ago
parent 11634ecc3a
commit b7ee6bb3ae

@ -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());
}
}
}

@ -88,6 +88,7 @@ Route::group(['middleware'=>['checktoken','log'],'prefix'=>'v1'],function () {
Route::post('admin/PlanTongJi','App\Http\Controllers\API\Admin\YeWu\PlanListController@TongJi');//计划统计
Route::post('admin/PlanDetailChangeInfo','App\Http\Controllers\API\Admin\YeWu\PlanListController@ChangeInfo');//修改计划详情信息
Route::post('admin/PlanListDel','App\Http\Controllers\API\Admin\YeWu\PlanListController@Del');//删除计划详情
Route::post('admin/SaveLockedCount','App\Http\Controllers\API\Admin\YeWu\PlanListController@SaveLockedCount');//保存占位数量
Route::post('admin/GetMainList','App\Http\Controllers\API\Admin\YeWu\WorkMainController@GetList');//获取主表列表
Route::post('admin/GetLoglist','App\Http\Controllers\API\Admin\YeWu\WorkMainController@GetLoglist');//获取日志
Route::post('admin/CancelYuYue','App\Http\Controllers\API\Admin\YeWu\PlanListController@CancelYuYue');//取消预约

Loading…
Cancel
Save