Create.php 23.0 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
<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/7/6
 * Time: 9:58
 */

namespace app\api\controller;


use app\common\controller\Api;

use Qiniu\Storage\UploadManager;
use think\Db;
use Qiniu\Auth;


/**
 * 发布接口
 */
class Create extends Api
{

    protected $noNeedLogin = [''];
    protected $noNeedRight = ['*'];


    /**
     * @ApiTitle    (创建文件夹)
     * @ApiSummary  (创建文件夹)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/create/publish_folder)
     *
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="id", type="inter", required=true, description="父级文件夹id首页为0")
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {

    }
    ]
    }
    })
     */
    public function publish_folder()
    {
        $user_id = $this->auth->id;
        $id = $this->request->param('id');
        $user = Db::name('user')->where('id',$user_id)->field('id,identity,audit')->find();
        //判断用户身份是否审核通过
        if($user['audit'] != 1){
            $this->error('身份身份通过才可发布!');
        }
        //判断用户身份是否有发布的权限
        if($user['identity'] == 1){
            $this->error('您的权限不足');
        }

        $res['user_id'] = $user_id;
        $res['folder_name'] = date('YmdHis');
        if(empty($id)){
            $res['pid'] = 0;
        }else{
            $res['pid'] = $id;
        }
        $res['createtime'] = time();
        $res['updatetime'] = time();

        $data = Db::name('folder')->insertGetId($res);
        if(empty($data)){
            $this->error('sql运行失败');
        }else{
            $this->success('success',$data);
        }
    }

    /**
     * @ApiTitle    (发布图片)
     * @ApiSummary  (发布图片)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/create/publish_pic)
     *
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="images", type="string", required=true, description="图片内容")
     * @ApiParams   (name="folder_id", type="inter", required=true, description="存储位置id 首页为0")
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {

    }
    })
     */
    public function publish_pic()
    {
        $user_id = $this->auth->id;
        $user = Db::name('user')->where('id',$user_id)->field('id,identity,audit')->find();
        //判断用户身份是否审核通过
        if($user['audit'] != 1){
            $this->error('身份身份通过才可发布!');
        }
        //判断用户身份是否有发布的权限
        if($user['identity'] == 1){
            $this->error('您的权限不足');
        }
        $folder_id = $this->request->param('folder_id');
        $images = $this->request->param('images');
        if(empty($images)){
            $this->error('缺少必要参数');
        }
        //判断图片大小
        $image = explode(',',$images);
        $count = count($image);
        if($count > 9){
            $this->error('最多上传9张图片');
        }
        //添加发布的文件数据表
        $res['user_id'] = $user_id;
        $res['type'] = 2;
        $res['name'] = date('YmdHis');
        $res['folder_id'] = $folder_id;
        $res['images'] = $images;
        $res['createtime'] = time();
        $res['updatetime'] = time();
        $data = Db::name('savemes')->insertGetId($res);
        if(empty($data)){
            $this->error('发布图片失败');
        }else{
            $this->success('发布图片成功');
        }
    }

    /**
     * @ApiTitle    (发布视频)
     * @ApiSummary  (发布视频)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/create/publish_video)
     *
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="video", type="string", required=true, description="视频内容")
     * @ApiParams   (name="folder_id", type="inter", required=true, description="存储位置id 首页为0")
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {

    }
    })
     */
    public function publish_video()
    {
        $user_id = $this->auth->id;
        $user = Db::name('user')->where('id',$user_id)->field('id,identity,audit')->find();
        //判断用户身份是否审核通过
        if($user['audit'] != 1){
            $this->error('身份身份通过才可发布!');
        }
        //判断用户身份是否有发布的权限
        if($user['identity'] == 1){
            $this->error('您的权限不足');
        }
        $folder_id = $this->request->param('folder_id');
        $video = $this->request->param('video');
        if(empty($video)){
            $this->error('缺少必要参数');
        }

        //添加发布的文件数据表
        $res['user_id'] = $user_id;
        $res['type'] = 3;
        $res['name'] = date('YmdHis');
        $res['folder_id'] = $folder_id;
        $res['video'] = $video;
        $res['createtime'] = time();
        $res['updatetime'] = time();
        $data = Db::name('savemes')->insertGetId($res);
        if(empty($data)){
            $this->error('发布视频失败');
        }else{
            $this->success('发布视频成功');
        }
    }

