diff --git a/app/Http/Controllers/Admin/CourseContentCheckController.php b/app/Http/Controllers/Admin/CourseContentCheckController.php new file mode 100644 index 0000000..ddbcf1c --- /dev/null +++ b/app/Http/Controllers/Admin/CourseContentCheckController.php @@ -0,0 +1,232 @@ +all(); + // 签到用户 + $courseContentCheck = 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']); + } + })->get(); + + $list = CourseSign::with(['course.typeDetail', 'user'])->whereHas('user', function ($query) use ($all) { + if (isset($all['name'])) { + $query->where('name', 'like', '%' . $all['name'] . '%'); + } + if (isset($all['mobile'])) { + $query->where('mobile', 'like', '%' . $all['mobile'] . '%'); + } + })->where(function ($query) use ($all, $courseContentCheck) { + if (isset($all['course_id'])) { + $query->where('course_id', $all['course_id']); + } + if (isset($all['has_check'])) { + if ($all['has_check'] == 1) { + $query->whereIn('user_id', $courseContentCheck->pluck('user_id')); + } else { + $query->whereNotIn('user_id', $courseContentCheck->pluck('user_id')); + } + } + if (isset($all['filter']) && !empty($all['filter'])) { + foreach ($all['filter'] as $condition) { + $key = $condition['key'] ?? null; + $op = $condition['op'] ?? null; + $value = $condition['value'] ?? null; + if (!isset($key) || !isset($op) || !isset($value)) { + continue; + } + // 等于 + if ($op == 'eq') { + $query->where($key, $value); + } + // 不等于 + if ($op == 'neq') { + $query->where($key, '!=', $value); + } + // 模糊搜索 + if ($op == 'like') { + $query->where($key, 'like', '%' . $value . '%'); + } + // 否定模糊搜索 + if ($op == 'notlike') { + $query->where($key, 'not like', '%' . $value . '%'); + } + // 范围搜索 + if ($op == 'range') { + list($from, $to) = explode(',', $value); + if (empty($from) || empty($to)) { + continue; + } + $query->whereBetween($key, [$from, $to]); + } + } + } + })->orderBy($all['sort_name'] ?? 'id', $all['sort_type'] ?? 'desc') + ->orderBy('created_at', 'desc'); + if (isset($all['is_export']) && !empty($all['is_export'])) { + $list = $list->limit(5000)->get()->toArray(); + foreach ($list as &$item) { + $courseContentCheck = CourseContentCheck::where('user_id', $item['user_id']) + ->where(function ($query) use ($all) { + if (isset($all['course_content_id'])) { + $query->where('course_content_id', $all['course_content_id']); + } + if (isset($all['course_id'])) { + $query->where('course_id', $all['course_id']); + } + })->first(); + // 是否存在courseContentCheck + $item['course_content_check_created_at'] = ''; + if ($courseContentCheck) { + $item['course_content_check_text'] = '已签到'; + $item['course_content_check_created_at'] = $courseContentCheck->created_at; + } else { + $item['course_content_check_text'] = '未签到'; + } + } + return Excel::download(new CommonExport($list, $all['export_fields'] ?? ''), $all['file_name'] ?? '' . date('YmdHis') . '.xlsx'); + } else { + // 输出 + $list = $list->paginate($all['page_size'] ?? 20); + foreach ($list as $item) { + $item->course_content_check = CourseContentCheck::where('user_id', $item->user_id) + ->where(function ($query) use ($all) { + if (isset($all['course_content_id'])) { + $query->where('course_content_id', $all['course_content_id']); + } + if (isset($all['course_id'])) { + $query->where('course_id', $all['course_id']); + } + })->first(); + } + } + return $this->success(['list' => $list, 'course_content_check_count' => $courseContentCheck->count()]); + } + + /** + * @OA\Get( + * path="/api/admin/course-content-check/show", + * tags={"签到管理"}, + * summary="详情", + * description="", + * @OA\Parameter(name="id", in="query", @OA\Schema(type="string"), required=true, description="id"), + * @OA\Parameter(name="show_relation", in="query", @OA\Schema(type="string"), required=false, description="需要输出的关联关系数组,填写输出指定数据"), + * @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"), + * @OA\Response( + * response="200", + * description="暂无" + * ) + * ) + */ + public + function show() + { + return parent::show(); + } + + /** + * @OA\Post( + * path="/api/admin/course-content-check/save", + * tags={"签到管理"}, + * summary="保存", + * description="", + * @OA\Parameter(name="id", in="query", @OA\Schema(type="int"), required=true, description="Id(存在更新,不存在新增)"), + * @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="认证token"), + * @OA\Response( + * response="200", + * description="操作成功" + * ) + * ) + */ + public + function save() + { + return parent::save(); + } + + /** + * @OA\Get( + * path="/api/admin/course-content-check/destroy", + * tags={"签到管理"}, + * summary="删除", + * description="", + * @OA\Parameter(name="id", in="query", @OA\Schema(type="string"), required=true, description="id"), + * @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"), + * @OA\Response( + * response="200", + * description="暂无" + * ) + * ) + */ + public + function destroy() + { + return parent::destroy(); + } + +} diff --git a/app/Http/Controllers/Mobile/UserController.php b/app/Http/Controllers/Mobile/UserController.php index 989b9bc..3a5e8c3 100755 --- a/app/Http/Controllers/Mobile/UserController.php +++ b/app/Http/Controllers/Mobile/UserController.php @@ -11,6 +11,7 @@ use App\Jobs\SendAppointCar; use App\Jobs\SendCourseCar; use App\Models\Appointment; use App\Models\Config; +use App\Models\CourseContentCheck; use App\Models\CourseSign; use App\Models\RelatedModel; use App\Models\ScoreLog; @@ -564,6 +565,7 @@ class UserController extends CommonController * summary="短信登陆发送验证码", * description="", * @OA\Parameter(name="course_id", in="query", @OA\Schema(type="string"), required=true, description="课程id"), + * @OA\Parameter(name="course_content_id", in="query", @OA\Schema(type="string"), required=true, description="课表id"), * @OA\Parameter(name="mobile", in="query", @OA\Schema(type="string"), required=true, description="手机号"), * @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"), * @OA\Response( @@ -596,6 +598,21 @@ class UserController extends CommonController if (empty($courseSigns)) { return $this->fail([ResponseCode::ERROR_BUSINESS, '未报名课程']); } + $user = User::where('mobile', $all['mobile'])->first(); + if (empty($user)) { + return $this->fail([ResponseCode::ERROR_BUSINESS, '用户不存在']); + } + $list = CourseContentCheck::where('course_id', $all['course_id']) + ->where(function ($query) use ($all) { + if (isset($all['course_content_id'])) { + $query->where('course_content_id', $all['course_content_id']); + } + })->where('user_id', $user->id) + ->orderBy('created_at', 'desc') + ->get(); + if ($list->isNotEmpty()) { + return $this->success($list); + } $key = 'sms_login_' . $all['mobile']; $check = Cache::get($key); if (isset($check) && time() - $check['time'] <= 60) { diff --git a/app/Models/CourseSign.php b/app/Models/CourseSign.php index ba230e8..31929ae 100755 --- a/app/Models/CourseSign.php +++ b/app/Models/CourseSign.php @@ -42,13 +42,15 @@ class CourseSign extends SoftDeletesModel public function getFilesAttribute($value) { - if (empty($this->file_ids)) return []; + if (empty($this->file_ids)) + return []; return Upload::whereIn('id', $this->file_ids)->get(); } public function getFeeFilesAttribute($value) { - if (empty($this->fee_file_ids)) return []; + if (empty($this->fee_file_ids)) + return []; return Upload::whereIn('id', $this->fee_file_ids)->get(); } diff --git a/public/sign/index.html b/public/sign/index.html index 2a841b9..7e48b14 100644 --- a/public/sign/index.html +++ b/public/sign/index.html @@ -1,2 +1,2 @@