<?php

namespace app\api\controller;

use think\console\input\Option;
use think\Db;
use app\common\controller\Api;

/**
 * 首页
 */
class Index extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * @ApiTitle    (首页-报修单列表)
     * @ApiSummary  (报修单列表)
     * @ApiMethod (POST)
     * @ApiRoute    (/api/Index/ReportList)
     * @ApiHeaders  (name="authorization", type=string, required=true, description="请求的Token")
     * @ApiParams   (name="ids", type="int", required=true, description="报修单编号排序:1=是,0=否")
     * @ApiParams   (name="istime", type="int", required=true, description="根据时间排序:1=是,0=否")
     * @ApiParams   (name="status", type="int", required=true, description="审核状态:0=无,1=等待审核,2=审核通过,3=审核未通过")
     * @ApiParams   (name="zhandian", type="int", required=true, description="站点ID:0=无")
     * @ApiParams   (name="keywords", type="string", required=true, description="搜索关键字")
     * @ApiParams   (name="pages", type="int", required=true, description="页数")
     * @ApiParams   (name="rows", type="int", required=true, description="数据数量")
     * @ApiReturnParams   (name="code", type="integer", required=true,  sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    "code":"1",
    "msg": "返回成功",
    "data": {
    "count": 总数,
    "list": [
    {
    "id": 1,
    "order_sn": "报修单编号",
    "type": 报修单状态:1=进行中,2=已完成,
    "repair_type": 维修状态:0=未接收,1=进行中,2=已完成,
    "status": 审核状态:0=不需要审核,1=等待审核,2=审核通过,3=审核未通过,
    "time": "2020-08-19"
    }
    ]
    }
    })
     */
    public function ReportList()
    {
        $param = $this->request->param();
        $user_id = $this->is_token($this->request->header());
        $user = Db::name('user')->where(['id' => $user_id])->find();
        $map = [];
        $map2 = [];
        $map3 = [];
        $map4 = [];
        if ($user['level'] == 5 || $user['level'] == 6) {
            $map['zhandian_id'] = ['eq', $user['zhandian_id']];
        }
        if ($param['status'] != 0) {
            $map2 ['status'] = ['eq', $param['status']];
        }
        if ($param['zhandian'] != 0) {
            $map3 ['zhandian_id'] = ['eq', $param['zhandian']];
        }
        if (!empty($param['keywords']) || $param['keywords'] != null || $param['keywords'] != '' || $param['keywords'] != "") {
            $map4 ['order_sn'] = ['LIKE', '%' . $param['keywords'] . '%'];
        }
        $arr = Db::name('baoxiudan')->where($map)->where($map2)->where($map3)->where($map4)->page($param['pages'], $param['rows'])->order('id desc')->select();
        $count = Db::name('baoxiudan')->where($map)->where($map2)->where($map3)->where($map4)->order('id desc')->select();
        if (empty($arr)) {
            $list = [
                'count' => 0,
                'list' => []
            ];
            $this->success('成功', $list);
            die;
        }
        foreach ($arr as $k => $v) {
            $list[$k]['id'] = $v['id'];   //报修单ID
            $list[$k]['order_sn'] = $v['order_sn'];   //订单编号
            $list[$k]['type'] = $v['type'];  //报修单状态
            $list[$k]['repair_type'] = $v['repair_type'];  //维修状态
            $list[$k]['status'] = $v['status'];  //审核状态
            $list[$k]['time'] = date('Y-m-d H:i:s', $v['createtime']);  //报修时间
//            $list[$k]['time'] = $v['createtime'];  //报修时间
            $list[$k]['BankRed'] = $this->SizeRed($user_id, $v['id']);  //标红
        }
        if ($param['ids'] == 1) {
            array_multisort(array_column($list, 'id'), SORT_ASC, $list);
        }
        if ($param['istime'] == 1) {
            array_multisort(array_column($list, 'time'), SORT_ASC, $list);
        }
        if ($user['level'] == 5) {
            $bool = $this->time();
            if ($bool == 1) {
                $today = strtotime(date('Y-m-d', time()));
                $is_p = Db::name('month_talk')->where('user_id', $user)->where('createtime', 'GT', $today)->find();
                if (empty($is_p)) {
                    $bools = true;
                } else {
                    $bools = false;
                }
            } else {
                $bools = false;
            }
        } else {
            $bools = false;
        }
        $list = [
            'month' => $bools,
            'count' => count($count),
            'list' => $list
        ];
        $this->success('成功', $list);
    }


    /**
     * @ApiTitle    (首页-站点列表)
     * @ApiSummary  (站点列表)
     * @ApiMethod (POST)
     * @ApiRoute    (/api/Index/ZhanDianList)
     * @ApiReturnParams   (name="code", type="integer", required=true,  sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    "code":"1",
    "msg": "返回成功",
    "data": [
    {
    "id": 1,
    "zhandian": "河北站"
    }
    ]
    })
     */
    public function ZhanDianList()
    {
        $arr = Db::name('zhandian')->select();
        if (empty($arr)) {
            $list = [];
        } else {
            foreach ($arr as $k => $v) {
                $list[$k]['id'] = $v['id'];
                $list[$k]['zhandian'] = $v['zhandian'];
            }
        }
        $this->success('成功', $list);
    }


    /**
     * @ApiTitle    (首页-填写报修单渲染)
     * @ApiSummary  (填写报修单渲染)
     * @ApiMethod (POST)
     * @ApiRoute    (/api/Index/InsertOrderList)
     * @ApiHeaders  (name="authorization", type=string, required=true, description="请求的Token")
     * @ApiReturnParams   (name="code", type="integer", required=true,  sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    "code":"1",
    "msg": "返回成功",
    "data": {
    "name": "张三",
    "zhandian": "北京站",
    "xitong": [
    {
    "id": 1,
    "xitong": "监控系统",
    "bianhao": "JK"
    }
    ]
    }
    })
     */
    public function InsertOrderList()
    {
        $user_id = $this->is_token($this->request->header());
        $arr = Db::name('user')
            ->alias('u')
            ->where(['u.id' => $user_id])
            ->join('zhandian z', 'z.id=u.zhandian_id')
            ->field('u.name,z.zhandian')
            ->find();
        if (empty($arr)) {
            $this->error('内部错误,请联系微信官方');
        }
        $xitong = Db::name('xitong')->select();
        if (empty($xitong)) {
            $xi = [];
        } else {
            $xi = $xitong;
        }
        $list = [
            'name' => $arr['name'],
            'zhandian' => $arr['zhandian'],
            'xitong' => $xi
        ];
        $this->success('成功', $list);
    }


    /**
     * @ApiTitle    (首页-填写报修单)
     * @ApiSummary  (填写报修单)
     * @ApiMethod (POST)
     * @ApiRoute    (/api/Index/InsertOrder)
     * @ApiHeaders  (name="authorization", type=string, required=true, description="请求的Token")
     * @ApiHeaders  (name="title", type=string, required=true, description="报修内容")
     * @ApiHeaders  (name="address", type=string, required=true, description="报修地点")
     * @ApiHeaders  (name="colum", type=string, required=true, description="故障设备名称")
     * @ApiHeaders  (name="system", type=string, required=true, description="所属系统ID")
     * @ApiHeaders  (name="up_time", type=string, required=true, description="上报时间:linux时间戳")
     * @ApiHeaders  (name="con", type=string, required=true, description="故障现象")
     * @ApiHeaders  (name="images", type=string, required=true, description="照片多个,分割")
     * @ApiReturnParams   (name="code", type="integer", required=true,  sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    "code":"1",
    "msg": "返回成功",
    "data": {
    "name": "张三",
    "zhandian": "北京站"
    }
    })
     */
    public function InsertOrder()
    {
        $user_id = $this->is_token($this->request->header());
        $param = $this->request->param();
        if ($param['title'] == null || $param['title'] == '' || $param['title'] == "" || empty($param['title'])) {
            $this->error('报修内容不能为空', 0);
        }
        if ($param['address'] == null || $param['address'] == '' || $param['address'] == "" || empty($param['address'])) {
            $this->error('报修地点不能为空', 0);
        }
        if ($param['colum'] == null || $param['colum'] == '' || $param['colum'] == "" || empty($param['colum'])) {
            $this->error('故障设备名称不能为空', 0);
        }
        if ($param['con'] == null || $param['con'] == '' || $param['con'] == "" || empty($param['con'])) {
            $this->error('故障现象不能为空', 0);
        }
        if ($param['system'] == 0) {
            $this->error('所属系统不能为空', 0);
        }
        //站点编号
        $prc = Db::name('user')
            ->alias('u')
            ->where(['u.id' => $user_id])
            ->join('zhandian z', 'z.id=u.zhandian_id')
            ->field('z.prc,u.name,z.id')
            ->find();
        //年份
        $year = date('Y');
        //系统
        $xitong = Db::name('xitong')->where(['id' => $param['system']])->value('bianhao');
        //号码
        $order_sn = Db::name('baoxiudan')->order('id desc')->limit(1)->where('order_sn', 'like', '%' . $xitong . '%')->value('order_sn');
        $arr = explode('-', $order_sn);
        if (empty($arr[3])) {
            $num = '001';
        } else {
            $str = $arr[3] + 1;
            $num = str_pad($str, 3, '0', STR_PAD_LEFT);
        }
        $up_time = substr($param['up_time'], 0, 10);
        $data = [
            'createtime' => time(),
            'updatetime' => time(),
            'user_id' => $user_id,
            'order_sn' => $prc['prc'] . '-' . $year . '-' . $xitong . '-' . $num,
            'title' => $param['title'],
            'address' => $param['address'],
            'colum' => $param['colum'],
            'system' => $param['system'],
            'time' => $up_time,
            'zhandian_id' => $prc['id'],
            'people_name' => $prc['name'],
            'colum_con' => $param['con'],
            'images' => $param['images'],
            'king_type' => 0,
            'type' => 1,
            'repair_type' => 0,
            'price' => 0,
            'status' => 0,
            'is_genghuan' => 2,
            'fenpei_type' => 0,
        ];
        $res = Db::name('baoxiudan')->insert($data);
        if ($res) {
            $this->success('提交成功', 1);
        } else {
            $this->error('提交失败', 0);
        }
    }


    /**
     * @ApiTitle    (首页-报修单详情)
     * @ApiSummary  (报修单详情)
     * @ApiMethod (POST)
     * @ApiRoute    (/api/Index/OrderContent)
     * @ApiHeaders  (name="authorization", type=string, required=true, description="请求的Token")
     * @ApiHeaders  (name="id", type=int, required=true, description="报修单ID")
     * @ApiReturnParams   (name="code", type="integer", required=true,  sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    "code":"1",
    "msg": "返回成功",
    "data": {
    "level": 用户等级,
    "repair_type": 维修状态:0=未接收,1=进行中,2=已完成,
    "type": 报修单状态:1=进行中,2=已完成,
    "is_weixiu": 非维修人员查看为0,维修人员查看详情时,1=分配到当前用户,2=否,
    "is_me":"是否是自己报修单 1=是0=否",
    "title": "报修内容",
    "address": "地点",
    "colum": "故障设备名称",
    "system": "所属系统",
    "time": "上报时间",
    "people_name": "上报人",
    "zhandian": "站点名称",
    "colum_con": "故障现象",
    "images": [
    "照片"
    ],
    "is_genghuan": 是否需要更换设备:1=是,2=否,
    "IsTalk": 是否可以评价 1=是,0=否,
    "price": 设备价格:0=不需要更换设备,1=2000以下,2=2000-10000元,3=10000元以上,
    "status": 审核状态:0=不需要审核,1=等待审核,2=审核通过,3=审核未通过,
    "weixiu": 维修情况,
    "jidian": 机电负责人意见,
    "holder": 分管领导意见,
    "fuzeren" : //维修负责人意见
    "zaicishenhe": [ //再次审核内容
    'king_type';  //KingType
    {
    "con": "内容",
    "images": [
    "图片"
    ]
    }
    ]
    }
    })
     */
    public function OrderContent()
    {
        $user_id = $this->is_token($this->request->header());
        $id = input('id');
        $level = Db::name('user')->where('id', $user_id)->value('level');
        $arr = Db::name('baoxiudan')->where(['id' => $id])->find();
        if (empty($arr['redio_user_id'])) {
            $redio_user = '';
        } else {
            $redio_user = Db::name('user')->where('id', $arr['redio_user_id'])->value('name');
            if (empty($redio_user)) {
                $redio_user = '';
            }
        }
        $xitong = Db::name('xitong')->where(['id' => $arr['system']])->value('xitong');
        $zhandian = Db::name('zhandian')
            ->where(['id' => $arr['zhandian_id']])
            ->value('zhandian');

        if (strstr($arr['images'], ',')) {
            $avatars = explode(',', $arr['images']);
        } else {
            $avatars = explode(' ', $arr['images']);
        }
        foreach ($avatars as $k => $v) {
            $images[$k] = cdnurl($v);
        }
        $is_weixiu = 0;
        if ($level == 4) {
            if ($arr['redio_user_id'] == $user_id) {
                $is_weixiu = 1;
            } else {
                $is_weixiu = 2;
            }
        }
        if ($level == 5) {
            if ($arr['type'] == 2) {
                if (empty($arr['talk_con'])) {
                    $Is_talk = 1;
                } else {
                    $Is_talk = 0;
                }
            } else {
                $Is_talk = 0;
            }
        } else {
            $Is_talk = 0;
        }
        $zcsq = Db::name('answer')->order('id desc')->where(['order_id' => $id])->select();
        if (!empty($zcsq)) {
            foreach ($zcsq as $k => $v) {
                $shenhe[$k]['con'] = $v['con'];
                $shenhe[$k]['images'] = $this->images($v['images']);
            }
        } else {
            $shenhe = [];
        }
        $is_me = Db::name('baoxiudan')->where(['user_id' => $user_id])->where(['id' => $id])->find();
        if (!empty($is_me)) {
            $is_me2222 = 1;
        } else {
            $is_me2222 = 0;
        }

        //
        if (empty($arr['redio_time']) || $arr['redio_time'] == null || $arr['redio_time'] == '' || $arr['redio_time'] == "") {
            $redio_time = '';
        } else {
            $redio_time = date('Y-m-d H:i:s', $arr['redio_time']);
        }
        if (empty($arr['ok_time']) || $arr['ok_time'] == null || $arr['ok_time'] == '' || $arr['ok_time'] == "") {
            $ok_time = '';
        } else {
            $ok_time = date('Y-m-d H:i:s', $arr['ok_time']);
        }
        if (empty($arr['yuji']) || $arr['yuji'] == null || $arr['yuji'] == '' || $arr['yuji'] == "") {
            $yuji = '';
        } else {
            $yuji = date('Y-m-d H:i:s', $arr['yuji']);
        }
        //是否是维修总负责人 是否可以分配给维修负责人
        if ($level == 7) {
            if ($arr['fenpei_type'] == 0) {
                $WXZFZR = 1;
            } else {
                $WXZFZR = 0;
            }
        } else {
            $WXZFZR = 0;
        }
        //是否是维修负责人 是否可以进行分配给维修成员
        if ($level == 3) {
            if ($arr['wx_user_id'] == $user_id) {
                if ($arr['fenpei_type'] == 1) {
                    $FPWXCY = 1;
                }
            } else {
                $FPWXCY = 0;
            }
        } else {
            $FPWXCY = 0;
        }
        $list = [
            'allocation' => $WXZFZR, //是否可以进行维修总负责人分配权限 1=是,0=否
            'fpwxcy' => $FPWXCY, //是否可以进行维修负责人分配维修成员 1=是,0=否
            'level' => $level, //用户等级
            'repair_type' => $arr['repair_type'], //维修状态:0=未接收,1=进行中,2=已完成
            'type' => $arr['type'], //报修单状态:1=进行中,2=已完成
            'is_weixiu' => $is_weixiu, //非维修人员查看为0,维修人员查看详情时,1=分配到当前用户,2=否
            'is_me' => $is_me2222,  //是否是自己报修单 1=是0=否
            'title' => $arr['title'], //报修内容
            'address' => $arr['address'], //地点
            'colum' => $arr['colum'], //故障设备名称
            'system' => $xitong, //所属系统
            'time' => date('Y-m-d H:i:s', $arr['time']), //上报时间
            'people_name' => $arr['people_name'], //上报人
            'redio_user' => $redio_user, //维修人
            'zhandian' => $zhandian, //站点名称
            'colum_con' => $arr['colum_con'], //故障现象
            'images' => $images, //照片
            'is_genghuan' => $arr['is_genghuan'], //是否需要更换设备:1=是,2=否
            'IsTalk' => $Is_talk, //是否可以评价 1=是,0=否
            'price' => $arr['price'], //设备价格:0=不需要更换设备,1=2000以下,2=2000-10000元,3=10000元以上
            'status' => $arr['status'], //审核状态:0=不需要审核,1=等待审核,2=审核通过,3=审核未通过
            'weixiu' => $arr['weixiu'],//维修情况
            'jidian' => $arr['jidian'], //机电负责人意见
            'holder' => $arr['holder'], //分管领导意见
            'fuzeren' => $arr['fuzeren'], //维修负责人意见
            'zaicishenhe' => $shenhe, //再次审核内容
            'king_type' => $arr['king_type'], //KingType
            'redio_time' => $redio_time, //维修时间
            'ok_time' => $ok_time, //修复时间
            'yuji' => $yuji, //预计修复时间
        ];
        $this->success('成功', $list);
    }


    /**
     * @ApiTitle    (首页-维修成员列表)
     * @ApiSummary  (维修成员列表)
     * @ApiMethod (POST)
     * @ApiRoute    (/api/Index/PeopleList)
     * @ApiReturnParams   (name="code", type="integer", required=true,  sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    "code":"1",
    "msg": "返回成功",
    "data": [
    {
    "id": 用户ID,
    "name": "姓名"
    }
    ]
    })
     */
    public function PeopleList()
    {
        $arr = Db::name('user')->where(['level' => 4])->order('id desc')->select();
        if (empty($arr)) {
            $list = [];
        } else {
            foreach ($arr as $k => $v) {
                $list[$k]['id'] = $v['id'];
                $list[$k]['name'] = $v['name'];
            }
        }
        $this->success('成功', $list);
    }


    /**
     * @ApiTitle    (首页-维修负责人列表)
     * @ApiSummary  (维修负责人列表)
     * @ApiMethod (POST)
     * @ApiRoute    (/api/Index/FuZePeopleList)
     * @ApiReturnParams   (name="code", type="integer", required=true,  sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    "code":"1",
    "msg": "返回成功",
    "data": [
    {
    "id": 用户ID,
    "name": "姓名"
    }
    ]
    })
     */
    public function FuZePeopleList()
    {
        $arr = Db::name('user')->where(['level' => 3])->order('id desc')->select();
        if (empty($arr)) {
            $list = [];
        } else {
            foreach ($arr as $k => $v) {
                $list[$k]['id'] = $v['id'];
                $list[$k]['name'] = $v['name'];
            }
        }
        $this->success('成功', $list);
    }


    /**
     * @ApiTitle    (首页-再次提交审核)
     * @ApiSummary  (再次提交审核)
     * @ApiMethod (POST)
     * @ApiRoute    (/api/Index/TiJiaoStatus)
     * @ApiHeaders  (name="id", type=int, required=true, description="报修单ID")
     * @ApiHeaders  (name="con", type=int, required=true, description="文本")
     * @ApiHeaders  (name="images", type=int, required=true, description="图片 多张,拼接")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    "code":"1",
    "msg": "返回成功",
    "data":{
    }
    })
     */
    public function TiJiaoStatus()
    {
        $param = $this->request->param();
        $data = [
            'order_id' => $param['id'],
            'con' => $param['con'],
            'images' => $param['images']
        ];
        $res = Db::name('answer')->insert($data);
        Db::name('baoxiudan')->where(['id' => $param['id']])->update(['status' => 1]);
        if ($res) {
            $this->success('提交成功', 1);
        } else {
            $this->error('提交失败', 0);
        }
    }


    /**
     * @ApiTitle    (首页-分配维修员)
     * @ApiSummary  (分配维修员)
     * @ApiMethod (POST)
     * @ApiRoute    (/api/Index/FenPei)
     * @ApiHeaders  (name="id", type=int, required=true, description="报修单ID")
     * @ApiHeaders  (name="user_id", type=int, required=true, description="维修人员用户ID")
     * @ApiHeaders  (name="start_time", type=int, required=true, description="维修时间 linux时间戳")
     * @ApiHeaders  (name="end_time", type=int, required=true, description="修复时间 linux时间戳")
     * @ApiHeaders  (name="con", type=int, required=true, description="修复内容")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    "code":"1",
    "msg": "返回成功",
    "data":{
    }
    })
     */
    public function FenPei()
    {
        $param = $this->request->param();
        $data = [
            'redio_user_id' => $param['user_id'],
            'redio_time' => $param['start_time'] / 1000,
            'ok_time' => $param['end_time'] / 1000,
            'redio_con' => $param['con']
        ];
        $res = Db::name('baoxiudan')->where(['id' => $param['id']])->update($data);
        if ($res) {
            $this->success('分配成功', 1);
        } else {
            $this->error('分配失败', 0);
        }
    }


    /**
     * @ApiTitle    (首页-分配维修负责人)
     * @ApiSummary  (分配维修负责人)
     * @ApiMethod (POST)
     * @ApiRoute    (/api/Index/FenPeiWxFzr)
     * @ApiHeaders  (name="authorization", type=string, required=true, description="请求的Token")
     * @ApiHeaders  (name="id", type=int, required=true, description="报修单ID")
     * @ApiHeaders  (name="user_id", type=int, required=true, description="维修负责人用户ID")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    "code":"1",
    "msg": "返回成功",
    "data":{
    }
    })
     */
    public function FenPeiWxFzr()
    {
        $user_id = $this->is_token($this->request->header());
        $param = $this->request->param();
        $data = [
            'wx_user_id' => $param['user_id'],
            'wxfzr_user_id' => $user_id,
        ];
        $res = Db::name('baoxiudan')->where(['id' => $param['id']])->update($data);
        if ($res) {
            $this->success('分配成功', 1);
        } else {
            $this->error('分配失败', 0);
        }
    }


    /**
     * @ApiTitle    (首页-维修成员报修单操作)
     * @ApiSummary  (维修成员报修单操作)
     * @ApiMethod (POST)
     * @ApiRoute    (/api/Index/OrderPlay)
     * @ApiHeaders  (name="id", type=int, required=true, description="报修单ID")
     * @ApiHeaders  (name="type", type=int, required=true, description="设备价格:0=不需要更换设备,1=需要更换设备")
     * @ApiHeaders  (name="con", type=int, required=true, description="维修情况")
     * @ApiHeaders  (name="time", type=int, required=true, description="时间戳")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    "code":"1",
    "msg": "返回成功",
    "data":{
    }
    })
     */
    public function OrderPlay()
    {
        $param = $this->request->param();
        if ($param['type'] == 2) {
            $is_genghuan = 2;
            $status = 0;
        } else {
            $is_genghuan = 1;
            $status = 1;
        }
        $res = Db::name('baoxiudan')->where(['id' => $param['id']])->update(
            [
                'is_genghuan' => $is_genghuan,
                'price' => $param['type'],
                'status' => $status,
                'repair_type' => 1,
                'yuji' => $param['time'] / 1000
            ]
        );
        if ($res) {
            $this->success('成功', $status);
        } else {
            $this->error('失败', 0);
        }
    }


    /**
     * @ApiTitle    (首页-维修负责人报修单操作)
     * @ApiSummary  (维修负责人报修单操作)
     * @ApiMethod (POST)
     * @ApiRoute    (/api/Index/OrderPlayKing)
     * @ApiHeaders  (name="id", type=int, required=true, description="报修单ID")
     * @ApiHeaders  (name="type", type=int, required=true, description="设备价格:1=2000以下,2=2000-10000元,3=10000元以上")
     * @ApiHeaders  (name="con", type=int, required=true, description="维修情况")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    "code":"1",
    "msg": "返回成功",
    "data":{
    }
    })
     */
    public function OrderPlayKing()
    {
        $param = $this->request->param();
        if ($param['type'] == 1) {
            $status = 2;
            $res = Db::name('baoxiudan')->where(['id' => $param['id']])->update(
                [
                    'price' => $param['type'],
                    'status' => $status,
                    'king_type' => 1,
                ]
            );
        }
        if ($param['type'] == 2) {
            $status = 1;
            $fuzeren = $param['con'];
            $res = Db::name('baoxiudan')->where(['id' => $param['id']])->update(
                [
                    'price' => $param['type'],
                    'status' => $status,
                    'fuzeren' => $fuzeren,
                    'king_type' => 1,
                ]
            );
        }
        if ($param['type'] == 3) {
            $status = 1;
            $fuzeren = $param['con'];
            $res = Db::name('baoxiudan')->where(['id' => $param['id']])->update(
                [
                    'price' => $param['type'],
                    'status' => $status,
                    'fuzeren' => $fuzeren,
                    'king_type' => 1,
                ]
            );
        }
        if ($res) {
            $this->success('成功', 1);
        } else {
            $this->error('失败', 0);
        }
    }


    /**
     * @ApiTitle    (首页-审核)
     * @ApiSummary  (审核)
     * @ApiMethod (POST)
     * @ApiRoute    (/api/Index/Status)
     * @ApiHeaders  (name="authorization", type=string, required=true, description="请求的Token")
     * @ApiHeaders  (name="id", type=int, required=true, description="报修单ID")
     * @ApiHeaders  (name="type", type=int, required=true, description="审核状态:2=通过,3=不通过")
     * @ApiHeaders  (name="con", type=string, required=true, description="意见")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    "code":"1",
    "msg": "返回成功",
    "data":{
    }
    })
     */
    public function Status()
    {
        $param = $this->request->param();
        $user_id = $this->is_token($this->request->header());
        $level = Db::name('user')->where(['id' => $user_id])->value('level');
        if ($level == 1 || $level == 2) {
            if ($level == 1) {
                Db::name('baoxiudan')->where(['id' => $param['id']])->update(
                    [
                        'holder' => $param['con']
                    ]
                );
            }
            if ($level == 2) {
                Db::name('baoxiudan')->where(['id' => $param['id']])->update(
                    [
                        'jidian' => $param['con']
                    ]
                );
            }
        } else {
            $this->error('内部错误,您没有权限,90111', 0);
            die;
        }
        $res = Db::name('baoxiudan')->where(['id' => $param['id']])->update(
            [
                'status' => $param['type']
            ]
        );
        if ($res) {
            $this->success('成功', 1);
        } else {
            $this->error('失败', 0);
        }
    }

    /**
     * @ApiTitle    (首页-维修情况添加)
     * @ApiSummary  (维修情况添加)
     * @ApiMethod (POST)
     * @ApiRoute    (/api/Index/WeiXiuQ)
     * @ApiHeaders  (name="authorization", type=string, required=true, description="请求的Token")
     * @ApiHeaders  (name="id", type=int, required=true, description="报修单ID")
     * @ApiHeaders  (name="con", type=string, required=true, description="维修情况)
     * @ApiReturnParams   (name="code", type="integer", required=true,  sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    "code":"1",
    "msg": "返回成功",
    "data":{
    }
    })
     */
    public function WeiXiuQ()
    {
        $param = $this->request->param();
        $user_id = $this->is_token($this->request->header());
        $level = Db::name('user')->where(['id' => $user_id])->value('level');
        if ($level != 4) {
            $this->error('身份错误', 0);
        }
        $data = [
            'weixiu' => $param['con']
        ];
        $res = Db::name('baoxiudan')->where(['id' => $param['id']])->update($data);
        if ($res) {
            $this->success('成功', 1);
        } else {
            $this->error('失败', 0);
        }
    }


    /**
     * @ApiTitle    (首页-维修完成)
     * @ApiSummary  (维修完成)
     * @ApiMethod (POST)
     * @ApiRoute    (/api/Index/WeiXiuAn)
     * @ApiHeaders  (name="authorization", type=string, required=true, description="请求的Token")
     * @ApiHeaders  (name="id", type=int, required=true, description="报修单ID")
     * @ApiHeaders  (name="con", type=int, required=true, description="维修情况")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    "code":"1",
    "msg": "返回成功",
    "data":{
    }
    })
     */
    public function WeiXiuAn()
    {
        $id = input('id');
        $con = input('con');
        $user_id = $this->is_token($this->request->header());
        $is_weixiu = Db::name('baoxiudan')->where(['id' => $id])->where(['redio_user_id' => $user_id])->find();
        if (empty($is_weixiu)) {
            $this->error('内部错误', 0);
        }
        $res = Db::name('baoxiudan')->where(['id' => $id])->update(['repair_type' => 2, 'weixiu' => $con]);
        if ($res) {
            $this->success('成功', 1);
        } else {
            $this->error('失败', 0);
        }
    }


    /**
     * @ApiTitle    (首页-验收)
     * @ApiSummary  (审核)
     * @ApiMethod (POST)
     * @ApiRoute    (/api/Index/YanShou)
     * @ApiHeaders  (name="authorization", type=string, required=true, description="请求的Token")
     * @ApiHeaders  (name="id", type=int, required=true, description="报修单ID")
     * @ApiHeaders  (name="type", type=int, required=true, description="1=验收已完成,2=验收未完成")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    "code":"1",
    "msg": "返回成功",
    "data":{
    }
    })
     */
    public function YanShou()
    {
        $id = input('id');
        $type = input('type');
        $user_id = $this->is_token($this->request->header());
        $is_weixiu = Db::name('baoxiudan')->where(['id' => $id])->where(['user_id' => $user_id])->find();
        if (empty($is_weixiu)) {
            $this->error('内部错误', 0);
        }
        if ($type == 1) {
            $res = Db::name('baoxiudan')->where(['id' => $id])->update(['type' => 2]);
        } else {
            $res = Db::name('baoxiudan')->where(['id' => $id])->update(['repair_type' => 1]);
        }
        if ($res) {
            $this->success('成功', 1);
        } else {
            $this->error('失败', 0);
        }
    }


    /**
     * @ApiTitle    (首页-添加评价)
     * @ApiSummary  (添加评价)
     * @ApiMethod (POST)
     * @ApiRoute    (/api/Index/AddTalk)
     * @ApiHeaders  (name="authorization", type=string, required=true, description="请求的Token")
     * @ApiHeaders  (name="id", type=int, required=true, description="报修单ID")
     * @ApiHeaders  (name="weixiu_star", type=int, required=true, description="维修服务")
     * @ApiHeaders  (name="taidu_star", type=int, required=true, description="维修态度")
     * @ApiHeaders  (name="talk_num", type=int, required=true, description="评价分数")
     * @ApiHeaders  (name="talk_con", type=int, required=true, description="评价内容")
     * @ApiReturnParams   (name="code", type="integer", required=true,  sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    "code":"1",
    "msg": "返回成功",
    "data": {
    }
    })
     */
    public function AddTalk()
    {
        $param = $this->request->param();
        if ($param['talk_num'] < 1 || $param['talk_num'] > 100) {
            $this->error('评价分数错误', 0);
        }
        $data = [
            'fuwu' => $param['weixiu_star'],
            'taiudu' => $param['taidu_star'],
            'talk_up' => $param['talk_num'],
            'talk_con' => $param['talk_con']
        ];
        $res = Db::name('baoxiudan')->where(['id' => $param['id']])->update($data);
        if ($res) {
            $this->success('成功', 1);
        } else {
            $this->error('失败', 0);
        }
    }


    /**
     * @ApiTitle    (首页-添加月评价)
     * @ApiSummary  (添加月评价)
     * @ApiMethod (POST)
     * @ApiRoute    (/api/Index/AddMonthTalk)
     * @ApiHeaders  (name="authorization", type=string, required=true, description="请求的Token")
     * @ApiHeaders  (name="weixiu_star", type=int, required=true, description="维修服务")
     * @ApiHeaders  (name="taidu_star", type=int, required=true, description="维修态度")
     * @ApiHeaders  (name="talk_num", type=int, required=true, description="评价分数")
     * @ApiHeaders  (name="talk_con", type=int, required=true, description="评价内容")
     * @ApiReturnParams   (name="code", type="integer", required=true,  sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    "code":"1",
    "msg": "返回成功",
    "data": {
    }
    })
     */
    public function AddMonthTalk()
    {
        $user_id = $this->is_token($this->request->header());
        $param = $this->request->param();
        $data = [
            'createtime' => time(),
            'weixiu_star' => $param['weixiu_star'],
            'taidu_star' => $param['taidu_star'],
            'talk_num' => $param['talk_num'],
            'talk_con' => $param['talk_con'],
            'user_id' => $user_id
        ];
        $res = Db::name('month_talk')->insert($data);
        if ($res) {
            $this->success('成功', 1);
        } else {
            $this->error('失败', 0);
        }
    }


}