SchedulePeriod.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: zilongs
  5. * Date: 20-9-30
  6. * Time: 下午2:51
  7. */
  8. namespace App\Models;
  9. class SchedulePeriod extends BaseModel
  10. {
  11. public function organization()
  12. {
  13. return $this->belongsTo(Organization::class)->select(['id', 'name', 'address', 'intro', 'latitude', 'longitude']);
  14. }
  15. public function timePeriod()
  16. {
  17. return $this->belongsTo(TimePeriod::class)->select(['id', 'start_time_period', 'end_time_period']);
  18. }
  19. public function docter()
  20. {
  21. return $this->hasOne(Docter::class,'id','docter_id');
  22. }
  23. public function getOrderNumAttribute()
  24. {
  25. $map = [1 => 3, 2 => 4, 3 => 5];
  26. $builder = Order::where('product_type', $map[$this->schedule_type]);
  27. if ($this->schedule_type == 1) {
  28. $builder->where('docter_id', $this->docter_id);
  29. }
  30. else {
  31. $builder->where('organization_id', $this->organization_id);
  32. }
  33. $timePeriod = TimePeriod::select(['start_time_period'])->where('id', $this->time_period_id)->first();
  34. $appoint_start_time = strtotime($this->schedule_date.' '.$timePeriod['start_time_period'].':00');
  35. $count = $builder->where('is_source', 1)->where('appoint_start_time', $appoint_start_time)->count();
  36. return $count;
  37. }
  38. }