CheckCard.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. dd($end_time - $begin_time);
  27. if($end_time > $begin_time) {
  28. $diff_time = $end_time - $begin_time;
  29. $tmp = floor($diff_time / 3600);
  30. $diff_time = $diff_time % 3600;
  31. if(!empty($tmp)) {
  32. $res .= $tmp . '小时';
  33. }
  34. $tmp = floor($diff_time / 3600);
  35. $diff_time = $diff_time % 60;
  36. if(!empty($tmp)) {
  37. $res .= $tmp . '分钟';
  38. }
  39. if(!empty($diff_time)) {
  40. $res .= $diff_time . '秒';
  41. }
  42. return $res;
  43. }
  44. }
  45. return $res;
  46. }
  47. }