|
@@ -6,6 +6,7 @@
|
|
|
* Date: 2019/6/5
|
|
|
* Time: 16:03
|
|
|
*/
|
|
|
+
|
|
|
namespace App\Repositories\Post;
|
|
|
|
|
|
use App\Models\CategoryTopic;
|
|
@@ -14,6 +15,7 @@ use App\Models\PostComment;
|
|
|
use App\Models\PostData;
|
|
|
use App\Models\PostImgs;
|
|
|
use App\Models\PostLog;
|
|
|
+use App\Models\PostStatistics;
|
|
|
use App\Models\Topic;
|
|
|
use App\Service\RabbitMqUtil;
|
|
|
use App\Traits\PostTrait;
|
|
@@ -41,6 +43,7 @@ class PostRepository
|
|
|
PostLog $postLog,
|
|
|
RabbitMqUtil $rabbitMqUtil,
|
|
|
CategoryTopic $categoryTopic,
|
|
|
+ PostStatistics $postStatistics,
|
|
|
Topic $topic)
|
|
|
{
|
|
|
$this->post = $post;
|
|
@@ -51,6 +54,7 @@ class PostRepository
|
|
|
$this->rabbitMqUtil = $rabbitMqUtil;
|
|
|
$this->categoryTopic = $categoryTopic;
|
|
|
$this->topic = $topic;
|
|
|
+ $this->postStatistics = $postStatistics;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -70,20 +74,20 @@ class PostRepository
|
|
|
//验证话题
|
|
|
$topicIdsArray = $this->topic->whereIn('id', explode(',', $request['topic_ids']))->pluck('id')->toArray();
|
|
|
$topicCount = count($topicIdsArray);
|
|
|
- if($topicCount == 0 || $topicCount > 5){
|
|
|
+ if ($topicCount == 0 || $topicCount > 5) {
|
|
|
return Response::create([
|
|
|
- 'message' => '所选话题必须1-5个',
|
|
|
- 'status_code' => 500
|
|
|
+ 'message' => '所选话题必须1-5个',
|
|
|
+ 'status_code' => 500
|
|
|
]);
|
|
|
}
|
|
|
$topicIds = implode(',', $topicIdsArray);
|
|
|
|
|
|
//验证内容字数
|
|
|
- $html = preg_replace("/<([a-zA-Z]+)[^>]*>/","<\\1>",$request['content']);
|
|
|
- if(mb_strlen($html,'UTF8') > 1000){
|
|
|
+ $html = preg_replace("/<([a-zA-Z]+)[^>]*>/", "<\\1>", $request['content']);
|
|
|
+ if (mb_strlen($html, 'UTF8') > 1000) {
|
|
|
return Response::create([
|
|
|
- 'message' => '所传内容不能超过1000字',
|
|
|
- 'status_code' => 500
|
|
|
+ 'message' => '所传内容不能超过1000字',
|
|
|
+ 'status_code' => 500
|
|
|
]);
|
|
|
}
|
|
|
|
|
@@ -94,11 +98,11 @@ class PostRepository
|
|
|
'avatar' => 'https://wx.qlogo.cn/mmopen/vi_32/DYAIOgq83ep3asJn8emiat1MnPdviaPNroWY3f65y5ezkTAk2qtibv7ea9Ht9R2ahxr9bicY1DIj5vN5FibpDOwXegg/132',
|
|
|
'type' => $request['type'],
|
|
|
'img' => $request['img'],
|
|
|
- 'video' => $request['video']??'',
|
|
|
+ 'video' => $request['video'] ?? '',
|
|
|
'topic_ids' => $topicIds,
|
|
|
- 'title' => $request['title']??'',
|
|
|
+ 'title' => $request['title'] ?? '',
|
|
|
'content' => $request['content'],
|
|
|
- 'location' => $request['location']??'',
|
|
|
+ 'location' => $request['location'] ?? '',
|
|
|
'is_suggest' => $request['is_suggest'],
|
|
|
'is_hide' => 0
|
|
|
];
|
|
@@ -107,7 +111,7 @@ class PostRepository
|
|
|
|
|
|
|
|
|
DB::beginTransaction();
|
|
|
- try{
|
|
|
+ try {
|
|
|
$post = $this->post->create($data);
|
|
|
|
|
|
$this->postData->create([
|
|
@@ -128,9 +132,9 @@ class PostRepository
|
|
|
'weight' => 0
|
|
|
]);
|
|
|
|
|
|
- if(!empty($request['imgs']) && $request['type'] == 'image'){
|
|
|
+ if (!empty($request['imgs']) && $request['type'] == 'image') {
|
|
|
$imgData = [];
|
|
|
- foreach($request['imgs'] as $img){
|
|
|
+ foreach ($request['imgs'] as $img) {
|
|
|
$imgData[] = [
|
|
|
'post_id' => $post->id,
|
|
|
'img' => $img,
|
|
@@ -143,18 +147,18 @@ class PostRepository
|
|
|
|
|
|
DB::commit();
|
|
|
Redis::zadd('post_trigger_type', 0, $post->id);
|
|
|
- foreach($topicIdsArray as $id){
|
|
|
- Redis::zincrby('topic.user_uid'.$request['uid'], 1, $id);
|
|
|
+ foreach ($topicIdsArray as $id) {
|
|
|
+ Redis::zincrby('topic.user_uid' . $request['uid'], 1, $id);
|
|
|
}
|
|
|
return Response::create();
|
|
|
|
|
|
- }catch (QueryException $exception){
|
|
|
+ } catch (QueryException $exception) {
|
|
|
DB::rollBack();
|
|
|
- Log::debug('发布内容:'.$exception->getMessage());
|
|
|
+ Log::debug('发布内容:' . $exception->getMessage());
|
|
|
return Response::create([
|
|
|
- 'message' => '发布失败,请重试',
|
|
|
+ 'message' => '发布失败,请重试',
|
|
|
'error' => $exception->getMessage(),
|
|
|
- 'status_code' => 500
|
|
|
+ 'status_code' => 500
|
|
|
]);
|
|
|
}
|
|
|
}
|
|
@@ -164,11 +168,11 @@ class PostRepository
|
|
|
*/
|
|
|
public function addData($request)
|
|
|
{
|
|
|
- $token = JWTAuth::decode(JWTAuth::getToken());
|
|
|
- if(!$token || $token['type'] != 1){
|
|
|
+ $token = JWTAuth::decode(JWTAuth::getToken());
|
|
|
+ if (!$token || $token['type'] != 1) {
|
|
|
return Response::create([
|
|
|
- 'message' => '获取登陆信息失败',
|
|
|
- 'status_code' => 500
|
|
|
+ 'message' => '获取登陆信息失败',
|
|
|
+ 'status_code' => 500
|
|
|
]);
|
|
|
}
|
|
|
$uid = $token['user']->id;
|
|
@@ -176,17 +180,17 @@ class PostRepository
|
|
|
//验证小号数量
|
|
|
|
|
|
$postData = $this->postData->where('post_id', $request['post_id'])->first();
|
|
|
- if(!$postData){
|
|
|
+ if (!$postData) {
|
|
|
return Response::create([
|
|
|
- 'message' => '获取内容失败',
|
|
|
- 'status_code' => 500
|
|
|
+ 'message' => '获取内容失败',
|
|
|
+ 'status_code' => 500
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
- if($request['add_pv'] == 0 && $request['add_praise_count'] == 0 && $request['add_collect_count'] == 0 && $request['add_share_count'] == 0){
|
|
|
+ if ($request['add_pv'] == 0 && $request['add_praise_count'] == 0 && $request['add_collect_count'] == 0 && $request['add_share_count'] == 0) {
|
|
|
return Response::create([
|
|
|
- 'message' => '增加数据不能同时为0',
|
|
|
- 'status_code' => 500
|
|
|
+ 'message' => '增加数据不能同时为0',
|
|
|
+ 'status_code' => 500
|
|
|
]);
|
|
|
}
|
|
|
$content = [
|
|
@@ -195,24 +199,24 @@ class PostRepository
|
|
|
'add_collect_count' => 0,
|
|
|
'add_share_count' => 0,
|
|
|
];
|
|
|
- if($request['add_pv']){
|
|
|
+ if ($request['add_pv']) {
|
|
|
$postData->pv += $request['add_pv'];
|
|
|
$content['add_pv'] = $request['add_pv'];
|
|
|
}
|
|
|
- if($request['add_praise_count']){
|
|
|
+ if ($request['add_praise_count']) {
|
|
|
$postData->praise_count += $request['add_praise_count'];
|
|
|
$content['add_praise_count'] = $request['add_praise_count'];
|
|
|
}
|
|
|
- if($request['add_collect_count']){
|
|
|
+ if ($request['add_collect_count']) {
|
|
|
$postData->collect_count += $request['add_collect_count'];
|
|
|
$content['add_collect_count'] = $request['add_collect_count'];
|
|
|
}
|
|
|
- if($request['add_share_count']){
|
|
|
+ if ($request['add_share_count']) {
|
|
|
$postData->share_count += $request['add_share_count'];
|
|
|
$content['add_share_count'] = $request['add_share_count'];
|
|
|
}
|
|
|
DB::beginTransaction();
|
|
|
- try{
|
|
|
+ try {
|
|
|
$postData->save();
|
|
|
$this->postLog->create([
|
|
|
'post_id' => $request['post_id'],
|
|
@@ -225,13 +229,13 @@ class PostRepository
|
|
|
DB::commit();
|
|
|
return Response::create();
|
|
|
|
|
|
- }catch (QueryException $exception){
|
|
|
+ } catch (QueryException $exception) {
|
|
|
DB::rollBack();
|
|
|
- Log::debug('内容增加数据:'.$request['post_id'].$exception->getMessage());
|
|
|
+ Log::debug('内容增加数据:' . $request['post_id'] . $exception->getMessage());
|
|
|
return Response::create([
|
|
|
- 'message' => '增加数据失败,请重试',
|
|
|
+ 'message' => '增加数据失败,请重试',
|
|
|
'error' => $exception->getMessage(),
|
|
|
- 'status_code' => 500
|
|
|
+ 'status_code' => 500
|
|
|
]);
|
|
|
}
|
|
|
}
|
|
@@ -243,19 +247,19 @@ class PostRepository
|
|
|
{
|
|
|
//验证小号
|
|
|
$userInfo = $this->getUserInfo($request['uid']);
|
|
|
- Log::debug('评论&回复小号'.json_encode($userInfo));
|
|
|
- if(!$userInfo || $userInfo['type'] != 1){
|
|
|
+ Log::debug('评论&回复小号' . json_encode($userInfo));
|
|
|
+ if (!$userInfo || $userInfo['type'] != 1) {
|
|
|
return Response::create([
|
|
|
- 'message' => '所选小号信息有误',
|
|
|
- 'status_code' => 500
|
|
|
+ 'message' => '所选小号信息有误',
|
|
|
+ 'status_code' => 500
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
$post = $this->post->find($request['post_id']);
|
|
|
- if(!$post){
|
|
|
+ if (!$post) {
|
|
|
return Response::create([
|
|
|
- 'message' => '获取内容失败',
|
|
|
- 'status_code' => 500
|
|
|
+ 'message' => '获取内容失败',
|
|
|
+ 'status_code' => 500
|
|
|
]);
|
|
|
}
|
|
|
$data = [
|
|
@@ -269,18 +273,18 @@ class PostRepository
|
|
|
'content' => $request['content'],
|
|
|
'is_delete' => 0,
|
|
|
];
|
|
|
- if(isset($request['parent_id']) && $request['parent_id'] != 0){
|
|
|
+ if (isset($request['parent_id']) && $request['parent_id'] != 0) {
|
|
|
$comment = $this->postComment->find($request['parent_id']);
|
|
|
- if(!$comment){
|
|
|
+ if (!$comment) {
|
|
|
return Response::create([
|
|
|
- 'message' => '获取评论信息失败',
|
|
|
- 'status_code' => 500
|
|
|
+ 'message' => '获取评论信息失败',
|
|
|
+ 'status_code' => 500
|
|
|
]);
|
|
|
}
|
|
|
- if($comment->parent_id){
|
|
|
+ if ($comment->parent_id) {
|
|
|
return Response::create([
|
|
|
- 'message' => '只能回复评论',
|
|
|
- 'status_code' => 500
|
|
|
+ 'message' => '只能回复评论',
|
|
|
+ 'status_code' => 500
|
|
|
]);
|
|
|
}
|
|
|
$data['parent_id'] = $request['parent_id'];
|
|
@@ -297,7 +301,7 @@ class PostRepository
|
|
|
'content' => subtext($request['content'], 20),
|
|
|
]
|
|
|
]);
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
$this->rabbitMqUtil->push('add_message', [
|
|
|
'uid' => $post->uid,
|
|
|
'message_show_type' => 'post_comment',
|
|
@@ -311,7 +315,7 @@ class PostRepository
|
|
|
]);
|
|
|
}
|
|
|
DB::beginTransaction();
|
|
|
- try{
|
|
|
+ try {
|
|
|
$this->postComment->create($data);
|
|
|
$post->data->comment_count += 1;
|
|
|
$post->data->save();
|
|
@@ -319,13 +323,13 @@ class PostRepository
|
|
|
DB::commit();
|
|
|
return Response::create();
|
|
|
|
|
|
- }catch (QueryException $exception){
|
|
|
+ } catch (QueryException $exception) {
|
|
|
DB::rollBack();
|
|
|
- Log::debug('评论内容:'.$request['post_id'].$exception->getMessage());
|
|
|
+ Log::debug('评论内容:' . $request['post_id'] . $exception->getMessage());
|
|
|
return Response::create([
|
|
|
- 'message' => '评论失败,请重试',
|
|
|
+ 'message' => '评论失败,请重试',
|
|
|
'error' => $exception->getMessage(),
|
|
|
- 'status_code' => 500
|
|
|
+ 'status_code' => 500
|
|
|
]);
|
|
|
}
|
|
|
}
|
|
@@ -337,26 +341,26 @@ class PostRepository
|
|
|
{
|
|
|
$perPage = isset($request['per_page']) ? $request['per_page'] : 20;
|
|
|
$where = [];
|
|
|
- if(isset($request['content'])){
|
|
|
+ if (isset($request['content'])) {
|
|
|
$where[] = ['content', 'like', "%{$request['content']}%"];
|
|
|
}
|
|
|
- if(isset($request['is_suggest'])){
|
|
|
+ if (isset($request['is_suggest'])) {
|
|
|
$where[] = ['is_suggest', $request['is_suggest']];
|
|
|
}
|
|
|
- if(isset($request['type'])){
|
|
|
+ if (isset($request['type'])) {
|
|
|
$where[] = ['type', $request['type']];
|
|
|
}
|
|
|
|
|
|
- if(isset($request['uid'])){
|
|
|
+ if (isset($request['uid'])) {
|
|
|
$where[] = ['uid', $request['uid']];
|
|
|
}
|
|
|
|
|
|
$sort = 'post.id';
|
|
|
- if(isset($request['sort']) && in_array($request['sort'], ['praise_count', 'share_count', 'pv', 'comment_count', 'create_bean'])){
|
|
|
+ if (isset($request['sort']) && in_array($request['sort'], ['praise_count', 'share_count', 'pv', 'comment_count', 'create_bean'])) {
|
|
|
$sort = $request['sort'];
|
|
|
}
|
|
|
$post = $this->post;
|
|
|
- if(isset($request['waste']) && $request['waste'] == 1){
|
|
|
+ if (isset($request['waste']) && $request['waste'] == 1) {
|
|
|
$post = $post->onlyTrashed();
|
|
|
}
|
|
|
|
|
@@ -364,21 +368,21 @@ class PostRepository
|
|
|
->join('post_data', 'post_data.post_id', '=', 'post.id')
|
|
|
->select('post.*')
|
|
|
->where($where)
|
|
|
- ->where(function($query) use ($request){
|
|
|
- if(isset($request['keyword'])){
|
|
|
+ ->where(function ($query) use ($request) {
|
|
|
+ if (isset($request['keyword'])) {
|
|
|
$query->where('uid', '=', $request['keyword'])
|
|
|
->orWhere('username', 'like', "%{$request['keyword']}%")
|
|
|
->orWhere('mobile', 'like', "%{$request['keyword']}%");
|
|
|
}
|
|
|
})
|
|
|
- ->where(function($query) use ($request){
|
|
|
- if(isset($request['created_at'])){
|
|
|
+ ->where(function ($query) use ($request) {
|
|
|
+ if (isset($request['created_at'])) {
|
|
|
$time = explode('_', $request['created_at']);
|
|
|
$query->whereBetween('post.created_at', $time);
|
|
|
}
|
|
|
})
|
|
|
- ->where(function ($query) use ($request){
|
|
|
- if(isset($request['category_ids']) || isset($request['topic_ids'])){
|
|
|
+ ->where(function ($query) use ($request) {
|
|
|
+ if (isset($request['category_ids']) || isset($request['topic_ids'])) {
|
|
|
$ids = [];
|
|
|
if (isset($request['category_ids'])) {
|
|
|
$categoryIds = explode('_', $request['category_ids']);
|
|
@@ -387,19 +391,19 @@ class PostRepository
|
|
|
if (isset($request['topic_ids'])) {
|
|
|
$ids = array_merge($ids, explode('_', $request['topic_ids']));
|
|
|
}
|
|
|
- foreach ($ids as $key=>$id) {
|
|
|
- if ($key==0) {
|
|
|
- $query = $query->whereRaw('FIND_IN_SET('.$id.',topic_ids)');
|
|
|
+ foreach ($ids as $key => $id) {
|
|
|
+ if ($key == 0) {
|
|
|
+ $query = $query->whereRaw('FIND_IN_SET(' . $id . ',topic_ids)');
|
|
|
} else {
|
|
|
- $query = $query->orWhereRaw('FIND_IN_SET('.$id.',topic_ids)');
|
|
|
+ $query = $query->orWhereRaw('FIND_IN_SET(' . $id . ',topic_ids)');
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
- ->orderBy($sort,'desc')
|
|
|
+ ->orderBy($sort, 'desc')
|
|
|
->paginate($perPage);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 内容详情
|
|
@@ -417,17 +421,17 @@ class PostRepository
|
|
|
$perPage = isset($request['per_page']) ? $request['per_page'] : 20;
|
|
|
|
|
|
$where = [];
|
|
|
- if(isset($request['post_id'])){
|
|
|
+ if (isset($request['post_id'])) {
|
|
|
$where[] = ['post_id', $request['post_id']];
|
|
|
}
|
|
|
|
|
|
- if(isset($request['uid'])){
|
|
|
+ if (isset($request['uid'])) {
|
|
|
$where[] = ['uid', $request['uid']];
|
|
|
}
|
|
|
|
|
|
return $this->postComment
|
|
|
->where($where)
|
|
|
- ->orderBy('id','desc')
|
|
|
+ ->orderBy('id', 'desc')
|
|
|
->paginate($perPage);
|
|
|
}
|
|
|
|
|
@@ -437,33 +441,33 @@ class PostRepository
|
|
|
public function suggest($request)
|
|
|
{
|
|
|
$post = $this->post->where('id', $request['id'])->first();
|
|
|
- if(!$post){
|
|
|
+ if (!$post) {
|
|
|
return Response::create([
|
|
|
- 'message' => '获取内容信息失败',
|
|
|
- 'status_code' => 500
|
|
|
+ 'message' => '获取内容信息失败',
|
|
|
+ 'status_code' => 500
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
- if($post->is_suggest == 1){
|
|
|
+ if ($post->is_suggest == 1) {
|
|
|
$post->is_suggest = 0;
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
$post->is_suggest = 1;
|
|
|
}
|
|
|
|
|
|
DB::beginTransaction();
|
|
|
- try{
|
|
|
+ try {
|
|
|
$post->save();
|
|
|
|
|
|
DB::commit();
|
|
|
return Response::create();
|
|
|
|
|
|
- }catch (QueryException $exception){
|
|
|
+ } catch (QueryException $exception) {
|
|
|
DB::rollBack();
|
|
|
- Log::debug('推荐内容:'.$request['id'].$exception->getMessage());
|
|
|
+ Log::debug('推荐内容:' . $request['id'] . $exception->getMessage());
|
|
|
return Response::create([
|
|
|
- 'message' => '操作失败,请重试',
|
|
|
+ 'message' => '操作失败,请重试',
|
|
|
'error' => $exception->getMessage(),
|
|
|
- 'status_code' => 500
|
|
|
+ 'status_code' => 500
|
|
|
]);
|
|
|
}
|
|
|
}
|
|
@@ -474,27 +478,27 @@ class PostRepository
|
|
|
public function delete($request)
|
|
|
{
|
|
|
$post = $this->post->where('id', $request['id'])->first();
|
|
|
- if(!$post){
|
|
|
+ if (!$post) {
|
|
|
return Response::create([
|
|
|
- 'message' => '获取内容信息失败',
|
|
|
- 'status_code' => 500
|
|
|
+ 'message' => '获取内容信息失败',
|
|
|
+ 'status_code' => 500
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
DB::beginTransaction();
|
|
|
- try{
|
|
|
+ try {
|
|
|
$post->delete();
|
|
|
|
|
|
DB::commit();
|
|
|
return Response::create();
|
|
|
|
|
|
- }catch (QueryException $exception){
|
|
|
+ } catch (QueryException $exception) {
|
|
|
DB::rollBack();
|
|
|
- Log::debug('删除内容:'.$request['id'].$exception->getMessage());
|
|
|
+ Log::debug('删除内容:' . $request['id'] . $exception->getMessage());
|
|
|
return Response::create([
|
|
|
- 'message' => '操作失败,请重试',
|
|
|
+ 'message' => '操作失败,请重试',
|
|
|
'error' => $exception->getMessage(),
|
|
|
- 'status_code' => 500
|
|
|
+ 'status_code' => 500
|
|
|
]);
|
|
|
}
|
|
|
}
|
|
@@ -505,27 +509,27 @@ class PostRepository
|
|
|
public function restore($request)
|
|
|
{
|
|
|
$post = $this->post->withTrashed()->where('id', $request['id'])->first();
|
|
|
- if(!$post){
|
|
|
+ if (!$post) {
|
|
|
return Response::create([
|
|
|
- 'message' => '获取内容信息失败',
|
|
|
- 'status_code' => 500
|
|
|
+ 'message' => '获取内容信息失败',
|
|
|
+ 'status_code' => 500
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
DB::beginTransaction();
|
|
|
- try{
|
|
|
+ try {
|
|
|
$post->restore();
|
|
|
|
|
|
DB::commit();
|
|
|
return Response::create();
|
|
|
|
|
|
- }catch (QueryException $exception){
|
|
|
+ } catch (QueryException $exception) {
|
|
|
DB::rollBack();
|
|
|
- Log::debug('复原内容:'.$request['id'].$exception->getMessage());
|
|
|
+ Log::debug('复原内容:' . $request['id'] . $exception->getMessage());
|
|
|
return Response::create([
|
|
|
- 'message' => '操作失败,请重试',
|
|
|
+ 'message' => '操作失败,请重试',
|
|
|
'error' => $exception->getMessage(),
|
|
|
- 'status_code' => 500
|
|
|
+ 'status_code' => 500
|
|
|
]);
|
|
|
}
|
|
|
}
|
|
@@ -536,35 +540,35 @@ class PostRepository
|
|
|
public function commentDelete($request)
|
|
|
{
|
|
|
$comment = $this->postComment->find($request['id']);
|
|
|
- if(!$comment){
|
|
|
+ if (!$comment) {
|
|
|
return Response::create([
|
|
|
- 'message' => '获取评论信息失败',
|
|
|
- 'status_code' => 500
|
|
|
+ 'message' => '获取评论信息失败',
|
|
|
+ 'status_code' => 500
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
- if($comment->is_delete == 1){
|
|
|
+ if ($comment->is_delete == 1) {
|
|
|
return Response::create([
|
|
|
- 'message' => '该评论已经删除',
|
|
|
- 'status_code' => 500
|
|
|
+ 'message' => '该评论已经删除',
|
|
|
+ 'status_code' => 500
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
DB::beginTransaction();
|
|
|
- try{
|
|
|
+ try {
|
|
|
$comment->is_delete = 1;
|
|
|
$comment->save();
|
|
|
|
|
|
DB::commit();
|
|
|
return Response::create();
|
|
|
|
|
|
- }catch (QueryException $exception){
|
|
|
+ } catch (QueryException $exception) {
|
|
|
DB::rollBack();
|
|
|
- Log::debug('删除评论:'.$request['id'].$exception->getMessage());
|
|
|
+ Log::debug('删除评论:' . $request['id'] . $exception->getMessage());
|
|
|
return Response::create([
|
|
|
- 'message' => '操作失败,请重试',
|
|
|
+ 'message' => '操作失败,请重试',
|
|
|
'error' => $exception->getMessage(),
|
|
|
- 'status_code' => 500
|
|
|
+ 'status_code' => 500
|
|
|
]);
|
|
|
}
|
|
|
}
|
|
@@ -575,33 +579,33 @@ class PostRepository
|
|
|
public function hide($request)
|
|
|
{
|
|
|
$post = $this->post->where('id', $request['id'])->first();
|
|
|
- if(!$post){
|
|
|
+ if (!$post) {
|
|
|
return Response::create([
|
|
|
- 'message' => '获取内容信息失败',
|
|
|
- 'status_code' => 500
|
|
|
+ 'message' => '获取内容信息失败',
|
|
|
+ 'status_code' => 500
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
- if($post->is_hide == 1){
|
|
|
+ if ($post->is_hide == 1) {
|
|
|
$post->is_hide = 0;
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
$post->is_hide = 1;
|
|
|
}
|
|
|
|
|
|
DB::beginTransaction();
|
|
|
- try{
|
|
|
+ try {
|
|
|
$post->save();
|
|
|
|
|
|
DB::commit();
|
|
|
return Response::create();
|
|
|
|
|
|
- }catch (QueryException $exception){
|
|
|
+ } catch (QueryException $exception) {
|
|
|
DB::rollBack();
|
|
|
- Log::debug('隐藏内容:'.$request['id'].$exception->getMessage());
|
|
|
+ Log::debug('隐藏内容:' . $request['id'] . $exception->getMessage());
|
|
|
return Response::create([
|
|
|
- 'message' => '操作失败,请重试',
|
|
|
+ 'message' => '操作失败,请重试',
|
|
|
'error' => $exception->getMessage(),
|
|
|
- 'status_code' => 500
|
|
|
+ 'status_code' => 500
|
|
|
]);
|
|
|
}
|
|
|
}
|
|
@@ -613,19 +617,19 @@ class PostRepository
|
|
|
{
|
|
|
$perPage = isset($request['per_page']) ? $request['per_page'] : 20;
|
|
|
$where = [];
|
|
|
- if(isset($request['log_type'])){
|
|
|
+ if (isset($request['log_type'])) {
|
|
|
$where[] = ['log_type', $request['log_type']];
|
|
|
}
|
|
|
|
|
|
return $this->postLog
|
|
|
->where($where)
|
|
|
- ->where(function($query) use ($request){
|
|
|
- if(isset($request['created_at'])){
|
|
|
+ ->where(function ($query) use ($request) {
|
|
|
+ if (isset($request['created_at'])) {
|
|
|
$time = explode('_', $request['created_at']);
|
|
|
$query->whereBetween('created_at', $time);
|
|
|
}
|
|
|
})
|
|
|
- ->orderBy('id','desc')
|
|
|
+ ->orderBy('id', 'desc')
|
|
|
->paginate($perPage);
|
|
|
}
|
|
|
|
|
@@ -641,11 +645,11 @@ class PostRepository
|
|
|
$writer = Writer::createFromPath(public_path($filePath), 'w+');
|
|
|
|
|
|
// 设置标题
|
|
|
- if($type == 'post'){
|
|
|
+ if ($type == 'post') {
|
|
|
$title = [
|
|
|
'内容', date('Y年m月d日')
|
|
|
];
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
$title = [
|
|
|
'回收站内容', date('Y年m月d日')
|
|
|
];
|
|
@@ -655,7 +659,7 @@ class PostRepository
|
|
|
$writer->insertone($title);
|
|
|
|
|
|
// 内容
|
|
|
- if($type == 'post') {
|
|
|
+ if ($type == 'post') {
|
|
|
$header = [
|
|
|
'内容ID', '发布时间', '用户昵称', '城市', '内容标签', '内容前20个字',
|
|
|
'真实浏览量', '总浏览量', '真实点赞数', '总赞数', '真实分享数', '总分享数',
|
|
@@ -673,43 +677,43 @@ class PostRepository
|
|
|
$writer->insertone($header);
|
|
|
|
|
|
$where = [];
|
|
|
- if(isset($request['content'])){
|
|
|
+ if (isset($request['content'])) {
|
|
|
$where[] = ['content', 'like', "%{$request['content']}%"];
|
|
|
}
|
|
|
- if(isset($request['is_suggest'])){
|
|
|
+ if (isset($request['is_suggest'])) {
|
|
|
$where[] = ['is_suggest', $request['is_suggest']];
|
|
|
}
|
|
|
- if(isset($request['type'])){
|
|
|
+ if (isset($request['type'])) {
|
|
|
$where[] = ['type', $request['type']];
|
|
|
}
|
|
|
|
|
|
$sort = 'post.id';
|
|
|
- if(isset($request['sort']) && in_array($request['sort'], ['praise_count', 'share_count', 'pv', 'comment_count', 'create_bean'])){
|
|
|
+ if (isset($request['sort']) && in_array($request['sort'], ['praise_count', 'share_count', 'pv', 'comment_count', 'create_bean'])) {
|
|
|
$sort = $request['sort'];
|
|
|
}
|
|
|
$post = $this->post;
|
|
|
- if($type == 'post_waste'){
|
|
|
+ if ($type == 'post_waste') {
|
|
|
$post = $post->onlyTrashed();
|
|
|
}
|
|
|
|
|
|
$post->join('post_data', 'post_data.post_id', '=', 'post.id')
|
|
|
->select('post.*')
|
|
|
->where($where)
|
|
|
- ->where(function($query) use ($request){
|
|
|
- if(isset($request['keyword'])){
|
|
|
+ ->where(function ($query) use ($request) {
|
|
|
+ if (isset($request['keyword'])) {
|
|
|
$query->where('uid', '=', $request['keyword'])
|
|
|
->orWhere('username', 'like', "%{$request['keyword']}%")
|
|
|
->orWhere('mobile', 'like', "%{$request['keyword']}%");
|
|
|
}
|
|
|
})
|
|
|
- ->where(function($query) use ($request){
|
|
|
- if(isset($request['created_at'])){
|
|
|
+ ->where(function ($query) use ($request) {
|
|
|
+ if (isset($request['created_at'])) {
|
|
|
$time = explode('_', $request['created_at']);
|
|
|
$query->whereBetween('post.created_at', $time);
|
|
|
}
|
|
|
})
|
|
|
- ->where(function ($query) use ($request){
|
|
|
- if(isset($request['category_ids']) || isset($request['topic_ids'])){
|
|
|
+ ->where(function ($query) use ($request) {
|
|
|
+ if (isset($request['category_ids']) || isset($request['topic_ids'])) {
|
|
|
$ids = [];
|
|
|
if (isset($request['category_ids'])) {
|
|
|
$categoryIds = explode('_', $request['category_ids']);
|
|
@@ -718,21 +722,21 @@ class PostRepository
|
|
|
if (isset($request['topic_ids'])) {
|
|
|
$ids = array_merge($ids, explode('_', $request['topic_ids']));
|
|
|
}
|
|
|
- Log::debug('话题ids:'.json_encode($ids));
|
|
|
- foreach ($ids as $key=>$id) {
|
|
|
- if ($key==0) {
|
|
|
- $query = $query->whereRaw('FIND_IN_SET('.$id.',topic_ids)');
|
|
|
+ Log::debug('话题ids:' . json_encode($ids));
|
|
|
+ foreach ($ids as $key => $id) {
|
|
|
+ if ($key == 0) {
|
|
|
+ $query = $query->whereRaw('FIND_IN_SET(' . $id . ',topic_ids)');
|
|
|
} else {
|
|
|
- $query = $query->orWhereRaw('FIND_IN_SET('.$id.',topic_ids)');
|
|
|
+ $query = $query->orWhereRaw('FIND_IN_SET(' . $id . ',topic_ids)');
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
})
|
|
|
- ->orderBy($sort,'desc')
|
|
|
- ->chunk(1, function ($posts) use ($writer, $type){
|
|
|
+ ->orderBy($sort, 'desc')
|
|
|
+ ->chunk(1, function ($posts) use ($writer, $type) {
|
|
|
$data = [];
|
|
|
foreach ($posts as $post) {
|
|
|
- if($type == 'post'){
|
|
|
+ if ($type == 'post') {
|
|
|
$tmp = [
|
|
|
$post->id,
|
|
|
Carbon::parse($post->created_at)->toDateTimeString(),
|
|
@@ -750,7 +754,7 @@ class PostRepository
|
|
|
$post->data->collect_count,
|
|
|
$post->data->comment_count
|
|
|
];
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
$tmp = [
|
|
|
$post->id,
|
|
|
Carbon::parse($post->created_at)->toDateTimeString(),
|
|
@@ -771,7 +775,7 @@ class PostRepository
|
|
|
$data[] = $tmp;
|
|
|
}
|
|
|
$writer->insertAll($data);
|
|
|
- });
|
|
|
+ });
|
|
|
Log::channel('download')->info('内容导出成功!');
|
|
|
|
|
|
} catch (CannotInsertRecord $e) {
|
|
@@ -781,4 +785,49 @@ class PostRepository
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 统计社区内容
|
|
|
+ * @param $start
|
|
|
+ * @param $end
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function statistics($start, $end)
|
|
|
+ {
|
|
|
+ $result = $this->postStatistics
|
|
|
+ ->where('created_at', '>=', $start)
|
|
|
+ ->where('created_at', '<=', $end)
|
|
|
+ ->get()->toArray();
|
|
|
+ $totalRead = 0;
|
|
|
+ $totalPost = 0;
|
|
|
+ $totalShare = 0;
|
|
|
+ $totalLike = 0;
|
|
|
+ $totalCollect = 0;
|
|
|
+ $totalComment = 0;
|
|
|
+ $info = [];
|
|
|
+ foreach($result as $row){
|
|
|
+ if($row){
|
|
|
+ $info['read'][date('Y-m-d',$row['created_at'])]=$row['read_count'];
|
|
|
+ $info['post'][date('Y-m-d',$row['created_at'])]=$row['post_count'];
|
|
|
+ $info['share'][date('Y-m-d',$row['created_at'])]=$row['share_count'];
|
|
|
+ $info['like'][date('Y-m-d',$row['created_at'])]=$row['like_count'];
|
|
|
+ $info['collect'][date('Y-m-d',$row['created_at'])]=$row['collect_count'];
|
|
|
+ $info['comment'][date('Y-m-d',$row['created_at'])]=$row['comment_count'];
|
|
|
+ $totalRead += $row['read_count'];
|
|
|
+ $totalPost += $row['post_count'];
|
|
|
+ $totalShare += $row['share_count'];
|
|
|
+ $totalLike += $row['like_count'];
|
|
|
+ $totalCollect += $row['collect_count'];
|
|
|
+ $totalComment += $row['comment_count'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $info['total_read'] = $totalRead;
|
|
|
+ $info['total_post'] = $totalPost;
|
|
|
+ $info['total_share'] = $totalShare;
|
|
|
+ $info['total_like'] = $totalLike;
|
|
|
+ $info['total_collect'] = $totalCollect;
|
|
|
+ $info['total_comment'] = $totalComment;
|
|
|
+ return $info;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|