User.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: 中闽 < 1464674022@qq.com >
  5. * Date: 2019/12/5
  6. * Time: 17:44
  7. */
  8. namespace app\api\controller;
  9. use app\api\controller\base\Permissions;
  10. use app\common\model\AppointmentApplication;
  11. use app\common\model\Appointment;
  12. use app\common\model\Feedback;
  13. use app\common\model\Webconfig;
  14. use time\DateHelper;
  15. class User extends Permissions
  16. {
  17. //个人资料接口
  18. public function info()
  19. {
  20. $this->json_success('success', $this->getUser());
  21. }
  22. //预约申请
  23. public function application()
  24. {
  25. $post = $this->request->param();
  26. $validate = new \think\Validate([
  27. ['name|姓名', 'require|max:50'],
  28. ['age|年龄', 'number'],
  29. ['birthday|出生年月', 'max:50'],
  30. ['sex|性别', 'number|in:1,2'],
  31. ['phone|电话', 'require|max:50'],
  32. ['id_card|身份证', 'max:50'],
  33. ['childs_num|子女数量', 'number'],
  34. ['problem_desc|问题描述', 'max:200'],
  35. ['requirement_desc|需求描述', 'max:200'],
  36. ['appointment_ticket_id', 'require|number'],
  37. ['appointment_period', 'require|number|in:1,2,3'],
  38. ['appointment_time|预约时间段', 'require|dateFormat:H:i:s - H:i:s'],
  39. ]);
  40. if (!$validate->check($post)) {
  41. $this->json_error('提交失败:' . $validate->getError());
  42. }
  43. $model = new AppointmentApplication();
  44. //爽约多少次后,多少天内不能再预约
  45. $break_the_promise_day_range = Webconfig::getValue('break_the_promise_day_range');
  46. $break_the_promise_times = Webconfig::getValue('break_the_promise_times');
  47. $stop_appointment_day = Webconfig::getValue('stop_appointment_day');
  48. //
  49. if ($stop_appointment_day && $break_the_promise_times && $break_the_promise_day_range) {
  50. $break_the_promise_count = $model->where('status', AppointmentApplication::STATUS_NOT_COME)->whereTime('finish_time', "-$break_the_promise_day_range day")->count();
  51. if ($break_the_promise_count >= $break_the_promise_times) {
  52. $maxtime = $model->where('status', AppointmentApplication::STATUS_NOT_COME)->max('finish_time');
  53. if (time() < ($maxtime + $stop_appointment_day * 3600 * 24)) {
  54. $this->json_error("此账号 $break_the_promise_day_range 天内爽约 $break_the_promise_count 次, $stop_appointment_day 天内不能再预约");
  55. }
  56. }
  57. }
  58. //检测预约号源是否可预约
  59. $ticket = Appointment::get($post['appointment_ticket_id']);
  60. if (!$ticket) {
  61. $this->json_error("获取预约号失败");
  62. }
  63. //判断该时间段,存在于时间列表中才行
  64. if ($post['appointment_period'] == 1) {
  65. $timePeriods = DateHelper::splitTimePeriod($ticket->morning_start_time, $ticket->morning_end_time, $ticket->morning_num);
  66. } elseif ($post['appointment_period'] == 2) {
  67. $timePeriods = DateHelper::splitTimePeriod($ticket->afternoon_start_time, $ticket->afternoon_end_time, $ticket->afternoon_num);
  68. } else {
  69. $timePeriods = DateHelper::splitTimePeriod($ticket->night_start_time, $ticket->night_end_time, $ticket->night_num);
  70. }
  71. if (!in_array($post['appointment_time'], $timePeriods)) {
  72. $this->json_error("该时间段不存在,请重新选择时间");
  73. }
  74. //排除过期时段
  75. $timerang = explode(' - ', $post['appointment_time']);
  76. $period_end = $timerang[1];
  77. if (time() > strtotime($ticket->daytime . ' ' . $period_end)) {
  78. $this->json_error("该时段已经过期,请重新选择时间");
  79. }
  80. //已经预约的时间段
  81. $ticketPeriods = (new AppointmentApplication())->where('appointment_ticket_id', $ticket->id)->column('appointment_time');
  82. foreach ($ticketPeriods as $period) {
  83. if ($period == $post['appointment_time']) {
  84. $this->json_error("该时段已被预约,请重新选择时间");
  85. }
  86. }
  87. //入库
  88. $data = [
  89. 'name' => $post['name'],
  90. 'user_id' => $this->getUserId(),
  91. 'age' => $post['age']??0,
  92. 'birthday' => $post['birthday']??'',
  93. 'sex' => $post['sex']??0,
  94. 'phone' => $post['phone'],
  95. 'id_card' => $post['id_card']??'',
  96. 'childs_num' => $post['childs_num']??0,
  97. 'problem_desc' => $post['problem_desc']??'',
  98. 'requirement_desc' => $post['requirement_desc']??'',
  99. 'address_id' => $ticket->address_id,
  100. 'provider_id' => $ticket->provider_id,
  101. 'appointment_ticket_id' => $post['appointment_ticket_id'],
  102. 'appointment_time' => $post['appointment_time'],
  103. 'appointment_period' => $post['appointment_period'],
  104. 'status' => AppointmentApplication::STATUS_NOT_SIGN
  105. ];
  106. if (false === $model->allowField(true)->save($data)) {
  107. $this->json_error("预约入库失败");
  108. } else {
  109. $this->json_success("预约成功");
  110. }
  111. }
  112. //我的预约列表接口
  113. public function applicationList()
  114. {
  115. $post = $this->request->param();
  116. $validate = new \think\Validate([
  117. ['status', 'number'],
  118. ['page', 'number'],
  119. ['pagenum', 'number|<=:1000']
  120. ]);
  121. if (!$validate->check($post)) {
  122. $this->json_error('提交失败:' . $validate->getError());
  123. }
  124. $where = ['user_id' => $this->getUserId()];
  125. $status = $this->request->param('status', 0, 'intval');
  126. if ($status == 1) {
  127. $where = ['finish_time' => 0];
  128. } elseif ($status == 2) {
  129. $where = ['finish_time' => ['>', 0]];
  130. }
  131. $pagenum = $this->request->param('pagenum', 20, 'intval');
  132. $datalist = (new AppointmentApplication())->where($where)->order('create_time desc')->paginate($pagenum, true);
  133. foreach ($datalist as $key => $item) {
  134. //专家信息
  135. $item->address;
  136. $item->specialist;
  137. $item->specialist->head_pic = geturl($item->specialist->head_pic, '', true);
  138. $datalist[$key] = $item;
  139. }
  140. if (empty($datalist)) {
  141. $this->json_error("没有数据");
  142. }
  143. $this->json_success("查询成功", $datalist);
  144. }
  145. //提交反馈接口
  146. public function feedback()
  147. {
  148. $post = $this->request->param();
  149. //验证
  150. $validate = new \think\Validate([
  151. ['content|内容', 'require|max:500'],
  152. ]);
  153. if (!$validate->check($post)) {
  154. $this->json_error('提交失败:' . $validate->getError());
  155. }
  156. $model = new Feedback();
  157. $data = [
  158. 'user_id' => $this->getUserId(),
  159. 'content' => $post['content']
  160. ];
  161. if (false === $model->allowField(true)->save($data)) {
  162. $this->json_error("失败");
  163. } else {
  164. $this->json_success("成功");
  165. }
  166. }
  167. }