User.php 6.0 KB

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