belongsTo(Organization::class)->select(['id', 'name', 'address', 'intro', 'latitude', 'longitude']); } public function timePeriod() { return $this->belongsTo(TimePeriod::class)->select(['id', 'start_time_period', 'end_time_period']); } public function docter() { return $this->hasOne(Docter::class,'id','docter_id'); } public function getOrderNumAttribute() { $map = [1 => 3, 2 => 4, 3 => 5]; $builder = Order::where('product_type', $map[$this->schedule_type]); if ($this->schedule_type == 1) { $builder->where('docter_id', $this->docter_id); } else { $builder->where('organization_id', $this->organization_id); } $timePeriod = TimePeriod::select(['start_time_period'])->where('id', $this->time_period_id)->first(); $appoint_start_time = strtotime($this->schedule_date.' '.$timePeriod['start_time_period'].':00'); $count = $builder->where('is_source', 1)->where('appoint_start_time', $appoint_start_time)->count(); return $count; } }