|
@@ -9,8 +9,11 @@
|
|
|
namespace app\api\controller;
|
|
|
|
|
|
|
|
|
-use app\common\model\Feedback;
|
|
|
use app\api\controller\base\Permissions;
|
|
|
+use app\common\model\AppointmentApplication;
|
|
|
+use app\common\model\AppointmentTicket;
|
|
|
+use app\common\model\Feedback;
|
|
|
+use app\common\model\Webconfig;
|
|
|
|
|
|
class User extends Permissions
|
|
|
{
|
|
@@ -20,6 +23,124 @@ class User extends Permissions
|
|
|
$this->json_success('success', $this->getUser());
|
|
|
}
|
|
|
|
|
|
+ //预约申请
|
|
|
+ public function application()
|
|
|
+ {
|
|
|
+ $post = $this->request->param();
|
|
|
+ $validate = new \think\Validate([
|
|
|
+ ['name|姓名', 'require|max:50'],
|
|
|
+ ['age|年龄', 'number'],
|
|
|
+ ['birthday|出生年月', 'max:50'],
|
|
|
+ ['sex|性别', 'number|in:1,2'],
|
|
|
+ ['phone|电话', 'require|max:50'],
|
|
|
+ ['id_card|身份证', 'max:50'],
|
|
|
+ ['childs_num|子女数量', 'number'],
|
|
|
+ ['problem_desc|问题描述', 'max:200'],
|
|
|
+ ['requirement_desc|需求描述', 'max:200'],
|
|
|
+ ['address_id', 'require|number'],
|
|
|
+ ['provider_id', 'require|number'],
|
|
|
+ ['appointment_ticket_id', 'require|number'],
|
|
|
+ ['appointment_period', 'require|number|in:1,2,3'],
|
|
|
+ ['appointment_time|预约时间段', 'require|dateFormat:H:i:s - H:i:s'],
|
|
|
+ ]);
|
|
|
+ if (!$validate->check($post)) {
|
|
|
+ $this->json_error('提交失败:' . $validate->getError());
|
|
|
+ }
|
|
|
+
|
|
|
+ $model = new AppointmentApplication();
|
|
|
+
|
|
|
+ //爽约多少次后,多少天内不能再预约
|
|
|
+ $break_the_promise_day_range = Webconfig::getValue('break_the_promise_day_range');
|
|
|
+ $break_the_promise_times = Webconfig::getValue('break_the_promise_times');
|
|
|
+ $stop_appointment_day = Webconfig::getValue('stop_appointment_day');
|
|
|
+ //
|
|
|
+ if ($stop_appointment_day && $break_the_promise_times && $break_the_promise_day_range) {
|
|
|
+ $break_the_promise_count = $model->where('status', AppointmentApplication::STATUS_NOT_COME)->whereTime('finish_time', "-$break_the_promise_day_range day")->count();
|
|
|
+ if ($break_the_promise_count >= $break_the_promise_times) {
|
|
|
+ $maxtime = $model->where('status', AppointmentApplication::STATUS_NOT_COME)->max('finish_time');
|
|
|
+ if (time() < ($maxtime + $stop_appointment_day * 3600 * 24)) {
|
|
|
+ $this->json_error("此账号 $break_the_promise_day_range 天内爽约 $break_the_promise_count 次, $stop_appointment_day 天内不能再预约");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //检测预约号源是否可预约
|
|
|
+ $ticket = AppointmentTicket::get($post['appointment_ticket_id']);
|
|
|
+ if (!$ticket) {
|
|
|
+ $this->json_error("获取预约号失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ //已经预约的时间段
|
|
|
+ $ticketPeriods = (new AppointmentApplication())->where('appointment_ticket_id', $ticket->appointment_id)->column('appointment_time');
|
|
|
+ foreach ($ticketPeriods as $period) {
|
|
|
+ if ($period == $post['appointment_time']) {
|
|
|
+ $this->json_error("该时间已经被预约了,请重新选择时间");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //入库
|
|
|
+ $data = [
|
|
|
+ 'name' => $post['name'],
|
|
|
+ 'user_id' => $this->getUserId(),
|
|
|
+ 'age' => $post['age']??0,
|
|
|
+ 'birthday' => $post['birthday']??'',
|
|
|
+ 'sex' => $post['sex']??0,
|
|
|
+ 'phone' => $post['phone'],
|
|
|
+ 'id_card' => $post['id_card']??'',
|
|
|
+ 'childs_num' => $post['childs_num']??0,
|
|
|
+ 'problem_desc' => $post['problem_desc']??'',
|
|
|
+ 'requirement_desc' => $post['requirement_desc']??'',
|
|
|
+ 'address_id' => $post['address_id'],
|
|
|
+ 'provider_id' => $post['provider_id'],
|
|
|
+ 'appointment_ticket_id' => $post['appointment_ticket_id'],
|
|
|
+ 'appointment_time' => $post['appointment_time'],
|
|
|
+ 'appointment_period' => $post['appointment_period'],
|
|
|
+ 'status' => AppointmentApplication::STATUS_NOT_SIGN
|
|
|
+ ];
|
|
|
+ if (false === $model->allowField(true)->save($data)) {
|
|
|
+ $this->json_error("预约入库失败");
|
|
|
+ } else {
|
|
|
+ $this->json_success("预约成功");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //我的预约列表接口
|
|
|
+ public function applicationList()
|
|
|
+ {
|
|
|
+ $post = $this->request->param();
|
|
|
+ $validate = new \think\Validate([
|
|
|
+ ['status', 'number'],
|
|
|
+ ['page', 'number'],
|
|
|
+ ['pagenum', 'number|<=:1000']
|
|
|
+ ]);
|
|
|
+ if (!$validate->check($post)) {
|
|
|
+ $this->json_error('提交失败:' . $validate->getError());
|
|
|
+ }
|
|
|
+
|
|
|
+ $where = ['user_id' => $this->getUserId()];
|
|
|
+ $status = $this->request->param('status', 0, 'intval');
|
|
|
+ if ($status == 1) {
|
|
|
+ $where = ['finish_time' => 0];
|
|
|
+ } elseif ($status == 2) {
|
|
|
+ $where = ['finish_time' => ['>', 0]];
|
|
|
+ }
|
|
|
+ $pagenum = $this->request->param('pagenum', 20, 'intval');
|
|
|
+ $datalist = (new AppointmentApplication())->where($where)->order('create_time desc')->paginate($pagenum, true);
|
|
|
+ foreach ($datalist as $key => $item) {
|
|
|
+ //专家信息
|
|
|
+ $item->address;
|
|
|
+ $item->specialist;
|
|
|
+ $item->specialist->head_pic = geturl($item->specialist->head_pic, '', true);
|
|
|
+ $datalist[$key] = $item;
|
|
|
+ }
|
|
|
+ if (empty($datalist)) {
|
|
|
+ $this->json_error("没有数据");
|
|
|
+ }
|
|
|
+ $this->json_success("查询成功", $datalist);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
//提交反馈接口
|
|
|
public function feedback()
|
|
|
{
|
|
@@ -33,12 +154,14 @@ class User extends Permissions
|
|
|
}
|
|
|
|
|
|
$model = new Feedback();
|
|
|
- $post['user_id'] = $this->getUserId();
|
|
|
- $res = $model->allowField(true)->save($post);
|
|
|
- if ($res) {
|
|
|
- $this->json_success("成功");
|
|
|
- } else {
|
|
|
+ $data = [
|
|
|
+ 'user_id' => $this->getUserId(),
|
|
|
+ 'content' => $post['content']
|
|
|
+ ];
|
|
|
+ if (false === $model->allowField(true)->save($data)) {
|
|
|
$this->json_error("失败");
|
|
|
+ } else {
|
|
|
+ $this->json_success("成功");
|
|
|
}
|
|
|
}
|
|
|
}
|