CheckCard.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. class CheckCard extends Model
  5. {
  6. protected $table = 'check_cards';
  7. protected $guarded = [];
  8. public function student()
  9. {
  10. return $this->belongsTo('App\Models\Student');
  11. }
  12. public function getStudentName()
  13. {
  14. return empty($this['student']) ? '' : $this['student']->name;
  15. }
  16. public function getCourseName()
  17. {
  18. return empty($this['course']) ? '' : $this['course']->name;
  19. }
  20. public function studentCourse()
  21. {
  22. return $this->belongsTo('App\Models\StudentCourse');
  23. }
  24. public function course()
  25. {
  26. return $this->belongsTo('App\Models\Course');
  27. }
  28. public function getDuration()
  29. {
  30. $res = '';
  31. if(!empty($this['begin_date_time']) && !empty($this['end_date_time'])) {
  32. $begin_time = strtotime($this['begin_date_time']);
  33. $end_time = strtotime($this['end_date_time']);
  34. if($end_time > $begin_time) {
  35. $diff_time = $end_time - $begin_time;
  36. $tmp = floor($diff_time / 3600);
  37. $diff_time = $diff_time % 3600;
  38. if(!empty($tmp)) {
  39. $res .= $tmp . '小时';
  40. }
  41. $tmp = floor($diff_time / 60);
  42. $diff_time = $diff_time % 60;
  43. if(!empty($tmp)) {
  44. $res .= $tmp . '分钟';
  45. }
  46. if(!empty($diff_time)) {
  47. $res .= $diff_time . '秒';
  48. }
  49. return $res;
  50. }
  51. }
  52. return $res;
  53. }
  54. }