| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 | <?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\AppointmentTicket;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'],            ['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'],            ['childs_num|子女数量', 'number|in:1,2,3'],            ['childs_num_str|子女数量', 'max:255'],            ['city|来自城市', 'max:50'],            ['job|职业', 'max:50'],            ['education_level|受教育程度', 'number|in:0,1,2,3,4'],            ['home_address|家庭住址', 'max:255'],            ['marriage|婚姻情况', 'number|in:0,1,2'],            ['problem_type|咨询问题类别', 'number|in:0,1,2,3,4,5'],            ['childs_age1|一孩年龄', 'number'],            ['childs_age2|二孩年龄', 'number'],            ['childs_age3|三孩年龄', 'number'],            ['childs_sex1|一孩性别', 'number'],            ['childs_sex2|二孩性别', 'number'],            ['childs_sex3|三孩性别', 'number'],        ]);        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 = (new AppointmentTicket())->where(['id' => $post['appointment_ticket_id'], 'status' => AppointmentTicket::STATUS_OPEN])->find();        if (!$ticket) {            $this->json_error("获取预约号失败");        }        $appoint = $ticket->appointment;        //判断该时间段,存在于时间列表中才行        if ($post['appointment_period'] == 1) {            $timePeriods = DateHelper::splitTimePeriod($appoint->morning_start_time, $appoint->morning_end_time, $appoint->morning_num);        } elseif ($post['appointment_period'] == 2) {            $timePeriods = DateHelper::splitTimePeriod($appoint->afternoon_start_time, $appoint->afternoon_end_time, $appoint->afternoon_num);        } else {            $timePeriods = DateHelper::splitTimePeriod($appoint->night_start_time, $appoint->night_end_time, $appoint->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->appointment_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' => htmlspecialchars($post['name']),            'user_id' => $this->getUserId(),            'age' => $post['age']??0,            'birthday' => $this->request->param('birthday', '', 'htmlspecialchars'),            'sex' => $post['sex']??0,            'phone' => $post['phone'],            'id_card' => $this->request->param('id_card', '', 'htmlspecialchars'),            'childs_num' => $post['childs_num']??0,            'problem_desc' => $this->request->param('problem_desc', '', 'htmlspecialchars'),            'requirement_desc' => $this->request->param('requirement_desc', '', 'htmlspecialchars'),            '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,            'city' => $this->request->param('city', '', 'htmlspecialchars'),            'job' => $this->request->param('job', '', 'htmlspecialchars'),            'education_level' => $post['education_level']??0,            'home_address' => $this->request->param('home_address', '', 'htmlspecialchars'),            'marriage' => $post['marriage']??0,            'problem_type' => $post['problem_type']??0,            'childs_num_str' => $this->request->param('childs_num_str', '', 'htmlspecialchars'),            'childs_age1' => $post['childs_age1']??0,            'childs_age2' => $post['childs_age2']??0,            'childs_age3' => $post['childs_age3']??0,            'childs_sex1' => $post['childs_sex1']??0,            'childs_sex2' => $post['childs_sex2']??0,            'childs_sex3' => $post['childs_sex3']??0,        ];        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' => $this->request->param('content', '', 'htmlspecialchars')        ];        if (false === $model->allowField(true)->save($data)) {            $this->json_error("失败");        } else {            $this->json_success("成功");        }    }}
 |