Appointment.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. namespace app\common\model;
  3. use think\Db;
  4. use think\Model;
  5. use time\DateHelper;
  6. class Appointment extends Model
  7. {
  8. protected $updateTime = false;
  9. public function getStartTimeAttr($value, $data)
  10. {
  11. return $value ? date('Y-m-d', $value) : '';
  12. }
  13. public function getEndTimeAttr($value, $data)
  14. {
  15. return $value ? date('Y-m-d', $value) : '';
  16. }
  17. //生成号源配置
  18. public function createTicket()
  19. {
  20. if (!$this->ifExitsTicket()) {
  21. $daylist = DateHelper::dateTimeList($this->start_time, $this->end_time, true);
  22. foreach ($daylist as $datetime) {
  23. (new AppointmentTicket())->save([
  24. 'appointment_id' => $this->id,
  25. 'appointment_daytime' => strtotime($datetime),
  26. 'provider_id' => $this->provider_id,
  27. 'address_id' => $this->specialist->address_id,
  28. ]);
  29. }
  30. $this->save(['ticket_status' => 1]);
  31. }
  32. }
  33. //是否已生成号源配置
  34. public function ifExitsTicket()
  35. {
  36. return $this->ticket_status > 0;
  37. }
  38. /**
  39. * 生成号源,保证预约取号正常运行
  40. */
  41. public static function createTicketFromAllAppointment()
  42. {
  43. $all = (new Appointment())->where('end_time', '>', time())->where('ticket_status', 0)->select();
  44. /** @var $item Appointment */
  45. foreach ($all as $item) {
  46. $item->createTicket();
  47. }
  48. }
  49. /**
  50. * 获取可预约地点列表
  51. * @return array
  52. */
  53. public static function availableAddressIds()
  54. {
  55. self::createTicketFromAllAppointment();
  56. $addressIds = (new AppointmentTicket())->where('appointment_daytime', '>=', strtotime(date('Y-m-d')))->distinct('true')->column('address_id');
  57. return $addressIds;
  58. }
  59. //按时间预约列表接口
  60. public static function listByDayTime()
  61. {
  62. self::createTicketFromAllAppointment();
  63. }
  64. //是否已存在预约订单
  65. public function ifExitsAppointmentApplication()
  66. {
  67. }
  68. //关联专家
  69. public function specialist()
  70. {
  71. return $this->belongsTo('Specialist', 'provider_id');
  72. }
  73. }