|
@@ -15,16 +15,23 @@ use App\Models\PostData;
|
|
|
use App\Models\PostImgs;
|
|
|
use App\Models\PostLog;
|
|
|
use App\Models\Topic;
|
|
|
+use App\Traits\PostTrait;
|
|
|
+use App\Traits\UserTrait;
|
|
|
use Illuminate\Database\QueryException;
|
|
|
use Dingo\Api\Http\Response;
|
|
|
+use Illuminate\Support\Carbon;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
use Illuminate\Support\Facades\Redis;
|
|
|
use Symfony\Component\HttpKernel\Exception\HttpException;
|
|
|
use Tymon\JWTAuth\Facades\JWTAuth;
|
|
|
+use League\Csv\Writer;
|
|
|
+use League\Csv\CannotInsertRecord;
|
|
|
|
|
|
class PostRepository
|
|
|
{
|
|
|
+ use PostTrait;
|
|
|
+ use UserTrait;
|
|
|
|
|
|
public function __construct(Post $post,
|
|
|
PostData $postData,
|
|
@@ -49,20 +56,29 @@ class PostRepository
|
|
|
public function create($request)
|
|
|
{
|
|
|
//验证小号
|
|
|
-
|
|
|
+ $userInfo = $this->getUserInfo($request['uid']);
|
|
|
+ if(!$userInfo || $userInfo['type'] != 1){
|
|
|
+ return Response::create([
|
|
|
+ 'message' => '所选小号信息有误',
|
|
|
+ 'status_code' => 500
|
|
|
+ ]);
|
|
|
+ }
|
|
|
//验证话题
|
|
|
$topicIds = $this->topic->whereIn('id', explode(',', $request['topic_ids']))->pluck('id')->toArray();
|
|
|
$topicCount = count($topicIds);
|
|
|
- if($topicCount == 0 || $topicCount >= 5){
|
|
|
- throw new HttpException(500, '所选话题必须1-5个');
|
|
|
+ if($topicCount == 0 || $topicCount > 5){
|
|
|
+ return Response::create([
|
|
|
+ 'message' => '所选话题必须1-5个',
|
|
|
+ 'status_code' => 500
|
|
|
+ ]);
|
|
|
}
|
|
|
$topicIds = implode(',', $topicIds);
|
|
|
|
|
|
$data = [
|
|
|
'uid' => $request['uid'],
|
|
|
- 'username' => '暂无',
|
|
|
- 'mobile' => '暂无',
|
|
|
- 'avatar' => '暂无',
|
|
|
+ 'username' => $userInfo['username'],
|
|
|
+ 'mobile' => $userInfo['mobile'],
|
|
|
+ 'avatar' => $userInfo['avatar'],
|
|
|
'type' => $request['type'],
|
|
|
'img' => $request['img'],
|
|
|
'video' => $request['video']??'',
|
|
@@ -94,8 +110,8 @@ class PostRepository
|
|
|
'comment_real_count' => 0,
|
|
|
'collect_count' => 0,
|
|
|
'collect_real_count' => 0,
|
|
|
- 'available_bean' => 0,
|
|
|
- 'will_collect_bean' => 0,
|
|
|
+ 'available_bean' => $this->availableBean(),
|
|
|
+ 'will_collect_bean' => rand(100, 200),
|
|
|
'collect_bean' => 0,
|
|
|
'weight' => 0
|
|
|
]);
|
|
@@ -127,6 +143,146 @@ class PostRepository
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 增加数据
|
|
|
+ */
|
|
|
+ public function addData($request)
|
|
|
+ {
|
|
|
+ $token = JWTAuth::decode(JWTAuth::getToken());
|
|
|
+ if(!$token || $token['type'] != 1){
|
|
|
+ return Response::create([
|
|
|
+ 'message' => '获取登陆信息失败',
|
|
|
+ 'status_code' => 500
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ $uid = $token['user']->id;
|
|
|
+ $username = $token['user']->username;
|
|
|
+ //验证小号数量
|
|
|
+
|
|
|
+ $postData = $this->postData->where('post_id', $request['post_id'])->first();
|
|
|
+ if(!$postData){
|
|
|
+ return Response::create([
|
|
|
+ 'message' => '获取内容失败',
|
|
|
+ 'status_code' => 500
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ 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
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ $content = '';
|
|
|
+ if($request['add_pv']){
|
|
|
+ $postData->pv += $request['add_pv'];
|
|
|
+ $content .= '浏览数增加'.$request['add_pv'].'、';
|
|
|
+ }
|
|
|
+ if($request['add_praise_count']){
|
|
|
+ $postData->praise_count += $request['add_praise_count'];
|
|
|
+ $content .= '点赞数增加'.$request['add_praise_count'].'、';
|
|
|
+ }
|
|
|
+ if($request['add_collect_count']){
|
|
|
+ $postData->collect_count += $request['add_collect_count'];
|
|
|
+ $content .= '收藏数增加'.$request['add_collect_count'].'、';
|
|
|
+ }
|
|
|
+ if($request['add_share_count']){
|
|
|
+ $postData->share_count += $request['add_share_count'];
|
|
|
+ $content .= '分享数增加'.$request['add_share_count'];
|
|
|
+ }
|
|
|
+ $content = rtrim($content, '、');
|
|
|
+ DB::beginTransaction();
|
|
|
+ try{
|
|
|
+ $postData->save();
|
|
|
+ $this->postLog->create([
|
|
|
+ 'post_id' => $request['post_id'],
|
|
|
+ 'uid' => $uid,
|
|
|
+ 'username' => $username,
|
|
|
+ 'log_type' => 'add_data',
|
|
|
+ 'content' => $content
|
|
|
+ ]);
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
+ return Response::create();
|
|
|
+
|
|
|
+ }catch (QueryException $exception){
|
|
|
+ DB::rollBack();
|
|
|
+ Log::debug('内容增加数据:'.$request['post_id'].$exception->getMessage());
|
|
|
+ return Response::create([
|
|
|
+ 'message' => '增加数据失败,请重试',
|
|
|
+ 'error' => $exception->getMessage(),
|
|
|
+ 'status_code' => 500
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 评论&回复
|
|
|
+ */
|
|
|
+ public function comment($request)
|
|
|
+ {
|
|
|
+ //验证小号
|
|
|
+ $userInfo = $this->getUserInfo($request['uid']);
|
|
|
+ if(!$userInfo || $userInfo['type'] != 1){
|
|
|
+ return Response::create([
|
|
|
+ 'message' => '所选小号信息有误',
|
|
|
+ 'status_code' => 500
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ $post = $this->post->find($request['post_id']);
|
|
|
+ if(!$post){
|
|
|
+ return Response::create([
|
|
|
+ 'message' => '获取内容失败',
|
|
|
+ 'status_code' => 500
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ $data = [
|
|
|
+ 'uid' => $request['uid'],
|
|
|
+ 'post_id' => $request['post_id'],
|
|
|
+ 'parent_id' => 0,
|
|
|
+ 'username' => $userInfo['username'],
|
|
|
+ 'avatar' => $userInfo['avatar'],
|
|
|
+ 'content' => $request['content'],
|
|
|
+ 'is_delete' => 0,
|
|
|
+ ];
|
|
|
+ if(isset($request['parent_id']) && $request['parent_id'] != 0){
|
|
|
+ $comment = $this->postComment->find($request['parent_id']);
|
|
|
+ if(!$comment){
|
|
|
+ return Response::create([
|
|
|
+ 'message' => '获取评论信息失败',
|
|
|
+ 'status_code' => 500
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ if($comment->parent_id){
|
|
|
+ return Response::create([
|
|
|
+ 'message' => '只能回复评论',
|
|
|
+ 'status_code' => 500
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ $data['parent_id'] = $request['parent_id'];
|
|
|
+ }
|
|
|
+ DB::beginTransaction();
|
|
|
+ try{
|
|
|
+ $this->postComment->create($data);
|
|
|
+ $post->data->comment_count += 1;
|
|
|
+ $post->data->comment_real_count += 1;
|
|
|
+ $post->data->save();
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
+ return Response::create();
|
|
|
+
|
|
|
+ }catch (QueryException $exception){
|
|
|
+ DB::rollBack();
|
|
|
+ Log::debug('评论内容:'.$request['post_id'].$exception->getMessage());
|
|
|
+ return Response::create([
|
|
|
+ 'message' => '评论失败,请重试',
|
|
|
+ 'error' => $exception->getMessage(),
|
|
|
+ 'status_code' => 500
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 内容列表
|
|
|
*/
|
|
@@ -148,8 +304,12 @@ class PostRepository
|
|
|
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){
|
|
|
+ $post = $post->onlyTrashed();
|
|
|
+ }
|
|
|
|
|
|
- return $this->post
|
|
|
+ return $post
|
|
|
->join('post_data', 'post_data.post_id', '=', 'post.id')
|
|
|
->select('post.*')
|
|
|
->where($where)
|
|
@@ -188,5 +348,377 @@ class PostRepository
|
|
|
->orderBy($sort,'desc')
|
|
|
->paginate($perPage);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 内容详情
|
|
|
+ */
|
|
|
+ public function detail($request)
|
|
|
+ {
|
|
|
+ return $this->post->withTrashed()->find($request['id']);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 评论列表
|
|
|
+ */
|
|
|
+ public function commentList($request)
|
|
|
+ {
|
|
|
+ $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
|
|
|
+
|
|
|
+ return $this->postComment
|
|
|
+ ->where('post_id', $request['post_id'])
|
|
|
+ ->orderBy('id','desc')
|
|
|
+ ->paginate($perPage);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 推荐内容
|
|
|
+ */
|
|
|
+ public function suggest($request)
|
|
|
+ {
|
|
|
+ $post = $this->post->where('id', $request['id'])->first();
|
|
|
+ if(!$post){
|
|
|
+ return Response::create([
|
|
|
+ 'message' => '获取内容信息失败',
|
|
|
+ 'status_code' => 500
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if($post->is_suggest == 1){
|
|
|
+ $post->is_suggest = 0;
|
|
|
+ }else{
|
|
|
+ $post->is_suggest = 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ DB::beginTransaction();
|
|
|
+ try{
|
|
|
+ $post->save();
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
+ return Response::create();
|
|
|
+
|
|
|
+ }catch (QueryException $exception){
|
|
|
+ DB::rollBack();
|
|
|
+ Log::debug('推荐内容:'.$request['id'].$exception->getMessage());
|
|
|
+ return Response::create([
|
|
|
+ 'message' => '操作失败,请重试',
|
|
|
+ 'error' => $exception->getMessage(),
|
|
|
+ 'status_code' => 500
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除内容
|
|
|
+ */
|
|
|
+ public function delete($request)
|
|
|
+ {
|
|
|
+ $post = $this->post->where('id', $request['id'])->first();
|
|
|
+ if(!$post){
|
|
|
+ return Response::create([
|
|
|
+ 'message' => '获取内容信息失败',
|
|
|
+ 'status_code' => 500
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ DB::beginTransaction();
|
|
|
+ try{
|
|
|
+ $post->delete();
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
+ return Response::create();
|
|
|
+
|
|
|
+ }catch (QueryException $exception){
|
|
|
+ DB::rollBack();
|
|
|
+ Log::debug('删除内容:'.$request['id'].$exception->getMessage());
|
|
|
+ return Response::create([
|
|
|
+ 'message' => '操作失败,请重试',
|
|
|
+ 'error' => $exception->getMessage(),
|
|
|
+ 'status_code' => 500
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 复原内容
|
|
|
+ */
|
|
|
+ public function restore($request)
|
|
|
+ {
|
|
|
+ $post = $this->post->withTrashed()->where('id', $request['id'])->first();
|
|
|
+ if(!$post){
|
|
|
+ return Response::create([
|
|
|
+ 'message' => '获取内容信息失败',
|
|
|
+ 'status_code' => 500
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ DB::beginTransaction();
|
|
|
+ try{
|
|
|
+ $post->restore();
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
+ return Response::create();
|
|
|
+
|
|
|
+ }catch (QueryException $exception){
|
|
|
+ DB::rollBack();
|
|
|
+ Log::debug('复原内容:'.$request['id'].$exception->getMessage());
|
|
|
+ return Response::create([
|
|
|
+ 'message' => '操作失败,请重试',
|
|
|
+ 'error' => $exception->getMessage(),
|
|
|
+ 'status_code' => 500
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除评论
|
|
|
+ */
|
|
|
+ public function commentDelete($request)
|
|
|
+ {
|
|
|
+ $comment = $this->postComment->find($request['id']);
|
|
|
+ if(!$comment){
|
|
|
+ return Response::create([
|
|
|
+ 'message' => '获取评论信息失败',
|
|
|
+ 'status_code' => 500
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if($comment->is_delete == 1){
|
|
|
+ return Response::create([
|
|
|
+ 'message' => '该评论已经删除',
|
|
|
+ 'status_code' => 500
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ DB::beginTransaction();
|
|
|
+ try{
|
|
|
+ $comment->is_delete = 1;
|
|
|
+ $comment->save();
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
+ return Response::create();
|
|
|
+
|
|
|
+ }catch (QueryException $exception){
|
|
|
+ DB::rollBack();
|
|
|
+ Log::debug('删除评论:'.$request['id'].$exception->getMessage());
|
|
|
+ return Response::create([
|
|
|
+ 'message' => '操作失败,请重试',
|
|
|
+ 'error' => $exception->getMessage(),
|
|
|
+ 'status_code' => 500
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 隐藏内容
|
|
|
+ */
|
|
|
+ public function hide($request)
|
|
|
+ {
|
|
|
+ $post = $this->post->where('id', $request['id'])->first();
|
|
|
+ if(!$post){
|
|
|
+ return Response::create([
|
|
|
+ 'message' => '获取内容信息失败',
|
|
|
+ 'status_code' => 500
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
+ if($post->is_hide == 1){
|
|
|
+ $post->is_hide = 0;
|
|
|
+ }else{
|
|
|
+ $post->is_hide = 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ DB::beginTransaction();
|
|
|
+ try{
|
|
|
+ $post->save();
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
+ return Response::create();
|
|
|
+
|
|
|
+ }catch (QueryException $exception){
|
|
|
+ DB::rollBack();
|
|
|
+ Log::debug('隐藏内容:'.$request['id'].$exception->getMessage());
|
|
|
+ return Response::create([
|
|
|
+ 'message' => '操作失败,请重试',
|
|
|
+ 'error' => $exception->getMessage(),
|
|
|
+ 'status_code' => 500
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 日志列表
|
|
|
+ */
|
|
|
+ public function log($request)
|
|
|
+ {
|
|
|
+ $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
|
|
|
+ $where = [];
|
|
|
+ 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'])){
|
|
|
+ $time = explode('_', $request['created_at']);
|
|
|
+ $query->whereBetween('created_at', $time);
|
|
|
+ }
|
|
|
+ })
|
|
|
+ ->orderBy('id','desc')
|
|
|
+ ->paginate($perPage);
|
|
|
+ }
|
|
|
+
|
|
|
+ public function download($filePath, $type, $request)
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ set_time_limit(0);
|
|
|
+ if (!ini_get("auto_detect_line_endings")) {
|
|
|
+ ini_set("auto_detect_line_endings", '1');
|
|
|
+ }
|
|
|
+
|
|
|
+ // 文件路径
|
|
|
+ $writer = Writer::createFromPath(public_path($filePath), 'w+');
|
|
|
+
|
|
|
+ // 设置标题
|
|
|
+ if($type == 'post'){
|
|
|
+ $title = [
|
|
|
+ '内容', date('Y年m月d日')
|
|
|
+ ];
|
|
|
+ }else{
|
|
|
+ $title = [
|
|
|
+ '回收站内容', date('Y年m月d日')
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ $title = eval('return ' . iconv('utf-8', 'gbk//IGNORE', var_export($title, true) . ';'));
|
|
|
+ $writer->insertone($title);
|
|
|
+
|
|
|
+ // 内容
|
|
|
+ if($type == 'post') {
|
|
|
+ $header = [
|
|
|
+ '内容ID', '发布时间', '用户昵称', '城市', '内容标签', '内容前20个字',
|
|
|
+ '真实浏览量', '总浏览量', '真实点赞数', '总赞数', '真实分享数', '总分享数',
|
|
|
+ '真实收藏数', '总收藏数', '评论数'
|
|
|
+ ];
|
|
|
+ } else {
|
|
|
+ $header = [
|
|
|
+ '内容ID', '发布时间', '用户昵称', '内容标签', '内容前20个字',
|
|
|
+ '真实浏览量', '真实点赞数', '真实点赞数', '真实分享数', '真实收藏数', '评论数'
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ $header = eval('return ' . iconv('utf-8', 'gbk//IGNORE', var_export($header, true) . ';'));
|
|
|
+// $writer->setOutputBOM(Reader::BOM_UTF8);
|
|
|
+ $writer->insertone($header);
|
|
|
+
|
|
|
+ $where = [];
|
|
|
+ if(isset($request['content'])){
|
|
|
+ $where[] = ['content', 'like', "%{$request['content']}%"];
|
|
|
+ }
|
|
|
+ if(isset($request['is_suggest'])){
|
|
|
+ $where[] = ['is_suggest', $request['is_suggest']];
|
|
|
+ }
|
|
|
+ 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'])){
|
|
|
+ $sort = $request['sort'];
|
|
|
+ }
|
|
|
+ $post = $this->post;
|
|
|
+ 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'])){
|
|
|
+ $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'])){
|
|
|
+ $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'])){
|
|
|
+ $ids = [];
|
|
|
+ if (isset($request['category_ids'])) {
|
|
|
+ $categoryIds = explode('_', $request['category_ids']);
|
|
|
+ $ids = $this->categoryTopic->whereIn('category_id', $categoryIds)->pluck('topic_id')->toArray();
|
|
|
+ }
|
|
|
+ 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)');
|
|
|
+ } else {
|
|
|
+ $query = $query->orWhereRaw('FIND_IN_SET('.$id.',topic_ids)');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ ->orderBy($sort,'desc')
|
|
|
+ ->chunk(1, function ($posts) use ($writer, $type){
|
|
|
+ $data = [];
|
|
|
+ foreach ($posts as $post) {
|
|
|
+ if($type == 'post'){
|
|
|
+ $tmp = [
|
|
|
+ $post->id,
|
|
|
+ Carbon::parse($post->created_at)->toDateTimeString(),
|
|
|
+ $post->username,
|
|
|
+ $post->location,
|
|
|
+ implode(' ', $post->topic()->toArray()),
|
|
|
+ subtext($post->content, 20),
|
|
|
+ $post->data->pv_real,
|
|
|
+ $post->data->pv,
|
|
|
+ $post->data->praise_real_count,
|
|
|
+ $post->data->praise_count,
|
|
|
+ $post->data->share_real_count,
|
|
|
+ $post->data->share_count,
|
|
|
+ $post->data->collect_real_count,
|
|
|
+ $post->data->collect_count,
|
|
|
+ $post->data->comment_count
|
|
|
+ ];
|
|
|
+ }else{
|
|
|
+ $tmp = [
|
|
|
+ $post->id,
|
|
|
+ Carbon::parse($post->created_at)->toDateTimeString(),
|
|
|
+ $post->username,
|
|
|
+ Carbon::parse($post->created_at)->toDateTimeString(),
|
|
|
+ subtext($post->content, 20),
|
|
|
+ $post->data->pv_real,
|
|
|
+ $post->data->praise_real_count,
|
|
|
+ $post->data->share_real_count,
|
|
|
+ $post->data->collect_real_count,
|
|
|
+ $post->data->comment_count
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ foreach ($tmp as $key => $value) {
|
|
|
+ $tmp[$key] = iconv('utf-8', 'gbk//IGNORE', $value);
|
|
|
+ }
|
|
|
+
|
|
|
+ $data[] = $tmp;
|
|
|
+ }
|
|
|
+ $writer->insertAll($data);
|
|
|
+ });
|
|
|
+ Log::channel('download')->info('内容导出成功!');
|
|
|
+
|
|
|
+ } catch (CannotInsertRecord $e) {
|
|
|
+ $e->getRecord();
|
|
|
+ Log::channel('download')->info('内容导出失败!');
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|