'json']; public function getStatusTextAttribute() { $array = [0 => '待发布', 1 => '已发布']; return $array[$this->attributes['status']]; } public function getIsFeeTextAttribute() { $array = [0 => '免费', 1 => '收费']; return $array[$this->attributes['is_fee']]; } public function getIsArrangeTextAttribute() { $array = [0 => '否', 1 => '是']; return $array[$this->attributes['is_arrange']]; } public function getShowTxlTextAttribute() { $array = [0 => '否', 1 => '是']; return $array[$this->attributes['show_txl']]; } public function getShowMobileTextAttribute() { $array = [0 => '否', 1 => '是']; return $array[$this->attributes['show_mobile']]; } public function getAutoSchoolmateTextAttribute() { $array = [0 => '否', 1 => '是']; return $array[$this->attributes['auto_schoolmate']]; } public function getIsVirtualTextAttribute() { $array = [0 => '否', 1 => '是']; return $array[$this->attributes['is_virtual']]; } public function getQrcodeAttribute($value) { return $this->getCourseQrcode($this->attributes['id']); } public function getTeacherDetailAttribute($value) { $teacherIds = explode(',', $this->teacher_id); return Teacher::whereIn('id', $teacherIds)->get(); } public function getPublicizeAttribute($value) { if (empty($this->publicize_ids)) return []; return Upload::whereIn('id', $this->publicize_ids)->get(); } public function getDateStatusAttribute() { $text = '课程未开始'; if ($this->course_status == 10) { $text = '课程进行中'; } if ($this->course_status == 40) { $text = '课程已结束'; } return $text; } public function getSignDateStatusAttribute() { $text = '未开始'; if ($this->sign_status == 10) { $text = '进行中'; } if ($this->sign_status == 40) { $text = '已结束'; } return $text; } public function typeDetail() { return $this->hasOne(CourseType::class, 'id', 'type'); } public function courseForms() { return $this->hasMany(CourseForm::class, 'course_id', 'id'); } public function teacher() { return $this->hasOne(Teacher::class, 'id', 'teacher_id'); } public function courseSettings() { return $this->hasMany(CourseSetting::class, 'course_id', 'id'); } public function coursePeriods() { return $this->hasMany(CoursePeriod::class, 'course_id', 'id'); } public function courseSigns() { return $this->hasMany(CourseSign::class, 'course_id', 'id'); } public function image() { return $this->hasOne(Upload::class, 'id', 'image_id'); } public function qunImage() { return $this->hasOne(Upload::class, 'id', 'qun_image_id'); } public function courseContents() { return $this->hasMany(CourseContent::class, 'course_id', 'id'); } public function courseContentEvaluation() { return $this->hasMany(CourseContentEvaluation::class, 'course_id', 'id'); } /** * 更新课程报名状态 */ public static function updateSignStatus($courseId) { // 进行中-未开始-已结束 $now = date('Y-m-d'); $course = Course::find($courseId); // 默认未开始 $sign_status = 30; if ($course->sign_start_date && $now < $course->sign_start_date) { // 未开始 $sign_status = 20; } if ($course->sign_start_date && $now >= $course->sign_start_date) { // 进行中 $sign_status = 10; } if ($course->sign_end_date && $now > $course->sign_end_date) { // 已结束 $sign_status = 40; } $course->sign_status = $sign_status; $course->save(); return $course; } /** * 更新课程状态 */ public static function updateStatus($courseId) { // 进行中-未开始-已结束 $now = date('Y-m-d'); $course = Course::find($courseId); // 默认待定 $course_status = 30; if ($course->start_date && $now < $course->start_date) { // 未开始 $course_status = 20; } if ($course->start_date && $now >= $course->start_date) { // 进行中 $course_status = 10; } if ($course->end_date && $now > $course->end_date) { // 已结束 $course_status = 40; } $course->course_status = $course_status; $course->save(); return $course; } /** * 获取课程详情小程序码 */ public function getCourseQrcode($courseId) { $course = Course::find($courseId); $path = config('filesystems.disks.public.root') . '/course_qrcode/' . $course->id . '.png'; $url = config('filesystems.disks.public.url') . '/course_qrcode/' . $course->id . '.png'; $fileSys = new Filesystem(); if ($fileSys->exists($path)) { return $url; } $config = [ 'app_id' => \config('app.applet_appid'), 'secret' => \config('app.applet_secret') ]; $app = Factory::miniProgram($config); $tmp = $app->app_code->get('packages/course/detail?' . 'id=' . $courseId, [ 'env_version' => "release" // 正式版 // 'env_version' => "trial" // 体验版 ]); $dir = dirname($path); $fileSys->ensureDirectoryExists($dir, 0755, true); $fileSys->put($path, $tmp); return $url; } /** * 获取课程报名小程序码 */ public function getCourseCheckQrcode($courseId) { $course = Course::find($courseId); $path = config('filesystems.disks.public.root') . '/course_check_qrcode/' . $course->id . '.png'; $url = config('filesystems.disks.public.url') . '/course_check_qrcode/' . $course->id . '.png'; $fileSys = new Filesystem(); if ($fileSys->exists($path)) { return $url; } $config = [ 'app_id' => \config('app.applet_appid'), 'secret' => \config('app.applet_secret') ]; $app = Factory::miniProgram($config); $tmp = $app->app_code->get('packages/sign/course?course_id=' . $courseId, [ 'env_version' => "release" // 正式版 ]); $dir = dirname($path); $fileSys->ensureDirectoryExists($dir, 0755, true); $fileSys->put($path, $tmp); return $url; } /** * 获取问卷小程序码 */ public function getEvaluationQrcode($id) { $courseContentEvaluation = CourseContentEvaluation::find($id); $path = config('filesystems.disks.public.root') . '/course_evaluation_qrcode/' . $courseContentEvaluation->id . '.png'; $url = config('filesystems.disks.public.url') . '/course_evaluation_qrcode/' . $courseContentEvaluation->id . '.png'; $fileSys = new Filesystem(); if ($fileSys->exists($path)) { return $url; } $config = [ 'app_id' => \config('app.applet_appid'), 'secret' => \config('app.applet_secret') ]; $app = Factory::miniProgram($config); $tmp = $app->app_code->get('packages/surveyFill/index?id=' . $id, [ // todo:: 版本切换 'env_version' => "release" // 正式版 // 'env_version' => "trial" // 体验版 ]); $dir = dirname($path); $fileSys->ensureDirectoryExists($dir, 0755, true); $fileSys->put($path, $tmp); return $url; } }