123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- <?php
- /**
- * Created by PhpStorm.
- * User: zilongs
- * Date: 20-9-30
- * Time: 下午2:51
- */
- namespace App\Models;
- class SchedulePeriod extends BaseModel
- {
- public function organization()
- {
- return $this->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;
- }
- }
|