Browse Source

发布朋友圈,图片传输和视频传输修改

author
wanghongjun 10 months ago
parent
commit
dd8b305a6a
  1. 32
      app/enterprise/controller/Posts.php

32
app/enterprise/controller/Posts.php

@ -16,6 +16,15 @@ use think\facade\Db;
class Posts extends BaseController class Posts extends BaseController
{ {
protected $url='';
public function __construct()
{
parent::__construct(app());
$this->url=getDiskUrl().'/';
}
// 朋友圈列表
public function index() public function index()
{ {
$where = []; $where = [];
@ -83,6 +92,7 @@ class Posts extends BaseController
return success('', $data,$list->total(),$list->currentPage()); return success('', $data,$list->total(),$list->currentPage());
} }
// 我的朋友圈列表
public function myPosts() public function myPosts()
{ {
$where = [ $where = [
@ -138,6 +148,7 @@ class Posts extends BaseController
return success('', $data); return success('', $data);
} }
// 删除帖子
public function del() public function del()
{ {
try { try {
@ -164,12 +175,13 @@ class Posts extends BaseController
} }
} }
// 添加帖子
public function add() public function add()
{ {
$content = $this->request->param('content', ''); $content = $this->request->param('content', '');
$privacy = $this->request->param('privacy', ''); $privacy = $this->request->param('privacy', '');
$location = $this->request->param('location', ''); $location = $this->request->param('location', '');
$video_file_id = $this->request->param('file_id', ''); $video_file = $this->request->param('video_file', '');
$imgArr = $this->request->param('img_arr', []); $imgArr = $this->request->param('img_arr', []);
$posts_id = $this->request->param('posts_id', ''); $posts_id = $this->request->param('posts_id', '');
$user_ids = $this->request->param('user_ids', []); $user_ids = $this->request->param('user_ids', []);
@ -226,7 +238,11 @@ class Posts extends BaseController
} }
$fileSaveArr = []; $fileSaveArr = [];
foreach ($imgArr as $key => $img_file_id) { 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[] = [ $fileSaveArr[] = [
'posts_id' => $posts_id, 'posts_id' => $posts_id,
'type' => 1, 'type' => 1,
@ -234,8 +250,13 @@ class Posts extends BaseController
'sort' => $key + 1 'sort' => $key + 1
]; ];
} }
}
if (!empty($video_file_id)) { if (!empty($video_file)) {
$videoUrl = str_replace($this->url, '', $video_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[] = [ $fileSaveArr[] = [
'posts_id' => $posts_id, 'posts_id' => $posts_id,
'type' => 2, 'type' => 2,
@ -243,6 +264,7 @@ class Posts extends BaseController
'sort' => 1 'sort' => 1
]; ];
} }
}
if ($fileSaveArr) { if ($fileSaveArr) {
(new PostsFile())->saveAll($fileSaveArr); (new PostsFile())->saveAll($fileSaveArr);
@ -270,6 +292,7 @@ class Posts extends BaseController
} }
} }
// 获取上传草稿帖子数据
public function getLastPosts() public function getLastPosts()
{ {
$existsWhere = ['user_id' => $this->uid, 'privacy' => 0, 'delete_time' => 0]; $existsWhere = ['user_id' => $this->uid, 'privacy' => 0, 'delete_time' => 0];
@ -297,6 +320,7 @@ class Posts extends BaseController
return success('', $data); return success('', $data);
} }
// 点赞帖子
public function like() public function like()
{ {
$posts_id = $this->request->param('posts_id'); $posts_id = $this->request->param('posts_id');
@ -322,6 +346,7 @@ class Posts extends BaseController
return success(lang('posts.success_like')); return success(lang('posts.success_like'));
} }
// 评论帖子
public function comment() public function comment()
{ {
$posts_id = $this->request->param('posts_id'); $posts_id = $this->request->param('posts_id');
@ -352,6 +377,7 @@ class Posts extends BaseController
return success(lang('system.success')); return success(lang('system.success'));
} }
// 删除评论
public function delComment() public function delComment()
{ {
$posts_id = $this->request->param('posts_id'); $posts_id = $this->request->param('posts_id');

Loading…
Cancel
Save