|
|
|
@ -176,7 +176,8 @@ class Posts extends BaseController |
|
|
|
$privacy = $this->request->param('privacy', ''); |
|
|
|
$location = $this->request->param('location', ''); |
|
|
|
$address = $this->request->param('address', ''); |
|
|
|
$video_file = $this->request->param('video_file', []); |
|
|
|
$video_file = $this->request->param('video_file', ''); |
|
|
|
$poster_file = $this->request->param('poster_file', ''); |
|
|
|
$imgArr = $this->request->param('img_arr', []); |
|
|
|
$posts_id = $this->request->param('posts_id', ''); |
|
|
|
$user_ids = $this->request->param('user_ids', []); |
|
|
|
@ -210,6 +211,38 @@ 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 = [ |
|
|
|
@ -233,37 +266,6 @@ class Posts extends BaseController |
|
|
|
$posts_id = (new PostsModel())->insertGetId($info); |
|
|
|
} |
|
|
|
|
|
|
|
$fileSaveArr = []; |
|
|
|
foreach ($imgArr as $key => $img_url) { |
|
|
|
$imgUrl = str_replace($this->url, '', $img_url); |
|
|
|
$whereFile = ['src' => $imgUrl, 'user_id' => $this->uid, 'delete_time' => 0]; |
|
|
|
$img_file_id = File::where($whereFile)->value('file_id'); |
|
|
|
if ($img_file_id) { |
|
|
|
$fileSaveArr[] = [ |
|
|
|
'posts_id' => $posts_id, |
|
|
|
'type' => 1, |
|
|
|
'file_id' => $img_file_id, |
|
|
|
'sort' => $key + 1 |
|
|
|
]; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (!empty($video_file)) { |
|
|
|
foreach ($video_file as $v_file) { |
|
|
|
$videoUrl = str_replace($this->url, '', $v_file); |
|
|
|
$whereFile = ['src' => $videoUrl, 'user_id' => $this->uid, 'delete_time' => 0]; |
|
|
|
$video_file_id = File::where($whereFile)->value('file_id'); |
|
|
|
if ($video_file_id) { |
|
|
|
$fileSaveArr[] = [ |
|
|
|
'posts_id' => $posts_id, |
|
|
|
'type' => 2, |
|
|
|
'file_id' => $video_file_id, |
|
|
|
'sort' => 1 |
|
|
|
]; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if ($fileSaveArr) { |
|
|
|
(new PostsFile())->saveAll($fileSaveArr); |
|
|
|
} |
|
|
|
@ -290,6 +292,23 @@ class Posts extends BaseController |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// 添加图片视频数据处理 |
|
|
|
protected function addPostsFileData($url, $posts_id, $data, $sort = 1, $type = 1) |
|
|
|
{ |
|
|
|
$imgUrl = str_replace($this->url, '', $url); |
|
|
|
$whereFile = ['src' => $imgUrl, 'user_id' => $this->uid, 'delete_time' => 0]; |
|
|
|
$img_file_id = File::where($whereFile)->value('file_id'); |
|
|
|
if ($img_file_id) { |
|
|
|
$data[] = [ |
|
|
|
'posts_id' => $posts_id, |
|
|
|
'type' => $type, |
|
|
|
'file_id' => $img_file_id, |
|
|
|
'sort' => $sort |
|
|
|
]; |
|
|
|
} |
|
|
|
return $data; |
|
|
|
} |
|
|
|
|
|
|
|
// 获取上传草稿帖子数据 |
|
|
|
public function getLastPosts() |
|
|
|
{ |
|
|
|
|