12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- namespace app\common\model;
- use think\Db;
- use think\Exception;
- use think\Model;
- use time\DateHelper;
- class Appointment extends Model
- {
- protected $updateTime = false;
- const STATUS_OPEN = 1;
- const STATUS_CLOSE = 0;
- //start_time
- public function getStartTimeAttr($value, $data)
- {
- return $value ? date('Y-m-d', $value) : '';
- }
- //end_time
- public function getEndTimeAttr($value, $data)
- {
- return $value ? date('Y-m-d', $value) : '';
- }
- //是否为工作日排号模式
- public function isWeekMode()
- {
- return $this->weeks ? true : false;
- }
- //生成工作日号源
- public static function createWeekTicketAll($daytime)
- {
- $daytimestamp = strtotime($daytime);
- if (strtotime(date('Y-m-d')) > $daytimestamp) {
- throw new Exception("该时间已过期,请重新选择时间");
- }
- $daytimeWeek = date('w', $daytimestamp);
- $appoints = (new Appointment())->where('weeks', '<>', '')->where('status', self::STATUS_OPEN)->select();
- foreach ($appoints as $appoint) {
- $weeks = explode(',', $appoint->weeks);
- if (in_array($daytimeWeek, $weeks)) {
- //生成号源记录
- if (0 == (new AppointmentTicket())->where(['appointment_id' => $appoint->id, 'appointment_daytime' => $daytimestamp])->count()) {
- (new AppointmentTicket())->allowField(true)->save([
- 'appointment_id' => $appoint->id,
- 'appointment_daytime' => $daytimestamp,
- 'address_id' => $appoint->address_id,
- 'provider_id' => $appoint->provider_id,
- 'status' => AppointmentTicket::STATUS_OPEN
- ]);
- }
- }
- }
- }
- //关联专家
- public function specialist()
- {
- return $this->belongsTo('Specialist', 'provider_id');
- }
- }
|