From 7c62174d81491a98a429692503157a7c510030c0 Mon Sep 17 00:00:00 2001 From: cody <648753004@qq.com> Date: Tue, 24 Jun 2025 11:41:36 +0800 Subject: [PATCH] update --- .../Controllers/Mobile/CourseController.php | 84 +++++++++++++++++++ app/Http/functions.php | 18 ++++ app/Models/CourseContentCheck.php | 11 +++ ...931_create_course_content_checks_table.php | 38 +++++++++ ..._24_111502_alert_course_contents_table.php | 35 ++++++++ routes/api.php | 5 ++ 6 files changed, 191 insertions(+) create mode 100755 app/Models/CourseContentCheck.php create mode 100644 database/migrations/2025_06_24_105931_create_course_content_checks_table.php create mode 100644 database/migrations/2025_06_24_111502_alert_course_contents_table.php diff --git a/app/Http/Controllers/Mobile/CourseController.php b/app/Http/Controllers/Mobile/CourseController.php index 551571f..ece9a5e 100755 --- a/app/Http/Controllers/Mobile/CourseController.php +++ b/app/Http/Controllers/Mobile/CourseController.php @@ -12,6 +12,7 @@ use App\Models\Config; use App\Models\Course; use App\Models\CourseAppointmentTotal; use App\Models\CourseContent; +use App\Models\CourseContentCheck; use App\Models\CourseSign; use App\Models\Notice; use App\Models\Order; @@ -357,6 +358,89 @@ class CourseController extends CommonController return $this->success(compact('list')); } + /** + * @OA\Get( + * path="/api/mobile/course/content-check", + * tags={"小程序-课程"}, + * summary="签到", + * @OA\Parameter(name="is_show", in="query", @OA\Schema(type="string"), required=false, description="预览0否1是(返回距离但是不提交签到)"), + * @OA\Parameter(name="course_content_id", in="query", @OA\Schema(type="string"), required=false, description="课表id"), + * @OA\Parameter(name="longitude", in="query", @OA\Schema(type="string"), required=false, description="longitude"), + * @OA\Parameter(name="latitude", in="query", @OA\Schema(type="string"), required=false, description="latitude"), + * @OA\Response( + * response=200, + * description="操作成功" + * ) + * ) + */ + public function contentCheck() + { + $all = \request()->all(); + $messages = [ + 'is_show.required' => '预览必填', + 'longitude.required' => '经度必填', + 'latitude.required' => '纬度必填', + 'course_content_id.required' => '课程id必填', + ]; + $validator = Validator::make($all, [ + 'is_show' => 'required', + 'longitude' => 'required', + 'latitude' => 'required', + 'course_content_id' => 'required' + ], $messages); + if ($validator->fails()) { + return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]); + } + // 获取打卡范围,千米 + $content_check_range = Config::getValueByKey('content_check_range'); + $courseContent = CourseContent::find($all['course_content_id']); + $distance = getDistance($courseContent->longitude, $courseContent->latitude, $all['longitude'], $all['latitude']); + if ($all['is_show'] == 1) { + return $this->success(compact('distance', 'content_check_range')); + } + if ($distance > $content_check_range) { + return $this->fail([ResponseCode::ERROR_BUSINESS, '超出打卡范围']); + } + CourseContentCheck::create([ + 'course_content_id' => $all['course_content_id'], + 'user_id' => $this->getUserId(), + 'longitude' => $all['longitude'], + 'latitude' => $all['latitude'], + ]); + return $this->success('打卡成功'); + } + + /** + * @OA\Get( + * path="/api/mobile/course/content-check-list", + * tags={"小程序-课程"}, + * summary="获取签到记录", + * @OA\Parameter(name="course_content_id", in="query", @OA\Schema(type="string"), required=false, description="课表id"), + * @OA\Response( + * response=200, + * description="操作成功" + * ) + * ) + */ + public function contentCheckList() + { + $all = \request()->all(); + $messages = [ + 'course_content_id.required' => '课程id必填', + ]; + $validator = Validator::make($all, [ + 'course_content_id' => 'required' + ], $messages); + if ($validator->fails()) { + return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]); + } + $list = CourseContentCheck::where('course_content_id', $all['course_content_id']) + ->where('user_id', $this->getUserId()) + ->orderBy('created_at', 'desc') + ->get(); + return $this->success(compact('list')); + } + /** * @OA\Get( * path="/api/mobile/course/user-list", diff --git a/app/Http/functions.php b/app/Http/functions.php index 37f483f..1bdc307 100755 --- a/app/Http/functions.php +++ b/app/Http/functions.php @@ -669,3 +669,21 @@ function isMultiDimensionalArray($array) { return is_array($array) && count(array_filter($array, 'is_array')) > 0; } + +/** + * 求两个已知经纬度之间的距离,单位为km + * @param lat1,lat2 纬度 + * @param lng1,lng2 经度 + * @return float 距离,单位为km + **/ +function getDistance($lat1,$lng1,$lat2,$lng2){ +//将角度转为狐度 + $radLat1 = deg2rad($lat1);//deg2rad()函数将角度转换为弧度 + $radLat2 = deg2rad($lat2); + $radLng1 = deg2rad($lng1); + $radLng2 = deg2rad($lng2); + $a = $radLat1 - $radLat2; + $b = $radLng1 - $radLng2; + $s =2*asin(sqrt(pow(sin($a/2),2)+cos($radLat1)*cos($radLat2)*pow(sin($b/2),2)))*6371; + return round($s,1); +} diff --git a/app/Models/CourseContentCheck.php b/app/Models/CourseContentCheck.php new file mode 100755 index 0000000..905877a --- /dev/null +++ b/app/Models/CourseContentCheck.php @@ -0,0 +1,11 @@ +id(); + $table->integer('course_content_id')->nullable()->comment('课程排课id'); + $table->integer('user_id')->nullable()->comment('用户id'); + // 经度 + $table->string('longitude')->nullable()->comment('经度'); + // 纬度 + $table->string('latitude')->nullable()->comment('纬度'); + $table->timestamps(); + $table->softDeletes(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('course_contents'); + } +}; diff --git a/database/migrations/2025_06_24_111502_alert_course_contents_table.php b/database/migrations/2025_06_24_111502_alert_course_contents_table.php new file mode 100644 index 0000000..8c500ea --- /dev/null +++ b/database/migrations/2025_06_24_111502_alert_course_contents_table.php @@ -0,0 +1,35 @@ +string('longitude')->nullable()->comment('经度'); + // 纬度 + $table->string('latitude')->nullable()->comment('纬度'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('course_contents', function (Blueprint $table) { + // + }); + } +}; diff --git a/routes/api.php b/routes/api.php index 2b27de9..9a231cb 100755 --- a/routes/api.php +++ b/routes/api.php @@ -231,6 +231,11 @@ Route::group(["namespace" => "Mobile", "prefix" => "mobile"], function () { Route::get('course/pay', [\App\Http\Controllers\Mobile\CourseController::class, "pay"]); Route::get('course/contents', [\App\Http\Controllers\Mobile\CourseController::class, "contents"]); + // 签到 + Route::get('course/content-check', [\App\Http\Controllers\Mobile\CourseController::class, "contentCheck"]); + // 签到列表 + Route::get('course/content-check-list', [\App\Http\Controllers\Mobile\CourseController::class, "contentCheckList"]); + // 校友库 Route::get('course/user-list', [\App\Http\Controllers\Mobile\CourseController::class, "userList"]); // 预约