|
@@ -72,7 +72,7 @@ class PostRepository
|
|
|
public function create($request)
|
|
|
{
|
|
|
//富文本标题
|
|
|
- if($request['type'] == 'html' && (!isset($request['title']) || !$request['title'])){
|
|
|
+ if ($request['type'] == 'html' && (!isset($request['title']) || !$request['title'])) {
|
|
|
return Response::create([
|
|
|
'message' => '当类型是富文本时,标题不能为空',
|
|
|
'status_code' => 500
|
|
@@ -87,13 +87,13 @@ class PostRepository
|
|
|
'status_code' => 500
|
|
|
]);
|
|
|
}
|
|
|
- if(isset($request['is_point']) && $request['is_point']){
|
|
|
+ if (isset($request['is_point']) && $request['is_point']) {
|
|
|
$res = $this->uploadImage($request['img']);
|
|
|
- if($res && isset($res['data']) && isset($res['data']['url'])){
|
|
|
- $request['img'] = config('customer.chxq_oss_url').$res['data']['url'];
|
|
|
- Log::debug('内容上传图片成功结果'.json_encode($res));
|
|
|
- }else{
|
|
|
- Log::debug('内容上传图片失败结果'.json_encode($res));
|
|
|
+ if ($res && isset($res['data']) && isset($res['data']['url'])) {
|
|
|
+ $request['img'] = config('customer.chxq_oss_url') . $res['data']['url'];
|
|
|
+ Log::debug('内容上传图片成功结果' . json_encode($res));
|
|
|
+ } else {
|
|
|
+ Log::debug('内容上传图片失败结果' . json_encode($res));
|
|
|
return Response::create([
|
|
|
'message' => '图片格式有误,请重试',
|
|
|
'status_code' => 500
|
|
@@ -113,7 +113,7 @@ class PostRepository
|
|
|
$topicIds = implode(',', $topicIdsArray);
|
|
|
|
|
|
//验证内容字数
|
|
|
- if($request['type'] != 'html'){
|
|
|
+ if ($request['type'] != 'html') {
|
|
|
$html = strip_tags($request['content']);
|
|
|
if (mb_strlen($html, 'UTF8') > 1000) {
|
|
|
return Response::create([
|
|
@@ -181,7 +181,7 @@ class PostRepository
|
|
|
$this->postImgs->insert($imgData);
|
|
|
}
|
|
|
|
|
|
- if(isset($request['store_id']) && $request['store_id']){
|
|
|
+ if (isset($request['store_id']) && $request['store_id']) {
|
|
|
$this->postStore->where('id', $request['store_id'])->update(['is_used' => 1]);
|
|
|
}
|
|
|
|
|
@@ -211,7 +211,7 @@ class PostRepository
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
- Redis::HSET('post_info_'.$post->id,
|
|
|
+ Redis::HSET('post_info_' . $post->id,
|
|
|
'id', $post->id,
|
|
|
'uid', $post->uid,
|
|
|
'type', $post->type,
|
|
@@ -456,16 +456,16 @@ class PostRepository
|
|
|
try {
|
|
|
$newComment = $this->postComment->create($data);
|
|
|
|
|
|
- if($newComment->parent_id){
|
|
|
+ if ($newComment->parent_id) {
|
|
|
$this->postComment->where('id', $newComment->parent_id)->increment('reply_count');
|
|
|
}
|
|
|
|
|
|
DB::commit();
|
|
|
|
|
|
- if($newComment->parent_id){
|
|
|
- Redis::DEL('post_new_reply_'.$newComment->parent_id);
|
|
|
- }else{
|
|
|
- Redis::DEL('post_new_comment_'.$newComment->post_id);
|
|
|
+ if ($newComment->parent_id) {
|
|
|
+ Redis::DEL('post_new_reply_' . $newComment->parent_id);
|
|
|
+ } else {
|
|
|
+ Redis::DEL('post_new_comment_' . $newComment->post_id);
|
|
|
}
|
|
|
$virus = $this->behavior->where('behavior_identification', 'comment')->first();
|
|
|
if ($virus) {
|
|
@@ -597,9 +597,9 @@ class PostRepository
|
|
|
{
|
|
|
$type = $this->post->where('id', $request['id'])->value('type');
|
|
|
return Response::create([
|
|
|
- 'message' => '成功',
|
|
|
- 'status_code' => 200,
|
|
|
- 'data' => $type
|
|
|
+ 'message' => '成功',
|
|
|
+ 'status_code' => 200,
|
|
|
+ 'data' => $type
|
|
|
]);
|
|
|
}
|
|
|
|
|
@@ -647,10 +647,17 @@ class PostRepository
|
|
|
DB::beginTransaction();
|
|
|
try {
|
|
|
$post->save();
|
|
|
-
|
|
|
DB::commit();
|
|
|
+ //内容被设为推荐时,发送推送消息
|
|
|
+ if($post->is_suggest==1){
|
|
|
+ $title = $post['title'] ? $post['title'] : subtext($post['content'], 18);
|
|
|
+ $rabbitmq = new RabbitMqUtil();
|
|
|
+ $push['uid'] = $post->uid;
|
|
|
+ $push['title'] = '【由你内容】推荐通知';
|
|
|
+ $push['text'] = '你的内容《'.$title.'》被小编推荐全平台优先展示喽,获得推荐位后你的内容会被更多人看到。记得多来和大家互动赚取更多U米~';
|
|
|
+ $rabbitmq->push('send_push_msg_queue',$push);
|
|
|
+ }
|
|
|
return Response::create();
|
|
|
-
|
|
|
} catch (QueryException $exception) {
|
|
|
DB::rollBack();
|
|
|
Log::debug('推荐内容:' . $request['id'] . $exception->getMessage());
|
|
@@ -668,7 +675,7 @@ class PostRepository
|
|
|
public function delete($request)
|
|
|
{
|
|
|
$token = JWTAuth::decode(JWTAuth::getToken());
|
|
|
- if($token['type'] != 1){
|
|
|
+ if ($token['type'] != 1) {
|
|
|
return Response::create([
|
|
|
'message' => '只有运营才能删除内容',
|
|
|
'status_code' => 500
|
|
@@ -683,7 +690,7 @@ class PostRepository
|
|
|
}
|
|
|
$uid = $post->uid;
|
|
|
$title = $post->title;
|
|
|
- if(!$title){
|
|
|
+ if (!$title) {
|
|
|
$title = subtext(strip_tags($post->content), 20);
|
|
|
}
|
|
|
$content = "经核实您的内容“{$title}”涉及违规,现已被删除,有任何问题请联系由你管理员";
|
|
@@ -794,10 +801,10 @@ class PostRepository
|
|
|
DB::commit();
|
|
|
Redis::SADD('delete_post_comment_ids', $comment->id);
|
|
|
|
|
|
- if(!$comment->parent_id){
|
|
|
- Redis::DEL('post_new_comment_'.$comment->post_id);
|
|
|
- }else{
|
|
|
- Redis::DEL('post_new_reply_'.$comment->id);
|
|
|
+ if (!$comment->parent_id) {
|
|
|
+ Redis::DEL('post_new_comment_' . $comment->post_id);
|
|
|
+ } else {
|
|
|
+ Redis::DEL('post_new_reply_' . $comment->id);
|
|
|
}
|
|
|
return Response::create();
|
|
|
|
|
@@ -1018,7 +1025,7 @@ class PostRepository
|
|
|
Log::info('内容导出成功!');
|
|
|
|
|
|
} catch (QueryException $e) {
|
|
|
- Log::debug('内容导出失败!'.$e->getMessage());
|
|
|
+ Log::debug('内容导出失败!' . $e->getMessage());
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -1091,7 +1098,7 @@ class PostRepository
|
|
|
public function updateTopic($request)
|
|
|
{
|
|
|
$token = JWTAuth::decode(JWTAuth::getToken());
|
|
|
- if($token['type'] != 1){
|
|
|
+ if ($token['type'] != 1) {
|
|
|
return Response::create([
|
|
|
'message' => '只有运营才能删除内容',
|
|
|
'status_code' => 500
|
|
@@ -1122,7 +1129,7 @@ class PostRepository
|
|
|
'post_id' => $request['id'],
|
|
|
'username' => $token['user']->username,
|
|
|
'log_type' => 'update_topic',
|
|
|
- 'content' => json_encode(['update_topic' => $request['id'].'-'.$topicIds]),
|
|
|
+ 'content' => json_encode(['update_topic' => $request['id'] . '-' . $topicIds]),
|
|
|
];
|
|
|
|
|
|
DB::beginTransaction();
|
|
@@ -1134,7 +1141,7 @@ class PostRepository
|
|
|
|
|
|
DB::commit();
|
|
|
|
|
|
- Redis::HSET('post_info_'.$request['id'], 'topic_ids', $topicIds);
|
|
|
+ Redis::HSET('post_info_' . $request['id'], 'topic_ids', $topicIds);
|
|
|
|
|
|
foreach ($topicIdsArray as $id) {
|
|
|
Redis::zincrby('topic.just_use_count', 1, $id);
|
|
@@ -1144,7 +1151,7 @@ class PostRepository
|
|
|
|
|
|
} catch (QueryException $exception) {
|
|
|
DB::rollBack();
|
|
|
- Log::debug('编辑内容话题:'.$post->id . $exception->getMessage());
|
|
|
+ Log::debug('编辑内容话题:' . $post->id . $exception->getMessage());
|
|
|
return Response::create([
|
|
|
'message' => '编辑失败,请重试',
|
|
|
'error' => $exception->getMessage(),
|
|
@@ -1159,12 +1166,12 @@ class PostRepository
|
|
|
public function createStore($startPage, $endPage, $size, $categoryId)
|
|
|
{
|
|
|
set_time_limit(1800);
|
|
|
- for($i=$startPage;$i<=$endPage;$i++){
|
|
|
+ for ($i = $startPage; $i <= $endPage; $i++) {
|
|
|
$this->addContent($i, $size, $categoryId);
|
|
|
usleep(100000);
|
|
|
}
|
|
|
|
|
|
-}
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 获取网站内容
|
|
@@ -1172,20 +1179,20 @@ class PostRepository
|
|
|
public function addContent($page, $size, $categoryId)
|
|
|
{
|
|
|
$lists = $this->getAcFunList($page, $size, $categoryId);
|
|
|
- if(empty($lists)){
|
|
|
+ if (empty($lists)) {
|
|
|
return Response::create([
|
|
|
'message' => '获取数据失败',
|
|
|
'status_code' => 500
|
|
|
]);
|
|
|
}
|
|
|
$data = [];
|
|
|
- foreach($lists as $item){
|
|
|
+ foreach ($lists as $item) {
|
|
|
$res = $this->getData($item['id'], $item['title']);
|
|
|
- if($res && $res['content'] && $res['images']){
|
|
|
+ if ($res && $res['content'] && $res['images']) {
|
|
|
$data[] = array_merge(['source_id' => $item['id']], $res);
|
|
|
}
|
|
|
}
|
|
|
- if(empty($data)){
|
|
|
+ if (empty($data)) {
|
|
|
return Response::create([
|
|
|
'message' => '处理数据失败',
|
|
|
'status_code' => 500
|
|
@@ -1196,8 +1203,8 @@ class PostRepository
|
|
|
$failNo = 0;
|
|
|
DB::beginTransaction();
|
|
|
try {
|
|
|
- foreach($data as $item){
|
|
|
- if($this->postStore->where('source', 'AcFun')->where('source_id', $item['source_id'])->exists()){
|
|
|
+ foreach ($data as $item) {
|
|
|
+ if ($this->postStore->where('source', 'AcFun')->where('source_id', $item['source_id'])->exists()) {
|
|
|
$failNo++;
|
|
|
continue;
|
|
|
}
|
|
@@ -1212,7 +1219,7 @@ class PostRepository
|
|
|
$postStore = $this->postStore->create($storeData);
|
|
|
|
|
|
$storeImgsData = [];
|
|
|
- foreach($item['images'] as $img){
|
|
|
+ foreach ($item['images'] as $img) {
|
|
|
$storeImgsData[] = [
|
|
|
'post_store_id' => $postStore->id,
|
|
|
'img' => $img,
|
|
@@ -1225,7 +1232,7 @@ class PostRepository
|
|
|
}
|
|
|
|
|
|
DB::commit();
|
|
|
- Log::info('第'.$page.'页添加内容数据成功'.$successNo.',失败'.$failNo);
|
|
|
+ Log::info('第' . $page . '页添加内容数据成功' . $successNo . ',失败' . $failNo);
|
|
|
return Response::create();
|
|
|
|
|
|
} catch (QueryException $exception) {
|
|
@@ -1245,31 +1252,31 @@ class PostRepository
|
|
|
*/
|
|
|
public function getData($id, $title = '')
|
|
|
{
|
|
|
- $url = 'https://www.acfun.cn/a/ac'.$id;
|
|
|
+ $url = 'https://www.acfun.cn/a/ac' . $id;
|
|
|
$webpage = file_get_contents($url);
|
|
|
preg_match_all('/parts[\s\S]*?}]/i', $webpage, $res);
|
|
|
- if(!isset($res[0][0])){
|
|
|
+ if (!isset($res[0][0])) {
|
|
|
return [];
|
|
|
}
|
|
|
$data = $res[0][0];
|
|
|
- preg_match_all('/<p[^>]*>(?:(?!<\/p>)[\s\S])*<\/p>/i ', $data, $contents);
|
|
|
-
|
|
|
- if(isset($contents[0])){
|
|
|
- $content = implode($contents[0]);
|
|
|
- }else{
|
|
|
- return [];
|
|
|
- }
|
|
|
- $content = strip_tags($content);
|
|
|
- $content = str_replace([' '],'',$content);
|
|
|
+ preg_match_all('/<p[^>]*>(?:(?!<\/p>)[\s\S])*<\/p>/i ', $data, $contents);
|
|
|
+
|
|
|
+ if (isset($contents[0])) {
|
|
|
+ $content = implode($contents[0]);
|
|
|
+ } else {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+ $content = strip_tags($content);
|
|
|
+ $content = str_replace([' '], '', $content);
|
|
|
preg_match_all('/src=(.*)>/U', $data, $imageArray);
|
|
|
$images = [];
|
|
|
- if(isset($imageArray[0])){
|
|
|
- foreach($imageArray[0] as $img){
|
|
|
- $imgArr = explode('"',$img);
|
|
|
- if(isset($imgArr[1])){
|
|
|
+ if (isset($imageArray[0])) {
|
|
|
+ foreach ($imageArray[0] as $img) {
|
|
|
+ $imgArr = explode('"', $img);
|
|
|
+ if (isset($imgArr[1])) {
|
|
|
$imgArr[1] = trim($imgArr[1], '\\');
|
|
|
$images[] = $imgArr[1];
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
return [];
|
|
|
}
|
|
|
}
|