Create.php 1.7 KB
<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/7/6
 * Time: 9:58
 */

namespace app\api\controller;


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


/**
 * 发布接口
 */
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")
     *
     * @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);
        }
    }

}