    /**
     * @ApiTitle    (发布笔记)
     * @ApiSummary  (发布笔记)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/create/publish_note)
     *
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="content", type="string", required=true, description="笔记内容")
     * @ApiParams   (name="folder_id", type="inter", required=true, description="存储位置id 首页为0")
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {

    }
    })
     */
    public function publish_note()
    {
        $user_id = $this->auth->id;
        $user = Db::name('user')->where('id',$user_id)->field('id,identity,audit')->find();
        //判断用户身份是否审核通过
        if($user['audit'] != 1){
            $this->error('身份身份通过才可发布!');
        }
        //判断用户身份是否有发布的权限
        if($user['identity'] == 1){
            $this->error('您的权限不足');
        }
        $folder_id = $this->request->param('folder_id');
        $content = $_POST['content'];
        if(empty($content)){
            $this->error('缺少必要参数');
        }

        //添加发布的文件数据表
        $res['user_id'] = $user_id;
        $res['type'] = 1;
        $res['name'] = date('YmdHis');
        $res['folder_id'] = $folder_id;
        $res['content'] = $content;
        $res['createtime'] = time();
        $res['updatetime'] = time();
        $data = Db::name('savemes')->insertGetId($res);
        if(empty($data)){
            $this->error('发布笔记失败');
        }else{
            $this->success('发布笔记成功');
        }
    }

    /**
     * @ApiTitle    (文佳列表)
     * @ApiSummary  (上传列表)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/create/publish_list)
     *
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {
     "id": //id,
    "user_id": //用户id,
    "type": //类型1笔记2图片3视频,
    "folder_id": //所在位置id,
    "name": //名称,
    "images": //图片,
    "video": //视频地址,
    "content": //内容,
    "is_open": //是否公开1公开2私密,
    "is_up": //是否上架1上架2下架,
    "uptime": //下架时间,
    "createtime": //创建时间,
    "updatetime": //修改时间,
    "video_image": //视频封面图
    }
    ]
    }
    })
     */
    public function publish_list()
    {
        $qiniu = get_addon_config('qiniu')['cdnurl'];
        $user_id = $this->auth->id;
        $data = Db::name('savemes')
            ->where('user_id',$user_id)
            ->order('type asc')
            ->select();
        foreach ($data as &$v){
            if($v['type'] == 3){
                $v['video'] = $qiniu.$v['video'];
                // 获取视频第一帧图片
                $video_info = json_decode(file_get_contents($v['video'] . '?avinfo'), true);
                $v['video_image'] = $this->get_video_first_image($v['video'], $video_info);
            }elseif ($v['type'] == 2){
                $v['images'] = explode(',',$v['images']);
                foreach ($v['images'] as &$val){
                    $val = $qiniu.$val;
                }
            }
        }
        $this->success('success',$data);

    }
    public function get_video_first_image($video_url,$video_info){
        if(empty($video_info['streams'][0]['width'])) {
            $width = $video_info['streams'][1]['width'];
            $height = $video_info['streams'][1]['height'];
        } else {
            $width = $video_info['streams'][0]['width'];
            $height = $video_info['streams'][0]['height'];
        }
        return $video_url.'?vframe/jpg/offset/1/w/'.$width.'/h/'.$height;
    }

    /**
     * @ApiTitle    (笔记详情)
     * @ApiSummary  (笔记详情)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/create/note_detail)
     *
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="id", type="inter", required=true, description="笔记id")
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {
        "id": //id,
        "user_id": //用户id,
        "folder_id": //存储位置0为首页,
        "name": //名称,
        "content": //内容,
        "is_open": //是否公开1公开2私密,
        "is_up": //是否上架1上架2下架,
        "uptime": //下架时间,
        "collect_num": //收藏数量,
        "createtime": "//创建时间",
        "is_mine"://是否为本人1是2否
         "is_collect"://是否收藏过1是2否
    }
    })
     */
    public function note_detail()
    {
        $user_id = $this->auth->id;
        $id = $this->request->param('id');
        if(empty($id)){
            $this->error('缺少必要参数');
        }
        $data = Db::name('savemes')->field('updatetime,images,video,type',true)->where('type',1)->where('id',$id)->find();
        if(empty($data)){
            $this->error('参数有误');
        }
        //是否本人打开
        if($data['user_id'] == $user_id){
            $data['is_mine'] = 1;
        }else{
            $data['is_mine'] = 2;
        }
        //是否收藏过
        $collect = Db::name('collect')->where('user_id',$user_id)->where('savemes_id',$id)->find();
        if(empty($collect)){
            $data['is_collect'] = 2;
        }else{
            $data['is_collect'] = 1;
        }
        $data['createtime'] = date('Y-m-d H:i:s',$data['createtime']);
        $this->success('success',$data);
    }

