You've already forked lubo_comment_query
							
							开打时间批量修复功能
This commit is contained in:
		| @@ -6,6 +6,7 @@ use App\Models\Programs; | ||||
| use App\Models\ProgramVideos; | ||||
| use Illuminate\Http\Request; | ||||
| use Illuminate\Routing\Controller as BaseController; | ||||
| use Illuminate\Support\Carbon; | ||||
| use Illuminate\Support\Facades\Storage; | ||||
| 
 | ||||
| class ProgramVideoConstructController extends BaseController | ||||
| @@ -98,4 +99,57 @@ class ProgramVideoConstructController extends BaseController | ||||
|             "program"=>$program_video->program_id | ||||
|         ])); | ||||
|     } | ||||
| 
 | ||||
|     public function to_fix_created_at(Request $request, ProgramVideos $program_video) { | ||||
|         if ($program_video->created_at === null) { | ||||
|             return back()->withErrors([ | ||||
|                 "id" => "没有开始时间,请先保存对应时间" | ||||
|             ]); | ||||
|         } | ||||
|         return view("program.construct.video.time_fix", [ | ||||
|             "program_video" => $program_video | ||||
|         ]); | ||||
|     } | ||||
| 
 | ||||
|     public function fix_created_at_base_on(Request $request, ProgramVideos $program_video) | ||||
|     { | ||||
|         $request->validate([ | ||||
|             "each_time" => ["required", "date_format:H:i:s"] | ||||
|         ]); | ||||
|         if ($program_video->created_at === null) { | ||||
|             return back()->withErrors([ | ||||
|                 "id" => "没有开始时间,请先保存对应时间" | ||||
|             ]); | ||||
|         } | ||||
|         $each_time = $request->post("each_time"); | ||||
|         $each_time_sec = Carbon::createFromFormat("H:i:s", $each_time)->secondsSinceMidnight(); | ||||
|         /** | ||||
|          * @var $program_videos ProgramVideos[] | ||||
|          */ | ||||
|         $program_videos = ProgramVideos::query() | ||||
|             ->where("video_bvid", "=", $program_video->video_bvid) | ||||
|             ->where("id", "!=", $program_video->id) | ||||
|             ->where(function ($query) use ($program_video) { | ||||
|                 $query->where("created_at", ">", $program_video->created_at)->orWhere("created_at", "=", null); | ||||
|             }) | ||||
|             ->get(); | ||||
|         /** | ||||
|          * @var $created_at Carbon | ||||
|          */ | ||||
|         $created_at = $program_video->created_at; | ||||
|         $base_time = $created_at->subSeconds($program_video->start_sec)->subSeconds(($program_video->start_part - 1) * $each_time_sec); | ||||
|         foreach ($program_videos as $video) { | ||||
|             if ($video->id === $program_video->id) { | ||||
|                 continue; | ||||
|             } | ||||
|             $time = $base_time->copy()->addSeconds(($video->start_part - 1) * $each_time_sec)->addSeconds($video->start_sec); | ||||
|             if ($time->second > 30) { | ||||
|                 $time->addMinute(); | ||||
|             } | ||||
|             $time->seconds(0); | ||||
|             $video->created_at = $time; | ||||
|             $video->update(); | ||||
|         } | ||||
|         return redirect(route("program.construct.list")); | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user