// +---------------------------------------------------------------------- namespace App\Models; /** * 会议-模型 * @author laravel开发员 * @since 2020/11/11 * @package App\Models */ class MeetingModel extends BaseModel { // 设置数据表 protected $table = 'meetings'; protected $appends = ['areas','start_time','meeting_time','time_text','time_text1']; public function getThumbAttribute($value) { return $value? get_image_url($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; } // 倒计时开始 public function getStartTimeAttribute() { $dateTime = time(); $time = $this->start_at? strtotime($this->start_at) : 0; return $time>$dateTime?intval($time-$dateTime) : 0; } // 会议时长 public function getMeetingTimeAttribute() { $dateTime = time(); $startTime = $this->start_at? strtotime($this->start_at) : 0; $endTime = $this->end_at? strtotime($this->end_at) : time(); $startTime = $dateTime>$startTime?$dateTime:$startTime; return $endTime>$startTime?intval($endTime-$startTime) : 0; } // 时间 public function getTimeText1Attribute() { $weeks = ['周日','周一','周二','周三','周四','周五','周六']; $startTime = $this->start_at? strtotime($this->start_at) : 0; $endTime = $this->end_at? strtotime($this->end_at) : time(); $w = date('w',$startTime); $week = isset($weeks[$w])?' '.$weeks[$w].' ': ''; $startAt = $this->start_at? datetime($this->start_at,"Y年m月d日").$week.datetime($this->start_at,"H:i") : ''; $formatType = 'm月d日 H:i'; if($endTime && $endTime <= $startTime+86400){ $formatType = 'H:i'; } $endAt = date($formatType,$endTime); return $startAt.' - '.$endAt; } /** * @return array */ public function getAreasAttribute() { return [$this->province_id.'',$this->city_id.'',$this->district_id.'']; } /** * @return array */ public function getStoreIdsAttribute($value) { return $value? array_filter(explode(',', $value)):[]; } /** * @return array */ public function getSupervisorIdsAttribute($value) { return $value? array_filter(explode(',', $value)):[]; } /** * 主办单位 * @return \Illuminate\Database\Eloquent\Relations\HasOne */ public function company() { return $this->hasOne(StoreModel::class, 'id', 'company_id') ->select(['id','user_id', 'realname','avatar', 'nickname', 'mobile', 'status']); } /** * 推荐组织人 */ public function member() { return $this->hasOne(MemberModel::class, 'id','user_id') ->where(['mark'=>1]) ->select(['id', 'nickname','avatar', 'realname','position','company','department','is_auth', 'mobile', 'status']); } /** * 省份 */ public function province() { return $this->hasOne(CityModel::class, 'citycode','province_id') ->where(['mark'=>1]); } /** * 城市 */ public function city() { return $this->hasOne(CityModel::class, 'citycode','city_id') ->where(['mark'=>1]); } /** * 区县 */ public function district() { return $this->hasOne(CityModel::class, 'citycode','district_id') ->where(['mark'=>1]); } /** * 签到记录 * @return \Illuminate\Database\Eloquent\Relations\HasMany */ public function records() { return $this->hasMany(MeetingRecordsModel::class, 'meeting_id','id') ->where(['mark'=>1]); } }