12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- <?php
- namespace app\common\model;
- use think\Db;
- use think\Model;
- use time\DateHelper;
- class Appointment extends Model
- {
- protected $updateTime = false;
- public function getStartTimeAttr($value, $data)
- {
- return $value ? date('Y-m-d', $value) : '';
- }
- public function getEndTimeAttr($value, $data)
- {
- return $value ? date('Y-m-d', $value) : '';
- }
- //生成号源配置
- public function createTicket()
- {
- if (!$this->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');
- }
- }
|