|
|
<?php
|
|
|
/**
|
|
|
* 课程
|
|
|
*/
|
|
|
|
|
|
namespace App\Http\Controllers\Mobile;
|
|
|
|
|
|
use App\Helpers\ResponseCode;
|
|
|
use App\Models\AccompanyOrder;
|
|
|
use App\Models\AppointmentTotalLog;
|
|
|
use App\Models\Calendar;
|
|
|
use App\Models\Config;
|
|
|
use App\Models\Course;
|
|
|
use App\Models\CourseAppointmentTotal;
|
|
|
use App\Models\CourseContent;
|
|
|
use App\Models\CourseContentCheck;
|
|
|
use App\Models\CourseContentEvaluation;
|
|
|
use App\Models\CourseContentEvaluationForm;
|
|
|
use App\Models\CourseSign;
|
|
|
use App\Models\Notice;
|
|
|
use App\Models\Order;
|
|
|
use App\Models\User;
|
|
|
use EasyWeChat\Factory;
|
|
|
use Illuminate\Support\Carbon;
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
|
|
|
class CourseController extends CommonController
|
|
|
{
|
|
|
|
|
|
/**
|
|
|
* @OA\Get(
|
|
|
* path="/api/mobile/course/notices",
|
|
|
* tags={"小程序-课程"},
|
|
|
* summary="通知公告",
|
|
|
* @OA\Parameter(name="page_size", in="query", @OA\Schema(type="string"), required=false, description="每页显示的条数"),
|
|
|
* @OA\Parameter(name="page", in="query", @OA\Schema(type="string"), required=false, description="页码"),
|
|
|
* @OA\Response(
|
|
|
* response=200,
|
|
|
* description="操作成功"
|
|
|
* )
|
|
|
* )
|
|
|
*/
|
|
|
public function notices()
|
|
|
{
|
|
|
$all = request()->all();
|
|
|
$list = Notice::with('image')->where(function ($query) use ($all) {
|
|
|
|
|
|
})->orderBy('id')->paginate($all['page_size'] ?? 20);
|
|
|
return $this->success($list);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @OA\Get(
|
|
|
* path="/api/mobile/course/course",
|
|
|
* tags={"小程序-课程"},
|
|
|
* summary="课程列表",
|
|
|
* @OA\Parameter(name="page_size", in="query", @OA\Schema(type="string"), required=false, description="每页显示的条数"),
|
|
|
* @OA\Parameter(name="sort_name", in="query", @OA\Schema(type="string"), required=false, description="排序字段名字"),
|
|
|
* @OA\Parameter(name="sort_type", in="query", @OA\Schema(type="string"), required=false, description="排序类型"),
|
|
|
* @OA\Parameter(name="type", in="query", @OA\Schema(type="integer"), description="课程类型"),
|
|
|
* @OA\Parameter(name="status", in="query", @OA\Schema(type="integer"), description="状态"),
|
|
|
* @OA\Parameter(name="page", in="query", @OA\Schema(type="string"), required=false, description="页码"),
|
|
|
* @OA\Response(
|
|
|
* response=200,
|
|
|
* description="操作成功"
|
|
|
* )
|
|
|
* )
|
|
|
*/
|
|
|
public function course()
|
|
|
{
|
|
|
$all = request()->all();
|
|
|
$list = Course::with('image', 'typeDetail')->withCount('courseSigns')->where(function ($query) use ($all) {
|
|
|
if (isset($all['type'])) {
|
|
|
$query->where('type', $all['type']);
|
|
|
}
|
|
|
if (isset($all['status'])) {
|
|
|
$query->where('status', $all['status']);
|
|
|
}
|
|
|
})->whereIn('sign_status', [10, 40])
|
|
|
->where('is_virtual', 0)
|
|
|
->orderBy('sign_status', 'asc')
|
|
|
->orderBy('start_date', 'desc')
|
|
|
->paginate($all['page_size'] ?? 20);
|
|
|
return $this->success($list);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @OA\Get(
|
|
|
* path="/api/mobile/course/course-detail",
|
|
|
* tags={"小程序-课程"},
|
|
|
* summary="课程详情",
|
|
|
* @OA\Parameter(name="course_id", in="query", @OA\Schema(type="string"), required=false, description="课程id"),
|
|
|
* @OA\Response(
|
|
|
* response=200,
|
|
|
* description="操作成功"
|
|
|
* )
|
|
|
* )
|
|
|
*/
|
|
|
public function courseDetail()
|
|
|
{
|
|
|
$all = \request()->all();
|
|
|
$messages = [
|
|
|
'course_id.required' => '课程id必填',
|
|
|
];
|
|
|
$validator = Validator::make($all, [
|
|
|
'course_id' => 'required'
|
|
|
], $messages);
|
|
|
if ($validator->fails()) {
|
|
|
return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
|
|
|
}
|
|
|
$detail = Course::with(['qunImage', 'typeDetail', 'courseForms', 'teacher', 'courseContentEvaluation' => function ($query) {
|
|
|
$query->with(['courseContentEvaluationAsks' => function ($q) {
|
|
|
$q->orderBy('sort', 'asc');
|
|
|
}]);
|
|
|
}])->withCount(['courseSigns as my_user' => function ($query) {
|
|
|
$query->where('user_id', $this->getUserId());
|
|
|
}])->find($all['course_id']);
|
|
|
return $this->success($detail);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @OA\Get(
|
|
|
* path="/api/mobile/course/evaluation-detail",
|
|
|
* tags={"小程序-课程"},
|
|
|
* summary="课程详情",
|
|
|
* @OA\Parameter(name="course_content_evaluation_id", in="query", @OA\Schema(type="string"), required=false, description="问卷id"),
|
|
|
* @OA\Response(
|
|
|
* response=200,
|
|
|
* description="操作成功"
|
|
|
* )
|
|
|
* )
|
|
|
*/
|
|
|
public function evaluationDetail()
|
|
|
{
|
|
|
$all = \request()->all();
|
|
|
$messages = [
|
|
|
'course_content_evaluation_id.required' => '问卷id必填',
|
|
|
];
|
|
|
$validator = Validator::make($all, [
|
|
|
'course_content_evaluation_id' => 'required'
|
|
|
], $messages);
|
|
|
if ($validator->fails()) {
|
|
|
return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
|
|
|
}
|
|
|
$detail = CourseContentEvaluation::with(['courseContentEvaluationAsks' => function ($q) {
|
|
|
$q->with('courseContent.teacher')->orderBy('sort', 'asc');
|
|
|
}])->find($all['course_content_evaluation_id']);
|
|
|
return $this->success($detail);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* @OA\Get(
|
|
|
* path="/api/mobile/course/course-detail-pc",
|
|
|
* tags={"小程序-课程"},
|
|
|
* summary="课程详情PC",
|
|
|
* @OA\Parameter(name="course_id", in="query", @OA\Schema(type="string"), required=false, description="课程id"),
|
|
|
* @OA\Response(
|
|
|
* response=200,
|
|
|
* description="操作成功"
|
|
|
* )
|
|
|
* )
|
|
|
*/
|
|
|
public function courseDetailPc()
|
|
|
{
|
|
|
$all = \request()->all();
|
|
|
$messages = [
|
|
|
'course_id.required' => '课程id必填',
|
|
|
];
|
|
|
$validator = Validator::make($all, [
|
|
|
'course_id' => 'required'
|
|
|
], $messages);
|
|
|
if ($validator->fails()) {
|
|
|
return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
|
|
|
}
|
|
|
$detail = Course::with('typeDetail', 'courseForms', 'teacher')->find($all['course_id']);
|
|
|
return $this->success($detail);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @OA\Post(
|
|
|
* path="/api/mobile/course/sign",
|
|
|
* tags={"小程序-课程"},
|
|
|
* summary="报名",
|
|
|
* @OA\Parameter(name="course_id", in="query", @OA\Schema(type="string"), required=false, description="课程id"),
|
|
|
* @OA\Parameter(name="is_change", in="query", @OA\Schema(type="string"), required=false, description="用户数据是否变化0否1是"),
|
|
|
* @OA\Parameter(name="change_data", in="query", @OA\Schema(type="string"), required=false, description="变化的数组,键值对形式的一维数组"),
|
|
|
* @OA\Parameter(name="data", in="query", @OA\Schema(type="string"), required=false, description="自定义数据的数据,二维数组。包括键名:name,field,value"),
|
|
|
* @OA\Response(
|
|
|
* response=200,
|
|
|
* description="操作成功"
|
|
|
* )
|
|
|
* )
|
|
|
*/
|
|
|
public function sign()
|
|
|
{
|
|
|
$all = \request()->all();
|
|
|
$messages = [
|
|
|
'course_id.required' => '课程id必填',
|
|
|
];
|
|
|
$validator = Validator::make($all, [
|
|
|
'course_id' => 'required'
|
|
|
], $messages);
|
|
|
if ($validator->fails()) {
|
|
|
return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
|
|
|
}
|
|
|
$sign = CourseSign::where('course_id', $all['course_id'])
|
|
|
->where('user_id', $this->getUserId())
|
|
|
->first();
|
|
|
if ($sign) {
|
|
|
return $this->fail([ResponseCode::ERROR_BUSINESS, '请勿重复报名']);
|
|
|
}
|
|
|
$course = Course::find($all['course_id']);
|
|
|
// 报名时间判断
|
|
|
if (!empty($course->sign_start_date)) {
|
|
|
if (time() < strtotime($course->sign_start_date)) {
|
|
|
return $this->fail([ResponseCode::ERROR_BUSINESS, '报名时间未到']);
|
|
|
}
|
|
|
}
|
|
|
if (!empty($course->sign_end_date)) {
|
|
|
if (time() > strtotime($course->sign_end_date) + 86400) {
|
|
|
return $this->fail([ResponseCode::ERROR_BUSINESS, '报名已结束']);
|
|
|
}
|
|
|
}
|
|
|
$result = CourseSign::create([
|
|
|
'is_change' => $all['is_change'] ?? 0,
|
|
|
'course_id' => $all['course_id'],
|
|
|
'user_id' => $this->getUserId(),
|
|
|
'data' => $all['data'] ?? [],
|
|
|
'change_data' => $all['change_data'] ?? [],
|
|
|
'no' => getBatchNo(),
|
|
|
'money' => $course->price,
|
|
|
'title' => $course->name
|
|
|
]);
|
|
|
// 发短信
|
|
|
$smsSign = Config::getValueByKey('sms_sign');
|
|
|
if ($course->is_fee) {
|
|
|
$content = "{$smsSign}您已提交【{$course->name}】报名申请,请等待审核结果。";
|
|
|
} else {
|
|
|
$content = "{$smsSign}您已提交【{$course->name}】报名申请,请等待审核结果通知。";
|
|
|
}
|
|
|
ymSms($this->getUser()->mobile, $content);
|
|
|
return $this->success($result);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @OA\Get(
|
|
|
* path="/api/mobile/course/my-course",
|
|
|
* tags={"小程序-课程"},
|
|
|
* summary="我的课程",
|
|
|
* @OA\Response(
|
|
|
* response=200,
|
|
|
* description="操作成功"
|
|
|
* )
|
|
|
* )
|
|
|
*/
|
|
|
public function myCourse()
|
|
|
{
|
|
|
$list = Course::with('typeDetail', 'courseContentEvaluation')->with(['courseSigns' => function ($query) {
|
|
|
$query->where('user_id', $this->getUserId());
|
|
|
}])->whereHas('courseSigns', function ($query) {
|
|
|
$query->where('user_id', $this->getUserId());
|
|
|
})->where('is_virtual', 0)->orderBy('id', 'desc')->paginate($all['page_size'] ?? 20);
|
|
|
return $this->success(compact('list'));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @OA\Get(
|
|
|
* path="/api/mobile/course/my-course-content",
|
|
|
* tags={"小程序-课程"},
|
|
|
* summary="我的课表",
|
|
|
* @OA\Parameter(name="date", in="query", @OA\Schema(type="string"), required=false, description="日期"),
|
|
|
* @OA\Response(
|
|
|
* response=200,
|
|
|
* description="操作成功"
|
|
|
* )
|
|
|
* )
|
|
|
*/
|
|
|
public function myCourseContent()
|
|
|
{
|
|
|
$date = request('date');
|
|
|
$list = CourseContent::with('course.typeDetail', 'teacher', 'courseContentEvaluation')
|
|
|
->where(function ($query) use ($date) {
|
|
|
if ($date) {
|
|
|
$query->where('date', $date);
|
|
|
}
|
|
|
})->whereHas('course', function ($query) {
|
|
|
$query->where('course_status', '!=', 40)->where('course_content_status', 1);
|
|
|
$query->whereHas('courseSigns', function ($query) {
|
|
|
$query->where('user_id', $this->getUserId())->where('status', 1)->where(function ($q) {
|
|
|
$q->where('fee_status', 1)->orWhere(function ($q) {
|
|
|
$q->whereHas('course', function ($qry) {
|
|
|
$qry->where('is_fee', 0);
|
|
|
});
|
|
|
});
|
|
|
});
|
|
|
});
|
|
|
})->orderBy('date')->get();
|
|
|
return $this->success(compact('list'));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @OA\Get(
|
|
|
* path="/api/mobile/course/course-content-detail",
|
|
|
* 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 courseContentDetail()
|
|
|
{
|
|
|
$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())]);
|
|
|
}
|
|
|
$detail = CourseContent::with(['course', 'teacher', 'courseKeeps', 'courseContentEvaluation' => function ($query) {
|
|
|
$query->with(['courseContentEvaluationAsks' => function ($q) {
|
|
|
$q->orderBy('sort');
|
|
|
}]);
|
|
|
}])->find($all['course_content_id']);
|
|
|
return $this->success($detail);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @OA\Post(
|
|
|
* path="/api/mobile/course/course-content-form",
|
|
|
* tags={"小程序-课程"},
|
|
|
* summary="提交评价",
|
|
|
* @OA\Parameter(name="course_content_evaluation_id", in="query", @OA\Schema(type="string"), required=false, description="问卷id"),
|
|
|
* @OA\Parameter(name="data", in="query", @OA\Schema(type="string"), required=false, description="表单数据数组"),
|
|
|
* @OA\Parameter(name="time_total", in="query", @OA\Schema(type="string"), required=false, description="用时,单位秒"),
|
|
|
* @OA\Response(
|
|
|
* response=200,
|
|
|
* description="操作成功"
|
|
|
* )
|
|
|
* )
|
|
|
*/
|
|
|
public function courseContentForm()
|
|
|
{
|
|
|
$all = \request()->all();
|
|
|
$messages = [
|
|
|
'course_content_evaluation_id.required' => '问卷id必填',
|
|
|
'data.required' => '表单数据必填',
|
|
|
];
|
|
|
$validator = Validator::make($all, [
|
|
|
'course_content_evaluation_id' => 'required',
|
|
|
'data' => 'required',
|
|
|
], $messages);
|
|
|
if ($validator->fails()) {
|
|
|
return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
|
|
|
}
|
|
|
$courseContentEvaluation = CourseContentEvaluation::find($all['course_content_evaluation_id']);
|
|
|
if ($courseContentEvaluation->status == 0) {
|
|
|
return $this->fail([ResponseCode::ERROR_BUSINESS, '问卷未发布']);
|
|
|
}
|
|
|
if (strtotime($courseContentEvaluation->start_time) > time()) {
|
|
|
return $this->fail([ResponseCode::ERROR_BUSINESS, '评价时间未开始']);
|
|
|
}
|
|
|
if (strtotime($courseContentEvaluation->end_time) < time()) {
|
|
|
return $this->fail([ResponseCode::ERROR_BUSINESS, '评价时间已结束']);
|
|
|
}
|
|
|
$courseContentEvaluationForm = CourseContentEvaluationForm::where('user_id', $this->getUserId())
|
|
|
->where('course_content_evaluation_id', $all['course_content_evaluation_id'])
|
|
|
->first();
|
|
|
if ($courseContentEvaluationForm) {
|
|
|
return $this->fail([ResponseCode::ERROR_BUSINESS, '您已提交过评价']);
|
|
|
}
|
|
|
$model = CourseContentEvaluationForm::create([
|
|
|
'course_id' => $courseContentEvaluation->course_id,
|
|
|
'course_content_evaluation_id' => $all['course_content_evaluation_id'],
|
|
|
'user_id' => $this->getUserId(),
|
|
|
'time_total' => $all['time_total'] ?? 0,
|
|
|
'data' => $all['data']
|
|
|
]);
|
|
|
return $this->success($model);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* @OA\Get(
|
|
|
* path="/api/mobile/course/get-sign",
|
|
|
* tags={"小程序-课程"},
|
|
|
* summary="课程报名详情",
|
|
|
* @OA\Response(
|
|
|
* response=200,
|
|
|
* description="操作成功"
|
|
|
* )
|
|
|
* )
|
|
|
*/
|
|
|
public function getSign()
|
|
|
{
|
|
|
$all = \request()->all();
|
|
|
$messages = [
|
|
|
'course_id.required' => '课程id必填',
|
|
|
];
|
|
|
$validator = Validator::make($all, [
|
|
|
'course_id' => 'required'
|
|
|
], $messages);
|
|
|
if ($validator->fails()) {
|
|
|
return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
|
|
|
}
|
|
|
$detail = CourseSign::with('course.typeDetail', 'user')
|
|
|
->where('user_id', $this->getUserId())->where('course_id', $all['course_id'])
|
|
|
->first();
|
|
|
return $this->success(compact('detail'));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @OA\Post(
|
|
|
* path="/api/mobile/course/update-sign",
|
|
|
* tags={"小程序-课程"},
|
|
|
* summary="更新报名信息",
|
|
|
* @OA\Parameter(name="id", in="query", @OA\Schema(type="string"), required=false, description="报名id"),
|
|
|
* @OA\Parameter(name="fee_file_ids", in="query", @OA\Schema(type="string"), required=false, description="文件id数组"),
|
|
|
* @OA\Response(
|
|
|
* response=200,
|
|
|
* description="操作成功"
|
|
|
* )
|
|
|
* )
|
|
|
*/
|
|
|
public function updateSign()
|
|
|
{
|
|
|
$all = \request()->all();
|
|
|
$messages = [
|
|
|
'id.required' => '报名id必填',
|
|
|
];
|
|
|
$validator = Validator::make($all, [
|
|
|
'id' => 'required',
|
|
|
], $messages);
|
|
|
if ($validator->fails()) {
|
|
|
return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
|
|
|
}
|
|
|
$signModel = CourseSign::find($all['id']);
|
|
|
// 如果已缴费或者已上传凭证,不允许修改
|
|
|
if ($signModel->fee_status == 1 || !empty($signModel->fee_file_ids)) {
|
|
|
return $this->fail([ResponseCode::ERROR_BUSINESS, '已缴费或已上传凭证,不允许修改']);
|
|
|
}
|
|
|
$original = $signModel->getOriginal();
|
|
|
$signModel->fill($all);
|
|
|
$signModel->save();
|
|
|
if ($original['status'] == 1 && $signModel->status != 1) {
|
|
|
// 审核通过到其他状态
|
|
|
// 减少预约次数
|
|
|
CourseAppointmentTotal::reduce($signModel->user_id, $signModel->id);
|
|
|
}
|
|
|
return $this->success(compact('signModel'));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @OA\Get(
|
|
|
* path="/api/mobile/course/contents",
|
|
|
* tags={"小程序-课程"},
|
|
|
* summary="课表",
|
|
|
* @OA\Parameter(name="course_id", in="query", @OA\Schema(type="string"), required=false, description="课程id"),
|
|
|
* @OA\Response(
|
|
|
* response=200,
|
|
|
* description="操作成功"
|
|
|
* )
|
|
|
* )
|
|
|
*/
|
|
|
public function contents()
|
|
|
{
|
|
|
$all = \request()->all();
|
|
|
$messages = [
|
|
|
'course_id.required' => '课程id必填',
|
|
|
];
|
|
|
$validator = Validator::make($all, [
|
|
|
'course_id' => 'required'
|
|
|
], $messages);
|
|
|
if ($validator->fails()) {
|
|
|
return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
|
|
|
}
|
|
|
$list = CourseContent::with('teacher', 'course')
|
|
|
->whereHas('course', function ($query) {
|
|
|
$query->where('course_content_status', 1);
|
|
|
})->where('course_id', $all['course_id'])
|
|
|
->orderBy('date', 'asc')
|
|
|
->get();
|
|
|
return $this->success(compact('list'));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @OA\Get(
|
|
|
* path="/api/mobile/course/distance",
|
|
|
* tags={"小程序-计算距离"},
|
|
|
* summary="签到",
|
|
|
* @OA\Parameter(name="course_id", in="query", @OA\Schema(type="string"), required=false, description="课程id(二选一)"),
|
|
|
* @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 distance()
|
|
|
{
|
|
|
$all = \request()->all();
|
|
|
$messages = [
|
|
|
'longitude.required' => '经度必填',
|
|
|
'latitude.required' => '纬度必填',
|
|
|
];
|
|
|
$validator = Validator::make($all, [
|
|
|
'longitude' => 'required',
|
|
|
'latitude' => 'required',
|
|
|
], $messages);
|
|
|
if ($validator->fails()) {
|
|
|
return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
|
|
|
}
|
|
|
// 获取打卡范围,千米
|
|
|
$content_check_range = Config::getValueByKey('content_check_range');
|
|
|
if (isset($all['course_id'])) {
|
|
|
$info = Course::find($all['course_id']);
|
|
|
}
|
|
|
if (isset($all['course_content_id'])) {
|
|
|
$info = CourseContent::find($all['course_content_id']);
|
|
|
}
|
|
|
if (!isset($info)) {
|
|
|
return $this->fail([ResponseCode::ERROR_PARAMETER, '数据不存在']);
|
|
|
}
|
|
|
$distance = getDistance($info->longitude, $info->latitude, $all['longitude'], $all['latitude']);
|
|
|
return $this->success(compact('distance', 'content_check_range'));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @OA\Get(
|
|
|
* path="/api/mobile/course/content-check",
|
|
|
* tags={"小程序-课程"},
|
|
|
* summary="课表签到",
|
|
|
* @OA\Parameter(name="batch_sign", 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 = [
|
|
|
'longitude.required' => '经度必填',
|
|
|
'latitude.required' => '纬度必填',
|
|
|
'course_content_id.required' => '课表id必填',
|
|
|
];
|
|
|
$validator = Validator::make($all, [
|
|
|
'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 ($distance > $content_check_range) {
|
|
|
return $this->fail([ResponseCode::ERROR_BUSINESS, '超出打卡范围']);
|
|
|
}
|
|
|
// 判断当天才能签到
|
|
|
$today = date('Y-m-d');
|
|
|
if ($today != $courseContent->date) {
|
|
|
return $this->fail([ResponseCode::ERROR_BUSINESS, '不在签到时间']);
|
|
|
}
|
|
|
// 不能重复签到
|
|
|
$courseContentCheck = CourseContentCheck::where('course_content_id', $all['course_content_id'])
|
|
|
->where('user_id', $this->getUserId())
|
|
|
->first();
|
|
|
if ($courseContentCheck) {
|
|
|
return $this->fail([ResponseCode::ERROR_BUSINESS, '不能重复签到']);
|
|
|
}
|
|
|
CourseContentCheck::create([
|
|
|
'course_content_id' => $all['course_content_id'],
|
|
|
'course_id' => $courseContent->course_id,
|
|
|
'user_id' => $this->getUserId(),
|
|
|
'longitude' => $all['longitude'],
|
|
|
'latitude' => $all['latitude'],
|
|
|
]);
|
|
|
// 同日期课程批量签到
|
|
|
$batch_sign = request('batch_sign', 0);
|
|
|
if ($batch_sign) {
|
|
|
$courseContentList = CourseContent::where('date', $today)
|
|
|
->whereHas('course', function ($query) {
|
|
|
$query->where('course_status', '!=', 40)->where('course_content_status', 1);
|
|
|
$query->whereHas('courseSigns', function ($query) {
|
|
|
$query->where('user_id', $this->getUserId())->where('status', 1)->where(function ($q) {
|
|
|
$q->where('fee_status', 1)->orWhere(function ($q) {
|
|
|
$q->whereHas('course', function ($qry) {
|
|
|
$qry->where('is_fee', 0);
|
|
|
});
|
|
|
});
|
|
|
});
|
|
|
});
|
|
|
})->get();
|
|
|
foreach ($courseContentList as $courseContent) {
|
|
|
CourseContentCheck::create([
|
|
|
'course_id' => $courseContent->course_id,
|
|
|
'course_content_id' => $courseContent->id,
|
|
|
'user_id' => $this->getUserId(),
|
|
|
'longitude' => $all['longitude'],
|
|
|
'latitude' => $all['latitude'],
|
|
|
]);
|
|
|
}
|
|
|
}
|
|
|
return $this->success('签到成功');
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @OA\Get(
|
|
|
* path="/api/mobile/course/course-check",
|
|
|
* tags={"小程序-课程"},
|
|
|
* summary="课程签到",
|
|
|
* @OA\Parameter(name="course_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 courseCheck()
|
|
|
{
|
|
|
$all = \request()->all();
|
|
|
$messages = [
|
|
|
'longitude.required' => '经度必填',
|
|
|
'latitude.required' => '纬度必填',
|
|
|
'course_id.required' => '课表id必填',
|
|
|
];
|
|
|
$validator = Validator::make($all, [
|
|
|
'longitude' => 'required',
|
|
|
'latitude' => 'required',
|
|
|
'course_id' => 'required'
|
|
|
], $messages);
|
|
|
if ($validator->fails()) {
|
|
|
return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
|
|
|
}
|
|
|
// 获取打卡范围,千米
|
|
|
$content_check_range = Config::getValueByKey('content_check_range');
|
|
|
$course = Course::find($all['course_id']);
|
|
|
if (empty($course->longitude) || empty($course->latitude)) {
|
|
|
return $this->fail([ResponseCode::ERROR_BUSINESS, '请先设置课程经纬度']);
|
|
|
}
|
|
|
$distance = getDistance($course->longitude, $course->latitude, $all['longitude'], $all['latitude']);
|
|
|
if ($distance > $content_check_range) {
|
|
|
return $this->fail([ResponseCode::ERROR_BUSINESS, '超出打卡范围']);
|
|
|
}
|
|
|
// 判断当天才能签到
|
|
|
$today = date('Y-m-d');
|
|
|
if ($today != $course->start_date) {
|
|
|
return $this->fail([ResponseCode::ERROR_BUSINESS, '不在签到时间']);
|
|
|
}
|
|
|
// 不能重复签到
|
|
|
$courseContentCheck = CourseContentCheck::where('course_id', $all['course_id'])
|
|
|
->where('user_id', $this->getUserId())
|
|
|
->first();
|
|
|
if ($courseContentCheck) {
|
|
|
return $this->fail([ResponseCode::ERROR_BUSINESS, '不能重复签到']);
|
|
|
}
|
|
|
CourseContentCheck::create([
|
|
|
'course_id' => $all['course_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_id", in="query", @OA\Schema(type="string"), required=false, description="课程id"),
|
|
|
* @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();
|
|
|
$list = CourseContentCheck::where(function ($query) use ($all) {
|
|
|
if (isset($all['course_id'])) {
|
|
|
$query->where('course_id', $all['course_id']);
|
|
|
}
|
|
|
if (isset($all['course_content_id'])) {
|
|
|
$query->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",
|
|
|
* tags={"小程序-课程"},
|
|
|
* summary="校友库和本班通讯录",
|
|
|
* @OA\Parameter(name="type", in="query", @OA\Schema(type="string"), required=false, description="类型1校友库2本班通讯录"),
|
|
|
* @OA\Parameter(name="course_id", in="query", @OA\Schema(type="string"), required=false, description="课程id"),
|
|
|
* @OA\Parameter(name="name", in="query", @OA\Schema(type="string"), required=false, description="名字"),
|
|
|
* @OA\Parameter(name="company_business", in="query", @OA\Schema(type="string"), required=false, description="主营业务"),
|
|
|
* @OA\Parameter(name="company_name", in="query", @OA\Schema(type="string"), required=false, description="公司名字"),
|
|
|
* @OA\Parameter(name="company_position", in="query", @OA\Schema(type="string"), required=false, description="职务"),
|
|
|
* @OA\Parameter(name="company_area", in="query", @OA\Schema(type="string"), required=false, description="所属区域"),
|
|
|
* @OA\Parameter(name="company_type", in="query", @OA\Schema(type="string"), required=false, description="企业性质"),
|
|
|
* @OA\Parameter(name="company_industry", in="query", @OA\Schema(type="string"), required=false, description="所属行业"),
|
|
|
* @OA\Parameter(name="letter", in="query", @OA\Schema(type="string"), required=false, description="首字母"),
|
|
|
* @OA\Response(
|
|
|
* response=200,
|
|
|
* description="操作成功"
|
|
|
* )
|
|
|
* )
|
|
|
*/
|
|
|
public function userList()
|
|
|
{
|
|
|
$all = \request()->all();
|
|
|
$messages = [
|
|
|
'type.required' => '类型必填',
|
|
|
];
|
|
|
$validator = Validator::make($all, [
|
|
|
'type' => 'required'
|
|
|
], $messages);
|
|
|
if ($validator->fails()) {
|
|
|
return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
|
|
|
}
|
|
|
$list = User::whereHas('courseSigns', function ($query) use ($all) {
|
|
|
if (isset($all['course_id'])) {
|
|
|
$query->where('course_id', $all['course_id']);
|
|
|
}
|
|
|
if ($all['type'] == 2) {
|
|
|
$query->where('status', 1);
|
|
|
}
|
|
|
})->with(['courseSigns' => function ($query) use ($all) {
|
|
|
$query->where('status', 1)->whereHas('course', function ($q) {
|
|
|
$q->where('is_fee', 1);
|
|
|
})->with('course.teacher', 'course.typeDetail')
|
|
|
->orderByRaw("FIELD(fee_status, 1, 0, 2,3)");
|
|
|
if (isset($all['course_id'])) {
|
|
|
$query->where('course_id', $all['course_id']);
|
|
|
}
|
|
|
}])->where(function ($query) use ($all) {
|
|
|
if ($all['type'] == 1) {
|
|
|
$query->where('is_schoolmate', 1);
|
|
|
}
|
|
|
if (isset($all['name'])) {
|
|
|
$query->where('name', 'like', '%' . $all['name'] . '%');
|
|
|
}
|
|
|
if (isset($all['company_business'])) {
|
|
|
$query->where('company_business', 'like', '%' . $all['company_business'] . '%');
|
|
|
}
|
|
|
if (isset($all['company_name'])) {
|
|
|
$query->where('company_name', 'like', '%' . $all['company_name'] . '%');
|
|
|
}
|
|
|
if (isset($all['company_position'])) {
|
|
|
$query->where('company_position', $all['company_position']);
|
|
|
}
|
|
|
if (isset($all['company_area'])) {
|
|
|
$query->where('company_area', 'like', '%' . $all['company_area'] . '%');
|
|
|
}
|
|
|
if (isset($all['company_type'])) {
|
|
|
$company_type = explode(',', $all['company_type']);
|
|
|
$query->where(function ($q) use ($company_type) {
|
|
|
foreach ($company_type as $v) {
|
|
|
$q->orWhereRaw('FIND_IN_SET(?, company_type)', [$v]);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
if (isset($all['company_industry'])) {
|
|
|
$company_industry = explode(',', $all['company_industry']);
|
|
|
$query->where(function ($q) use ($company_industry) {
|
|
|
foreach ($company_industry as $v) {
|
|
|
$q->orWhereRaw('FIND_IN_SET(?, company_industry)', [$v]);
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
if (isset($all['letter'])) {
|
|
|
$query->where('letter', $all['letter']);
|
|
|
}
|
|
|
});
|
|
|
if (isset($all['type']) && $all['type'] == 2) {
|
|
|
$list = $list->orderBy('letter')
|
|
|
->paginate(10);
|
|
|
} else {
|
|
|
$list = $list->orderBy('letter')->paginate(20);
|
|
|
}
|
|
|
$teacher = [];
|
|
|
if (isset($all['type']) && $all['type'] == 2) {
|
|
|
$course = Course::find($all['course_id']);
|
|
|
$teacher = $course['teacher_detail'];
|
|
|
}
|
|
|
return $this->success(compact('list', 'teacher'));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @OA\Get(
|
|
|
* path="/api/mobile/course/news",
|
|
|
* tags={"小程序-课程"},
|
|
|
* summary="文章列表",
|
|
|
* @OA\Parameter(name="page_size", in="query", @OA\Schema(type="string"), required=false, description="每页显示的条数"),
|
|
|
* @OA\Parameter(name="page", in="query", @OA\Schema(type="string"), required=false, description="页码"),
|
|
|
* @OA\Response(
|
|
|
* response=200,
|
|
|
* description="操作成功"
|
|
|
* )
|
|
|
* )
|
|
|
*/
|
|
|
public function news()
|
|
|
{
|
|
|
$page = request('page', 1);
|
|
|
$page_size = request('page_size', 8);
|
|
|
$url = config('app.new_api') . "/e/extend/news.php?page={$page}&pagesize={$page_size}";
|
|
|
$content = file_get_contents($url);
|
|
|
$content = json_decode($content, true);
|
|
|
$pattern = '/\/d\/file\//';
|
|
|
$replacement = config('app.new_api') . '/d/file/';
|
|
|
foreach ($content['rows'] as &$item) {
|
|
|
$item['titlepic'] = preg_replace($pattern, $replacement, $item['titlepic']);
|
|
|
}
|
|
|
return $this->success($content);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @OA\Get(
|
|
|
* path="/api/mobile/course/news-detail",
|
|
|
* tags={"小程序-课程"},
|
|
|
* summary="文章详情",
|
|
|
* @OA\Parameter(name="id", in="query", @OA\Schema(type="string"), required=false, description="id"),
|
|
|
* @OA\Response(
|
|
|
* response=200,
|
|
|
* description="操作成功"
|
|
|
* )
|
|
|
* )
|
|
|
*/
|
|
|
public function newsDetail()
|
|
|
{
|
|
|
$all = \request()->all();
|
|
|
$messages = [
|
|
|
'id.required' => 'id必填',
|
|
|
];
|
|
|
$validator = Validator::make($all, [
|
|
|
'id' => 'required'
|
|
|
], $messages);
|
|
|
if ($validator->fails()) {
|
|
|
return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
|
|
|
}
|
|
|
$url = config('app.new_api') . "/e/extend/news_detail.php?id={$all['id']}";
|
|
|
$detail = file_get_contents($url);
|
|
|
$detail = json_decode($detail, true);
|
|
|
$detail = $detail['rows'];
|
|
|
// 正则表达式替换
|
|
|
// 使用正则表达式替换图片路径
|
|
|
$pattern = '/\/d\/file\//';
|
|
|
$replacement = config('app.new_api') . '/d/file/';
|
|
|
$detail['newstext'] = preg_replace($pattern, $replacement, $detail['newstext']);
|
|
|
return $this->success($detail);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @OA\Get(
|
|
|
* path="/api/mobile/course/pay",
|
|
|
* tags={"小程序-课程"},
|
|
|
* summary="获取支付参数",
|
|
|
* @OA\Parameter(name="payment_no", in="query", @OA\Schema(type="string"), required=false, description="payment_no"),
|
|
|
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
|
|
|
* @OA\Response(
|
|
|
* response="200",
|
|
|
* description="暂无"
|
|
|
* )
|
|
|
* )
|
|
|
*/
|
|
|
public function pay()
|
|
|
{
|
|
|
$all = \request()->all();
|
|
|
$messages = [
|
|
|
'payment_no.required' => '支付订单号必填',
|
|
|
];
|
|
|
$validator = Validator::make($all, [
|
|
|
'payment_no' => 'required',
|
|
|
], $messages);
|
|
|
if ($validator->fails()) {
|
|
|
return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
|
|
|
}
|
|
|
$courseSign = CourseSign::where('payment_no', $all['payment_no'])->first();
|
|
|
if (!$courseSign) {
|
|
|
return $this->fail([ResponseCode::ERROR_PARAMETER, '订单不存在']);
|
|
|
}
|
|
|
if ($courseSign->status != 1) {
|
|
|
return $this->fail([ResponseCode::ERROR_PARAMETER, '审核状态异常']);
|
|
|
}
|
|
|
if ($courseSign->fee_status == 1) {
|
|
|
return $this->fail([ResponseCode::ERROR_PARAMETER, '请勿重复缴费']);
|
|
|
}
|
|
|
$course = Course::find($courseSign->course_id);
|
|
|
if ($course->supply_wechat_pay != 1) {
|
|
|
return $this->fail([ResponseCode::ERROR_PARAMETER, '不支持微信支付']);
|
|
|
}
|
|
|
if (empty($course->is_fee)) {
|
|
|
return $this->fail([ResponseCode::ERROR_PARAMETER, '课程未设置收费']);
|
|
|
}
|
|
|
// 下单
|
|
|
$config = [
|
|
|
'app_id' => config('app.applet_appid'),
|
|
|
'mch_id' => config('app.applet_mch_id'),
|
|
|
'key' => config('app.applet_key')
|
|
|
];
|
|
|
$app = Factory::payment($config);
|
|
|
$result = $app->order->unify([
|
|
|
'trade_type' => 'NATIVE',
|
|
|
'product_id' => $courseSign->payment_no,
|
|
|
'body' => $courseSign->title,
|
|
|
'out_trade_no' => $courseSign->payment_no,
|
|
|
'total_fee' => $courseSign->money * 100,
|
|
|
'notify_url' => getDomain() . '/api/mobile/course/pay_callback',
|
|
|
]);
|
|
|
return $this->success(compact('result'));
|
|
|
}
|
|
|
|
|
|
public function payCallback()
|
|
|
{
|
|
|
$config = [
|
|
|
'app_id' => config('app.applet_appid'),
|
|
|
'mch_id' => config('app.applet_mch_id'),
|
|
|
'key' => config('app.applet_key')
|
|
|
];
|
|
|
// 获取支付参数
|
|
|
$app = Factory::payment($config);
|
|
|
$response = $app->handlePaidNotify(function ($message, $fail) {
|
|
|
if ($message['return_code'] === 'SUCCESS') {
|
|
|
if ($message['result_code'] === 'SUCCESS') {
|
|
|
$order = CourseSign::where('no', $message['out_trade_no'])->first();
|
|
|
if ($order) {
|
|
|
$order->fee_status = 1;
|
|
|
$order->save();
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
} else {
|
|
|
return $fail('通信失败,请稍后再通知我');
|
|
|
}
|
|
|
return true; // 返回处理完成
|
|
|
});
|
|
|
$response->send();
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* @OA\Get(
|
|
|
* path="/api/mobile/course/calendars",
|
|
|
* tags={"小程序-课程"},
|
|
|
* summary="日历",
|
|
|
* @OA\Parameter(name="type", in="query", @OA\Schema(type="string"), required=false, description="类型"),
|
|
|
* @OA\Parameter(name="month", in="query", @OA\Schema(type="string"), required=false, description="月份,例如:2025-01"),
|
|
|
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
|
|
|
* @OA\Response(
|
|
|
* response="200",
|
|
|
* description="暂无"
|
|
|
* )
|
|
|
* )
|
|
|
*/
|
|
|
public function calendars()
|
|
|
{
|
|
|
$all = \request()->all();
|
|
|
$messages = [
|
|
|
'month.required' => '月份必填',
|
|
|
];
|
|
|
$validator = Validator::make($all, [
|
|
|
'month' => 'required',
|
|
|
], $messages);
|
|
|
if ($validator->fails()) {
|
|
|
return $this->fail([ResponseCode::ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
|
|
|
}
|
|
|
$list = Calendar::with('course', 'courseContent')
|
|
|
->where(function ($query) use ($all) {
|
|
|
if (isset($all['type'])) {
|
|
|
$query->where('type', $all['type']);
|
|
|
}
|
|
|
})->where('start_time', 'like', '%' . $all['month'] . '%')
|
|
|
->where('is_publish', 1)
|
|
|
->orderBy('start_time', 'asc')
|
|
|
->get();
|
|
|
|
|
|
return $this->success($list);
|
|
|
}
|
|
|
|
|
|
}
|