    /**
     * @ApiTitle    (收藏/取消收藏)
     * @ApiSummary  (收藏/取消收藏)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/create/collect)
     *
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="id", type="inter", required=true, description="文件id")
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {

    }
    })
     */
    public function collect()
    {
        $user_id = $this->auth->id;
        $id = $this->request->param('id');
        if(empty($id)){
            $this->error('缺少必要参数');
        }
        $data = Db::name('collect')->where('user_id',$user_id)->where('savemes_id',$id)->find();
        if(empty($data)){
            $res['user_id'] = $user_id;
            $res['savemes_id'] = $id;
            $res['createtime'] = time();
            $res['updatetime'] = time();
            $info = Db::name('collect')->insertGetId($res);
            if(empty($info)){
                $this->error('收藏失败');
            }else{
                $this->success('收藏成功');
            }
        }else{
            $info = Db::name('collect')->where('user_id',$user_id)->where('savemes_id',$id)->delete();
            if(empty($info)){
                $this->error('取消收藏失败');
            }else{
                $this->success('取消收藏成功');
            }
        }
    }


    //批量操作

    /**
     * @ApiTitle    (文件删除)
     * @ApiSummary  (文件删除)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/create/del)
     *
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="ids", type="inter", required=true, description="文件ids字符串")
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {

    }
    })
     */
    public function del()
    {
        $user_id = $this->auth->id;
        $ids = $this->request->param('ids');
        if(empty($ids)){
            $this->error('缺少必要参数');
        }
        $arr_ids = explode(',',$ids);
        //删除文件
        Db::startTrans();
        try{
            Db::name('savemes')->whereIn('id',$arr_ids)->delete();
            Db::name('collect')->whereIn('savemes_id',$arr_ids)->delete();
            Db::name('rotor')->whereIn('savemes_id',$arr_ids)->delete();
            Db::commit();
        } catch (\Exception $e) {
            // 回滚事务
            Db::rollback();
        }
        $this->success('删除成功');
    }

    /**
     * @ApiTitle    (设为公开)
     * @ApiSummary  (设为公开)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/create/set_gong)
     *
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="ids", type="inter", required=true, description="文件ids字符串")
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {

    }
    })
     */
    public function set_gong()
    {
        $user_id = $this->auth->id;
        $ids = $this->request->param('ids');
        if(empty($ids)){
            $this->error('缺少必要参数');
        }
        $arr_ids = explode(',',$ids);

        //设置为公开
        Db::startTrans();
        try{
            Db::name('savemes')->whereIn('id',$arr_ids)->update(['is_open'=>1]);
            Db::name('rotor')->whereIn('savemes_id',$arr_ids)->update(['is_open'=>1]);
            Db::commit();
        } catch (\Exception $e) {
            // 回滚事务
            Db::rollback();
        }
        $this->success('设置成功');
    }

    /**
     * @ApiTitle    (设为私密)
     * @ApiSummary  (设为私密)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/create/set_si)
     *
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="ids", type="inter", required=true, description="文件ids字符串")
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {

    }
    })
     */
    public function set_si()
    {
        $user_id = $this->auth->id;
        $ids = $this->request->param('ids');
        if(empty($ids)){
            $this->error('缺少必要参数');
        }
        $arr_ids = explode(',',$ids);

        //设置为公开
        Db::startTrans();
        try{
            Db::name('savemes')->whereIn('id',$arr_ids)->update(['is_open'=>2]);
            Db::name('rotor')->whereIn('savemes_id',$arr_ids)->update(['is_open'=>2]);
            Db::commit();
        } catch (\Exception $e) {
            // 回滚事务
            Db::rollback();
        }
        $this->success('设置成功');
    }

    /**
     * @ApiTitle    (全部上架)
     * @ApiSummary  (全部上架)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/create/all_up)
     *
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="ids", type="inter", required=true, description="文件ids字符串")
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {

    }
    })
     */
    public function all_up()
    {
        $user_id = $this->auth->id;
        $ids = $this->request->param('ids');
        if(empty($ids)){
            $this->error('缺少必要参数');
        }
        $arr_ids = explode(',',$ids);

        //全部上架
        Db::startTrans();
        try{
            Db::name('savemes')->whereIn('id',$arr_ids)->update(['is_up'=>1,'uptime'=>0]);
            Db::name('rotor')->whereIn('savemes_id',$arr_ids)->update(['is_up'=>1]);
            Db::commit();
        } catch (\Exception $e) {
            // 回滚事务
            Db::rollback();
        }
        $this->success('成功');
    }

    /**
     * @ApiTitle    (全部下架)
     * @ApiSummary  (全部下架)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/create/all_down)
     *
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="ids", type="inter", required=true, description="文件ids字符串")
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {

    }
    })
     */
    public function all_down()
    {
        $user_id = $this->auth->id;
        $ids = $this->request->param('ids');
        if(empty($ids)){
            $this->error('缺少必要参数');
        }
        $arr_ids = explode(',',$ids);

        //全部上架
        Db::startTrans();
        try{
            Db::name('savemes')->whereIn('id',$arr_ids)->update(['is_up'=>2,'uptime'=>time()]);
            Db::name('rotor')->whereIn('savemes_id',$arr_ids)->update(['is_up'=>2]);
            Db::commit();
        } catch (\Exception $e) {
            // 回滚事务
            Db::rollback();
        }
        $this->success('成功');
    }

