Yuyue.php 27.5 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
<?php


namespace app\api\controller;

use think\Db;
use app\common\controller\Api;
use think\Request;

/**
 * 预约单接口
 */
class Yuyue extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = '*';


    /**
     * @ApiTitle    (我的预约单)
     * @ApiSummary  (我的预约单)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/Yuyue/MyYuyueOrder)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="YMD", type="string", required=true, description="2021-07-21筛选时间")
     * @ApiParams   (name="nickname", type="string", required=true, description="姓名")
     * @ApiParams   (name="pages", type="string", required=true, description="pages")
     * @ApiParams   (name="rows", type="string", required=true, description="rows")
     * @ApiParams   (name="status", type="string", required=true, description="状态:0=待使用,1=已使用,2=已失效,3=已评论,-1=全部")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功',
    "data": {
    "UserStatus": 0,  //身份:0=用户,1=教练,2=超级教练员
    "Count": 2, //总数
    "List": [
    {
    "id": 5407,
    "avatar": "http://www.airplane.net/uploads/20210409/c67e12745beeef9acbbdfdca0c14dec1.jpg",
    "plane_title": "阿波罗三号",
    "timeA": "2021-04-09",
    "timeB": "17 - 18",
    "UserNmae": "王叨叨", //用户
    "TeacherNmae": "教练", //教练
    "status": 2, //状态:0=待使用,1=已使用,2=已失效,3=已评论
    "type": 2, //失效类型:0=未失效,1=禁飞,2=爽约
    "no_price_type": 0 //是否需要支付爽约费用:0=否,1=是
    }
    ]
    }
    })
     */
    public function MyYuyueOrder()
    {
        $UserIO = $this->IsToken();
        $Params = $this->request->param();
        $Map = [];
        $List = [];
        if (Db::name('user')->where('id', $UserIO)->value('status') == 0) $Map['y.user_id'] = ['EQ', $UserIO];
        else $Map['y.teacher_id'] = ['EQ', $UserIO];
        if ($Params['status'] == 1) $Map['y.status'] = ['IN', '1,3'];
        elseif ($Params['status'] != -1) $Map['y.status'] = ['EQ', $Params['status']];
        if (isset($Params['YMD'])) {
            $Sto = strtotime($Params['YMD']);
            $start_time = mktime(0, 0, 0, date('m', $Sto), date('d', $Sto), date('Y', $Sto));
            $end_time = mktime(0, 0, 0, date('m', $Sto), date('d', $Sto) + 1, date('Y', $Sto)) - 1;
            $Map['y.sun_createtime'] = ['between', [$start_time, $end_time]];
        }
        if (isset($Params['nickname'])) {
            $Map['u.nickname'] = ['LIKE', '%' . $Params['nickname'] . '%'];
        }
        $Info = Db::name('yuyue')
            ->alias('y')
            ->where($Map)
            ->join('plane p', 'p.id=y.plane_id')
            ->join('sun s', 's.id=y.sun_id')
            ->join('time t', 't.id=s.time_id')
            ->join('user u', 'u.id=y.user_id')
            ->order('y.sun_createtime desc,s.time_id desc')
            ->page($Params['pages'], $Params['rows'])
            ->field('y.id,p.avatar,p.title as plane_title,y.sun_createtime,t.title as time_title,y.user_id,y.teacher_id,y.status,y.type,y.no_price_type')
            ->select();
        if (!empty($Info)) foreach ($Info as $k => $v) {
            $List[$k]['id'] = $v['id'];
            $List[$k]['avatar'] = cdnurl($v['avatar']);
            $List[$k]['plane_title'] = $v['plane_title'];
            $List[$k]['timeA'] = date('Y-m-d', $v['sun_createtime']);
            $List[$k]['timeB'] = $v['time_title'];
            $List[$k]['UserNmae'] = Db::name('user')->where('id', $v['user_id'])->value('nickname');
            $List[$k]['TeacherNmae'] = Db::name('user')->where('id', $v['teacher_id'])->value('nickname');
            $List[$k]['status'] = $v['status'];
            $List[$k]['type'] = $v['type'];
            $List[$k]['no_price_type'] = $v['no_price_type'];
        }
        $data = [
            'UserStatus' => Db::name('user')->where('id', $UserIO)->value('status'),
            'Count' => count(Db::name('yuyue')
                ->alias('y')
                ->where($Map)
                ->join('plane p', 'p.id=y.plane_id')
                ->join('sun s', 's.id=y.sun_id')
                ->join('time t', 't.id=s.time_id')
                ->field('y.id')
                ->select()),
            'List' => $List
        ];
        $this->success('成功', $data);
    }

    /**
     * @ApiTitle    (预约单详情)
     * @ApiSummary  (预约单详情)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/Yuyue/OrderCon)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="id", type="string", 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": {
    "UserStatus": 0,  //身份:0=用户,1=教练,2=超级教练员
    "id": 5407,
    "avatar": "http://www.airplane.net/uploads/20210409/c67e12745beeef9acbbdfdca0c14dec1.jpg",
    "base_title": "上海澄胡基地",
    "plane_title": "阿波罗三号",
    "timeA": "2021-04-09",
    "timeB": "17 - 18",
    "user_id": 1,
    "teacher_id": 2,
    "UserNmae": "王叨叨", //用户
    "TeacherNmae": "教练", //教练
    "status": 2, //状态:0=待使用,1=已使用,2=已失效,3=已评论
    "type": 2, //失效类型:0=未失效,1=禁飞,2=爽约
    "no_price_type": 0 //是否需要支付爽约费用:0=否,1=是
    "IsTalk": 1  //1=已评论,0=否,
    "Json": [//json
    {
    "open_car_time": "11:00",//开车时间
    "close_car_time": "11:00",//关车时间
    "down_time": "11:00",//着陆时间
    "flysky_time": "11:00",//起飞时间
    "number": "11:00",//起落次数
    "count_fly_time": "11:00"//飞行时间
    }
    ]
    }
    })
     */
    public function OrderCon()
    {
        $UserID = $this->IsToken();
        $Info = Db::name('yuyue')
            ->alias('y')
            ->where('y.id', input('id'))
            ->join('plane p', 'p.id=y.plane_id')
            ->join('sun s', 's.id=y.sun_id')
            ->join('base b', 'b.id=p.base_id')
            ->join('time t', 't.id=s.time_id')
            ->order('y.id desc')
            ->field('y.id,p.avatar,b.title as base_title,p.title as plane_title,y.FlyMinutes,y.json,y.sun_createtime as timeA,t.title as timeB,y.user_id,y.teacher_id,y.status,y.type,y.no_price_type,y.name,y.work,y.cloud_card_num,y.airplane_type,y.airplane_number,y.fly_type,y.teacher_name,y.beizhu')
            ->find();
        $Info['avatar'] = cdnurl($Info['avatar']);
        $Info['timeA'] = date('Y-m-d', $Info['timeA']);
        $Info['UserNmae'] = Db::name('user')->where('id', $Info['user_id'])->value('nickname');
        $Info['TeacherNmae'] = Db::name('user')->where('id', $Info['teacher_id'])->value('nickname');
        $Info['IsTalk'] = (Db::name('yuyue')->where('id', input('id'))->value('talk') == null) ? 0 : 1;
        $Info['UserStatus'] = Db::name('user')->where('id', $UserID)->value('status');
//        $Info['FlyMinutes'] = $Info['FlyMinutes'] / 60;
//        $Info['open_car_time'] = date('Y-m-d H:i:s', $Info['open_car_time']);
//        $Info['flysky_time'] = date('Y-m-d H:i:s', $Info['flysky_time']);
//        $Info['down_time'] = date('Y-m-d H:i:s', $Info['down_time']);
//        $Info['close_car_time'] = date('Y-m-d H:i:s', $Info['close_car_time']);
        $Json = json_decode($Info['json'], true);
        if (!empty($Json)) {
            foreach ($Json as $k => $v) {
                $Info['Json'][$k]['open_car_time'] = $v['open_car_time'];
                $Info['Json'][$k]['close_car_time'] = $v['close_car_time'];
                $Info['Json'][$k]['down_time'] = $v['down_time'];
                $Info['Json'][$k]['flysky_time'] = $v['flysky_time'];
                $Info['Json'][$k]['number'] = $v['number'];
                $Info['Json'][$k]['count_fly_time'] = $v['count_fly_time'];
            }
        } else {
            $Info['Json'] = [];
        }
        $this->success('成功', $Info);
    }


    /**
     * @ApiTitle    (评论问题列表)
     * @ApiSummary  (评论问题列表)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/Yuyue/QuestionList)
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功',
    "data": [
    {
    "question": "本次飞行训练教员保障飞行安全评分"
    },
    {
    "question": "本次飞行训练教员理论指导评分"
    },
    {
    "question": "本次飞行训练教员飞行技术评分"
    },
    {
    "question": "本次飞行训练教员空中专心施教评分"
    },
    {
    "question": "本次飞行训练教员鼓励教学方式评分"
    },
    {
    "question": "本次飞行训练教员态度热情评分"
    },
    {
    "question": "本次飞行训练教员耐心施教评分"
    },
    {
    "question": "本次飞行训练教员个人仪容仪表评分"
    },
    {
    "question": "本次飞行训练座舱干净整洁评分"
    }
    ]
    })
     */
    public function QuestionList()
    {
        $List = [];
        $List = Db::name('question')->order('weigh desc')->field('question')->select();
        $this->success('成功', $List);
    }


    /**
     * @ApiTitle    (评论)
     * @ApiSummary  (评论)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/Yuyue/InsertTalk)
     * @ApiParams   (name="id", type="string", required=true, description="预约单ID")
     * @ApiParams   (name="json", type="string", required=true, description="评论内容Json[{‘List’:[{’question‘:‘问题文字’,‘num’:1/分数}],‘Content‘:‘评论详情‘}]")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功',
    })
     */
    public function InsertTalk()
    {
        $Params = Request::instance()->post(false);
        if (Db::name('yuyue')->where('id', $Params['id'])->value('talk') != null) $this->error('不允许重复评论');
        $Res = Db::name('yuyue')->where('id', $Params['id'])->update(['status' => 3, 'talk' => $Params['json'], 'updatetime' => time()]);
        $this->Res($Res);
    }


    /**
     * @ApiTitle    (查看评论)
     * @ApiSummary  (查看评论)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/Yuyue/LookTalk)
     * @ApiParams   (name="id", type="string", 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": {
    "List": [
    {
    "question": "本次飞行训练教员保障飞行安全评分",
    "num": 1
    },
    {
    "question": "本次飞行训练教员理论指导评分",
    "num": 1
    },
    {
    "question": "本次飞行训练教员飞行技术评分",
    "num": 1
    },
    {
    "question": "本次飞行训练教员空中专心施教评分",
    "num": 1
    },
    {
    "question": "本次飞行训练教员鼓励教学方式评分",
    "num": 1
    },
    {
    "question": "本次飞行训练教员态度热情评分",
    "num": 1
    },
    {
    "question": "本次飞行训练教员耐心施教评分",
    "num": 1
    },
    {
    "question": "本次飞行训练教员个人仪容仪表评分",
    "num": 1
    },
    {
    "question": "本次飞行训练座舱干净整洁评分",
    "num": 1
    }
    ],
    "Content": "评论内容"
    }
    })
     */
    public function LookTalk()
    {
        $this->success('成功', json_decode(Db::name('yuyue')->where('id', input('id'))->value('talk'), true));
    }


    /**
     * @ApiTitle    (预约单操作)
     * @ApiSummary  (预约单操作)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/Yuyue/YuyueOrderUpdate)
     * @ApiParams   (name="id", type="string", required=true, description="预约单ID")
     * @ApiParams   (name="status", type="string", required=true, description="0=未爽约1=爽约")
     * @ApiParams   (name="fly_time", type="string", required=true, description="飞行时间(分钟)")
     * @ApiParams   (name="name", type="string", required=true, description="姓名")
     * @ApiParams   (name="work", type="string", required=true, description="职位")
     * @ApiParams   (name="cloud_card_num", type="string", required=true, description="云执照档案号")
     * @ApiParams   (name="json", type="string", required=true, description="json")
     * @ApiParams   (name="airplane_type", type="string", required=true, description="飞机型号")
     * @ApiParams   (name="airplane_number", type="string", required=true, description="飞机登记号")
     * @ApiParams   (name="fly_type", type="string", required=true, description="飞行种类:0=训练,1=机长,2=单飞")
     * @ApiParams   (name="teacher_name", type="string", required=true, description="本次飞行教员姓名")
     * @ApiParams   (name="IsFirst", type="string", required=true, description="1=首次,0=否")
     * @ApiParams   (name="car_image_zheng", type="string", required=true, description="身份证正")
     * @ApiParams   (name="car_image_fan", type="string", required=true, description="身份证反")
     * @ApiParams   (name="kaoshi_image", type="string", required=true, description="考试")
     * @ApiParams   (name="danfei_image", type="string", required=true, description="单飞")
     * @ApiParams   (name="jieye_image", type="string", required=true, description="结业")
     * @ApiParams   (name="tijian_image", type="string", required=true, description="体检")
     * @ApiParams   (name="beizhu", 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 YuyueOrderUpdate()
    {
        $Params = $this->request->param();
        $Params['json'] = htmlspecialchars_decode($this->request->post('json'));
        $Info = Db::name('yuyue')->where('id', $Params['id'])->find();
        if ($Params['status'] == 0) {
            /*未爽约*/
            $data = [
                'status' => 1,
                'FlyMinutes' => $Params['fly_time'],
                'updatetime' => time()
            ];
            $DeleteMinutes = $Params['fly_time'];
            $CountMinutes = Db::name('user')->where('id', $Info['user_id'])->value('CountMinutes');
            Db::name('user')->where('id', $Info['user_id'])->update(['CountMinutes' => $CountMinutes + $Params['fly_time']]);
        } else {
            /*已爽约*/
            $data = [
                'status' => 2,
                'type' => 2,
                'no_price_type' => 1,
                'no_price' => Db::name('plane')->where('id', $Info['plane_id'])->value('no_price'),
                'updatetime' => time()
            ];
            $DeleteMinutes = 0;
        }
        /*更改预约单状态*/
        Db::name('yuyue')->where('id', $Params['id'])->update($data);
        /*新增数据*/
        $NewAdd = [
            'name' => $Params['name'],
            'work' => $Params['work'],
            'cloud_card_num' => $Params['cloud_card_num'],
//            'open_car_time' => strtotime($Params['open_car_time']),
//            'flysky_time' => strtotime($Params['flysky_time']),
//            'down_time' => strtotime($Params['down_time']),
//            'close_car_time' => strtotime($Params['close_car_time']),
//            'number' => $Params['number'],
            'json' => $Params['json'],
            'airplane_type' => $Params['airplane_type'],
            'airplane_number' => $Params['airplane_number'],
            'fly_type' => $Params['fly_type'],
            'teacher_name' => $Params['teacher_name'],
            'beizhu' => $Params['beizhu'],
            'updatetime' => time()
        ];
        Db::name('yuyue')->where('id', $Params['id'])->update($NewAdd);
        /*是否首次*/
        if ($Params['IsFirst'] == 1) {
            $First = [
                'car_image_zheng' => $Params['car_image_zheng'],
                'car_image_fan' => $Params['car_image_fan'],
                'kaoshi_image' => $Params['kaoshi_image'],
                'danfei_image' => $Params['danfei_image'],
                'jieye_image' => $Params['jieye_image'],
                'tijian_image' => $Params['tijian_image']
            ];
            Db::name('user')->where('id', $Info['user_id'])->update($First);
        }
        /*减少待扣除时间 减少剩余飞行时间*/
        $GoodsAfter = Db::name('goods_after')->where('plane_type_id', Db::name('plane')->where('id', $Info['plane_id'])->value('plane_type_id'))->where('user_id', $Info['user_id'])->find();
        if (empty($GoodsAfter)) $this->error('您还没有购买该产品', 0);
        Db::name('goods_after')->where('plane_type_id', Db::name('plane')->where('id', $Info['plane_id'])->value('plane_type_id'))->where('user_id', $Info['user_id'])->update(['AfterMinutes' => $GoodsAfter['AfterMinutes'] - 60, 'SupMinutes' => $GoodsAfter['SupMinutes'] - $DeleteMinutes]);
        $this->success('成功', 1);
    }


    /**
     * @ApiTitle    (发布禁飞通知)
     * @ApiSummary  (发布禁飞通知)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/Yuyue/InsertKillPlane)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="base_id", type="string", required=true, description="基地ID")
     * @ApiParams   (name="start_time", type="string", required=true, description="2021-04-08 12开始时间")
     * @ApiParams   (name="end_time", type="string", required=true, description="2021-04-08 13结束时间")
     * @ApiParams   (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 InsertKillPlane()
    {
        $UserID = $this->IsToken();
        $Params = $this->request->param();
        $data = [
            'user_id' => $UserID,
            'base_id' => $Params['base_id'],
            'start_time' => strtotime($Params['start_time'] . ':00'),
            'end_time' => strtotime($Params['end_time'] . ':00'),
            'con' => $Params['con'],
            'createtime' => time()
        ];
        /*新增禁飞通知*/
        $Kill_plane_id = Db::name('kill_plane')->insertGetId($data);
        /*查询所有预约*/
        $Map['s.createtime'] = ['between', [strtotime(date('Y-m-d', strtotime($Params['start_time'] . ':00'))), strtotime(date('Y-m-d', strtotime($Params['end_time'] . ':00'))) + 86399]];
        $SunInfo = Db::name('sun')->field('s.*')->alias('s')->join('plane p', 'p.id=s.plane_id')->where('p.base_id', $Params['base_id'])->where($Map)->select();
        if (!empty($SunInfo)) foreach ($SunInfo as $k => $v) {
            if (($this->TimeCrcle($v['id']) > strtotime($Params['start_time'] . ':00') - 1) && ($this->TimeCrcle($v['id']) < strtotime($Params['end_time'] . ':00'))) {
                if ($v['status'] == 3) {
                    /*修改用户产品剩余时间统计表*/
                    $GoodsAfter = Db::name('goods_after')->where('plane_type_id', Db::name('plane')->where('id', $v['plane_id'])->value('plane_type_id'))->where('user_id', $v['user_id'])->find();
                    Db::name('goods_after')->where('plane_type_id', Db::name('plane')->where('id', $v['plane_id'])->value('plane_type_id'))->where('user_id', $v['user_id'])->update(['AfterMinutes' => $GoodsAfter['AfterMinutes'] - 60]);
                    /*修改预约单*/
                    Db::name('yuyue')->where('sun_id', $v['id'])->update(['status' => 2, 'type' => 1, 'updatetime' => time()]);
                    /*发送短信*/
                    $Mobile = Db::name('user')->where('id', $v['user_id'])->value('mobile');
                    if (!empty($Mobile) || $Mobile != '') {
                        $this->SendSms($Mobile, '【华北飞行基地】' . $Params['con']);
                    }
                }
                /*修改预约列表*/
                Db::name('sun')->where('id', $v['id'])->update(['user_id' => '', 'status' => 2, 'updatetime' => time()]);
            }
        }
        $this->success('成功', 1);
    }


    /**
     * @ApiTitle    (禁飞通知列表)
     * @ApiSummary  (禁飞通知列表)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/Yuyue/KillPlaneList)
     * @ApiParams   (name="base_id", type="string", required=true, description="基地")
     * @ApiParams   (name="pages", type="string", required=true, description="pages")
     * @ApiParams   (name="rows", type="string", required=true, description="rows")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功',
    "data": {
    "Count": 56,
    "List": [
    {
    "start_time": "2021-04-13 08",
    "end_time": "2021-04-13 10",
    "con": "禁飞通知",
    "createtime": "2021-04-09 17"
    }
    ]
    }
    })
     */
    public function KillPlaneList()
    {
        $Params = $this->request->param();
        $Info = [];
        $Info = Db::name('kill_plane')
            ->alias('k')
            ->order('k.id desc')
            ->where('k.base_id', $Params['base_id'])
            ->page($Params['pages'], $Params['rows'])
            ->field('k.start_time,k.end_time,k.con,k.createtime')
            ->select();
        if (!empty($Info)) foreach ($Info as $k => $v) {
            $Info[$k]['start_time'] = date('Y-m-d H', $v['start_time']);
            $Info[$k]['end_time'] = date('Y-m-d H', $v['end_time']);
            $Info[$k]['createtime'] = date('Y-m-d H', $v['createtime']);

        }
        $this->success('成功', ['Count' => count(Db::name('kill_plane')->order('id desc')->select()), 'List' => $Info]);
    }

    /**
     * @ApiTitle    (发布开飞通知)
     * @ApiSummary  (发布开飞通知)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/Yuyue/InsertKillNoPlane)
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="base_id", type="string", required=true, description="基地ID")
     * @ApiParams   (name="start_time", type="string", required=true, description="2021-04-08 12开始时间")
     * @ApiParams   (name="end_time", type="string", required=true, description="2021-04-08 13结束时间")
     * @ApiParams   (name="con", type="string", required=true, description="禁飞描述")
     * @ApiParams   (name="kong", type="string", required=true, description="空域情况")
     * @ApiParams   (name="status", type="string", required=true, description="是否发送短信:1=发送,0=不发送短信")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功',
    "data": {
    })
     */
    public function InsertKillNoPlane()
    {
        $UserID = $this->IsToken();
        $Params = $this->request->param();
        $data = [
            'user_id' => $UserID,
            'base_id' => $Params['base_id'],
            'start_time' => strtotime($Params['start_time'] . ':00'),
            'end_time' => strtotime($Params['end_time'] . ':00'),
            'con' => $Params['con'],
            'kong' => $Params['kong'],
            'createtime' => time()
        ];
        /*新增开飞通知*/
        $Kill_plane_id = Db::name('kill_no_plane')->insertGetId($data);
        /*查询所有预约*/
        $Map['s.createtime'] = ['between', [strtotime(date('Y-m-d', strtotime($Params['start_time'] . ':00'))), strtotime(date('Y-m-d', strtotime($Params['end_time'] . ':00'))) + 86399]];
        $SunInfo = Db::name('sun')->field('s.*')->alias('s')->join('plane p', 'p.id=s.plane_id')->where('p.base_id', $Params['base_id'])->where($Map)->select();
        if (!empty($SunInfo)) foreach ($SunInfo as $k => $v) {
            if (($this->TimeCrcle($v['id']) > strtotime($Params['start_time'] . ':00') - 1) && ($this->TimeCrcle($v['id']) < strtotime($Params['end_time'] . ':00'))) {
                /*发送短信*/
                $Bool = $this->Send($v['user_id'], $v['id']);
                if ($Params['status'] == 1) {
                    $User = \app\common\model\User::get($v['user_id']);
                    $this->SendSms($User->mobile, '【华北飞行基地】' . $Params['con'] . '空域情况:' . $Params['kong']);
                }
            }
        }
        $this->success('成功', 1);
    }

    /**
     * @ApiTitle    (开飞通知列表)
     * @ApiSummary  (开飞通知列表)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/Yuyue/KillNoPlaneList)
     * @ApiParams   (name="base_id", type="string", required=true, description="基地")
     * @ApiParams   (name="pages", type="string", required=true, description="pages")
     * @ApiParams   (name="rows", type="string", required=true, description="rows")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功',
    "data": {
    "Count": 56,
    "List": [
    {
    "start_time": "2021-04-13 08",
    "end_time": "2021-04-13 10",
    "con": "禁飞通知",
    "kong": "空域情况",
    "createtime": "2021-04-09 17"
    }
    ]
    }
    })
     */
    public function KillNoPlaneList()
    {
        $Params = $this->request->param();
        $Info = [];
        $Info = Db::name('kill_no_plane')
            ->alias('k')
            ->order('k.id desc')
            ->where('k.base_id', $Params['base_id'])
            ->page($Params['pages'], $Params['rows'])
            ->field('k.start_time,k.end_time,k.con,k.createtime,k.kong')
            ->select();
        if (!empty($Info)) foreach ($Info as $k => $v) {
            $Info[$k]['start_time'] = date('Y-m-d H', $v['start_time']);
            $Info[$k]['end_time'] = date('Y-m-d H', $v['end_time']);
            $Info[$k]['createtime'] = date('Y-m-d H', $v['createtime']);

        }
        $this->success('成功', ['Count' => count(Db::name('kill_plane')->order('id desc')->select()), 'List' => $Info]);
    }


    /**
     * @ApiTitle    (教练列表)
     * @ApiSummary  (教练列表)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/Yuyue/TeacherList)
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="返回成功")
     * @ApiReturn   ({
    'code':'1',
    'msg':'返回成功',
    })
     */
    public function TeacherList()
    {
        $Info = [];
        $Info = Db::name('user')->where('type', 0)->where('status', 'NEQ', 0)->field('id,nickname')->select();
        $this->success('成功', $Info);
    }
}