CheckCard.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 studentCourse()
  13. {
  14. return $this->belongsTo('App\Models\StudentCourse');
  15. }
  16. public function course()
  17. {
  18. return $this->belongsTo('App\Models\Course');
  19. }
  20. public function getDuration()
  21. {
  22. $res = '';
  23. if(!empty($this['begin_date_time']) && !empty($this['end_date_time'])) {
  24. $begin_time = strtotime($this['begin_date_time']);
  25. $end_time = strtotime($this['end_date_time']);
  26. if($end_time > $begin_time) {
  27. $diff_time = $end_time - $begin_time;
  28. $tmp = $diff_time / 3600;
  29. $diff_time = $diff_time % 3600;
  30. if(!empty($tmp)) {
  31. $res .= $tmp . '小时';
  32. }
  33. $tmp = $diff_time / 60;
  34. $diff_time = $diff_time % 60;
  35. if(!empty($tmp)) {
  36. $res .= $tmp . '分钟';
  37. }
  38. if(!empty($diff_time)) {
  39. $res .= $diff_time . '秒';
  40. }
  41. return $res;
  42. }
  43. }
  44. return $res;
  45. }
  46. }