...
|
...
|
@@ -10,7 +10,10 @@ namespace app\api\controller; |
|
|
|
|
|
|
|
|
use app\common\controller\Api;
|
|
|
|
|
|
use Qiniu\Storage\UploadManager;
|
|
|
use think\Db;
|
|
|
use Qiniu\Auth;
|
|
|
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -30,13 +33,14 @@ class Create extends Api |
|
|
* @ApiRoute (/api/create/publish_folder)
|
|
|
*
|
|
|
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
|
|
|
* @ApiParams (name="id", type="inter", required=true, description="父级文件夹id")
|
|
|
* @ApiParams (name="id", type="inter", required=true, description="父级文件夹id首页为0")
|
|
|
*
|
|
|
* @ApiReturn({
|
|
|
"code": 1,
|
|
|
"msg": "成功",
|
|
|
"time": "1571492001",
|
|
|
"data": {
|
|
|
|
|
|
}
|
|
|
]
|
|
|
}
|
...
|
...
|
@@ -74,4 +78,698 @@ class Create extends Api |
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @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('重命名成功');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|