Appointment.php 1.9 KB

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