    /**
     * @ApiTitle    (移动到)
     * @ApiSummary  (移动到)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/create/all_move)
     *
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="ids", type="inter", required=true, description="文件ids字符串")
     * @ApiParams   (name="move_id", type="inter", required=true, description="移动的目标id首页为0")
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {

    }
    })
     */
    public function all_move()
    {
        $user_id = $this->auth->id;
        $ids = $this->request->param('ids');
        if(empty($ids)){
            $this->error('缺少必要参数');
        }
        $arr_ids = explode(',',$ids);

        $move_id = $this->request->param('move_id');
        if(empty($move_id)){
            $this->error('缺少必要参数');
        }
        //全部上架
        $data = Db::name('savemes')->whereIn('id',$arr_ids)->update(['folder_id'=>$move_id]);
        if(empty($data)){
            $this->error('失败');
        }else{
            $this->success('成功');
        }
    }

    /**
     * @ApiTitle    (下载)
     * @ApiSummary  (下载)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/create/download)
     *
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="ids", type="inter", required=true, description="文件ids字符串")
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {
          "info"://下载的文件
    }
    })
     */
    public function download()
    {
        $qiniu = get_addon_config('qiniu')['cdnurl'];
        $user_id = $this->auth->id;
        $ids = $this->request->param('ids');
        if(empty($ids)){
            $this->error('缺少必要参数');
        }
        $arr_ids = explode(',',$ids);

        $data = Db::name('savemes')->field('id,type,images,video')->whereIn('id',$arr_ids)->select();
        $arr = [];
        foreach ($data as &$v){
            //判断是否有笔记
            if($v['type'] == 1){
                $this->error('笔记不能下载');
            }
            if($v['type'] == 2){
                $v['video'] = '';
                $v['images'] = explode(',',$v['images']);
                foreach ($v['images'] as &$val){
                    $qiuniu_url = $qiniu.$val;
                    $a = file_get_contents($qiuniu_url);
                    $path = './uploads/'.explode('/',$val)[2].'/';
                    if(!file_exists($path)) {
                        mkdir($path,0777,true);
                    }
                    file_put_contents('.'.$val,$a);
                    $val = request()->domain().$val;
                    array_push($arr,$val);
                }
            }
            if($v['type'] == 3){
                $v['images'] = '';
                $qiuniu_url = $qiniu.$v['video'];
                $a = file_get_contents($qiuniu_url);
                $path = './uploads/'.explode('/',$v['video'])[2].'/';
                if(!file_exists($path)) {
                    mkdir($path,0777,true);
                }
                file_put_contents('.'.$v['video'],$a);
                $v['video'] = request()->domain().$v['video'];
                array_push($arr,$v['video']);
            }
        }
        $this->success('success',['info'=>$arr]);
    }

    /**
     * @ApiTitle    (重命名)
     * @ApiSummary  (重命名)
     * @ApiMethod   (POST)
     * @ApiRoute    (/api/create/rename)
     *
     * @ApiHeaders  (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams   (name="id", type="inter", required=true, description="文件id")
     * @ApiParams   (name="type", type="inter", required=true, description="类型1文件2文件夹")
     * @ApiParams   (name="name", type="string", required=true, description="修改后的名称")
     *
     * @ApiReturn({
    "code": 1,
    "msg": "成功",
    "time": "1571492001",
    "data": {

    }
    })
     */
    public function rename()
    {
        $user_id = $this->auth->id;
        $id = $this->request->param('id');
        $name = $this->request->param('name');
        $type = $this->request->param('type');
        if(empty($id) || empty($name) || empty($type)){
            $this->error('缺少必要参数');
        }
        if($type == 1){
            $data = Db::name('savemes')->where('id',$id)->find();
            if($data['user_id'] != $user_id){
                $this->error('没有权限重命名');
            }
            $res = Db::name('savemes')->where('id',$id)->update(['name'=>$name]);
        }elseif ($type == 2){
            $data = Db::name('folder')->where('id',$id)->find();
            if($data['user_id'] != $user_id){
                $this->error('没有权限重命名');
            }
            $res = Db::name('folder')->where('id',$id)->update(['folder_name'=>$name]);
        }
        if(empty($res)){
            $this->error('重命名失败');
        }else{
            $this->success('重命名成功');
        }
    }

}