'json', 'file_ids' => 'json']; protected $appends = ['publicize', 'files']; public function getFilesAttribute($value) { if (empty($this->file_ids)) return []; return Upload::whereIn('id', $this->file_ids)->get(); } public function getPublicizeAttribute($value) { if (empty($this->publicize_ids)) return []; return Upload::whereIn('id', $this->publicize_ids)->get(); } public function course() { return $this->hasOne(Course::class, 'id', 'course_id'); } public function coursePeriod() { return $this->hasOne(CoursePeriod::class, 'id', 'course_period_id'); } public function courseSetting() { return $this->hasOne(CourseSetting::class, 'id', 'course_setting_id'); } public function teacher() { return $this->hasOne(Teacher::class, 'id', 'teacher_id'); } public function courseKeeps() { return $this->hasMany(CourseKeep::class, 'course_content_id', 'id'); } public function courseSigns() { return $this->hasMany(CourseSign::class, 'course_id', 'course_id'); } public function courseContentEvaluation() { return $this->hasOne(CourseContentEvaluation::class, 'course_content_id', 'id'); } public function courseContentEvaluationAsks() { return $this->hasMany(CourseContentEvaluationAsk::class, 'course_content_id', 'id'); } // public function directionDetail() // { // return $this->hasOne(ParameterDetail::class, 'id', 'direction'); // } /** * 获取课程详情小程序码 */ public function getCourseContentCheckQrcode($courseContentId) { $courseContent = self::find($courseContentId); $path = config('filesystems.disks.public.root') . '/course_content_qrcode/' . $courseContent->id . '.png'; $url = config('filesystems.disks.public.url') . '/course_content_qrcode/' . $courseContent->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/index?course_content_id=' . $courseContentId, [ 'env_version' => "release" // 正式版 //'env_version' => "trial" // 体验版 ]); $dir = dirname($path); $fileSys->ensureDirectoryExists($dir, 0755, true); $fileSys->put($path, $tmp); return $url; } }