Appointment.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. namespace app\api\controller;
  3. use app\api\controller\base\Base;
  4. use app\common\model\Address;
  5. use app\common\model\Appointment as appointmentModel;
  6. use app\common\model\AppointmentApplication;
  7. use app\common\model\AppointmentTicket;
  8. use time\DateHelper;
  9. class Appointment extends Base
  10. {
  11. //获取地址列表
  12. public function addressList()
  13. {
  14. $post = $this->request->param();
  15. $validate = new \think\Validate([
  16. ['page', 'number'],
  17. ['pagenum', 'number|<=:1000']
  18. ]);
  19. if (!$validate->check($post)) {
  20. $this->json_error('提交失败:' . $validate->getError());
  21. }
  22. $where = [];
  23. $addressIds = (new appointmentModel())->availableAddressIds();
  24. $where['id'] = ['in', $addressIds];
  25. $pagenum = $this->request->param('pagenum', 20, 'intval');
  26. $datalist = (new Address())->where($where)->paginate($pagenum, true);
  27. if (empty($datalist)) {
  28. $this->json_error("没有数据");
  29. }
  30. $this->json_success("查询成功", $datalist);
  31. }
  32. //按地址id获取号源信息
  33. public function getTicketByAddressId()
  34. {
  35. $post = $this->request->param();
  36. $validate = new \think\Validate([
  37. ['address_id', 'require|number'],
  38. ['daytime', 'dateFormat:Y-m-d'],
  39. ]);
  40. if (!$validate->check($post)) {
  41. $this->json_error('提交失败:' . $validate->getError());
  42. }
  43. $address_id = $this->request->param('address_id');
  44. $daytime = $this->request->param('daytime', date('Y-m-d'));
  45. $ticketModel = new AppointmentTicket();
  46. $tickets = $ticketModel->where('address_id', $address_id)->where('appointment_daytime', strtotime($daytime))->select();
  47. foreach ($tickets as $k => $item) {
  48. $appoint = $item->appointment;
  49. $item['price'] = $appoint->price;
  50. //日期
  51. $item['appointment_daytime_text'] = date('Y-m-d', $item->appointment_daytime);
  52. //专家信息
  53. $item->specialist;
  54. $item->specialist->head_pic = geturl($item->specialist->head_pic, '', true);
  55. //剩余预约号码
  56. $item['morning_remaining'] = $appoint->morning_num - $item->morning_use;
  57. $item['afternoon_remaining'] = $appoint->afternoon_num - $item->afternoon_use;
  58. $item['night_remaining'] = $appoint->night_num - $item->night_use;
  59. //拆分预约时段
  60. $ticketPeriods = (new AppointmentApplication())->where('appointment_ticket_id', $item->id)->column('appointment_time');
  61. $item['morning_time_period'] = $this->setPeriodStatus(DateHelper::splitTimePeriod($appoint->morning_start_time, $appoint->morning_end_time, $appoint->morning_num), $ticketPeriods);
  62. $item['afternoon_time_period'] = $this->setPeriodStatus(DateHelper::splitTimePeriod($appoint->afternoon_start_time, $appoint->afternoon_end_time, $appoint->afternoon_num), $ticketPeriods);
  63. $item['night_time_period'] = $this->setPeriodStatus(DateHelper::splitTimePeriod($appoint->night_start_time, $appoint->night_end_time, $appoint->night_num), $ticketPeriods);
  64. $tickets[$k] = $item;
  65. }
  66. $this->json_success($tickets);
  67. }
  68. /**
  69. * @param $timePeriods array 拆分的时间段
  70. * @param $ticketPeriods array 已经预约的时间段
  71. * @return array
  72. */
  73. private function setPeriodStatus($timePeriods, $ticketPeriods)
  74. {
  75. $arr = [];
  76. foreach ($timePeriods as $ticket => $period) {
  77. if (in_array($period, $ticketPeriods)) {
  78. $arr[] = ['period' => $period, 'status' => 1];
  79. } else {
  80. $arr[] = ['period' => $period, 'status' => 0];
  81. }
  82. }
  83. return $arr;
  84. }
  85. //按时间获取地址列表
  86. public function addressListByDayTime()
  87. {
  88. appointmentModel::createTicketFromAllAppointment();
  89. $ticketModel = new AppointmentTicket();
  90. //可预约日期列表
  91. // $maxEndTime = $ticketModel->max('end_time');
  92. // $daylist = DateHelper::getDateList(date('Y-m-d'), date('Y-m-d', $maxEndTime), true);
  93. $post = $this->request->param();
  94. $validate = new \think\Validate([
  95. ['daytime', 'date|dateFormat:Y-m-d'],
  96. ['page', 'number'],
  97. ['pagenum', 'number|<=:1000']
  98. ]);
  99. if (!$validate->check($post)) {
  100. $this->json_error('提交失败:' . $validate->getError());
  101. }
  102. $daytime = $this->request->param('daytime', date('Y-m-d'));
  103. $addressIds = $ticketModel->where('appointment_daytime', strtotime($daytime))->column('address_id');
  104. $where = [];
  105. $where['id'] = ['in', $addressIds];
  106. $pagenum = $this->request->param('pagenum', 20, 'intval');
  107. $datalist = (new Address())->where($where)->paginate($pagenum, true);
  108. if (empty($datalist)) {
  109. $this->json_error("没有数据");
  110. }
  111. $this->json_success("查询成功", $datalist);
  112. }
  113. }