You've already forked lubo_comment_query
							
							
		
			
				
	
	
		
			143 lines
		
	
	
		
			5.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			143 lines
		
	
	
		
			5.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| namespace App\Http\Controllers;
 | |
| 
 | |
| use App\Models\Programs;
 | |
| use App\Models\ProgramVideos;
 | |
| use App\Util\ProgramVideoUtil;
 | |
| use Illuminate\Http\Request;
 | |
| use Illuminate\Routing\Controller as BaseController;
 | |
| use Illuminate\Support\Carbon;
 | |
| use Illuminate\Support\Facades\Storage;
 | |
| 
 | |
| class ProgramVideoConstructController extends BaseController
 | |
| {
 | |
|     public function index(Request $request, Programs $program) {
 | |
|         return view("program.construct.video.index", [
 | |
|             "program" => $program,
 | |
|             "videos" => $program->video_pivots,
 | |
|         ]);
 | |
|     }
 | |
| 
 | |
|     public function add(Request $request) {
 | |
|         return view("program.construct.video.create", [
 | |
|             "program_video" => new ProgramVideos()
 | |
|         ]);
 | |
|     }
 | |
| 
 | |
|     public function create(Request $request, Programs $program) {
 | |
|         $request->validate([
 | |
|             "video_bvid" => ["required"],
 | |
|             "start_part" => ["required", "int"],
 | |
|             "stop_part" => ["required", "int", "gte:start_part"],
 | |
|             "start_time" => ["required", "date_format:H:i:s"],
 | |
|             "stop_time" => ["required", "date_format:H:i:s"],
 | |
|             "created_at" => ["date"],
 | |
|         ]);
 | |
|         $program_video = new ProgramVideos();
 | |
|         $createPayload = $request->only(["start_part", "start_time", "stop_part", "stop_time"]);
 | |
|         $program_video->fill($createPayload);
 | |
|         $program_video->video_bvid = $request->post("video_bvid");
 | |
|         if ($request->hasFile("start_image")) {
 | |
|             $file = $request->file("start_image");
 | |
|             $path = $file->store("lubo_file");
 | |
|             $full_path = Storage::url($path);
 | |
|             $program_video->start_image = $full_path;
 | |
|         }
 | |
|         if ($request->hasFile("stop_image")) {
 | |
|             $file = $request->file("stop_image");
 | |
|             $path = $file->store("lubo_file");
 | |
|             $full_path = Storage::url($path);
 | |
|             $program_video->stop_image = $full_path;
 | |
|         }
 | |
|         if ($request->has("created_at")) {
 | |
|             $program_video->created_at = $request->post("created_at");
 | |
|         }
 | |
|         $program->video_pivots()->save($program_video);
 | |
|         return redirect(route("program.construct.video.list", [
 | |
|             "program"=>$program_video->program_id
 | |
|         ]));
 | |
|     }
 | |
| 
 | |
|     public function edit(Request $request, ProgramVideos $program_video) {
 | |
|         return view("program.construct.video.create", [
 | |
|             "program_video" => $program_video
 | |
|         ]);
 | |
|     }
 | |
| 
 | |
|     public function submit(Request $request, ProgramVideos $program_video) {
 | |
|         $request->validate([
 | |
|             "start_part" => ["required", "int"],
 | |
|             "stop_part" => ["required", "int", "gte:start_part"],
 | |
|             "start_time" => ["required", "date_format:H:i:s"],
 | |
|             "stop_time" => ["required", "date_format:H:i:s"],
 | |
|             "created_at" => ["date"],
 | |
|         ]);
 | |
|         $updatePayload = $request->only(["start_part", "start_time", "stop_part", "stop_time"]);
 | |
|         if ($request->hasFile("start_image")) {
 | |
|             $file = $request->file("start_image");
 | |
|             $path = $file->store("lubo_file");
 | |
|             $full_path = Storage::url($path);
 | |
|             $program_video->start_image = $full_path;
 | |
|         }
 | |
|         if ($request->hasFile("stop_image")) {
 | |
|             $file = $request->file("stop_image");
 | |
|             $path = $file->store("lubo_file");
 | |
|             $full_path = Storage::url($path);
 | |
|             $program_video->stop_image = $full_path;
 | |
|         }
 | |
|         if ($request->has("created_at")) {
 | |
|             $program_video->created_at = $request->post("created_at");
 | |
|         }
 | |
|         $program_video->update($updatePayload);
 | |
|         /**
 | |
|          * @var $program Programs
 | |
|          */
 | |
|         $program = $program_video->program;
 | |
|         $program->created_at = $program->video_pivots()->first()->created_at;
 | |
|         $program->save();
 | |
|         return redirect(route("program.construct.video.list", [
 | |
|             "program"=>$program_video->program_id
 | |
|         ]));
 | |
|     }
 | |
| 
 | |
|     public function to_fix_created_at(Request $request, ProgramVideos $program_video) {
 | |
|         if ($program_video->created_at === null) {
 | |
|             return back()->withInput()->withErrors([
 | |
|                 "id" => "没有开始时间,请先保存对应时间"
 | |
|             ]);
 | |
|         }
 | |
|         return view("program.construct.video.manual_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()->withInput()->withErrors([
 | |
|                 "id" => "没有开始时间,请先保存对应时间"
 | |
|             ]);
 | |
|         }
 | |
|         $each_time = $request->post("each_time");
 | |
|         $each_time_sec = Carbon::createFromFormat("H:i:s", $each_time)->secondsSinceMidnight();
 | |
|         ProgramVideoUtil::fix_created_at_by_manual($program_video, $each_time_sec);
 | |
|         return redirect(route("program.construct.list"));
 | |
|     }
 | |
| 
 | |
|     public function auto_fix_created_at(Request $request, string $bvid)
 | |
|     {
 | |
|         $result = ProgramVideoUtil::fix_created_at_by_part_info($bvid, true);
 | |
|         if ($result) {
 | |
|             return redirect(route("program.construct.list"));
 | |
|         } else {
 | |
|             return back()->withErrors([
 | |
|                 "video_bvid" => "自动修复失败"
 | |
|             ]);
 | |
|         }
 | |
|     }
 | |
| }
 |