Appointment.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace app\common\model;
  3. use think\Exception;
  4. use think\Model;
  5. class Appointment extends Model
  6. {
  7. protected $updateTime = false;
  8. const STATUS_OPEN = 1;
  9. const STATUS_CLOSE = 0;
  10. const WEEK_TEXTS = ['', '周一', '周二', '周三', '周四', '周五', '周六', '周日'];
  11. //morning_time_periods
  12. public function getMorningTimePeriodsAttr($value, $data)
  13. {
  14. return json_decode($this->morning_time_periods, true);
  15. }
  16. //afternoon_time_periods
  17. public function getAfternoonTimePeriodsAttr($value, $data)
  18. {
  19. return json_decode($this->afternoon_time_periods, true);
  20. }
  21. //生成工作日号源
  22. public static function createWeekTicketAll($daytime)
  23. {
  24. $daytimestamp = strtotime($daytime);
  25. if (strtotime(date('Y-m-d')) > $daytimestamp) {
  26. throw new Exception("该时间已过期,请重新选择时间");
  27. }
  28. $daytimeWeek = date('w', $daytimestamp);
  29. $appoints = (new Appointment())->where('weeks', '<>', '')->where('status', self::STATUS_OPEN)->select();
  30. foreach ($appoints as $appoint) {
  31. $weeks = explode(',', $appoint->weeks);
  32. if (in_array($daytimeWeek, $weeks)) {
  33. //生成号源记录
  34. if (0 == (new AppointmentTicket())->where(['appointment_id' => $appoint->id, 'appointment_daytime' => $daytimestamp])->count()) {
  35. (new AppointmentTicket())->allowField(true)->save([
  36. 'appointment_id' => $appoint->id,
  37. 'appointment_daytime' => $daytimestamp,
  38. 'address_id' => $appoint->specialist->address_id,
  39. 'provider_id' => $appoint->provider_id,
  40. 'status' => AppointmentTicket::STATUS_OPEN
  41. ]);
  42. }
  43. }
  44. }
  45. }
  46. //关联专家
  47. public function specialist()
  48. {
  49. return $this->belongsTo('Specialist', 'provider_id');
  50. }
  51. }