ifExitsTicket()) { $daylist = DateHelper::dateTimeList($this->start_time, $this->end_time, true); foreach ($daylist as $datetime) { (new AppointmentTicket())->save([ 'appointment_id' => $this->id, 'appointment_daytime' => strtotime($datetime), 'provider_id' => $this->provider_id, 'address_id' => $this->specialist->address_id, ]); } $this->save(['ticket_status' => 1]); } } //是否已生成号源配置 public function ifExitsTicket() { return $this->ticket_status > 0; } /** * 生成号源,保证预约取号正常运行 */ public static function createTicketFromAllAppointment() { $all = (new Appointment())->where('end_time', '>', time())->where('ticket_status', 0)->select(); /** @var $item Appointment */ foreach ($all as $item) { $item->createTicket(); } } /** * 获取可预约地点列表 * @return array */ public static function availableAddressIds() { self::createTicketFromAllAppointment(); $addressIds = (new AppointmentTicket())->where('appointment_daytime', '>=', strtotime(date('Y-m-d')))->distinct('true')->column('address_id'); return $addressIds; } //按时间预约列表接口 public static function listByDayTime() { self::createTicketFromAllAppointment(); } //是否已存在预约订单 public function ifExitsAppointmentApplication() { } //关联专家 public function specialist() { return $this->belongsTo('Specialist', 'provider_id'); } }