1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- namespace App\Models;
- use Carbon\Carbon;
- use function foo\func;
- use Illuminate\Database\Eloquent\Model;
- class Student extends Model
- {
- protected $table = 'students';
- protected $guarded = [];
- public $marry_list;
- public function __construct(array $attributes = [])
- {
- parent::__construct($attributes);
- $this->marry_list = collect([
- ['key' => 1, 'value' => 1, 'show_value' => '未婚'],
- ['key' => 2, 'value' => 2, 'show_value' => '已婚'],
- // ['key' => 3, 'value' => 3, 'show_value' => '离婚'],
- ]);
- }
- public function getMarryList()
- {
- return $this->marry_list;
- }
- public function getMarry($key = null)
- {
- $key = empty($key) ? $this['marry'] : 1;
- $item = $this->marry_list->where('key', $key)->first();
- return empty($item) ? '未婚' : $item['show_value'];
- }
- public function course()
- {
- return $this->belongsTo('App\Models\Course');
- }
- public function getCheckCardDates()
- {
- return CheckCard::where('student_id', $this['id'])->whereNotNull('begin_date_time')->whereNotNull('end_date_time')->get()->pluck('begin_date_time')->map(function ($item) {
- return substr($item, 0, 10);
- })->unique();
- }
- public function getStudentCourse()
- {
- return StudentCourse::where('student_id', $this['id'])->first();
- }
- public function getIsNew()
- {
- $today = Carbon::today();
- $this_week_begin = null;
- while($today->dayOfWeekIso != 1) {
- $today = $today->subDay();
- }
- $this_week_begin = $today->toDateTimeString();
- $this_week_end = $today->addDays(7)->toDateTimeString();
- $tmp = Remark::where([
- ['student_id', '=', $this['id']],
- ['created_at', '>=', $this_week_begin],
- ['created_at', '<', $this_week_end],
- ])->first();
- return empty($tmp) ? true : false;
- }
- public function getThisWeekAverageScore(Remark $remark)
- {
- $today = Carbon::today();
- $this_week_begin = null;
- while($today->dayOfWeekIso != 1) {
- $today = $today->subDay();
- }
- $this_week_begin = $today->toDateTimeString();
- return RemarkDetail::where([
- ['remark_id', '=', $remark['id']],
- ['created_at', '>=', $this_week_begin],
- ])->get()->avg('score');
- }
- }
|