master
cody 6 months ago
parent 71a16f0627
commit 7c62174d81

@ -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",

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

@ -0,0 +1,11 @@
<?php
namespace App\Models;
class CourseContentCheck extends SoftDeletesModel
{
}

@ -0,0 +1,38 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('course_content_checks', function (Blueprint $table) {
$table->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');
}
};

@ -0,0 +1,35 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('course_contents', function (Blueprint $table) {
// 经度
$table->string('longitude')->nullable()->comment('经度');
// 纬度
$table->string('latitude')->nullable()->comment('纬度');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('course_contents', function (Blueprint $table) {
//
});
}
};

@ -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"]);
// 预约

Loading…
Cancel
Save