Browse Source

朋友圈上传图片视频接口4

author
wanghongjun 6 months ago
parent
commit
630784d712
  1. 25
      app/common/controller/Upload.php
  2. 72
      app/enterprise/controller/Posts.php

25
app/common/controller/Upload.php

@ -110,17 +110,6 @@ class Upload extends BaseController
'user_id'=>$uid,
'videoInfo'=>$imageInfo
];
// 上传视频切片
if ($fileType == 4) {
$videoInfo=$this->getVideoCover($filePath);
if($videoInfo){
$poster=$this->url.$videoInfo['src'];
}else{
$poster=getMainHost().'/static/common/img/video.png';
}
$ret['poster'] = $poster;
}
if($message){
// 自动获取视频第一帧,视频并且是使用的阿里云
@ -164,6 +153,16 @@ class Upload extends BaseController
}
return $data;
}else{
// 上传视频切片
if ($fileType == 4) {
$videoInfo=$this->getVideoCover($filePath);
if($videoInfo){
$poster=$this->url.$videoInfo['src'];
}else{
$poster=getMainHost().'/static/common/img/video.png';
}
$ret['poster'] = $poster;
}
return $ret;
}
@ -368,6 +367,10 @@ class Upload extends BaseController
$info=$this->upload([],$savePath,'cover/'.date('Y-m-d').'/',false);
$info['videoInfo']['duration']= ceil($duration);
unlink($savePath);
if ($info) {
$fileInfo=new FileModel;
$fileInfo->save($info);
}
return $info;
}

72
app/enterprise/controller/Posts.php

@ -27,8 +27,8 @@ class Posts extends BaseController
// 朋友圈列表
public function index()
{
$where = [];
$whereOr = ' (p.delete_time = 0 and p.privacy > 0) and p.user_id = ' . $this->uid;
$where = '(p.delete_time = 0 and p.privacy > 0) and ';
$whereOr = $where . ' ( p.user_id = ' . $this->uid;
$friendIds = Friend::getFriendIds($this->uid);
@ -49,12 +49,12 @@ class Posts extends BaseController
$whereOr .= " or ( p.privacy = 4 and not exists (
select 1 from {$prefix}posts_privacy_users peu
where peu.posts_id = p.id and peu.user_id = p.user_id and peu.type = 2
))";
)))";
$field = 'p.id,p.content,p.location,p.address as location_address,p.type,p.user_id,p.create_time';
$order = 'p.create_time desc';
$model = new PostsModel();
$list = $this->paginate($model->alias('p')->where($where)->whereOr($whereOr)->field($field)->order($order));
$list = $this->paginate($model->alias('p')->where($whereOr)->field($field)->order($order));
$data = [];
if ($list) {
@ -211,38 +211,6 @@ class Posts extends BaseController
}
}
$fileSaveArr = [];
if ($imgArr) {
foreach ($imgArr as $key => $img_url) {
$fileSaveArr = $this->addPostsFileData(
$img_url,
$posts_id,
$fileSaveArr,
$key + 1
);
}
} elseif ($video_file && $poster_file) {
$fileSaveArr = $this->addPostsFileData(
$video_file,
$posts_id,
$fileSaveArr,
1,
2
);
$fileSaveArr = $this->addPostsFileData(
$poster_file,
$posts_id,
$fileSaveArr,
2
);
}
if ($imgArr || ($video_file && $poster_file)) {
if (empty($fileSaveArr)) {
return error(lang('system.error'));
}
}
Db::startTrans();
try {
$info = [
@ -266,6 +234,38 @@ class Posts extends BaseController
$posts_id = (new PostsModel())->insertGetId($info);
}
$fileSaveArr = [];
if ($imgArr) {
foreach ($imgArr as $key => $img_url) {
$fileSaveArr = $this->addPostsFileData(
$img_url,
$posts_id,
$fileSaveArr,
$key + 1
);
}
} elseif ($video_file && $poster_file) {
$fileSaveArr = $this->addPostsFileData(
$video_file,
$posts_id,
$fileSaveArr,
1,
2
);
$fileSaveArr = $this->addPostsFileData(
$poster_file,
$posts_id,
$fileSaveArr,
2
);
}
if ($imgArr || ($video_file && $poster_file)) {
if (empty($fileSaveArr)) {
throw new \Exception(lang('system.error'));
}
}
if ($fileSaveArr) {
(new PostsFile())->saveAll($fileSaveArr);
}

Loading…
Cancel
Save