// +---------------------------------------------------------------------- namespace App\Models; /** * 活动-模型 * @author laravel开发员 * @since 2020/11/11 * @package App\Models */ class ActivityModel extends BaseModel { // 设置数据表 protected $table = 'activitys'; protected $appends = ['time_text']; // 封面图 public function getThumbAttribute($value) { $value = $value ? get_image_url($value) : ''; return $value; } public function setThumbAttribute($value) { return $value ? get_image_path($value) : ''; } // 时间 public function getCreateTimeAttribute($value) { return $value ? datetime($value) : ''; } // 时间 public function getTimeTextAttribute() { $startTime = $this->start_at? strtotime($this->start_at) : 0; $endTime = $this->end_at? strtotime($this->end_at) : time(); $startAt = $this->start_at? datetime($this->start_at,'m月d日 H:i') : ''; $formatType = 'm月d日 H:i'; if($endTime && $endTime <= $startTime+86400){ $formatType = 'H:i'; } $endAt = date($formatType,$endTime); return $startAt.'~'.$endAt; } /** * 签到记录 * @return \Illuminate\Database\Eloquent\Relations\HasMany */ public function signs() { return $this->hasMany(ActivitySignModel::class, 'activity_id','id') ->where(['mark'=>1]); } }