| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 | <?php/** * Created by PhpStorm. * User: 中闽 < 1464674022@qq.com > * Date: 2019/12/5 * Time: 17:44 */namespace app\api\controller;use app\api\controller\base\Permissions;use app\common\model\AppointmentApplication;use app\common\model\Appointment;use app\common\model\Feedback;use app\common\model\Webconfig;use time\DateHelper;class User extends Permissions{    //个人资料接口    public function info()    {        $user = $this->getUser();        $info = [            "nickname" => $user->nickname,            "head_pic" => $user->head_pic,            "sex" => $user->sex,            "country" =>$user->country,            "province" => $user->province,            "city" =>$user->city        ];        $this->json_success('success', $info);    }    //预约申请    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'],            ['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 = Appointment::get($post['appointment_ticket_id']);        if (!$ticket) {            $this->json_error("获取预约号失败");        }        //判断该时间段,存在于时间列表中才行        if ($post['appointment_period'] == 1) {            $timePeriods = DateHelper::splitTimePeriod($ticket->morning_start_time, $ticket->morning_end_time, $ticket->morning_num);        } elseif ($post['appointment_period'] == 2) {            $timePeriods = DateHelper::splitTimePeriod($ticket->afternoon_start_time, $ticket->afternoon_end_time, $ticket->afternoon_num);        } else {            $timePeriods = DateHelper::splitTimePeriod($ticket->night_start_time, $ticket->night_end_time, $ticket->night_num);        }        if (!in_array($post['appointment_time'], $timePeriods)) {            $this->json_error("该时间段不存在,请重新选择时间");        }        //排除过期时段        $timerang = explode(' - ', $post['appointment_time']);        $period_end = $timerang[1];        if (time() > strtotime($ticket->daytime . ' ' . $period_end)) {            $this->json_error("该时段已经过期,请重新选择时间");        }        //已经预约的时间段        $ticketPeriods = (new AppointmentApplication())->where('appointment_ticket_id', $ticket->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' => $ticket->address_id,            'provider_id' => $ticket->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()    {        $post = $this->request->param();        //验证        $validate = new \think\Validate([            ['content|内容', 'require|max:500'],        ]);        if (!$validate->check($post)) {            $this->json_error('提交失败:' . $validate->getError());        }        $model = new Feedback();        $data = [            'user_id' => $this->getUserId(),            'content' => $post['content']        ];        if (false === $model->allowField(true)->save($data)) {            $this->json_error("失败");        } else {            $this->json_success("成功");        }    }}
 |