PostRepositories.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: edz
  5. * Date: 2019-06-10
  6. * Time: 17:53
  7. */
  8. namespace App\Repositories;
  9. use App\Models\Behavior;
  10. use App\Models\Post;
  11. use App\Models\PostCollect;
  12. use App\Models\PostComment;
  13. use App\Models\PostData;
  14. use App\Models\PostDislike;
  15. use App\Models\PostImgs;
  16. use App\Models\PostLike;
  17. use App\Models\PostLog;
  18. use App\Models\PostShare;
  19. use App\Models\Topic;
  20. use App\Service\AliYunVodService;
  21. use App\Service\DetectionService;
  22. use App\Traits\CmsTrait;
  23. use App\Traits\PostTrait;
  24. use App\Traits\UserTrait;
  25. use Illuminate\Database\QueryException;
  26. use Illuminate\Support\Carbon;
  27. use Illuminate\Support\Facades\Log;
  28. use Illuminate\Support\Facades\Redis;
  29. use Illuminate\Support\Facades\DB;
  30. use Tymon\JWTAuth\Facades\JWTAuth;
  31. class PostRepositories
  32. {
  33. use UserTrait;
  34. use PostTrait;
  35. use CmsTrait;
  36. public function __construct(Post $post,
  37. PostData $postData,
  38. PostImgs $postImgs,
  39. PostComment $postComment,
  40. PostCollect $postCollect,
  41. PostShare $postShare,
  42. PostLog $postLog,
  43. DetectionService $detectionService,
  44. AliYunVodService $aliYunVodService,
  45. Topic $topic)
  46. {
  47. $this->post = $post;
  48. $this->postData = $postData;
  49. $this->postImgs = $postImgs;
  50. $this->postComment = $postComment;
  51. $this->postCollect = $postCollect;
  52. $this->postShare = $postShare;
  53. $this->postLog = $postLog;
  54. $this->detectionService = $detectionService;
  55. $this->topic = $topic;
  56. $this->aliYunVodService = $aliYunVodService;
  57. }
  58. /**
  59. * 发布内容
  60. */
  61. public function create($request)
  62. {
  63. //验证小号
  64. $userInfo = $this->getUserInfo();
  65. if (empty($userInfo)) {
  66. return jsonError('获取用户信息失败');
  67. }
  68. if(!$userInfo['sns_status']){
  69. return jsonError('您已被禁言');
  70. }
  71. $isValid = 0;
  72. if($userInfo['strength']){
  73. $isValid = 1;
  74. }
  75. // $oneHourTime = Carbon::now()->addHours(-1)->toDateTimeString();
  76. // $oneHourPostCount = $this->post->where('uid', $userInfo['uid'])->where('created_at', '>', $oneHourTime)->count();
  77. // if($oneHourPostCount > 5){
  78. // return jsonError('创作欲望太强啦,休息一下,看看其他用户的内容吧!');
  79. // }
  80. $detectionText = $request['title'] .','. $request['content'];
  81. $detectionTextResult = $this->detectionService->checkText($detectionText);
  82. if ($detectionTextResult['code']<0) {
  83. return jsonError('内容违规,请修正哦');
  84. }
  85. $topicIds = json_decode($request['topic_ids'], true);
  86. $topicCount = count($topicIds);
  87. if($topicCount == 0 || $topicCount > 5){
  88. return jsonError('所选话题必须1-5个');
  89. }
  90. //验证话题
  91. $hasTopicCount = $this->topic->whereIn('id', $topicIds)->count();
  92. if($topicCount != $hasTopicCount){
  93. Log::error('所选话题非法'.$request['topic_ids']);
  94. return jsonError('所选话题非法');
  95. }
  96. $imgs = [];
  97. if($request['type'] == 'image'){
  98. $imgs = json_decode($request['imgs'], true);
  99. $imgCount = count($imgs);
  100. if($imgCount == 0 || $imgCount > 9){
  101. return jsonError('所传图集必须1-9个');
  102. }
  103. }
  104. $allImg = array_merge($imgs, [$request['img']]);
  105. $detectionImageResult = $this->detectionService->checkImg($allImg);
  106. if ($detectionImageResult['code']<0) {
  107. return jsonError('图片违规,请修正哦');
  108. }
  109. $videoUrl = "";
  110. $videoId = "";
  111. if(isset($request['video']) && $request['video']){
  112. $videoId = $request['video'];
  113. for($i=0;$i<3;$i++){
  114. $videoUrl = $this->aliYunVodService->getPlayUrlByVideoId($request['video']);
  115. Log::debug('video-url:'.$videoUrl);
  116. if($videoUrl){
  117. break;
  118. }
  119. }
  120. if(empty($videoUrl)){
  121. return jsonError('发布失败,请重试');
  122. }
  123. }
  124. $data = [
  125. 'uid' => $userInfo['uid'],
  126. 'username' => $userInfo['username'],
  127. 'mobile' => $userInfo['mobile'],
  128. 'avatar' => $userInfo['avatar']??'',
  129. 'type' => $request['type'],
  130. 'img' => $request['img'],
  131. 'video' => $videoUrl,
  132. 'video_id' => $videoId,
  133. 'topic_ids' => implode(',', $topicIds),
  134. 'title' => isset($request['title'])? $request['title'] : '',
  135. 'content' => $request['content'],
  136. 'location' => isset($request['location'])? $request['location'] : '',
  137. 'is_suggest' => 0,
  138. 'is_hide' => 0
  139. ];
  140. $date = date('Y-m-d H:i:s');
  141. $fresh = (Carbon::now()->timestamp) - (Carbon::parse("2019-05-01 00:00:00")->timestamp);
  142. $score = $fresh / 86400;
  143. DB::beginTransaction();
  144. try{
  145. $post = $this->post->create($data);
  146. $postData = $this->postData->create([
  147. 'post_id' => $post->id,
  148. 'pv' => 0,
  149. 'pv_real' => 0,
  150. 'dislike_count' => 0,
  151. 'praise_count' => 0,
  152. 'praise_real_count' => 0,
  153. 'share_count' => 0,
  154. 'share_real_count' => 0,
  155. 'comment_count' => 0,
  156. 'collect_count' => 0,
  157. 'collect_real_count' => 0,
  158. 'available_bean' => $this->availableBean(),
  159. 'will_collect_bean' => rand(100, 200),
  160. 'collect_bean' => 0,
  161. 'weight' => $score
  162. ]);
  163. if($imgs){
  164. $imgData = [];
  165. foreach($imgs as $img){
  166. $imgData[] = [
  167. 'post_id' => $post->id,
  168. 'img' => $img,
  169. 'created_at' => $date,
  170. 'updated_at' => $date
  171. ];
  172. }
  173. $this->postImgs->insert($imgData);
  174. }
  175. DB::commit();
  176. Redis::zadd('post_trigger_type', $isValid, $post->id);
  177. foreach($topicIds as $id){
  178. Redis::zincrby('topic.user_uid'.$userInfo['uid'], 1, $id);
  179. }
  180. return jsonSuccess([
  181. 'post_id' => $post->id,
  182. 'h5url' => config('customer.share_post_h5url')."?post_id={$post->id}&invite_code={$userInfo['invite_code']}",
  183. 'bean' => $postData->available_bean,
  184. ]);
  185. }catch (QueryException $exception){
  186. DB::rollBack();
  187. Log::debug('发布内容失败:'.$exception->getMessage());
  188. return jsonError('发布内容失败,请重试');
  189. }
  190. }
  191. /**
  192. * 评论&回复
  193. */
  194. public function comment($request)
  195. {
  196. //验证小号
  197. $userInfo = $this->getUserInfo();
  198. if (empty($userInfo)) {
  199. return jsonError('获取用户信息失败');
  200. }
  201. if(!$userInfo['sns_status']){
  202. return jsonError('您已被禁言');
  203. }
  204. $oneHourTime = Carbon::now()->addHours(-1)->toDateTimeString();
  205. $oneHourCommentCount = $this->postComment->where('uid', $userInfo['uid'])->where('created_at', '>', $oneHourTime)->count();
  206. if($oneHourCommentCount > 59){
  207. return jsonError('回复了这么多,休息休息,喝口水吧!');
  208. }
  209. $detectionTextResult = $this->detectionService->checkText($request['content']);
  210. if ($detectionTextResult['code']<0) {
  211. return jsonError('内容违规,请修正哦');
  212. }
  213. $post = $this->post->find($request['post_id']);
  214. if(!$post){
  215. return jsonError('获取内容信息失败');
  216. }
  217. $data = [
  218. 'uid' => $userInfo['uid'],
  219. 'post_id' => $request['post_id'],
  220. 'parent_id' => 0,
  221. 'username' => $userInfo['username'],
  222. 'reply_uid' => 0,
  223. 'reply_username' => '',
  224. 'avatar' => $userInfo['avatar']??'',
  225. 'content' => $request['content'],
  226. 'is_delete' => 0,
  227. ];
  228. if(isset($request['parent_id']) && $request['parent_id'] != 0){
  229. $comment = $this->postComment->find($request['parent_id']);
  230. if(!$comment || $comment->post_id != $post->id){
  231. return jsonError('获取评论信息失败');
  232. }
  233. if($comment->parent_id){
  234. return jsonError('只能回复评论');
  235. }
  236. if($comment->is_delete){
  237. return jsonError('不能回复已删除评论');
  238. }
  239. $data['parent_id'] = $request['parent_id'];
  240. if(isset($request['reply_uid']) && isset($request['reply_username'])){
  241. $data['reply_uid'] = $request['reply_uid'];
  242. $data['reply_username'] = $request['reply_username'];
  243. }else{
  244. $data['reply_uid'] = 0;
  245. $data['reply_username'] = '';
  246. }
  247. }
  248. DB::beginTransaction();
  249. try{
  250. $comment = $this->postComment->create($data);
  251. DB::commit();
  252. return jsonSuccess(['id' => $comment->id], '评论成功');
  253. }catch (QueryException $exception){
  254. DB::rollBack();
  255. Log::debug('评论内容失败:'.$exception->getMessage());
  256. return jsonError('评论内容失败,请重试');
  257. }
  258. }
  259. /**
  260. * 内容列表
  261. */
  262. public function lists($request)
  263. {
  264. Log::debug('内容列表'.json_encode($request));
  265. $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
  266. return $this->post
  267. ->join('post_data', 'post_data.post_id', '=', 'post.id')
  268. ->select('post.*')
  269. ->where(function($query) use ($request){
  270. if(isset($request['keyword'])){
  271. $query->where('title', 'like', "%{$request['keyword']}%")
  272. ->orWhere('content', 'like', "%{$request['keyword']}%");
  273. }
  274. })
  275. ->where(function($query) use ($request){
  276. if(isset($request['topic_ids']) && $request['topic_ids']){
  277. $topicIds = json_decode($request['topic_ids'], true);
  278. foreach ($topicIds as $key=>$id) {
  279. if ($key==0) {
  280. $query->whereRaw('FIND_IN_SET('.$id.', post.topic_ids)');
  281. } else {
  282. $query->orWhereRaw('FIND_IN_SET('.$id.', post.topic_ids)');
  283. }
  284. }
  285. }
  286. })
  287. ->orderBy('weight','desc')
  288. ->paginate($perPage);
  289. }
  290. /**
  291. * 视频列表
  292. */
  293. public function video($request)
  294. {
  295. $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
  296. $where = [];
  297. $id = 0;
  298. if(isset($request['id'])){
  299. $id = $request['id'];
  300. }
  301. $where[] = ['type', 'video'];
  302. if(isset($request['type'])){
  303. if($request['type'] == 'hot'){
  304. $ids = Redis::get('hotVideoIds');
  305. if(!$ids){
  306. $ids = $this->hotVideoIds();
  307. if(!$ids){
  308. $ids = '';
  309. }
  310. }
  311. Log::debug('热门视频ids'.$ids);
  312. return $this->post
  313. ->join('post_data', 'post_data.post_id', '=', 'post.id')
  314. ->select('post.*', DB::raw("IF (post.id = {$id},1,0) as sort"))
  315. ->where($where)
  316. ->whereIn('post.id', explode(',', $ids))
  317. ->orderBy('sort', 'desc')
  318. ->orderByRaw(DB::raw("FIELD(post.id,{$ids})"))
  319. ->paginate($perPage);
  320. }elseif($request['type'] == 'one'){
  321. $where[] = ['post.id', $id];
  322. return $this->post
  323. ->join('post_data', 'post_data.post_id', '=', 'post.id')
  324. ->select('post.*')
  325. ->where($where)
  326. ->paginate($perPage);
  327. }
  328. }
  329. return $this->post
  330. ->join('post_data', 'post_data.post_id', '=', 'post.id')
  331. ->select('post.*', DB::raw("IF (post.id = {$id},1,0) as sort"))
  332. ->where($where)
  333. ->orderBy('sort', 'desc')
  334. ->orderBy('weight','desc')
  335. ->paginate($perPage);
  336. }
  337. /**
  338. * 个人中心内容列表
  339. */
  340. public function MyPost($request, $uid)
  341. {
  342. $type = $request['type'];
  343. $perPage = isset($request['per_page']) ? $request['per_page'] : 18;
  344. $where = [];
  345. if($type == 'create'){
  346. $where[] = ['post.uid', $uid];
  347. $post = $this->post;
  348. $order = 'post.id';
  349. }elseif($type == 'collect'){
  350. $post = $this->post->withTrashed()->join('post_collect', 'post_collect.post_id', '=', 'post.id');
  351. $where[] = ['post_collect.uid', $uid];
  352. $order = 'post_collect.id';
  353. }else{
  354. $post = $this->post->withTrashed()->join('post_share', 'post_share.post_id', '=', 'post.id');
  355. $where[] = ['post_share.uid', $uid];
  356. $order = 'post_share.updated_at';
  357. }
  358. return $post
  359. ->join('post_data', 'post_data.post_id', '=', 'post.id')
  360. ->select('post.*')
  361. ->where($where)
  362. ->orderBy($order,'desc')
  363. ->paginate($perPage);
  364. }
  365. /**
  366. * 内容详情
  367. */
  368. public function detail($id)
  369. {
  370. return $this->post
  371. ->join('post_data', 'post_data.post_id', '=', 'post.id')
  372. ->select('post.*')
  373. ->find($id);
  374. }
  375. /**
  376. * 内容是否存在
  377. */
  378. public function detailExists($id)
  379. {
  380. return $this->post->where('id', $id)->exists();
  381. }
  382. /**
  383. * 推荐内容列表
  384. */
  385. public function suggestPost($request)
  386. {
  387. $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
  388. return $this->post
  389. ->join('post_data', 'post_data.post_id', '=', 'post.id')
  390. ->select('post.*')
  391. ->orderBy('is_suggest','desc')
  392. ->orderBy('weight','desc')
  393. ->paginate($perPage);
  394. }
  395. /**
  396. * 话题内容
  397. */
  398. public function topicPost($request)
  399. {
  400. $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
  401. return $this->post
  402. ->join('post_data', 'post_data.post_id', '=', 'post.id')
  403. ->select('post.*')
  404. ->whereRaw('FIND_IN_SET(' . $request['id'] . ',post.topic_ids)')
  405. ->orderBy('id','desc')
  406. ->paginate($perPage);
  407. }
  408. /**
  409. * 评论列表
  410. */
  411. public function commentList($request)
  412. {
  413. $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
  414. return $this->postComment
  415. ->where('post_id', $request['post_id'])
  416. ->where('parent_id', 0)
  417. ->orderBy('id','desc')
  418. ->paginate($perPage);
  419. }
  420. /**
  421. * 回复列表
  422. */
  423. public function replyList($request)
  424. {
  425. $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
  426. return $this->postComment
  427. ->where('parent_id', $request['id'])
  428. ->orderBy('id','desc')
  429. ->paginate($perPage);
  430. }
  431. /**
  432. * 话题列表
  433. */
  434. public function topicList($request)
  435. {
  436. $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
  437. $where = [];
  438. if(isset($request['category_id']) && $request['category_id']){
  439. $topic = $this->topic->join('category_topic', 'category_topic.topic_id', '=', 'topic.id')->select('topic.*');
  440. $where[] = ['category_topic.category_id', $request['category_id']];
  441. }else{
  442. $topic = $this->topic;
  443. }
  444. if(isset($request['is_suggest']) && $request['is_suggest']){
  445. $where[] = ['topic.is_hot', $request['is_suggest']];
  446. }
  447. if(isset($request['name'])){
  448. $where[] = ['topic.name', 'like', "%{$request['name']}%"];
  449. }
  450. return $topic
  451. ->where($where)
  452. ->orderBy('id','desc')
  453. ->paginate($perPage);
  454. }
  455. /**
  456. * 更新帖子统计数量
  457. * @param $request
  458. * @return mixed
  459. */
  460. public function updatePostData($request)
  461. {
  462. $postId = isset($request['post_id'])?$request['post_id']:0;
  463. if(empty($postId)){
  464. Log::debug("非帖子类操作,不操作帖子统计数量".json_encode($request));
  465. return true;
  466. }
  467. $post = PostData::where('post_id', $postId)->first();
  468. if(!$post) return true;
  469. if (isset($request['behavior_flag']) && $request['behavior_flag'] == 'read') {
  470. $post->pv += 1;
  471. $post->pv_real += 1;
  472. Log::debug("帖子:".$postId."被阅读,pv +1");
  473. } elseif (isset($request['behavior_flag']) && $request['behavior_flag'] == 'unlike') {
  474. $post->dislike_count += 1;
  475. PostDislike::create(['uid'=>$request['target_id'],'post_id'=>$request['post_id']]);
  476. Log::debug("帖子:".$postId."被不喜欢,unlike +1");
  477. } elseif (isset($request['behavior_flag']) && $request['behavior_flag'] == 'like') {
  478. if($request['behavior_value']){
  479. $post->praise_count += 1;
  480. $post->praise_real_count += 1;
  481. PostLike::create(['uid'=>$request['target_id'],'post_id'=>$request['post_id']]);
  482. Log::debug("帖子:".$postId."被点赞,praise_count +1");
  483. }else{
  484. $post->praise_count -= 1;
  485. $post->praise_real_count -= 1;
  486. PostLike::where(['uid'=>$request['target_id'],'post_id'=>$request['post_id']])->delete();
  487. Log::debug("帖子:".$postId."被取消点赞,praise_count -1");
  488. }
  489. } elseif (isset($request['behavior_flag']) && $request['behavior_flag'] == 'forward') {
  490. $post->share_count += 1;
  491. $post->share_real_count += 1;
  492. $shareRow = PostShare::where(['uid'=>$request['target_id'],'post_id'=>$request['post_id']])->first();
  493. if($shareRow){
  494. PostShare::where(['uid'=>$request['target_id'],'post_id'=>$request['post_id']])->update(['uid'=>$request['target_id'],'post_id'=>$request['post_id']]);
  495. }else{
  496. PostShare::create(['uid'=>$request['target_id'],'post_id'=>$request['post_id']]);
  497. }
  498. Log::debug("帖子:".$postId."被分享,share_count +1");
  499. } elseif (isset($request['behavior_flag']) && $request['behavior_flag'] == 'comment') {
  500. $post->comment_count += 1;
  501. Log::debug("帖子:".$postId."被评论,comment_count +1");
  502. } elseif (isset($request['behavior_flag']) && $request['behavior_flag'] == 'collect') {
  503. if($request['behavior_value']) {
  504. $post->collect_count += 1;
  505. $post->collect_real_count += 1;
  506. PostCollect::create(['uid'=>$request['target_id'],'post_id'=>$request['post_id']]);
  507. Log::debug("帖子:".$postId."被收藏,collect_count +1");
  508. }else{
  509. $post->collect_count -= 1;
  510. $post->collect_real_count -= 1;
  511. PostCollect::where(['uid'=>$request['target_id'],'post_id'=>$request['post_id']])->delete();
  512. Log::debug("帖子:".$postId."被取消收藏,collect_count -1");
  513. }
  514. }
  515. $this->collectPostId($request['post_id']);
  516. return $post->save();
  517. }
  518. /**
  519. * 收集所有有操作的帖子,存入redis
  520. * 供后续计算帖子权重
  521. * @param $id
  522. */
  523. public function collectPostId($id)
  524. {
  525. $key = "community_calc_post_score";
  526. Redis::sadd($key,$id);
  527. Log::debug('存入帖子'.$id.'到权重列表');
  528. }
  529. /**
  530. * 话题详情
  531. */
  532. public function topicDetail($id)
  533. {
  534. return $this->topic
  535. ->find($id);
  536. }
  537. /**
  538. * 获取话题
  539. */
  540. public function getTopic($ids)
  541. {
  542. $topics = $this->topic
  543. ->whereIn('id', explode(',',$ids))
  544. ->orderByRaw(DB::raw("FIELD(id,{$ids})"))
  545. ->get();
  546. $data = [];
  547. foreach($topics as $topic){
  548. $data[] = [
  549. 'id' => $topic->id,
  550. 'name' => $topic->name,
  551. 'img' => $topic->img,
  552. 'follow_count' => getNumber($topic->follow->count() + $topic->base_count),
  553. ];
  554. }
  555. return $data;
  556. }
  557. /**
  558. * 获取内容视频组
  559. */
  560. public function getPostVideo($ids)
  561. {
  562. return $this->post
  563. ->select('id', 'img', 'uid', 'username', 'avatar')
  564. ->whereIn('id', explode(',',$ids))
  565. ->where('type', 'video')
  566. ->get();
  567. }
  568. //用户内容数,转发数,收藏数统计
  569. public function memberPostStatistics($uid){
  570. $postCount = $this->post->where('uid',$uid)->count();
  571. $postCollectCount = $this->postCollect->where('uid',$uid)->count();
  572. $postShareCount = $this->postShare->where('uid',$uid)->count();
  573. $data = ['post_count'=>$postCount,'share_count'=>$postShareCount,'collect_count'=>$postCollectCount];
  574. return jsonSuccess($data);
  575. }
  576. /**
  577. * 删除内容
  578. */
  579. public function delete($request)
  580. {
  581. //验证用户信息
  582. $userInfo = $this->getUserInfo();
  583. if (empty($userInfo)) {
  584. return jsonError('获取用户信息失败');
  585. }
  586. $post = $this->post->find($request['id']);
  587. if(!$post){
  588. return jsonError('获取内容信息失败');
  589. }
  590. if($post->uid != $userInfo['uid']){
  591. return jsonError('只能删除自己发布的内容');
  592. }
  593. $logData = [
  594. 'uid' => $userInfo['uid'],
  595. 'operator_type' => 'user',
  596. 'post_id' => $request['id'],
  597. 'username' => $userInfo['username'],
  598. 'log_type' => 'delete',
  599. 'content' => json_encode(['delete' => $request['id']]),
  600. ];
  601. DB::beginTransaction();
  602. try{
  603. $post->delete();
  604. $this->postLog->create($logData);
  605. DB::commit();
  606. Redis::SADD('delete_post_ids', $request['id']);
  607. Log::debug('删除内容失败:'.$request['id']);
  608. return jsonSuccess('删除内容成功');
  609. }catch (QueryException $exception){
  610. DB::rollBack();
  611. Log::debug('删除内容失败:'.$request['id'].$exception->getMessage());
  612. return jsonError('删除内容失败,请重试');
  613. }
  614. }
  615. /**
  616. * 内容评论数
  617. */
  618. public function getCommentCount($id)
  619. {
  620. return $this->postComment->where('post_id', $id)->count();
  621. }
  622. }