User.php 7.3 KB

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