ActivityModel.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2017~2021 LARAVEL研发中心
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://www.laravel.cn
  8. // +----------------------------------------------------------------------
  9. // | Author: laravel开发员 <laravel.qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace App\Models;
  12. /**
  13. * 活动-模型
  14. * @author laravel开发员
  15. * @since 2020/11/11
  16. * @package App\Models
  17. */
  18. class ActivityModel extends BaseModel
  19. {
  20. // 设置数据表
  21. protected $table = 'activitys';
  22. protected $appends = ['time_text'];
  23. // 封面图
  24. public function getThumbAttribute($value)
  25. {
  26. $value = $value ? get_image_url($value) : '';
  27. return $value;
  28. }
  29. public function setThumbAttribute($value)
  30. {
  31. return $value ? get_image_path($value) : '';
  32. }
  33. // 时间
  34. public function getCreateTimeAttribute($value)
  35. {
  36. return $value ? datetime($value) : '';
  37. }
  38. // 时间
  39. public function getTimeTextAttribute()
  40. {
  41. $startTime = $this->start_at? strtotime($this->start_at) : 0;
  42. $endTime = $this->end_at? strtotime($this->end_at) : time();
  43. $startAt = $this->start_at? datetime($this->start_at,'m月d日 H:i') : '';
  44. $formatType = 'm月d日 H:i';
  45. if($endTime && $endTime <= $startTime+86400){
  46. $formatType = 'H:i';
  47. }
  48. $endAt = date($formatType,$endTime);
  49. return $startAt.'~'.$endAt;
  50. }
  51. /**
  52. * 签到记录
  53. * @return \Illuminate\Database\Eloquent\Relations\HasMany
  54. */
  55. public function signs()
  56. {
  57. return $this->hasMany(ActivitySignModel::class, 'activity_id','id')
  58. ->where(['mark'=>1]);
  59. }
  60. }