1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Model;
- class CheckCard extends Model
- {
- protected $table = 'check_cards';
- protected $guarded = [];
- public function student()
- {
- return $this->belongsTo('App\Models\Student');
- }
-
- public function getStudentName()
- {
- return empty($this['student']) ? '' : $this['student']->name;
- }
- public function getCourseName()
- {
- return empty($this['course']) ? '' : $this['course']->name;
- }
- public function studentCourse()
- {
- return $this->belongsTo('App\Models\StudentCourse');
- }
- public function course()
- {
- return $this->belongsTo('App\Models\Course');
- }
- public function getDuration()
- {
- $res = '';
- if(!empty($this['begin_date_time']) && !empty($this['end_date_time'])) {
- $begin_time = strtotime($this['begin_date_time']);
- $end_time = strtotime($this['end_date_time']);
- if($end_time > $begin_time) {
- $diff_time = $end_time - $begin_time;
- $tmp = floor($diff_time / 3600);
- $diff_time = $diff_time % 3600;
- if(!empty($tmp)) {
- $res .= $tmp . '小时';
- }
- $tmp = floor($diff_time / 60);
- $diff_time = $diff_time % 60;
- if(!empty($tmp)) {
- $res .= $tmp . '分钟';
- }
- if(!empty($diff_time)) {
- $res .= $diff_time . '秒';
- }
- return $res;
- }
- }
- return $res;
- }
- }
|