User.php 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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. 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. ['problem_desc|问题描述', 'max:200'],
  43. ['requirement_desc|需求描述', 'max:200'],
  44. ['appointment_ticket_id', 'require|number'],
  45. ['appointment_period', 'require|number|in:1,2,3'],
  46. ['appointment_time|预约时间段', 'require|dateFormat:H:i:s - H:i:s'],
  47. ['childs_num|子女数量', 'number|in:1,2,3'],
  48. ['childs_num_str|子女数量', 'max:255'],
  49. ['city|来自城市', 'max:50'],
  50. ['job|职业', 'max:50'],
  51. ['education_level|受教育程度', 'number|in:0,1,2,3,4'],
  52. ['home_address|家庭住址', 'max:255'],
  53. ['marriage|婚姻情况', 'number|in:0,1,2'],
  54. ['problem_type|咨询问题类别', 'number|in:0,1,2,3,4,5'],
  55. ['childs_age1|一孩年龄', 'number'],
  56. ['childs_age2|二孩年龄', 'number'],
  57. ['childs_age3|三孩年龄', 'number'],
  58. ['childs_sex1|一孩性别', 'number'],
  59. ['childs_sex2|二孩性别', 'number'],
  60. ['childs_sex3|三孩性别', 'number'],
  61. ]);
  62. if (!$validate->check($post)) {
  63. $this->json_error('提交失败:' . $validate->getError());
  64. }
  65. $model = new AppointmentApplication();
  66. //爽约多少次后,多少天内不能再预约
  67. $break_the_promise_day_range = Webconfig::getValue('break_the_promise_day_range');
  68. $break_the_promise_times = Webconfig::getValue('break_the_promise_times');
  69. $stop_appointment_day = Webconfig::getValue('stop_appointment_day');
  70. //
  71. if ($stop_appointment_day && $break_the_promise_times && $break_the_promise_day_range) {
  72. $break_the_promise_count = $model->where('status', AppointmentApplication::STATUS_NOT_COME)->whereTime('finish_time', "-$break_the_promise_day_range day")->count();
  73. if ($break_the_promise_count >= $break_the_promise_times) {
  74. $maxtime = $model->where('status', AppointmentApplication::STATUS_NOT_COME)->max('finish_time');
  75. if (time() < ($maxtime + $stop_appointment_day * 3600 * 24)) {
  76. $this->json_error("此账号 $break_the_promise_day_range 天内爽约 $break_the_promise_count 次, $stop_appointment_day 天内不能再预约");
  77. }
  78. }
  79. }
  80. //检测预约号源是否可预约
  81. $ticket = (new AppointmentTicket())->where(['id' => $post['appointment_ticket_id'], 'status' => AppointmentTicket::STATUS_OPEN])->find();
  82. if (!$ticket) {
  83. $this->json_error("获取预约号失败");
  84. }
  85. $appoint = $ticket->appointment;
  86. //判断该时间段,存在于时间列表中才行
  87. if ($post['appointment_period'] == 1) {
  88. $timePeriods = DateHelper::splitTimePeriod($appoint->morning_start_time, $appoint->morning_end_time, $appoint->morning_num);
  89. } elseif ($post['appointment_period'] == 2) {
  90. $timePeriods = DateHelper::splitTimePeriod($appoint->afternoon_start_time, $appoint->afternoon_end_time, $appoint->afternoon_num);
  91. } else {
  92. $timePeriods = DateHelper::splitTimePeriod($appoint->night_start_time, $appoint->night_end_time, $appoint->night_num);
  93. }
  94. if (!in_array($post['appointment_time'], $timePeriods)) {
  95. $this->json_error("该时间段不存在,请重新选择时间");
  96. }
  97. //排除过期时段
  98. $timerang = explode(' - ', $post['appointment_time']);
  99. $period_end = $timerang[1];
  100. if (time() > strtotime($ticket->appointment_daytime . ' ' . $period_end)) {
  101. $this->json_error("该时段已经过期,请重新选择时间");
  102. }
  103. //已经预约的时间段
  104. $ticketPeriods = (new AppointmentApplication())->where('appointment_ticket_id', $ticket->id)->column('appointment_time');
  105. foreach ($ticketPeriods as $period) {
  106. if ($period == $post['appointment_time']) {
  107. $this->json_error("该时段已被预约,请重新选择时间");
  108. }
  109. }
  110. //入库
  111. $data = [
  112. 'name' => htmlspecialchars($post['name']),
  113. 'user_id' => $this->getUserId(),
  114. 'age' => $post['age']??0,
  115. 'birthday' => $this->request->param('birthday', '', 'htmlspecialchars'),
  116. 'sex' => $post['sex']??0,
  117. 'phone' => $post['phone'],
  118. 'id_card' => $this->request->param('id_card', '', 'htmlspecialchars'),
  119. 'childs_num' => $post['childs_num']??0,
  120. 'problem_desc' => $this->request->param('problem_desc', '', 'htmlspecialchars'),
  121. 'requirement_desc' => $this->request->param('requirement_desc', '', 'htmlspecialchars'),
  122. 'address_id' => $ticket->address_id,
  123. 'provider_id' => $ticket->provider_id,
  124. 'appointment_ticket_id' => $post['appointment_ticket_id'],
  125. 'appointment_time' => $post['appointment_time'],
  126. 'appointment_period' => $post['appointment_period'],
  127. 'status' => AppointmentApplication::STATUS_NOT_SIGN,
  128. 'city' => $this->request->param('city', '', 'htmlspecialchars'),
  129. 'job' => $this->request->param('job', '', 'htmlspecialchars'),
  130. 'education_level' => $post['education_level']??0,
  131. 'home_address' => $this->request->param('home_address', '', 'htmlspecialchars'),
  132. 'marriage' => $post['marriage']??0,
  133. 'problem_type' => $post['problem_type']??0,
  134. 'childs_num_str' => $this->request->param('childs_num_str', '', 'htmlspecialchars'),
  135. 'childs_age1' => $post['childs_age1']??0,
  136. 'childs_age2' => $post['childs_age2']??0,
  137. 'childs_age3' => $post['childs_age3']??0,
  138. 'childs_sex1' => $post['childs_sex1']??0,
  139. 'childs_sex2' => $post['childs_sex2']??0,
  140. 'childs_sex3' => $post['childs_sex3']??0,
  141. ];
  142. if (false === $model->allowField(true)->save($data)) {
  143. $this->json_error("预约入库失败");
  144. } else {
  145. $this->json_success("预约成功");
  146. }
  147. }
  148. //我的预约列表接口
  149. public function applicationList()
  150. {
  151. $post = $this->request->param();
  152. $validate = new \think\Validate([
  153. ['status', 'number'],
  154. ['page', 'number'],
  155. ['pagenum', 'number|<=:1000']
  156. ]);
  157. if (!$validate->check($post)) {
  158. $this->json_error('提交失败:' . $validate->getError());
  159. }
  160. $where = ['user_id' => $this->getUserId()];
  161. $status = $this->request->param('status', 0, 'intval');
  162. if ($status == 1) {
  163. $where['finish_time'] = 0;
  164. } elseif ($status == 2) {
  165. $where['finish_time'] = ['>', 0];
  166. }
  167. $pagenum = $this->request->param('pagenum', 20, 'intval');
  168. $datalist = (new AppointmentApplication())->where($where)->order('create_time desc')->paginate($pagenum, true);
  169. foreach ($datalist as $key => $item) {
  170. //专家信息
  171. $item->address;
  172. $item->specialist;
  173. $item->specialist->head_pic = geturl($item->specialist->head_pic, '', true);
  174. $datalist[$key] = $item;
  175. }
  176. if (empty($datalist)) {
  177. $this->json_error("没有数据");
  178. }
  179. $this->json_success("查询成功", $datalist);
  180. }
  181. //提交反馈接口
  182. public function feedback()
  183. {
  184. $post = $this->request->param();
  185. //验证
  186. $validate = new \think\Validate([
  187. ['content|内容', 'require|max:500'],
  188. ]);
  189. if (!$validate->check($post)) {
  190. $this->json_error('提交失败:' . $validate->getError());
  191. }
  192. $model = new Feedback();
  193. $data = [
  194. 'user_id' => $this->getUserId(),
  195. 'content' => $this->request->param('content', '', 'htmlspecialchars')
  196. ];
  197. if (false === $model->allowField(true)->save($data)) {
  198. $this->json_error("失败");
  199. } else {
  200. $this->json_success("成功");
  201. }
  202. }
  203. }