// +---------------------------------------------------------------------- namespace App\Models; /** * 会议-模型 * @author laravel开发员 * @since 2020/11/11 * @package App\Models */ class MeetingModel extends BaseModel { // 设置数据表 protected $table = 'meetings'; protected $appends = ['areas','time_text']; 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; } /** * @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)):[]; } /** * 推荐组织人 */ 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]); } }