NewsService.php 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268
  1. <?php
  2. namespace App\JsonRpc;
  3. use App\Model\Article;
  4. use App\Model\ArticleData;
  5. use App\Model\Category;
  6. use App\Model\Website;
  7. use App\Model\WebsiteCategory;
  8. use Hyperf\DbConnection\Db;
  9. use Hyperf\RpcServer\Annotation\RpcService;
  10. use App\Tools\Result;
  11. use App\Model\ArticleSurvey;
  12. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  13. class NewsService implements NewsServiceInterface
  14. {
  15. /**
  16. * 获取导航池列表
  17. * @param array $data
  18. * @return array
  19. */
  20. public function getCategoryList(array $data): array
  21. {
  22. $where = [];
  23. if(isset($data['name']) && $data['name']){
  24. array_push($where, ['category.name','like','%'.$data['name'].'%']);
  25. }
  26. if(isset($data['department_id']) && $data['department_id']){
  27. array_push($where, ['category.department_id','=',$data['department_id']]);
  28. }
  29. if(isset($data['city_id']) && $data['city_id']){
  30. array_push($where, ['category.city_id','=',$data['city_id']]);
  31. }
  32. $rep = Category::where($where)
  33. ->leftJoin('district','category.city_id','district.id')
  34. ->leftJoin('department','category.department_id','department.id')
  35. ->select("category.*","district.name as city_name","department.name as department_name")
  36. ->limit($data['pageSize'])->orderBy("category.sort","desc")->orderByDesc('category.updated_at')->offset(($data['page']-1)*$data['pageSize'])->get();
  37. $count = Category::where($where)->count();
  38. $data = [
  39. 'rows'=>$rep->toArray(),
  40. 'count'=>$count
  41. ];
  42. if(empty($rep->toArray())){
  43. return Result::error("没有导航池数据");
  44. }
  45. return Result::success($data);
  46. }
  47. /**
  48. * @param array $data
  49. * @return array
  50. */
  51. public function categoryList(array $data): array
  52. {
  53. $where[] = [
  54. 'pid','=',$data['pid']
  55. ];
  56. if(isset($data['name'])){
  57. array_push($where, ['category.name','like','%'.$data['name'].'%']);
  58. }
  59. var_dump($where);
  60. $result = Category::where($where)->select('category.*','category.id as category_id')->get();
  61. if(empty($result)){
  62. return Result::error("没有栏目数据");
  63. }
  64. return Result::success($result);
  65. }
  66. /**
  67. * @param array $data
  68. * @return array
  69. */
  70. public function addCategory(array $data): array
  71. {
  72. $id = Category::insertGetId($data);
  73. if(empty($id)){
  74. return Result::error("添加失败");
  75. }
  76. return Result::success(['id'=>$id]);
  77. }
  78. /**
  79. * @param array $data
  80. * @return array
  81. */
  82. public function delCategory(array $data): array
  83. {
  84. $categoryList = Category::where(['pid'=>$data['id']])->get();
  85. var_dump("分类列表:",$data,$categoryList);
  86. if($categoryList->toArray()){
  87. return Result::error("分类下面有子分类不能删除");
  88. }
  89. $articleList = Article::where(['catid'=>$data['id']])->get();
  90. var_dump("文章列表:",$articleList);
  91. if($articleList->toArray()){
  92. return Result::error("分类下面有资讯不能删除");
  93. }
  94. $result = Category::where($data)->delete();
  95. if(!$result){
  96. return Result::error("删除失败");
  97. }
  98. return Result::success($result);
  99. }
  100. /**
  101. * @param array $data
  102. * @return array
  103. */
  104. public function updateCategory(array $data): array
  105. {
  106. $where = [
  107. 'id'=>$data['id']
  108. ];
  109. $result = Category::where($where)->update($data);
  110. if($result){
  111. return Result::success($result);
  112. }else{
  113. return Result::error("更新失败");
  114. }
  115. }
  116. /**
  117. * 获取导航池信息
  118. * @param array $data
  119. * @return array
  120. */
  121. public function getCategoryInfo(array $data): array
  122. {
  123. $where = [
  124. 'id'=>$data['id']
  125. ];
  126. $result = Category::where($where)->first();
  127. if($result){
  128. return Result::success($result);
  129. }else{
  130. return Result::error("更新失败");
  131. }
  132. }
  133. /**
  134. * @param array $data
  135. * @return array
  136. */
  137. public function getArticleList(array $data): array
  138. {
  139. $where= [];
  140. if(isset($data['title']) && $data['title']){
  141. array_push($where,['article.title','like','%'.$data['title'].'%']);
  142. }
  143. if(isset($data['category_name']) && $data['category_name']){
  144. array_push($where,['category.name','like','%'.$data['category_name'].'%']);
  145. }
  146. if(isset($data['author']) && $data['author']){
  147. array_push($where,['article.author','=',$data['author']]);
  148. }
  149. if(isset($data['islink']) && $data['islink']!==""){
  150. array_push($where,['article.islink','=',$data['islink']]);
  151. }
  152. if(isset($data['status']) && $data['status']!==""){
  153. array_push($where,['article.status','=',$data['status']]);
  154. }
  155. $rep = Article::where($where)
  156. ->whereNotIn('article.status',[404])
  157. ->leftJoin('category','article.catid','category.id')
  158. ->select("article.*","category.name as category_name")
  159. ->orderBy("article.id","desc")
  160. ->limit($data['pageSize'])
  161. ->offset(($data['page']-1)*$data['pageSize'])->get();
  162. $count = Article::where($where)->whereNotIn('article.status',[404])
  163. ->leftJoin('category','article.catid','category.id')->count();
  164. $data = [
  165. 'rows'=>$rep->toArray(),
  166. 'count'=>$count
  167. ];
  168. if(empty($rep)){
  169. return Result::error("没有信息数据");
  170. }
  171. return Result::success($data);
  172. }
  173. /**
  174. * @param array $data
  175. * @return array
  176. */
  177. public function addArticle(array $data): array
  178. {
  179. Db::beginTransaction();
  180. try{
  181. $articleData = $data;
  182. unset($articleData['content']);
  183. $id = Article::insertGetId($articleData);
  184. $articleDataContent = [
  185. 'article_id'=>$id,
  186. 'content'=>$data['content']
  187. ];
  188. ArticleData::insertGetId($articleDataContent);
  189. Db::commit();
  190. } catch(\Throwable $ex){
  191. Db::rollBack();
  192. var_dump($ex->getMessage());
  193. return Result::error("创建失败",0);
  194. }
  195. return Result::success(['id'=>$id]);
  196. }
  197. /**
  198. * @param array $data
  199. * @return array
  200. */
  201. public function delArticle(array $data): array
  202. {
  203. $result = Article::where($data)->update(['status'=>404]);
  204. if(!$result){
  205. return Result::error("删除失败");
  206. }
  207. return Result::success($result);
  208. }
  209. /**
  210. * @param array $data
  211. * @return array
  212. */
  213. public function updateArticle(array $data): array
  214. {
  215. Db::beginTransaction();
  216. try{
  217. $data['cat_arr_id'] = isset($data['cat_arr_id'])?json_encode($data['cat_arr_id']):'';
  218. $data['tag'] = isset($data['tag'])?json_encode($data['tag']):'';
  219. $articleData = $data;
  220. unset($articleData['content']);
  221. unset($articleData['status_name']);
  222. unset($articleData['name']);
  223. unset($articleData['content']);
  224. unset($articleData['pid_arr']);
  225. unset($articleData['pid']);
  226. $id = Article::where(['id'=>$data['id']])->update($articleData);
  227. $articleDataContent = [
  228. 'content'=>$data['content']
  229. ];
  230. ArticleData::where(['article_id'=>$data['id']])->update($articleDataContent);
  231. } catch(\Throwable $ex){
  232. Db::rollBack();
  233. var_dump($ex->getMessage());
  234. return Result::error("更新失败",0);
  235. }
  236. return Result::success([]);
  237. }
  238. /**
  239. * 更新资讯状态
  240. * @param array $data
  241. * @return array
  242. */
  243. public function upArticleStatus(array $data):array
  244. {
  245. $result = Article::where(['id'=>$data['id']])->update($data);
  246. if($result){
  247. return Result::success();
  248. }else{
  249. return Result::error("更新状态失败",0);
  250. }
  251. }
  252. /**
  253. * 获取新闻详情
  254. * @param array $data
  255. * @return array
  256. */
  257. public function getArticleInfo(array $data): array
  258. {
  259. $where = [
  260. 'article.id'=>$data['id'],
  261. // 'article.status'=>1
  262. ];
  263. $result = Article::where($where)->leftJoin("article_data","article.id","article_data.article_id")->first();
  264. if(empty($result)){
  265. return Result::error("查询失败",0);
  266. }
  267. return Result::success($result);
  268. }
  269. /**
  270. * 获取头条新闻
  271. * @param array $data
  272. * @return array
  273. */
  274. public function getWebsiteArticlett(array $data): array
  275. {
  276. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
  277. $category = array_values(array_unique($category->toArray()));
  278. $result = [];
  279. if ($category) {
  280. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  281. $where = [
  282. 'status' => 1,
  283. ];
  284. var_dump($data, 'data-----------------');
  285. // level=7 根据文章key来匹配文章
  286. if (isset($data['level']) && $data['level'] == 7) {
  287. // 根据文章id获取key
  288. // $data['id'] = 50142;
  289. if (isset($data['id']) && !empty($data['id'])) {
  290. $keyword = Article::where('id', $data['id'])->value('keyword');
  291. $keywordArray = explode(',', $keyword);
  292. $whereL7 = [];
  293. foreach ($keywordArray as $k => $v) {
  294. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  295. }
  296. // 原始查询
  297. $result = Article::where($whereL7)
  298. ->offset($placeid)
  299. ->limit($data['pageSize'])
  300. ->orderBy('updated_at', 'desc')
  301. ->get()
  302. ->map(function ($article ) use ($data) {
  303. $catid = $article->catid;
  304. $pinyin = '';
  305. $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
  306. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  307. if ($category->pid != 0 && !empty($category->aLIas_pinyin)) {
  308. $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
  309. $pinyin = $childCategory->aLIas_pinyin ? $childCategory->aLIas_pinyin.'/'. $category->aLIas_pinyin : null;
  310. }
  311. $article->pinyin = $pinyin;
  312. return $article;
  313. });
  314. if (empty($result)) {
  315. return Result::success([]);
  316. }
  317. return Result::success($result);
  318. } else {
  319. return Result::error("参数错误level=7,id不能为空", 0);
  320. }
  321. }
  322. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  323. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  324. var_dump($where, 'where-----------------');
  325. $result = Article::where($where)
  326. ->whereIn("catid", $category)
  327. // ->leftJoin('website_category', 'article.catid', 'website_category.category_id')
  328. // ->where('website_category.website_id', $data['website_id'])
  329. ->where(function ($query) use ($data) {
  330. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  331. ->orWhereNull("ignore_ids");
  332. })
  333. //$data['level'] == 4 || $data['level'] == 5 查询随机
  334. ->when($data['level'] == 5, function ($query) {
  335. $query->inRandomOrder()
  336. //updated_at最近三十天;
  337. ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  338. })
  339. ->when($data['level'] == 4, function ($query) {
  340. $query->orderBy("article.updated_at", "desc");
  341. })
  342. ->when(!empty($data['level']), function ($query) use ($data) {
  343. if ($data['level'] != 4 && $data['level'] != 5) {
  344. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  345. ->orderBy("article.updated_at", "desc");
  346. }
  347. })
  348. ->select('article.*')
  349. ->offset($placeid)
  350. ->limit($data['pageSize'])
  351. ->get()
  352. ->map(function ($article ) use ($data) {
  353. $catid = $article->catid;
  354. $pinyin = '';
  355. // $category = WebsiteCategory::whereIn('category_id', $catArrId)->where('website_category.website_id', $data['website_id'])->get()->all();
  356. // if ($catArrId) {
  357. // foreach ($catArrId as $categoryId) {
  358. $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
  359. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  360. if ($category->pid != 0 && !empty($category->aLIas_pinyin)) {
  361. $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
  362. $pinyin = $childCategory->aLIas_pinyin ? $childCategory->aLIas_pinyin.'/'. $category->aLIas_pinyin : null;
  363. }
  364. // }
  365. // }
  366. $article->pinyin = $pinyin;
  367. return $article;
  368. });
  369. if (empty($result)) {
  370. return Result::error("暂无头条新闻", 0);
  371. }
  372. return Result::success($result);
  373. } else {
  374. return Result::error("本网站下暂无相关栏目", 0);
  375. }
  376. }
  377. /**
  378. * 获取模块新闻
  379. * @param array $data
  380. * @return array
  381. */
  382. public function getWebsiteModelArticles(array $data): array
  383. {
  384. $catid = $data['catid'];
  385. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  386. $category = $category->toArray();
  387. if (!empty($category)) {
  388. $where = [
  389. 'status' => 1,
  390. 'catid' => $catid,
  391. ];
  392. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  393. // 1:文字新闻;2:轮播图;3:图文;
  394. // 级别:0:未分类
  395. // 3:推荐图片
  396. if ($data['level'] == 1) {
  397. $data['level'] = 0;
  398. }
  399. $result = Article::where($where)
  400. ->where(function ($query) use ($data) {
  401. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  402. ->orWhereNull("level")
  403. ->orWhereRaw("level = '[]'");
  404. })
  405. ->where(function ($query) use ($data) {
  406. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  407. ->orWhereNull("ignore_ids");
  408. })
  409. ->orderBy("updated_at", "desc")
  410. ->offset($placeid)
  411. ->limit($data['pagesize'])
  412. ->get();
  413. if (empty($result)) {
  414. return Result::error("此栏目暂无相关新闻", 0);
  415. }
  416. } else {
  417. return Result::error("此网站暂无此栏目", 0);
  418. }
  419. return Result::success($result);
  420. }
  421. /**
  422. *获取新闻列表
  423. * @param array $data
  424. * @return array
  425. */
  426. public function getWebsiteArticleList(array $data): array
  427. {
  428. // return Result::success($data);
  429. $where[] = ['status', '=', 1];
  430. if(isset($data['keyword']) && !empty($data['keyword'])){
  431. array_push($where,['article.title','like','%'.$data['keyword'].'%']);
  432. }
  433. if(isset($data['catid']) && !empty($data['catid'])){
  434. if(is_array($data['catid'])){
  435. $category = WebsiteCategory::where('website_id',$data['website_id'])->whereIn('category_id',$data['catid'])->pluck('category_id');
  436. array_push($where,['catid', 'in', $data['catid']]);
  437. }else{
  438. $category = WebsiteCategory::where('website_id',$data['website_id'])->where('category_id',$data['catid'])->pluck('category_id');
  439. array_push($where,['catid', '=', $data['catid']]);
  440. }
  441. if(empty($category)){
  442. return Result::error("此网站暂无此栏目",0);
  443. }
  444. }
  445. // return Result::success($where);
  446. $rep = Article::where(function ($query) use ($where) {
  447. foreach ($where as $condition) {
  448. if ($condition[1] === 'in') {
  449. $query->whereIn($condition[0], $condition[2]);
  450. } else {
  451. $query->where($condition[0], $condition[1], $condition[2]);
  452. }
  453. }
  454. })
  455. ->where(function ($query) use ($data) {
  456. $query->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0")
  457. ->orWhereNull("ignore_ids");
  458. })
  459. ->select(
  460. 'article.id',
  461. 'article.title',
  462. 'article.imgurl',
  463. 'article.author',
  464. 'article.updated_at',
  465. 'article.introduce',
  466. 'article.islink',
  467. 'article.linkurl',
  468. 'article.copyfrom',
  469. 'article.catid')
  470. ->orderBy("updated_at", "desc")
  471. ->limit($data['pageSize'])
  472. ->offset(($data['page'] - 1) * $data['pageSize'])
  473. ->get()
  474. // ;
  475. ->map(function ($article ) use ($data) {
  476. $catid = $article->catid ?? 0;
  477. $pinyin = '';
  478. $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
  479. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  480. if ($category->pid != 0 && !empty($category->aLIas_pinyin)) {
  481. $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
  482. $pinyin = $childCategory->aLIas_pinyin ? $childCategory->aLIas_pinyin.'/'. $category->aLIas_pinyin : null;
  483. }
  484. $article->pinyin = $pinyin;
  485. return $article;
  486. });
  487. $count = Article::where(function ($query) use ($where) {
  488. foreach ($where as $condition) {
  489. if ($condition[1] === 'in') {
  490. $query->whereIn($condition[0], $condition[2]);
  491. } else {
  492. $query->where($condition[0], $condition[1], $condition[2]);
  493. }
  494. }
  495. })->count();
  496. $data = [
  497. 'rows'=>$rep->toArray(),
  498. 'count'=>$count
  499. ];
  500. if(empty($rep)){
  501. return Result::error("没有信息数据");
  502. }
  503. return Result::success($data);
  504. }
  505. /**
  506. * 前端-获取新闻详情
  507. * @param array $data
  508. * @return array
  509. */
  510. public function selectWebsiteArticleInfo(array $data): array
  511. {
  512. $where = [
  513. 'article.id'=>$data['id'],
  514. 'article.status'=>1
  515. ];
  516. $result = Article::where($where)->leftJoin("article_data","article.id","article_data.article_id")
  517. ->where(function ($query) use ($data) {
  518. $query->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0")
  519. ->orWhereNull("ignore_ids");
  520. })
  521. ->first();
  522. if(empty($result)){
  523. return Result::error("暂无此新闻!",0);
  524. }
  525. $category = WebsiteCategory::where('website_id',$data['website_id'])->where(['category_id'=>$result['catid']])->first();
  526. if(empty($category)){
  527. return Result::error("查询失败",0);
  528. }
  529. $result['category_id'] = $category['category_id'];
  530. $result['cat_name'] = $category['alias'];
  531. return Result::success($result);
  532. }
  533. /**
  534. * 前端-获取网站调查问卷
  535. * @param array $data
  536. * @return array
  537. */
  538. public function getWebsiteSurvey(array $data): array
  539. {
  540. if(isset($data['website_id']) && !empty($data['website_id'])){
  541. $website = Website::where('id',$data['website_id'])->first();
  542. if(empty($website)){
  543. return Result::error("暂无此网站",0);
  544. }
  545. }
  546. if(isset($data['art_id']) && !empty($data['art_id'])){
  547. $article = Article::where('id',$data['art_id'])->where('status',1)->first();
  548. if(empty($article)){
  549. return Result::error("暂无此文章",0);
  550. }
  551. // return Result::error($data,0);
  552. $where['art_id'] = $data['art_id'];
  553. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  554. }else{
  555. $survey = Article::where(function ($query) {
  556. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  557. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  558. })
  559. ->where('status',1)
  560. ->where('is_survey',1)
  561. ->select('survey_id')
  562. ->orderBy('updated_at','desc')
  563. ->first();
  564. if(empty($survey)){
  565. return Result::error("暂无调查问卷",0);
  566. }
  567. $where['sur_id'] = $survey['survey_id'];
  568. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  569. }
  570. // return Result::success($where);
  571. $result = ArticleSurvey::where($where)
  572. ->where(function ($query) {
  573. $query->where('is_other', 0)
  574. ->orWhere(function ($subQuery) {
  575. $subQuery->where('is_other', 1)
  576. ->where('other_id', 0);
  577. });
  578. })
  579. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  580. ->select('article_survey.*', 'article.survey_type')
  581. ->get()->all();
  582. if(empty($result)){
  583. return Result::error("此文章暂无调查问卷",0);
  584. }
  585. return Result::success($result);
  586. }
  587. /**
  588. * 前端-添加网站调查问卷选项
  589. * @param array $data
  590. * @return array
  591. */
  592. public function addWebsiteSurveyOption(array $data): array
  593. {
  594. if(isset($data['website_id']) && !empty($data['website_id'])){
  595. $website = Website::where('id',$data['website_id'])->first();
  596. if(empty($website)){
  597. return Result::error("暂无此网站",0);
  598. }
  599. if(isset($data['sur_id']) && !empty($data['sur_id'])){
  600. $survey = ArticleSurvey::where('sur_id',$data['sur_id'])->where('website_id',$data['website_id'])->where('is_other',1)->where('other_id',0)->first();
  601. if(empty($survey)){
  602. return Result::error("此调查问卷不可添加选项",0);
  603. }
  604. if(isset($data['choice_name']) &&!empty($data['choice_name'])){
  605. $choice = [
  606. 'art_id'=>$survey['art_id'],
  607. 'website_id'=>$data['website_id'],
  608. 'survey_name'=>$survey['survey_name'],
  609. 'choice_name'=>$data['choice_name'],
  610. 'sur_id'=>$survey['sur_id'],
  611. 'is_other'=>1,
  612. 'other_id'=>$survey['id'],
  613. ];
  614. $result = ArticleSurvey::insertGetId($choice);
  615. if(empty($result)){
  616. return Result::error("添加失败",0);
  617. }
  618. return Result::success($result);
  619. }
  620. }
  621. return Result::error("添加失败",0);
  622. }
  623. return Result::error("添加失败",0);
  624. }
  625. /**
  626. * 前端-调查问卷投票
  627. * @param array $data
  628. * @return array
  629. */
  630. public function addWebsiteSurveyVote(array $data): array
  631. {
  632. // return Result::success($data);
  633. if(isset($data['website_id']) && !empty($data['website_id'])){
  634. $website = Website::where('id',$data['website_id'])->first();
  635. if(empty($website)){
  636. return Result::error("暂无此网站",0);
  637. }
  638. if(isset($data['sur_id']) && !empty($data['sur_id'])){
  639. $is_survey = ArticleSurvey::where('sur_id',$data['sur_id'])->first();
  640. // return Result::success($survey);
  641. if(empty($is_survey)){
  642. return Result::error("此调查问卷不存在",0);
  643. }
  644. // return Result::success($survey);
  645. // 调查问卷类型
  646. if(isset($data['choice_id']) &&!empty($data['choice_id'])){
  647. //多选 若是json型则转化成数组类型
  648. if (strpos($data['choice_id'], '[') === 0) {
  649. $data['choice_id'] = json_decode($data['choice_id'], true);
  650. } else {
  651. // 单选 也转换成数组
  652. $data['choice_id'] = [$data['choice_id']];
  653. }
  654. $data['choice_id'] = array_map('intval', $data['choice_id']);
  655. $other = ArticleSurvey::whereIn('id',$data['choice_id'])
  656. ->where('website_id',$data['website_id'])
  657. ->where('is_other',1)
  658. ->where('other_id',0)
  659. ->first();
  660. if(!empty($other)){
  661. return Result::error("请选择已有的选项!",0);
  662. }
  663. $choice['other'] = ArticleSurvey::whereIn('id',$data['choice_id'])
  664. ->where('website_id',$data['website_id'])
  665. ->where('is_other',1)
  666. ->where('other_id','!=',0)
  667. ->first();
  668. // return Result::success($choice['other']);
  669. $choice_id = $data['choice_id'];
  670. if(!empty($choice['other'])){
  671. // array_push($data['choice_id'],$choice['other']['other_id']);
  672. if(!empty($choice_id)){
  673. $key = array_search($choice['other']['id'], $choice_id);
  674. if ($key!== false) {
  675. unset($choice_id[$key]);
  676. $choice_id = array_values($choice_id);
  677. }
  678. array_push($choice_id,$choice['other']['other_id']);
  679. }else{
  680. $choice_id[0] = $choice['other']['other_id'];
  681. }
  682. array_push($data['choice_id'],$choice['other']['other_id']);
  683. }
  684. // return Result::success($data);
  685. $choice = ArticleSurvey::whereIn('id',$data['choice_id'])
  686. ->where('website_id',$data['website_id'])
  687. ->increment('results', 1);
  688. if(empty($choice)){
  689. return Result::error("请选择已有的选项!",0);
  690. }
  691. $survey['data'] = ArticleSurvey::where('sur_id',$data['sur_id'])
  692. ->where('website_id',$data['website_id'])
  693. ->where('other_id', 0)
  694. ->get();
  695. $survey['choice'] = $choice_id;
  696. return Result::success($survey);
  697. }
  698. return Result::error("参数必填!");
  699. }
  700. return Result::error("此调查问卷不存在",0);
  701. }
  702. return Result::error("参数必填!");
  703. }
  704. /**
  705. * 后端-获取网站调查问卷列表
  706. * @param array $data
  707. * @return array
  708. */
  709. public function getSurveyList(array $data): array
  710. {
  711. $where = [];
  712. if(isset($data['survey_name']) &&!empty($data['survey_name'])){
  713. array_push($where,['survey_name','like','%'.$data['survey_name'].'%']);
  714. }
  715. if(isset($data['survey_type']) && $data['survey_type'] != null){
  716. array_push($where,['survey_type','=',$data['survey_type']]);
  717. }
  718. if(isset($data['is_survey']) && $data['is_survey'] != null){
  719. array_push($where,['is_survey','=',$data['is_survey']]);
  720. }
  721. // return Result::success($where);
  722. if (!empty($where)) {
  723. $query = Article::where($where)->where(function ($q) {
  724. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  725. });
  726. } else {
  727. $query = Article::where(function ($q) {
  728. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  729. });
  730. }
  731. $count = $query->count();
  732. $survey = $query->orderByDesc('id')
  733. ->limit($data['pageSize'])
  734. ->offset(($data['page']-1)*$data['pageSize'])
  735. ->get();
  736. if(empty($survey->toArray())){
  737. return Result::error("暂无调查问卷!",0);
  738. }
  739. $result = [
  740. 'rows'=>$survey,
  741. 'count'=>$count
  742. ];
  743. return Result::success($result);
  744. }
  745. /**
  746. * 后端-获取网站调查问卷详情
  747. * @param array $data
  748. * @return array
  749. */
  750. public function getSurveyInfo(array $data): array
  751. {
  752. if(isset($data['sur_id']) &&!empty($data['sur_id'])){
  753. $where = [ 'sur_id'=>$data['sur_id']];
  754. $choose = ArticleSurvey::where($where)->where('is_other',0)
  755. ->leftJoin('article','article_survey.art_id','article.id')
  756. ->select('article_survey.*','article.survey_type')
  757. ->get()->all();
  758. if(empty($choose)){
  759. return Result::error("此调查问卷不存在",0);
  760. }
  761. $resultsArray = array_column($choose, 'results');
  762. $total = array_sum($resultsArray);
  763. $other = ArticleSurvey::where($where)->where('is_other',1)->where('other_id',0)->first();
  764. $others = ArticleSurvey::where($where)->where('is_other',1)->where('other_id','!=',0)->orderByDesc('created_at')->get()->all();
  765. // $total = 0;
  766. if(!empty($other)){
  767. $total = $total + $other['results'];
  768. $other['choice_name'] ='(其他)';
  769. if(!empty($others)){
  770. $other['hasChildren'] = true;
  771. // array_push($other,['hasChildren','=',true]);
  772. $other['children'] = $others;
  773. $other_choices = [$other->toArray()];
  774. $mer_choice = array_merge($choose,$other_choices);
  775. $value_choice = array_values($mer_choice);
  776. }
  777. else{
  778. // return Result::error('1111');
  779. $other_choices = [$other->toArray()];
  780. $other_choices = array_merge($choose,$other_choices);
  781. $value_choice = array_values($other_choices);
  782. // return Result::success($result);
  783. }
  784. }else{
  785. $value_choice = $choose;
  786. }
  787. $result = [
  788. 'choose'=>$value_choice,
  789. 'total'=>$total
  790. ];
  791. }
  792. return Result::success($result);
  793. }
  794. /**
  795. * 前端-搜索新闻列表
  796. * @param array $data
  797. * @return array
  798. */
  799. public function selectWebsiteArticle(array $data): array
  800. {
  801. $where = [];
  802. // 初始化查询构造器
  803. $category = WebsiteCategory::where('website_id',$data['website_id'])->pluck('category_id');
  804. $query = Article::where('status', 1)
  805. ->whereIn('catid', $category)
  806. ->where(function ($query) use ($data) {
  807. $query->where(function ($subQuery) use ($data) {
  808. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0");
  809. })->orWhereNull("ignore_ids");
  810. });
  811. // return Result::success($all_articles);
  812. // 检查是否存在 cityid 参数
  813. if (isset($data['cityid']) && !empty($data['cityid'])) {
  814. $query->whereRaw("JSON_CONTAINS(city_arr_id, '".intval($data['cityid'])."')");
  815. }
  816. // 检查是否存在 department_id 参数
  817. if (isset($data['department_id']) && !empty($data['department_id'])) {
  818. $query->whereRaw("JSON_CONTAINS(department_arr_id, '".intval($data['department_id'])."')");
  819. }
  820. // 检查是否存在 keyword 参数
  821. if (isset($data['keyword']) && !empty($data['keyword'])) {
  822. $query->where('title', 'like', '%'.$data['keyword'].'%');
  823. }
  824. // 计算总数
  825. $count = $query->count();
  826. // 分页查询
  827. $articles = $query->orderBy("updated_at", "desc")
  828. ->limit($data['pageSize'])
  829. ->offset(($data['page'] - 1) * $data['pageSize'])
  830. ->get()->all();
  831. if (empty($articles)) {
  832. return Result::error("没有符合条件的资讯数据");
  833. }
  834. $data = [
  835. 'rows' => $articles,
  836. 'count' => $count
  837. ];
  838. return Result::success($data);
  839. }
  840. /**
  841. * 模块新闻加强版
  842. * @param array $data
  843. * @return array
  844. */
  845. public function getWebsiteCatidArticle(array $data): array
  846. {
  847. // return Result::success($data);
  848. $where = [
  849. // 'category.status' => 1,
  850. 'website_category.category_id' => $data['catid'],
  851. 'website_category.website_id' => $data['website_id'],
  852. // 'article.status' => 1,
  853. ];
  854. // $category = WebsiteCategory::where($where);
  855. if(isset($data['child_catnum']) && !empty($data['child_catnum'])){
  856. $child_catnum = $data['child_catnum']?? 1;
  857. $category['child'] = WebsiteCategory::where('pid',$data['catid'])->where('website_id',$data['website_id'])->select('category_id','alias')->limit($child_catnum)->get()->toArray();
  858. $childCategoryIds = array_column($category['child'], 'category_id');
  859. if(empty($childCategoryIds)){
  860. return Result::error("暂无子栏目",0);
  861. }
  862. $imgArticles = [];
  863. $textArticles = [];
  864. // return Result::success($childCategoryIds);
  865. if(isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum']!=0){
  866. // 初始化子分类图片新闻和文字新闻数组
  867. // 查询所有子级栏目的图文新闻
  868. $imgArticles = Article::where('catid', $childCategoryIds[0])
  869. ->where(function ($query) use ($data) {
  870. $query->where(function ($subQuery) use ($data) {
  871. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0");
  872. })->orWhereNull("ignore_ids");
  873. })
  874. ->where('status', 1)
  875. ->where('imgurl', '!=', '')
  876. ->select('*')
  877. ->orderBy('updated_at', 'desc')
  878. ->limit($data['child_imgnum'])
  879. ->get();
  880. }
  881. if( isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum']!=0){
  882. // 查询所有子级栏目的文字新闻
  883. $textArticles = Article::where('catid', $childCategoryIds[0])
  884. ->where('status', 1)
  885. ->where(function ($query) use ($data) {
  886. $query->where(function ($subQuery) use ($data) {
  887. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0");
  888. })->orWhereNull("ignore_ids");
  889. })
  890. // ->where(function ($query) {
  891. // $query->whereNull('imgurl')
  892. // ->orWhere('imgurl', '');
  893. // })
  894. ->select('*')
  895. ->orderBy('updated_at', 'desc')
  896. ->limit($data['child_textnum'])
  897. ->get();
  898. }
  899. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  900. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  901. $child['img'] = $imgArticles? $imgArticles->where('catid', $child['category_id']) : [];
  902. $child['text'] = $textArticles? $textArticles->where('catid', $child['category_id']) : [];
  903. return $child;
  904. }, $category['child']);
  905. }
  906. // }
  907. if (isset($data['img_num']) && !empty($data['img_num'])) {
  908. $category['img'] = WebsiteCategory::where($where)
  909. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  910. ->where('article.status', 1)
  911. ->where('article.imgurl', '!=', '')
  912. ->select('article.*','website_category.category_id','website_category.alias')
  913. ->orderBy('article.updated_at', 'desc')
  914. ->limit($data['img_num'])
  915. ->get();
  916. }
  917. if (isset($data['text_num']) && !empty($data['text_num'])) {
  918. $category['text'] = WebsiteCategory::where($where)
  919. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  920. ->where('article.status', 1)
  921. // ->where(function ($query) {
  922. // $query->whereNull('article.imgurl')
  923. // ->orWhere('article.imgurl', '');
  924. // })
  925. ->select('article.*','website_category.category_id','website_category.alias')
  926. ->orderBy('article.updated_at', 'desc')
  927. ->limit($data['text_num'])
  928. ->get();
  929. }
  930. // $category = $category->get();
  931. if(empty($category)){
  932. return Result::error("查询失败", 0);
  933. }
  934. return Result::success($category);
  935. }
  936. /**
  937. * 模块新闻加强plus版
  938. * @param array $data
  939. * @return array
  940. */
  941. public function getWebsiteAllArticle(array $data): array
  942. {
  943. // 修正传入的字符串,将单引号替换为双引号
  944. $input['id'] = $data['id'];
  945. $input['website_id'] = $data['website_id'];
  946. // 将 JSON 字符串转换为 PHP 数组
  947. $data = json_decode($input['id'], true);
  948. // 使用 array_map 处理每个元素
  949. $result = array_map(function ($item) use ($input) {
  950. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  951. $website = [
  952. 'website_id' => $input['website_id'],
  953. ];
  954. // 查询栏目名称
  955. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id','aLIas_pinyin']);
  956. if(empty($category)){
  957. $imgArticles = [];
  958. $textArticles = [];
  959. // return Result::error("暂无此栏目",0);
  960. }else{
  961. $parent_alias = $category->alias ?? '';
  962. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  963. // 查询图片新闻
  964. $imgArticles = Article::where('catid', $parentCatId)
  965. ->where('status', 1)
  966. ->where(function ($query) use ($website) {
  967. $query->where(function ($subQuery) use ($website) {
  968. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($website['website_id'])."') = 0");
  969. })->orWhereNull("ignore_ids");
  970. })
  971. ->where('imgurl', '!=', '')
  972. ->select(
  973. 'article.id',
  974. 'article.title',
  975. 'article.imgurl',
  976. 'article.author',
  977. 'article.updated_at',
  978. 'article.introduce',
  979. 'article.islink',
  980. 'article.linkurl',
  981. 'article.copyfrom',
  982. DB::raw("'$parent_pinyin' as pinyin") // 添加 pinyin 字段
  983. )
  984. ->orderBy('updated_at', 'desc')
  985. ->limit($parentImgNum)
  986. ->get()->all();
  987. // 查询文字新闻
  988. $textArticles = Article::where('catid', $parentCatId)
  989. ->where('status', 1)
  990. ->where(function ($query) use ($website) {
  991. $query->where(function ($subQuery) use ($website) {
  992. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($website['website_id'])."') = 0");
  993. })->orWhereNull("ignore_ids");
  994. })
  995. ->select(
  996. 'article.id',
  997. 'article.title',
  998. 'article.author',
  999. 'article.updated_at',
  1000. 'article.introduce',
  1001. 'article.islink',
  1002. 'article.linkurl',
  1003. 'article.copyfrom',
  1004. DB::raw("'$parent_pinyin' as pinyin"))
  1005. ->orderBy('updated_at', 'desc')
  1006. ->limit($parentTextNum)
  1007. ->get()->all();
  1008. }
  1009. $resultItem = [
  1010. 'alias' => $parent_alias,
  1011. 'category_id' => $parentCatId,
  1012. 'pinyin' => $parent_pinyin,
  1013. 'imgnum' => $imgArticles,
  1014. 'textnum' => $textArticles,
  1015. ];
  1016. if (!empty($item['child']) && $item['child'] != "") {
  1017. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin.'/' : '';
  1018. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  1019. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  1020. ->get()->all();
  1021. if ($childCategory) {
  1022. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  1023. // 查询子栏目名称
  1024. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  1025. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  1026. ->first();
  1027. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  1028. if(empty($childCategoryInfo)){
  1029. $childImgArticles = [];
  1030. $childTextArticles = [];
  1031. }else{
  1032. // 查询子栏目图片新闻
  1033. $childImgArticles = Article::where('catid', $childCatId)
  1034. ->where('status', 1)
  1035. ->where(function ($query) use ($website) {
  1036. $query->where(function ($subQuery) use ($website) {
  1037. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($website['website_id'])."') = 0");
  1038. })->orWhereNull("ignore_ids");
  1039. })
  1040. ->select(
  1041. 'article.id',
  1042. 'article.title',
  1043. 'article.imgurl',
  1044. 'article.author',
  1045. 'article.updated_at',
  1046. 'article.introduce',
  1047. 'article.islink',
  1048. 'article.linkurl',
  1049. 'article.copyfrom',
  1050. DB::raw("'$child_pinyin' as pinyin"))
  1051. ->where('imgurl', '!=', '')
  1052. ->orderBy('updated_at', 'desc')
  1053. ->limit($childImgNum)
  1054. ->get()->all();
  1055. // 查询子栏目文字新闻
  1056. $childTextArticles = Article::where('catid', $childCatId)
  1057. ->where('status', 1)
  1058. ->where(function ($query) use ($website) {
  1059. $query->where(function ($subQuery) use ($website) {
  1060. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($website['website_id'])."') = 0");
  1061. })->orWhereNull("ignore_ids");
  1062. })
  1063. ->select(
  1064. 'article.id',
  1065. 'article.title',
  1066. 'article.author',
  1067. 'article.updated_at',
  1068. 'article.introduce',
  1069. 'article.islink',
  1070. 'article.linkurl',
  1071. 'article.copyfrom',
  1072. DB::raw("'$child_pinyin' as pinyin"))
  1073. ->orderBy('updated_at', 'desc')
  1074. ->limit($childTextNum)
  1075. ->get()->all();
  1076. }
  1077. $resultItem['child'] = [
  1078. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  1079. 'category_id' => $childCatId,
  1080. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  1081. 'all_childcat' => $childCategory,
  1082. 'imgnum' => $childImgArticles,
  1083. 'textnum' => $childTextArticles,
  1084. ];
  1085. // $resultItem['pinyin'] = $childCategoryInfo->aLIas_pinyin ?? '';
  1086. }
  1087. }
  1088. return $resultItem;
  1089. }, $data);
  1090. return Result::success($result);
  1091. // return Result::success($data);
  1092. }
  1093. /**
  1094. * 乡村网-获取特殊新闻模块
  1095. * @param array $data
  1096. * @return array
  1097. */
  1098. public function getWebsiteArticles(array $data): array
  1099. {
  1100. $input['id'] = $data['id'];
  1101. $input['website_id'] = $data['website_id'];
  1102. $data = json_decode($input['id'], true);
  1103. // 使用 array_map 处理每个元素
  1104. $result = array_map(function ($item) use ($input) {
  1105. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  1106. $website = [
  1107. 'website_id' => $input['website_id']
  1108. ];
  1109. // 查询栏目名称
  1110. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id','aLIas_pinyin']);
  1111. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  1112. if(empty($category)){
  1113. $imgArticles = [];
  1114. $textArticles = [];
  1115. // return Result::error("暂无此栏目",0);
  1116. }else{
  1117. $parent_alias = $category->aLIas_pinyin ? $category->aLIas_pinyin.'/' : null;
  1118. // return Result::success($website);
  1119. // 查询图片新闻
  1120. // 合并查询条件
  1121. $baseQuery = Article::where(function ($query) use ($website) {
  1122. $query->where(function ($subQuery) use ($website) {
  1123. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1124. })->orWhereNull("ignore_ids");
  1125. })
  1126. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($parentCatId) . "')")
  1127. ->leftJoin('website_category', 'website_category.category_id', 'article.catid')
  1128. ->where('website_category.website_id', $website['website_id'])
  1129. ->where('article.status', 1);
  1130. // 查询文字新闻
  1131. $textArticles = clone $baseQuery;
  1132. $textArticles = $textArticles
  1133. ->select(
  1134. 'article.id',
  1135. 'article.title',
  1136. // 'article.imgurl',
  1137. 'article.author',
  1138. 'article.updated_at',
  1139. 'article.introduce',
  1140. 'article.islink',
  1141. 'article.linkurl',
  1142. 'article.copyfrom',
  1143. 'website_category.category_id',
  1144. 'website_category.alias',
  1145. 'website_category.aLIas_pinyin'
  1146. )
  1147. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1148. ->orderBy('article.updated_at', 'desc')
  1149. ->limit($parentTextNum)
  1150. ->get()
  1151. ->all();
  1152. // 查询图片新闻
  1153. $imgArticles = clone $baseQuery;
  1154. $imgArticles = $imgArticles
  1155. ->select(
  1156. 'article.id',
  1157. 'article.title',
  1158. 'article.imgurl',
  1159. 'article.author',
  1160. 'article.updated_at',
  1161. 'article.introduce',
  1162. 'article.islink',
  1163. 'article.linkurl',
  1164. 'article.copyfrom',
  1165. 'website_category.category_id',
  1166. 'website_category.alias',
  1167. 'website_category.aLIas_pinyin'
  1168. )
  1169. ->selectRaw("CONCAT(?, aLIas_pinyin ) as aLIas_pinyin", [$parent_alias])
  1170. ->orderBy('article.updated_at', 'desc')
  1171. ->where('imgurl', '!=', '')
  1172. ->limit($parentImgNum)
  1173. ->get()
  1174. ->all();
  1175. }
  1176. $resultItem = [
  1177. 'alias' => $category ? $category->alias : null,
  1178. 'category_id' => $parentCatId,
  1179. 'pinyin' => $pinyin ? $pinyin : null,
  1180. 'imgnum' => $imgArticles ?? [],
  1181. 'textnum' => $textArticles ?? [],
  1182. ];
  1183. return $resultItem;
  1184. }, $data);
  1185. return Result::success($result);
  1186. }
  1187. /**
  1188. *获取头条类新闻模块-合集
  1189. * @param array $data
  1190. * @return array
  1191. */
  1192. public function getWebsiteAllArticlett(array $data): array
  1193. {
  1194. $input['id'] = $data['id'];
  1195. $input['website_id'] = $data['website_id'];
  1196. $data = json_decode($input['id'], true);
  1197. // 使用 array_map 处理每个元素
  1198. $result = array_map(function ($item) use ($input) {
  1199. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  1200. $website = [
  1201. 'website_id' => $input['website_id']
  1202. ];
  1203. $category = WebsiteCategory::where('website_id', $input['website_id'])->pluck('category_id');
  1204. $category = array_values(array_unique($category->toArray()));
  1205. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  1206. $where = [
  1207. 'status' => 1,
  1208. ];
  1209. return $category;
  1210. }, $data); // 添加第二个参数 $data,确保 array_map 函数有两个参数
  1211. return Result::success($result);
  1212. }
  1213. }