User.php 6.1 KB

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