attributes['teach_teacher_ids'] = '-' . arr2str($val, '-') . '-'; } public function getTeachTeacherIdsAttribute($val) { return str2arr(trim($val, '-'), '-'); } public function getGroupNameAttribute() { $group = (int)$this->attributes['group']; return chr(65 + $group) . '组'; } public function lesson() { return $this->belongsTo(Lesson::class)->select(['id', 'name']); } // public function teacher() // { // return $this->belongsTo(Teacher::class)->select(['id', 'name', 'account']); // } public function teacher() { return $this->belongsTo(Admin::class, 'teacher_admin_id')->select(['id', 'name', 'username']); } public function grade() { return $this->belongsTo(Grade::class)->select(['id', 'name']); } public function room() { return $this->belongsTo(Room::class)->select(['id', 'name']); } public function time() { return $this->belongsTo(Time::class)->select(['id', 'name']); } public static function byTimeGetDate($term_id, $week, $week_index) { return Carbon::parse(optional(Term::byId($term_id))->start_date)->addWeeks($week - 1)->addDays($week_index)->toDateString(); } public static function byDateGetWeek($term_id, $day) { // $day = Carbon::parse($day)->toDateString(); // $week = ceil(Carbon::parse($day)->diffInDays(optional(Term::byId($term_id))->start_date) / 7); $week = ceil((Carbon::parse($day)->diffInDays(optional(Term::byId(1))->start_date) + 1) / 7); $w = Carbon::parse($day)->dayOfWeek; switch ($w) { case 0: $week_index = 6; break; case 1: case 2: case 3: case 4: case 5: case 6: $week_index = $w - 1; break; } return [ 'week' => $week, 'week_index' => $week_index, ]; } public static function toWeekIndex($w) { switch ($w) { case 0: $week_index = 6; break; case 1: case 2: case 3: case 4: case 5: case 6: $week_index = $w - 1; break; } return $week_index; } public static function weekInt2name($week_index) { $map = [ '一', '二', '三', '四', '五', '六', '日', ]; return $map[$week_index]; } public static function groupInt2Name($group) { return chr(65 + $group) . '组'; } }