PostRepository.php 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2019/6/5
  6. * Time: 16:03
  7. */
  8. namespace App\Repositories\Post;
  9. use App\Models\Behavior;
  10. use App\Models\CategoryTopic;
  11. use App\Models\Post;
  12. use App\Models\PostComment;
  13. use App\Models\PostData;
  14. use App\Models\PostImgs;
  15. use App\Models\PostLog;
  16. use App\Models\PostStatistics;
  17. use App\Models\PostStore;
  18. use App\Models\PostStoreImgs;
  19. use App\Models\Topic;
  20. use App\Service\RabbitMqUtil;
  21. use App\Traits\PostTrait;
  22. use App\Traits\UserTrait;
  23. use Illuminate\Database\QueryException;
  24. use Dingo\Api\Http\Response;
  25. use Illuminate\Support\Carbon;
  26. use Illuminate\Support\Facades\DB;
  27. use Illuminate\Support\Facades\Log;
  28. use Illuminate\Support\Facades\Redis;
  29. use Symfony\Component\HttpKernel\Exception\HttpException;
  30. use Tymon\JWTAuth\Facades\JWTAuth;
  31. use League\Csv\Writer;
  32. use League\Csv\CannotInsertRecord;
  33. class PostRepository
  34. {
  35. use PostTrait;
  36. use UserTrait;
  37. public function __construct(Post $post,
  38. PostData $postData,
  39. PostComment $postComment,
  40. PostImgs $postImgs,
  41. PostLog $postLog,
  42. RabbitMqUtil $rabbitMqUtil,
  43. Behavior $behavior,
  44. CategoryTopic $categoryTopic,
  45. PostStatistics $postStatistics,
  46. PostStore $postStore,
  47. PostStoreImgs $postStoreImgs,
  48. Topic $topic)
  49. {
  50. $this->post = $post;
  51. $this->postData = $postData;
  52. $this->postComment = $postComment;
  53. $this->postImgs = $postImgs;
  54. $this->postLog = $postLog;
  55. $this->rabbitMqUtil = $rabbitMqUtil;
  56. $this->behavior = $behavior;
  57. $this->categoryTopic = $categoryTopic;
  58. $this->topic = $topic;
  59. $this->postStatistics = $postStatistics;
  60. $this->postStore = $postStore;
  61. $this->postStoreImgs = $postStoreImgs;
  62. }
  63. /**
  64. * 发布内容
  65. */
  66. public function create($request)
  67. {
  68. //富文本标题
  69. if ($request['type'] == 'html' && (!isset($request['title']) || !$request['title'])) {
  70. return Response::create([
  71. 'message' => '当类型是富文本时,标题不能为空',
  72. 'status_code' => 500
  73. ]);
  74. }
  75. //验证小号
  76. $userInfo = $this->getUserInfo($request['uid']);
  77. Log::debug('发布内容小号信息:' . json_encode($userInfo));
  78. if (!$userInfo || $userInfo['type'] != 1) {
  79. return Response::create([
  80. 'message' => '所选小号信息有误',
  81. 'status_code' => 500
  82. ]);
  83. }
  84. if (isset($request['is_point']) && $request['is_point']) {
  85. $res = $this->uploadImage($request['img']);
  86. if ($res && isset($res['data']) && isset($res['data']['url'])) {
  87. $request['img'] = config('customer.chxq_oss_url') . $res['data']['url'];
  88. Log::debug('内容上传图片成功结果' . json_encode($res));
  89. } else {
  90. Log::debug('内容上传图片失败结果' . json_encode($res));
  91. return Response::create([
  92. 'message' => '图片格式有误,请重试',
  93. 'status_code' => 500
  94. ]);
  95. }
  96. }
  97. //验证话题
  98. $topicIdsArray = $this->topic->whereIn('id', explode(',', $request['topic_ids']))->pluck('id')->toArray();
  99. $topicCount = count($topicIdsArray);
  100. if ($topicCount == 0 || $topicCount > 5) {
  101. return Response::create([
  102. 'message' => '所选话题必须1-5个',
  103. 'status_code' => 500
  104. ]);
  105. }
  106. $topicIds = implode(',', $topicIdsArray);
  107. //验证内容字数
  108. if ($request['type'] != 'html') {
  109. $html = strip_tags($request['content']);
  110. if (mb_strlen($html, 'UTF8') > 1000) {
  111. return Response::create([
  112. 'message' => '所传内容不能超过1000字',
  113. 'status_code' => 500
  114. ]);
  115. }
  116. }
  117. $fresh = (Carbon::now()->timestamp) - (Carbon::parse("2019-05-01 00:00:00")->timestamp);
  118. $score = $fresh / 43200;
  119. $data = [
  120. 'uid' => $userInfo['uid'],
  121. 'username' => $userInfo['username'],
  122. 'mobile' => $userInfo['mobile'],
  123. 'avatar' => $userInfo['avatar'] ?? '',
  124. 'type' => $request['type'],
  125. 'img' => $request['img'],
  126. 'video' => $request['video'] ?? '',
  127. 'video_id' => $request['video_id'] ?? '',
  128. 'topic_ids' => $topicIds,
  129. 'title' => $request['title'] ?? '',
  130. 'content' => $request['content'],
  131. 'location' => $request['location'] ?? '',
  132. 'is_suggest' => $request['is_suggest'],
  133. 'is_hide' => 0,
  134. 'weight' => $score
  135. ];
  136. $date = date('Y-m-d H:i:s');
  137. DB::beginTransaction();
  138. try {
  139. $post = $this->post->create($data);
  140. $postData = $this->postData->create([
  141. 'post_id' => $post->id,
  142. 'pv' => 0,
  143. 'pv_real' => 0,
  144. 'dislike_count' => 0,
  145. 'praise_count' => 0,
  146. 'praise_real_count' => 0,
  147. 'share_count' => 0,
  148. 'share_real_count' => 0,
  149. 'comment_count' => 0,
  150. 'collect_count' => 0,
  151. 'collect_real_count' => 0,
  152. 'available_bean' => $this->availableBean(),
  153. 'will_collect_bean' => rand(100, 200),
  154. 'collect_bean' => 0
  155. ]);
  156. $imgs = [];
  157. if (!empty($request['imgs']) && $request['type'] == 'image') {
  158. $imgData = [];
  159. foreach ($request['imgs'] as $img) {
  160. $imgs[] = $img;
  161. $imgData[] = [
  162. 'post_id' => $post->id,
  163. 'img' => $img,
  164. 'created_at' => $date,
  165. 'updated_at' => $date
  166. ];
  167. }
  168. $this->postImgs->insert($imgData);
  169. }
  170. if (isset($request['store_id']) && $request['store_id']) {
  171. $this->postStore->where('id', $request['store_id'])->update(['is_used' => 1]);
  172. }
  173. DB::commit();
  174. Redis::zadd('post_trigger_type', 0, $post->id);
  175. foreach ($topicIdsArray as $id) {
  176. Redis::zincrby('topic.user_uid' . $request['uid'], 1, $id);
  177. Redis::zincrby('topic.just_use_count', 1, $id);
  178. }
  179. $virus = $this->behavior->where('behavior_identification', 'publish')->first();
  180. if ($virus) {
  181. if ($post->title) {
  182. $desc = $post->title;
  183. } else {
  184. $desc = subtext(strip_tags($post->content), 20);
  185. }
  186. $this->rabbitMqUtil->push('virus_add', [
  187. 'behavior_id' => $virus->virus_behavior_id,
  188. 'behavior_flag' => 'publish',
  189. 'post_id' => $post->id,
  190. 'post_type' => $post->type,
  191. 'post_desc' => $desc,
  192. 'post_cover' => $post->img,
  193. 'target_id' => $post->uid,
  194. 'action_id' => $post->id,
  195. ]);
  196. }
  197. Redis::HSET('post_info_' . $post->id,
  198. 'id', $post->id,
  199. 'uid', $post->uid,
  200. 'type', $post->type,
  201. 'img', $post->img,
  202. 'imgs', json_encode($imgs),
  203. 'video', $post->video,
  204. 'topic_ids', $post->topic_ids,
  205. 'title', $post->title,
  206. 'content', $post->content,
  207. 'location', $post->location,
  208. 'pv', $postData->pv,
  209. 'dislike_count', $postData->dislike_count,
  210. 'praise_count', $postData->praise_count,
  211. 'share_count', $postData->share_count,
  212. 'comment_count', $postData->comment_count,
  213. 'collect_count', $postData->collect_count,
  214. 'available_bean', $postData->available_bean,
  215. 'will_collect_bean', $postData->will_collect_bean,
  216. 'create_bean', $postData->create_bean,
  217. 'collect_bean', $postData->collect_bean,
  218. 'created_at', $post->created_at);
  219. return Response::create();
  220. } catch (QueryException $exception) {
  221. DB::rollBack();
  222. Log::debug('发布内容:' . $exception->getMessage());
  223. return Response::create([
  224. 'message' => '发布失败,请重试',
  225. 'error' => $exception->getMessage(),
  226. 'status_code' => 500
  227. ]);
  228. }
  229. }
  230. /**
  231. * 增加数据
  232. */
  233. public function addData($request)
  234. {
  235. $token = JWTAuth::decode(JWTAuth::getToken());
  236. if (!$token || $token['type'] != 1) {
  237. return Response::create([
  238. 'message' => '获取登陆信息失败',
  239. 'status_code' => 500
  240. ]);
  241. }
  242. $uid = $token['user']->id;
  243. $username = $token['user']->username;
  244. //验证小号数量
  245. $number = max([
  246. $request['add_pv'],
  247. $request['add_praise_count'],
  248. $request['add_collect_count'],
  249. $request['add_share_count']
  250. ]);
  251. $members = $this->getSystemMember($number);
  252. if (!$members || $members['status_code'] != 200) {
  253. return Response::create([
  254. 'message' => $members['message'],
  255. 'status_code' => 500
  256. ]);
  257. }
  258. $post = $this->post->find($request['post_id']);
  259. $postData = $this->postData->where('post_id', $request['post_id'])->first();
  260. if (!$postData || !$post) {
  261. return Response::create([
  262. 'message' => '获取内容失败',
  263. 'status_code' => 500
  264. ]);
  265. }
  266. if ($request['add_pv'] == 0 && $request['add_praise_count'] == 0 && $request['add_collect_count'] == 0 && $request['add_share_count'] == 0) {
  267. return Response::create([
  268. 'message' => '增加数据不能同时为0',
  269. 'status_code' => 500
  270. ]);
  271. }
  272. $content = [
  273. 'add_pv' => 0,
  274. 'add_praise_count' => 0,
  275. 'add_collect_count' => 0,
  276. 'add_share_count' => 0,
  277. ];
  278. if ($request['add_pv']) {
  279. $postData->pv += $request['add_pv'];
  280. $content['add_pv'] = $request['add_pv'];
  281. }
  282. if ($request['add_praise_count']) {
  283. $postData->praise_count += $request['add_praise_count'];
  284. $content['add_praise_count'] = $request['add_praise_count'];
  285. }
  286. if ($request['add_collect_count']) {
  287. $postData->collect_count += $request['add_collect_count'];
  288. $content['add_collect_count'] = $request['add_collect_count'];
  289. }
  290. if ($request['add_share_count']) {
  291. $postData->share_count += $request['add_share_count'];
  292. $content['add_share_count'] = $request['add_share_count'];
  293. }
  294. DB::beginTransaction();
  295. try {
  296. $postData->save();
  297. $this->postLog->create([
  298. 'post_id' => $request['post_id'],
  299. 'uid' => $uid,
  300. 'username' => $username,
  301. 'log_type' => 'add_data',
  302. 'content' => json_encode($content)
  303. ]);
  304. DB::commit();
  305. $virus = $this->behavior
  306. ->whereIn('behavior_identification', ['read', 'forward', 'like', 'collect'])
  307. ->pluck('virus_behavior_id', 'behavior_identification');
  308. if ($post->title) {
  309. $desc = $post->title;
  310. } else {
  311. $desc = subtext(strip_tags($post->content), 20);
  312. }
  313. $data = [
  314. 'behavior_value' => 1,
  315. 'post_id' => $post->id,
  316. 'post_type' => $post->type,
  317. 'post_author_uid' => $post->uid,
  318. 'post_desc' => $desc,
  319. 'post_cover' => $post->img,
  320. 'action_id' => $post->id,
  321. ];
  322. foreach ($members['data'] as $key => $member) {
  323. if (isset($virus['read']) && $request['add_pv'] > $key) {
  324. $newData = array_merge($data, [
  325. 'behavior_id' => $virus['read'],
  326. 'behavior_flag' => 'read',
  327. 'target_id' => $member['uid'],
  328. ]);
  329. $this->rabbitMqUtil->push('virus_add', $newData);
  330. }
  331. if (isset($virus['like']) && $request['add_praise_count'] > $key) {
  332. $newData = array_merge($data, [
  333. 'behavior_id' => $virus['like'],
  334. 'behavior_flag' => 'like',
  335. 'target_id' => $member['uid'],
  336. ]);
  337. $this->rabbitMqUtil->push('virus_add', $newData);
  338. }
  339. if (isset($virus['collect']) && $request['add_collect_count'] > $key) {
  340. $newData = array_merge($data, [
  341. 'behavior_id' => $virus['collect'],
  342. 'behavior_flag' => 'collect',
  343. 'target_id' => $member['uid'],
  344. ]);
  345. $this->rabbitMqUtil->push('virus_add', $newData);
  346. }
  347. if (isset($virus['forward']) && $request['add_share_count'] > $key) {
  348. $newData = array_merge($data, [
  349. 'behavior_id' => $virus['forward'],
  350. 'behavior_flag' => 'forward',
  351. 'target_id' => $member['uid'],
  352. ]);
  353. $this->rabbitMqUtil->push('virus_add', $newData);
  354. }
  355. }
  356. return Response::create();
  357. } catch (QueryException $exception) {
  358. DB::rollBack();
  359. Log::debug('内容增加数据:' . $request['post_id'] . $exception->getMessage());
  360. return Response::create([
  361. 'message' => '增加数据失败,请重试',
  362. 'error' => $exception->getMessage(),
  363. 'status_code' => 500
  364. ]);
  365. }
  366. }
  367. /**
  368. * 评论&回复
  369. */
  370. public function comment($request)
  371. {
  372. //验证小号
  373. $userInfo = $this->getUserInfo($request['uid']);
  374. Log::debug('评论&回复小号' . json_encode($userInfo));
  375. if (!$userInfo || $userInfo['type'] != 1) {
  376. return Response::create([
  377. 'message' => '所选小号信息有误',
  378. 'status_code' => 500
  379. ]);
  380. }
  381. $post = $this->post->find($request['post_id']);
  382. if (!$post) {
  383. return Response::create([
  384. 'message' => '获取内容失败',
  385. 'status_code' => 500
  386. ]);
  387. }
  388. $data = [
  389. 'uid' => $request['uid'],
  390. 'post_id' => $request['post_id'],
  391. 'parent_id' => 0,
  392. 'username' => $userInfo['username'],
  393. 'reply_uid' => 0,
  394. 'reply_username' => '',
  395. 'avatar' => $userInfo['avatar'] ?? '',
  396. 'content' => $request['content'],
  397. 'is_delete' => 0,
  398. ];
  399. $parentCommentContent = '';
  400. $parentCommentUid = 0;
  401. $parentCommentTime = '';
  402. if (isset($request['parent_id']) && $request['parent_id'] != 0) {
  403. $comment = $this->postComment->find($request['parent_id']);
  404. if (!$comment) {
  405. return Response::create([
  406. 'message' => '获取评论信息失败',
  407. 'status_code' => 500
  408. ]);
  409. }
  410. if ($comment->parent_id) {
  411. return Response::create([
  412. 'message' => '只能回复评论',
  413. 'status_code' => 500
  414. ]);
  415. }
  416. $data['parent_id'] = $request['parent_id'];
  417. $data['reply_uid'] = $comment->uid;
  418. $data['reply_username'] = $comment->username;
  419. $parentCommentContent = $comment->content;
  420. $parentCommentUid = $comment->uid;
  421. $parentCommentTime = Carbon::parse($comment->created_at)->toDateTimeString();
  422. }
  423. DB::beginTransaction();
  424. try {
  425. $newComment = $this->postComment->create($data);
  426. if ($newComment->parent_id) {
  427. $this->postComment->where('id', $newComment->parent_id)->increment('reply_count');
  428. }
  429. DB::commit();
  430. if ($newComment->parent_id) {
  431. Redis::DEL('post_new_reply_' . $newComment->parent_id);
  432. } else {
  433. Redis::DEL('post_new_comment_' . $newComment->post_id);
  434. }
  435. $virus = $this->behavior->where('behavior_identification', 'comment')->first();
  436. if ($virus) {
  437. if ($post->title) {
  438. $desc = $post->title;
  439. } else {
  440. $desc = subtext(strip_tags($post->content), 20);
  441. }
  442. $this->rabbitMqUtil->push('virus_add', [
  443. 'behavior_id' => $virus->virus_behavior_id,
  444. 'behavior_flag' => 'comment',
  445. 'post_id' => $post->id,
  446. 'post_type' => $post->type,
  447. 'post_author_uid' => $post->uid,
  448. 'post_desc' => $desc,
  449. 'post_cover' => $post->img,
  450. 'comment_id' => $newComment->id,
  451. 'comment_content' => $newComment->content,
  452. 'parent_comment_id' => $newComment->parent_id,
  453. 'parent_comment_content' => $parentCommentContent,
  454. 'parent_comment_uid' => $parentCommentUid,
  455. 'parent_comment_time' => $parentCommentTime,
  456. 'reply_uid' => $newComment->reply_uid,
  457. 'reply_username' => $newComment->reply_username,
  458. 'target_id' => $newComment->uid,
  459. 'action_id' => $newComment->id,
  460. ]);
  461. }
  462. return Response::create();
  463. } catch (QueryException $exception) {
  464. DB::rollBack();
  465. Log::debug('评论内容:' . $request['post_id'] . $exception->getMessage());
  466. return Response::create([
  467. 'message' => '评论失败,请重试',
  468. 'error' => $exception->getMessage(),
  469. 'status_code' => 500
  470. ]);
  471. }
  472. }
  473. /**
  474. * 内容列表
  475. */
  476. public function lists($request)
  477. {
  478. $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
  479. $where = [];
  480. if (isset($request['is_suggest'])) {
  481. $where[] = ['is_suggest', $request['is_suggest']];
  482. }
  483. if (isset($request['type'])) {
  484. $where[] = ['type', $request['type']];
  485. }
  486. if (isset($request['uid'])) {
  487. $where[] = ['uid', $request['uid']];
  488. }
  489. $sort = 'post.id';
  490. if (isset($request['sort']) && in_array($request['sort'], ['praise_count', 'share_count', 'pv', 'comment_count', 'create_bean'])) {
  491. $sort = $request['sort'];
  492. }
  493. $post = $this->post;
  494. if (isset($request['waste']) && $request['waste'] == 1) {
  495. $post = $post->onlyTrashed();
  496. }
  497. return $post
  498. ->join('post_data', 'post_data.post_id', '=', 'post.id')
  499. ->with('data')
  500. ->select('post.*')
  501. ->where($where)
  502. ->where(function ($query) use ($request) {
  503. if (isset($request['keyword'])) {
  504. $query->where('uid', '=', $request['keyword'])
  505. ->orWhere('username', 'like', "%{$request['keyword']}%")
  506. ->orWhere('mobile', 'like', "%{$request['keyword']}%");
  507. }
  508. })
  509. ->where(function ($query) use ($request) {
  510. if (isset($request['content'])) {
  511. $query->where('title', 'like', "%{$request['content']}%")
  512. ->orWhere('content', 'like', "%{$request['content']}%");
  513. }
  514. })
  515. ->where(function ($query) use ($request) {
  516. if (isset($request['created_at'])) {
  517. $time = explode('_', $request['created_at']);
  518. $query->whereBetween('post.created_at', $time);
  519. }
  520. })
  521. ->where(function ($query) use ($request) {
  522. if (isset($request['category_ids']) || isset($request['topic_ids'])) {
  523. $ids = [];
  524. if (isset($request['category_ids'])) {
  525. $categoryIds = explode('_', $request['category_ids']);
  526. $ids = $this->categoryTopic->whereIn('category_id', $categoryIds)->pluck('topic_id')->toArray();
  527. }
  528. if (isset($request['topic_ids'])) {
  529. $ids = array_merge($ids, explode('_', $request['topic_ids']));
  530. }
  531. foreach ($ids as $key => $id) {
  532. if ($key == 0) {
  533. $query = $query->whereRaw('FIND_IN_SET(' . $id . ',topic_ids)');
  534. } else {
  535. $query = $query->orWhereRaw('FIND_IN_SET(' . $id . ',topic_ids)');
  536. }
  537. }
  538. }
  539. })
  540. ->orderBy($sort, 'desc')
  541. ->paginate($perPage);
  542. }
  543. /**
  544. * 内容详情
  545. */
  546. public function detail($request)
  547. {
  548. return $this->post->withTrashed()->find($request['id']);
  549. }
  550. /**
  551. * 内容类型
  552. */
  553. public function getType($request)
  554. {
  555. $type = $this->post->where('id', $request['id'])->value('type');
  556. return Response::create([
  557. 'message' => '成功',
  558. 'status_code' => 200,
  559. 'data' => $type
  560. ]);
  561. }
  562. /**
  563. * 评论列表
  564. */
  565. public function commentList($request)
  566. {
  567. $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
  568. $where = [];
  569. if (isset($request['post_id'])) {
  570. $where[] = ['post_id', $request['post_id']];
  571. }
  572. if (isset($request['uid'])) {
  573. $where[] = ['uid', $request['uid']];
  574. }
  575. return $this->postComment
  576. ->where($where)
  577. ->orderBy('id', 'desc')
  578. ->paginate($perPage);
  579. }
  580. /**
  581. * 推荐内容
  582. */
  583. public function suggest($request)
  584. {
  585. $token = JWTAuth::decode(JWTAuth::getToken());
  586. if ($token['type'] != 1) {
  587. return Response::create([
  588. 'message' => '只有运营才能修改推荐',
  589. 'status_code' => 500
  590. ]);
  591. }
  592. $post = $this->post->where('id', $request['id'])->first();
  593. if (!$post) {
  594. return Response::create([
  595. 'message' => '获取内容信息失败',
  596. 'status_code' => 500
  597. ]);
  598. }
  599. if ($post->is_suggest == 1) {
  600. $post->is_suggest = 0;
  601. $logData = [
  602. 'uid' => $token['user']->id,
  603. 'operator_type' => 'admin',
  604. 'post_id' => $request['id'],
  605. 'username' => $token['user']->username,
  606. 'log_type' => 'cancel_suggest',
  607. 'content' => json_encode(['cancel_suggest' => $request['id']]),
  608. ];
  609. } else {
  610. $post->is_suggest = 1;
  611. $logData = [
  612. 'uid' => $token['user']->id,
  613. 'operator_type' => 'admin',
  614. 'post_id' => $request['id'],
  615. 'username' => $token['user']->username,
  616. 'log_type' => 'suggest',
  617. 'content' => json_encode(['suggest' => $request['id']]),
  618. ];
  619. }
  620. $date = Carbon::now()->toDateTimeString();
  621. DB::beginTransaction();
  622. try {
  623. $post->save();
  624. $this->postLog->create($logData);
  625. DB::commit();
  626. //内容被设为推荐时,发送推送消息
  627. if($post->is_suggest==1){
  628. $title = $post['title'] ? $post['title'] : subtext($post['content'], 18);
  629. $push['uid'] = $post->uid;
  630. $push['title'] = '【由你内容】推荐通知';
  631. $push['text'] = '你的内容《'.$title.'》被小编推荐全平台优先展示喽,获得推荐位后你的内容会被更多人看到。记得多来和大家互动赚取更多U米~';
  632. Redis::LPUSH('send_push_msg_queue',json_encode($push));
  633. $rabbitmq = new RabbitMqUtil();
  634. $rabbitmq->push('add_message_one', [
  635. 'uid' => $post->uid,
  636. 'message_rule_id' => 0,
  637. 'message_type' => 1,
  638. 'message_show_type' => 'system_common',
  639. 'param' => [
  640. 'title' => $push['title'],
  641. 'content' => $push['text'],
  642. 'cover' => '',
  643. 'activity_url' => 0,
  644. 'activity_time' => '',
  645. ],
  646. 'is_read' => 0,
  647. 'created_at' => $date,
  648. 'updated_at' => $date,
  649. ]);
  650. }
  651. return Response::create();
  652. } catch (QueryException $exception) {
  653. DB::rollBack();
  654. Log::debug('推荐内容:' . $request['id'] . $exception->getMessage());
  655. return Response::create([
  656. 'message' => '操作失败,请重试',
  657. 'error' => $exception->getMessage(),
  658. 'status_code' => 500
  659. ]);
  660. }
  661. }
  662. /**
  663. * 删除内容
  664. */
  665. public function delete($request)
  666. {
  667. $token = JWTAuth::decode(JWTAuth::getToken());
  668. if ($token['type'] != 1) {
  669. return Response::create([
  670. 'message' => '只有运营才能删除内容',
  671. 'status_code' => 500
  672. ]);
  673. }
  674. $post = $this->post->where('id', $request['id'])->first();
  675. if (!$post) {
  676. return Response::create([
  677. 'message' => '获取内容信息失败',
  678. 'status_code' => 500
  679. ]);
  680. }
  681. $uid = $post->uid;
  682. $title = $post->title;
  683. if (!$title) {
  684. $title = subtext(strip_tags($post->content), 20);
  685. }
  686. $content = "经核实您的内容“{$title}”涉及违规,现已被删除,有任何问题请联系由你管理员";
  687. $logData = [
  688. 'uid' => $token['user']->id,
  689. 'operator_type' => 'admin',
  690. 'post_id' => $request['id'],
  691. 'username' => $token['user']->username,
  692. 'log_type' => 'delete',
  693. 'content' => json_encode(['delete' => $request['id']]),
  694. ];
  695. $date = Carbon::now()->toDateTimeString();
  696. DB::beginTransaction();
  697. try {
  698. $post->delete();
  699. $this->postLog->create($logData);
  700. DB::commit();
  701. Redis::SADD('delete_post_ids', $request['id']);
  702. $this->rabbitMqUtil->push('add_message_one', [
  703. 'uid' => $uid,
  704. 'message_rule_id' => 0,
  705. 'message_type' => 1,
  706. 'message_show_type' => 'system_common',
  707. 'param' => [
  708. 'title' => '内容删除',
  709. 'content' => $content,
  710. 'cover' => '',
  711. 'activity_url' => 0,
  712. 'activity_time' => '',
  713. ],
  714. 'is_read' => 0,
  715. 'created_at' => $date,
  716. 'updated_at' => $date,
  717. ]);
  718. return Response::create();
  719. } catch (QueryException $exception) {
  720. DB::rollBack();
  721. Log::debug('删除内容:' . $request['id'] . $exception->getMessage());
  722. return Response::create([
  723. 'message' => '操作失败,请重试',
  724. 'error' => $exception->getMessage(),
  725. 'status_code' => 500
  726. ]);
  727. }
  728. }
  729. /**
  730. * 复原内容
  731. */
  732. public function restore($request)
  733. {
  734. $post = $this->post->withTrashed()->where('id', $request['id'])->first();
  735. if (!$post) {
  736. return Response::create([
  737. 'message' => '获取内容信息失败',
  738. 'status_code' => 500
  739. ]);
  740. }
  741. DB::beginTransaction();
  742. try {
  743. $post->restore();
  744. DB::commit();
  745. Redis::SREM('delete_post_ids', $request['id']);
  746. return Response::create();
  747. } catch (QueryException $exception) {
  748. DB::rollBack();
  749. Log::debug('复原内容:' . $request['id'] . $exception->getMessage());
  750. return Response::create([
  751. 'message' => '操作失败,请重试',
  752. 'error' => $exception->getMessage(),
  753. 'status_code' => 500
  754. ]);
  755. }
  756. }
  757. /**
  758. * 删除评论
  759. */
  760. public function commentDelete($request)
  761. {
  762. $comment = $this->postComment->find($request['id']);
  763. if (!$comment) {
  764. return Response::create([
  765. 'message' => '获取评论信息失败',
  766. 'status_code' => 500
  767. ]);
  768. }
  769. if ($comment->is_delete == 1) {
  770. return Response::create([
  771. 'message' => '该评论已经删除',
  772. 'status_code' => 500
  773. ]);
  774. }
  775. DB::beginTransaction();
  776. try {
  777. $comment->is_delete = 1;
  778. $comment->save();
  779. DB::commit();
  780. Redis::SADD('delete_post_comment_ids', $comment->id);
  781. if (!$comment->parent_id) {
  782. Redis::DEL('post_new_comment_' . $comment->post_id);
  783. } else {
  784. Redis::DEL('post_new_reply_' . $comment->id);
  785. }
  786. return Response::create();
  787. } catch (QueryException $exception) {
  788. DB::rollBack();
  789. Log::debug('删除评论:' . $request['id'] . $exception->getMessage());
  790. return Response::create([
  791. 'message' => '操作失败,请重试',
  792. 'error' => $exception->getMessage(),
  793. 'status_code' => 500
  794. ]);
  795. }
  796. }
  797. /**
  798. * 隐藏内容
  799. */
  800. public function hide($request)
  801. {
  802. $post = $this->post->where('id', $request['id'])->first();
  803. if (!$post) {
  804. return Response::create([
  805. 'message' => '获取内容信息失败',
  806. 'status_code' => 500
  807. ]);
  808. }
  809. if ($post->is_hide == 1) {
  810. $post->is_hide = 0;
  811. } else {
  812. $post->is_hide = 1;
  813. }
  814. DB::beginTransaction();
  815. try {
  816. $post->save();
  817. DB::commit();
  818. return Response::create();
  819. } catch (QueryException $exception) {
  820. DB::rollBack();
  821. Log::debug('隐藏内容:' . $request['id'] . $exception->getMessage());
  822. return Response::create([
  823. 'message' => '操作失败,请重试',
  824. 'error' => $exception->getMessage(),
  825. 'status_code' => 500
  826. ]);
  827. }
  828. }
  829. /**
  830. * 日志列表
  831. */
  832. public function log($request)
  833. {
  834. $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
  835. $where = [];
  836. if (isset($request['log_type'])) {
  837. $where[] = ['log_type', $request['log_type']];
  838. }
  839. return $this->postLog
  840. ->where($where)
  841. ->where(function ($query) use ($request) {
  842. if (isset($request['created_at'])) {
  843. $time = explode('_', $request['created_at']);
  844. $query->whereBetween('created_at', $time);
  845. }
  846. })
  847. ->orderBy('id', 'desc')
  848. ->paginate($perPage);
  849. }
  850. public function download($filePath, $type, $request)
  851. {
  852. try {
  853. set_time_limit(0);
  854. if (!ini_get("auto_detect_line_endings")) {
  855. ini_set("auto_detect_line_endings", '1');
  856. }
  857. // 文件路径
  858. $writer = Writer::createFromPath(public_path($filePath), 'w+');
  859. // 设置标题
  860. if ($type == 'post') {
  861. $title = [
  862. '内容', date('Y年m月d日')
  863. ];
  864. } else {
  865. $title = [
  866. '回收站内容', date('Y年m月d日')
  867. ];
  868. }
  869. $title = eval('return ' . iconv('utf-8', 'gbk//IGNORE', var_export($title, true) . ';'));
  870. $writer->insertone($title);
  871. // 内容
  872. if ($type == 'post') {
  873. $header = [
  874. '内容ID', '发布时间', '用户昵称', '城市', '内容标签', '内容前20个字',
  875. '真实浏览量', '总浏览量', '真实点赞数', '总赞数', '真实分享数', '总分享数',
  876. '真实收藏数', '总收藏数', '评论数'
  877. ];
  878. } else {
  879. $header = [
  880. '内容ID', '发布时间', '用户昵称', '内容标签', '内容前20个字',
  881. '真实浏览量', '真实点赞数', '真实点赞数', '真实分享数', '真实收藏数', '评论数'
  882. ];
  883. }
  884. $header = eval('return ' . iconv('utf-8', 'gbk//IGNORE', var_export($header, true) . ';'));
  885. // $writer->setOutputBOM(Reader::BOM_UTF8);
  886. $writer->insertone($header);
  887. $where = [];
  888. if (isset($request['content'])) {
  889. $where[] = ['content', 'like', "%{$request['content']}%"];
  890. }
  891. if (isset($request['is_suggest'])) {
  892. $where[] = ['is_suggest', $request['is_suggest']];
  893. }
  894. if (isset($request['type'])) {
  895. $where[] = ['type', $request['type']];
  896. }
  897. $sort = 'post.id';
  898. if (isset($request['sort']) && in_array($request['sort'], ['praise_count', 'share_count', 'pv', 'comment_count', 'create_bean'])) {
  899. $sort = $request['sort'];
  900. }
  901. $post = $this->post;
  902. if ($type == 'post_waste') {
  903. $post = $post->onlyTrashed();
  904. }
  905. $post->join('post_data', 'post_data.post_id', '=', 'post.id')
  906. ->select('post.*')
  907. ->where($where)
  908. ->where(function ($query) use ($request) {
  909. if (isset($request['keyword'])) {
  910. $query->where('uid', '=', $request['keyword'])
  911. ->orWhere('username', 'like', "%{$request['keyword']}%")
  912. ->orWhere('mobile', 'like', "%{$request['keyword']}%");
  913. }
  914. })
  915. ->where(function ($query) use ($request) {
  916. if (isset($request['created_at'])) {
  917. $time = explode('_', $request['created_at']);
  918. $query->whereBetween('post.created_at', $time);
  919. }
  920. })
  921. ->where(function ($query) use ($request) {
  922. if (isset($request['category_ids']) || isset($request['topic_ids'])) {
  923. $ids = [];
  924. if (isset($request['category_ids'])) {
  925. $categoryIds = explode('_', $request['category_ids']);
  926. $ids = $this->categoryTopic->whereIn('category_id', $categoryIds)->pluck('topic_id')->toArray();
  927. }
  928. if (isset($request['topic_ids'])) {
  929. $ids = array_merge($ids, explode('_', $request['topic_ids']));
  930. }
  931. Log::debug('话题ids:' . json_encode($ids));
  932. foreach ($ids as $key => $id) {
  933. if ($key == 0) {
  934. $query = $query->whereRaw('FIND_IN_SET(' . $id . ',topic_ids)');
  935. } else {
  936. $query = $query->orWhereRaw('FIND_IN_SET(' . $id . ',topic_ids)');
  937. }
  938. }
  939. }
  940. })
  941. ->orderBy($sort, 'desc')
  942. ->chunk(1, function ($posts) use ($writer, $type) {
  943. $data = [];
  944. foreach ($posts as $post) {
  945. if ($type == 'post') {
  946. $tmp = [
  947. $post->id,
  948. Carbon::parse($post->created_at)->toDateTimeString(),
  949. $post->username,
  950. $post->location,
  951. implode(' ', $this->getTopic($post->topic_ids)),
  952. subtext(strip_tags($post->content), 20),
  953. $post->data->pv_real,
  954. $post->data->pv,
  955. $post->data->praise_real_count,
  956. $post->data->praise_count,
  957. $post->data->share_real_count,
  958. $post->data->share_count,
  959. $post->data->collect_real_count,
  960. $post->data->collect_count,
  961. $post->data->comment_count
  962. ];
  963. } else {
  964. $tmp = [
  965. $post->id,
  966. Carbon::parse($post->created_at)->toDateTimeString(),
  967. $post->username,
  968. Carbon::parse($post->created_at)->toDateTimeString(),
  969. subtext(strip_tags($post->content), 20),
  970. $post->data->pv_real,
  971. $post->data->praise_real_count,
  972. $post->data->share_real_count,
  973. $post->data->collect_real_count,
  974. $post->data->comment_count
  975. ];
  976. }
  977. foreach ($tmp as $key => $value) {
  978. $tmp[$key] = iconv('utf-8', 'gbk//IGNORE', $value);
  979. }
  980. $data[] = $tmp;
  981. }
  982. $writer->insertAll($data);
  983. });
  984. Log::info('内容导出成功!');
  985. } catch (QueryException $e) {
  986. Log::debug('内容导出失败!' . $e->getMessage());
  987. }
  988. }
  989. /**
  990. * 统计社区内容
  991. * @param $start
  992. * @param $end
  993. * @return array
  994. */
  995. public function statistics($start, $end)
  996. {
  997. $result = $this->postStatistics
  998. ->where('created_at', '>=', $start)
  999. ->where('created_at', '<=', $end)
  1000. ->get()->toArray();
  1001. $stimestamp = strtotime($start);
  1002. $etimestamp = strtotime($end);
  1003. $days = ($etimestamp - $stimestamp) / 86400;
  1004. $date = array();
  1005. for ($i = 0; $i < $days; $i++) {
  1006. $date[] = date('Y-m-d', $stimestamp + (86400 * $i));
  1007. }
  1008. $totalRead = 0;
  1009. $totalPost = 0;
  1010. $totalShare = 0;
  1011. $totalLike = 0;
  1012. $totalCollect = 0;
  1013. $totalComment = 0;
  1014. $info = [];
  1015. foreach ($date as $key => $value) {
  1016. $info[$value] = [
  1017. 'read' => 0,
  1018. 'post' => 0,
  1019. 'share' => 0,
  1020. 'like' => 0,
  1021. 'collect' => 0,
  1022. 'comment' => 0,
  1023. ];
  1024. foreach ($result as $row) {
  1025. if ($value == date('Y-m-d', strtotime($row['created_at']))) {
  1026. $info[$value]['read'] = $row['read_count'];
  1027. $info[$value]['post'] = $row['post_count'];
  1028. $info[$value]['share'] = $row['share_count'];
  1029. $info[$value]['like'] = $row['like_count'];
  1030. $info[$value]['collect'] = $row['collect_count'];
  1031. $info[$value]['comment'] = $row['comment_count'];
  1032. $totalRead += $row['read_count'];
  1033. $totalPost += $row['post_count'];
  1034. $totalShare += $row['share_count'];
  1035. $totalLike += $row['like_count'];
  1036. $totalCollect += $row['collect_count'];
  1037. $totalComment += $row['comment_count'];
  1038. }
  1039. }
  1040. }
  1041. $info['data']['total_read'] = $totalRead;
  1042. $info['data']['total_post'] = $totalPost;
  1043. $info['data']['total_share'] = $totalShare;
  1044. $info['data']['total_like'] = $totalLike;
  1045. $info['data']['total_collect'] = $totalCollect;
  1046. $info['data']['total_comment'] = $totalComment;
  1047. return $info;
  1048. }
  1049. /**
  1050. * 编辑内容话题
  1051. */
  1052. public function updateTopic($request)
  1053. {
  1054. $token = JWTAuth::decode(JWTAuth::getToken());
  1055. if ($token['type'] != 1) {
  1056. return Response::create([
  1057. 'message' => '只有运营才能删除内容',
  1058. 'status_code' => 500
  1059. ]);
  1060. }
  1061. $post = $this->post->where('id', $request['id'])->first();
  1062. if (!$post) {
  1063. return Response::create([
  1064. 'message' => '获取内容信息失败',
  1065. 'status_code' => 500
  1066. ]);
  1067. }
  1068. //验证话题
  1069. $topicIdsArray = $this->topic->whereIn('id', explode(',', $request['topic_ids']))->pluck('id')->toArray();
  1070. $topicCount = count($topicIdsArray);
  1071. if ($topicCount == 0 || $topicCount > 5) {
  1072. return Response::create([
  1073. 'message' => '所选话题必须1-5个',
  1074. 'status_code' => 500
  1075. ]);
  1076. }
  1077. $topicIds = implode(',', $topicIdsArray);
  1078. $logData = [
  1079. 'uid' => $token['user']->id,
  1080. 'operator_type' => 'admin',
  1081. 'post_id' => $request['id'],
  1082. 'username' => $token['user']->username,
  1083. 'log_type' => 'update_topic',
  1084. 'content' => json_encode(['update_topic' => $request['id'] . '-' . $topicIds]),
  1085. ];
  1086. DB::beginTransaction();
  1087. try {
  1088. $post->topic_ids = $topicIds;
  1089. $post->save();
  1090. $this->postLog->create($logData);
  1091. DB::commit();
  1092. Redis::HSET('post_info_' . $request['id'], 'topic_ids', $topicIds);
  1093. foreach ($topicIdsArray as $id) {
  1094. Redis::zincrby('topic.just_use_count', 1, $id);
  1095. }
  1096. return Response::create();
  1097. } catch (QueryException $exception) {
  1098. DB::rollBack();
  1099. Log::debug('编辑内容话题:' . $post->id . $exception->getMessage());
  1100. return Response::create([
  1101. 'message' => '编辑失败,请重试',
  1102. 'error' => $exception->getMessage(),
  1103. 'status_code' => 500
  1104. ]);
  1105. }
  1106. }
  1107. /**
  1108. * 添加网站内容
  1109. */
  1110. public function createStore($startPage, $endPage, $size, $categoryId)
  1111. {
  1112. set_time_limit(1800);
  1113. for ($i = $startPage; $i <= $endPage; $i++) {
  1114. $this->addContent($i, $size, $categoryId);
  1115. usleep(100000);
  1116. }
  1117. }
  1118. /**
  1119. * 获取网站内容
  1120. */
  1121. public function addContent($page, $size, $categoryId)
  1122. {
  1123. $lists = $this->getAcFunList($page, $size, $categoryId);
  1124. if (empty($lists)) {
  1125. return Response::create([
  1126. 'message' => '获取数据失败',
  1127. 'status_code' => 500
  1128. ]);
  1129. }
  1130. $data = [];
  1131. foreach ($lists as $item) {
  1132. $res = $this->getData($item['id'], $item['title']);
  1133. if ($res && $res['content'] && $res['images']) {
  1134. $data[] = array_merge(['source_id' => $item['id']], $res);
  1135. }
  1136. }
  1137. if (empty($data)) {
  1138. return Response::create([
  1139. 'message' => '处理数据失败',
  1140. 'status_code' => 500
  1141. ]);
  1142. }
  1143. $date = Carbon::now()->toDateTimeString();
  1144. $successNo = 0;
  1145. $failNo = 0;
  1146. DB::beginTransaction();
  1147. try {
  1148. foreach ($data as $item) {
  1149. if ($this->postStore->where('source', 'AcFun')->where('source_id', $item['source_id'])->exists()) {
  1150. $failNo++;
  1151. continue;
  1152. }
  1153. $storeData = [
  1154. 'source' => 'Acfun',
  1155. 'source_id' => $item['source_id'],
  1156. 'category_id' => $categoryId,
  1157. 'title' => $item['title'],
  1158. 'content' => $item['content'],
  1159. 'img' => $item['images'][0],
  1160. ];
  1161. $postStore = $this->postStore->create($storeData);
  1162. $storeImgsData = [];
  1163. foreach ($item['images'] as $img) {
  1164. $storeImgsData[] = [
  1165. 'post_store_id' => $postStore->id,
  1166. 'img' => $img,
  1167. 'created_at' => $date,
  1168. 'updated_at' => $date,
  1169. ];
  1170. }
  1171. $this->postStoreImgs->insert($storeImgsData);
  1172. $successNo++;
  1173. }
  1174. DB::commit();
  1175. Log::info('第' . $page . '页添加内容数据成功' . $successNo . ',失败' . $failNo);
  1176. return Response::create();
  1177. } catch (QueryException $exception) {
  1178. DB::rollBack();
  1179. Log::debug('添加内容数据失败:' . $exception->getMessage());
  1180. return Response::create([
  1181. 'message' => '添加内容数据失败',
  1182. 'error' => $exception->getMessage(),
  1183. 'status_code' => 500
  1184. ]);
  1185. }
  1186. }
  1187. /**
  1188. * 获取网站内容
  1189. */
  1190. public function getData($id, $title = '')
  1191. {
  1192. $url = 'https://www.acfun.cn/a/ac' . $id;
  1193. $webpage = file_get_contents($url);
  1194. preg_match_all('/parts[\s\S]*?}]/i', $webpage, $res);
  1195. if (!isset($res[0][0])) {
  1196. return [];
  1197. }
  1198. $data = $res[0][0];
  1199. preg_match_all('/<p[^>]*>(?:(?!<\/p>)[\s\S])*<\/p>/i ', $data, $contents);
  1200. if (isset($contents[0])) {
  1201. $content = implode($contents[0]);
  1202. } else {
  1203. return [];
  1204. }
  1205. $content = strip_tags($content);
  1206. $content = str_replace(['&nbsp;'], '', $content);
  1207. preg_match_all('/src=(.*)>/U', $data, $imageArray);
  1208. $images = [];
  1209. if (isset($imageArray[0])) {
  1210. foreach ($imageArray[0] as $img) {
  1211. $imgArr = explode('"', $img);
  1212. if (isset($imgArr[1])) {
  1213. $imgArr[1] = trim($imgArr[1], '\\');
  1214. $images[] = $imgArr[1];
  1215. } else {
  1216. return [];
  1217. }
  1218. }
  1219. }
  1220. return [
  1221. 'title' => $title,
  1222. 'content' => $content,
  1223. 'images' => $images,
  1224. ];
  1225. }
  1226. /**
  1227. * 获取网站内容
  1228. */
  1229. public function getStore($request)
  1230. {
  1231. $perPage = isset($request['per_page']) ? $request['per_page'] : 20;
  1232. $where = [];
  1233. if (isset($request['type'])) {
  1234. $where[] = ['type', $request['type']];
  1235. }
  1236. if (isset($request['category_id'])) {
  1237. $where[] = ['category_id', $request['category_id']];
  1238. }
  1239. if (isset($request['title'])) {
  1240. $where[] = ['title', 'like', "%{$request['title']}%"];
  1241. }
  1242. if (isset($request['content'])) {
  1243. $where[] = ['content', 'like', "%{$request['content']}%"];
  1244. }
  1245. if (isset($request['source'])) {
  1246. $where[] = ['source', $request['source']];
  1247. }
  1248. if (isset($request['is_used'])) {
  1249. $where[] = ['is_used', $request['is_used']];
  1250. }
  1251. return $this->postStore
  1252. ->where($where)
  1253. ->orderBy('id', 'desc')
  1254. ->paginate($perPage);
  1255. }
  1256. /**
  1257. * 网站内容详情
  1258. */
  1259. public function getStoreDetail($request)
  1260. {
  1261. return $this->postStore->find($request['id']);
  1262. }
  1263. }