<?php
namespace app\admin\controller\medical;

use app\admin\controller\BaseController;
use app\admin\server\medical\DoctorServer;

class Doctor extends BaseController
{
    /**
     * Notes:医生列表
     * @return \support\Response
     * User: yym
     * Date: 2022/9/26
     */
    public function getDoctorList()
    {
        [$page, $limit] = $this->getPage();
        $keywords = $this->request->get('keywords');
        $result         = DoctorServer::getDoctorList($page, $limit,$keywords);
        return json_success($result, '成功');
    }

    /**
     * Notes:添加医生
     * @return \support\Response
     * @throws \Exception
     * User: yym
     * Date: 2022/9/26
     */
    public function addDoctor()
    {
        $param = $this->request->post();
        $this->validateCheck('medical\DoctorValidate',
            [
                'doctor_name'       => $param['doctor_name'] ?? '',//医生姓名
                'doctor_position'   => $param['doctor_position'] ?? '',//医生职位
                'doctor_head'       => $param['doctor_head'] ?? '',//医生头像
                'doctor_mobile'     => $param['doctor_mobile'] ?? '',//医生手机号
                'doctor_info'       => $param['doctor_info'] ?? '',//医生擅长技能
                'doctor_visit'      => $param['doctor_visit'] ?? '',//是否支持出诊 0否  1是
                'doctor_visit_time' => $param['doctor_visit_time'] ?? '',//出诊时间
                'doctor_work'       => $param['doctor_work'] ?? '',//上班时间 一,三,五
                'doctor_money'      => $param['doctor_money'] ?? '',//收费标准
                'doctor_type'       => $param['doctor_type'] ?? '',//医生类型 0医院   1健康管理师   2家庭医生
                'doctor_on_line'    => $param['doctor_on_line'] ?? '',//是否支持线上沟通 0否   1是
                'doctor_shop_id'    => $param['doctor_shop_id'] ?? '',//医疗店铺ID
                'doctor_subject_id' => $param['doctor_subject_id'] ?? '',//科目编号
                'doctor_address'    => $param['doctor_address'] ?? '',//科室地点
                'doctor_status'     => $param['doctor_status'] ?? '',//医生状态 0休班   1在班
            ],
            'add');
        $admin_id = $this->request->admin_id;
        $result = DoctorServer::insertDoctor($param, $admin_id);
        return json_success($result, '添加成功');
    }

    /**
     * Notes:医生编辑
     * @return \support\Response
     * @throws \Exception
     * User: yym
     * Date: 2022/9/26
     */
    public function updateDoctor()
    {
        $param      = $this->request->post();
        $this->validateCheck('medical\DoctorValidate',
            [
                'doctor_id'         => $param['doctor_id'] ?? '',//医生编号
                'doctor_name'       => $param['doctor_name'] ?? '',//医生姓名
                'doctor_position'   => $param['doctor_position'] ?? '',//医生职位
                'doctor_head'       => $param['doctor_head'] ?? '',//医生头像
                'doctor_mobile'     => $param['doctor_mobile'] ?? '',//医生手机号
                'doctor_info'       => $param['doctor_info'] ?? '',//医生擅长技能
                'doctor_visit'      => $param['doctor_visit'] ?? '',//是否支持出诊 0否  1是
                'doctor_visit_time' => $param['doctor_visit_time'] ?? '',//出诊时间
                'doctor_work'       => $param['doctor_work'] ?? '',//上班时间 一,三,五
                'doctor_money'      => $param['doctor_money'] ?? '',//收费标准
                'doctor_type'       => $param['doctor_type'] ?? '',//医生类型 0医院   1健康管理师   2家庭医生
                'doctor_on_line'    => $param['doctor_on_line'] ?? '',//是否支持线上沟通 0否   1是
                'doctor_shop_id'    => $param['doctor_shop_id'] ?? '',//医疗店铺ID
                'doctor_subject_id' => $param['doctor_subject_id'] ?? '',//科目编号
                'doctor_address'    => $param['doctor_address'] ?? '',//科室地点
                'doctor_status'     => $param['doctor_status'] ?? '',//医生状态 0休班   1在班
            ],
            'update');
        $admin_id = $this->request->admin_id;
        $result = DoctorServer::updateDoctor($param, $admin_id);
        return json_success($result, '修改成功');
    }

    /**
     * Notes:删除医生
     * @return \support\Response
     * User: yym
     * Date: 2022/9/19
     */
    public function deleteDoctor()
    {
        $doctor_id = $this->request->post('doctor_id');
        $this->validateCheck('medical\DoctorValidate', ['doctor_id' => $doctor_id], 'del');
        $admin_id = $this->request->admin_id;
        DoctorServer::deleteDoctor($doctor_id, $admin_id);
        return json_success([], '删除成功');
    }

    /**
     * Notes:获取医生详情
     * @return \support\Response
     * @throws \Exception
     * User: yym
     * Date: 2022/9/26
     */
    public function getDoctorInfo()
    {
        $doctor_id = $this->request->get('doctor_id');
        $this->validateCheck('medical\DoctorValidate', ['doctor_id' => $doctor_id], 'info');
        $result = DoctorServer::getDoctorInfo($doctor_id);
        return json_success($result, '获取成功');
    }

    /**
     * Notes:医生每日工作接纳人数设置----目前按照每半小时时间段设置
     * @return \support\Response
     * @throws \Exception
     * User: yym
     * Date: 2022/9/27
     */
    public function setAppointment()
    {
        $doctor_id       = (int)$this->request->post('doctor_id');//医生编号
        $work_time       = $this->request->post('work_time');//工作时间 一代表周一  二代表周二
        $appointment_sum = (int)$this->request->post('appointment_sum');//每半小时预约人数
        $morning_start   = $this->request->post('morning_start', '');//上午开始时间
        $morning_end     = $this->request->post('morning_end', '');//上午结束时间
        $afternoon_start = $this->request->post('afternoon_start', '');//下午开始时间
        $afternoon_end   = $this->request->post('afternoon_end', '');//下午结束时间
        $this->validateCheck('medical\DoctorValidate',
            [
                'doctor_id'       => $doctor_id,
                'work_time'       => $work_time,
                'appointment_sum' => $appointment_sum,
//                'morning_start'   => $morning_start,
//                'morning_end'     => $morning_end,
//                'afternoon_start' => $afternoon_start,
//                'afternoon_end'   => $afternoon_end
            ],
            'set');
        $admin_id = $this->request->admin_id;
        DoctorServer::setAppointment($doctor_id, $admin_id, $work_time, $morning_start, $morning_end, $afternoon_start, $afternoon_end, $appointment_sum);
        return json_success([], '设置成功');
    }

    /**
     * Notes:获取设置详情
     * @return \support\Response
     * User: yym
     * Date: 2022/10/13
     */
    public function getAppointment()
    {
        $doctor_id = $this->request->get('doctor_id');//医生列表
        $this->validateCheck('medical\DoctorValidate',
            [
                'doctor_id'       => $doctor_id
            ],
            'info');
        return json_success(DoctorServer::getAppointment($doctor_id));
    }
}
