Index.php 32.6 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914
<?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'];  //报修时间
        }
        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
        ];
        $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']);
        }
        $list = [
            '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/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/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);
        }
    }


}