NewsService.php 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243
  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. $where[] = ['status', '=', 1];
  429. if(isset($data['keyword']) && !empty($data['keyword'])){
  430. array_push($where,['article.title','like','%'.$data['keyword'].'%']);
  431. }
  432. if(isset($data['catid']) && !empty($data['catid'])){
  433. if(is_array($data['catid'])){
  434. $category = WebsiteCategory::where('website_id',$data['website_id'])->whereIn('category_id',$data['catid'])->pluck('category_id');
  435. array_push($where,['catid', 'in', $data['catid']]);
  436. }else{
  437. $category = WebsiteCategory::where('website_id',$data['website_id'])->where('category_id',$data['catid'])->pluck('category_id');
  438. array_push($where,['catid', '=', $data['catid']]);
  439. }
  440. if(empty($category)){
  441. return Result::error("此网站暂无此栏目",0);
  442. }
  443. }
  444. // return Result::success($where);
  445. $rep = Article::where(function ($query) use ($where) {
  446. foreach ($where as $condition) {
  447. if ($condition[1] === 'in') {
  448. $query->whereIn($condition[0], $condition[2]);
  449. } else {
  450. $query->where($condition[0], $condition[1], $condition[2]);
  451. }
  452. }
  453. })
  454. ->where(function ($query) use ($data) {
  455. $query->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0")
  456. ->orWhereNull("ignore_ids");
  457. })
  458. ->orderBy("updated_at", "desc")
  459. ->limit($data['pageSize'])
  460. ->offset(($data['page'] - 1) * $data['pageSize'])
  461. ->get();
  462. $count = Article::where(function ($query) use ($where) {
  463. foreach ($where as $condition) {
  464. if ($condition[1] === 'in') {
  465. $query->whereIn($condition[0], $condition[2]);
  466. } else {
  467. $query->where($condition[0], $condition[1], $condition[2]);
  468. }
  469. }
  470. })->count();
  471. $data = [
  472. 'rows'=>$rep->toArray(),
  473. 'count'=>$count
  474. ];
  475. if(empty($rep)){
  476. return Result::error("没有信息数据");
  477. }
  478. return Result::success($data);
  479. }
  480. /**
  481. * 前端-获取新闻详情
  482. * @param array $data
  483. * @return array
  484. */
  485. public function selectWebsiteArticleInfo(array $data): array
  486. {
  487. $where = [
  488. 'article.id'=>$data['id'],
  489. 'article.status'=>1
  490. ];
  491. $result = Article::where($where)->leftJoin("article_data","article.id","article_data.article_id")
  492. ->where(function ($query) use ($data) {
  493. $query->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0")
  494. ->orWhereNull("ignore_ids");
  495. })
  496. ->first();
  497. if(empty($result)){
  498. return Result::error("暂无此新闻!",0);
  499. }
  500. $category = WebsiteCategory::where('website_id',$data['website_id'])->where(['category_id'=>$result['catid']])->first();
  501. if(empty($category)){
  502. return Result::error("查询失败",0);
  503. }
  504. $result['category_id'] = $category['category_id'];
  505. $result['cat_name'] = $category['alias'];
  506. return Result::success($result);
  507. }
  508. /**
  509. * 前端-获取网站调查问卷
  510. * @param array $data
  511. * @return array
  512. */
  513. public function getWebsiteSurvey(array $data): array
  514. {
  515. if(isset($data['website_id']) && !empty($data['website_id'])){
  516. $website = Website::where('id',$data['website_id'])->first();
  517. if(empty($website)){
  518. return Result::error("暂无此网站",0);
  519. }
  520. }
  521. if(isset($data['art_id']) && !empty($data['art_id'])){
  522. $article = Article::where('id',$data['art_id'])->where('status',1)->first();
  523. if(empty($article)){
  524. return Result::error("暂无此文章",0);
  525. }
  526. // return Result::error($data,0);
  527. $where['art_id'] = $data['art_id'];
  528. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  529. }else{
  530. $survey = Article::where(function ($query) {
  531. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  532. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  533. })
  534. ->where('status',1)
  535. ->where('is_survey',1)
  536. ->select('survey_id')
  537. ->orderBy('updated_at','desc')
  538. ->first();
  539. if(empty($survey)){
  540. return Result::error("暂无调查问卷",0);
  541. }
  542. $where['sur_id'] = $survey['survey_id'];
  543. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  544. }
  545. // return Result::success($where);
  546. $result = ArticleSurvey::where($where)
  547. ->where(function ($query) {
  548. $query->where('is_other', 0)
  549. ->orWhere(function ($subQuery) {
  550. $subQuery->where('is_other', 1)
  551. ->where('other_id', 0);
  552. });
  553. })
  554. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  555. ->select('article_survey.*', 'article.survey_type')
  556. ->get()->all();
  557. if(empty($result)){
  558. return Result::error("此文章暂无调查问卷",0);
  559. }
  560. return Result::success($result);
  561. }
  562. /**
  563. * 前端-添加网站调查问卷选项
  564. * @param array $data
  565. * @return array
  566. */
  567. public function addWebsiteSurveyOption(array $data): array
  568. {
  569. if(isset($data['website_id']) && !empty($data['website_id'])){
  570. $website = Website::where('id',$data['website_id'])->first();
  571. if(empty($website)){
  572. return Result::error("暂无此网站",0);
  573. }
  574. if(isset($data['sur_id']) && !empty($data['sur_id'])){
  575. $survey = ArticleSurvey::where('sur_id',$data['sur_id'])->where('website_id',$data['website_id'])->where('is_other',1)->where('other_id',0)->first();
  576. if(empty($survey)){
  577. return Result::error("此调查问卷不可添加选项",0);
  578. }
  579. if(isset($data['choice_name']) &&!empty($data['choice_name'])){
  580. $choice = [
  581. 'art_id'=>$survey['art_id'],
  582. 'website_id'=>$data['website_id'],
  583. 'survey_name'=>$survey['survey_name'],
  584. 'choice_name'=>$data['choice_name'],
  585. 'sur_id'=>$survey['sur_id'],
  586. 'is_other'=>1,
  587. 'other_id'=>$survey['id'],
  588. ];
  589. $result = ArticleSurvey::insertGetId($choice);
  590. if(empty($result)){
  591. return Result::error("添加失败",0);
  592. }
  593. return Result::success($result);
  594. }
  595. }
  596. return Result::error("添加失败",0);
  597. }
  598. return Result::error("添加失败",0);
  599. }
  600. /**
  601. * 前端-调查问卷投票
  602. * @param array $data
  603. * @return array
  604. */
  605. public function addWebsiteSurveyVote(array $data): array
  606. {
  607. // return Result::success($data);
  608. if(isset($data['website_id']) && !empty($data['website_id'])){
  609. $website = Website::where('id',$data['website_id'])->first();
  610. if(empty($website)){
  611. return Result::error("暂无此网站",0);
  612. }
  613. if(isset($data['sur_id']) && !empty($data['sur_id'])){
  614. $is_survey = ArticleSurvey::where('sur_id',$data['sur_id'])->first();
  615. // return Result::success($survey);
  616. if(empty($is_survey)){
  617. return Result::error("此调查问卷不存在",0);
  618. }
  619. // return Result::success($survey);
  620. // 调查问卷类型
  621. if(isset($data['choice_id']) &&!empty($data['choice_id'])){
  622. //多选 若是json型则转化成数组类型
  623. if (strpos($data['choice_id'], '[') === 0) {
  624. $data['choice_id'] = json_decode($data['choice_id'], true);
  625. } else {
  626. // 单选 也转换成数组
  627. $data['choice_id'] = [$data['choice_id']];
  628. }
  629. $data['choice_id'] = array_map('intval', $data['choice_id']);
  630. $other = ArticleSurvey::whereIn('id',$data['choice_id'])
  631. ->where('website_id',$data['website_id'])
  632. ->where('is_other',1)
  633. ->where('other_id',0)
  634. ->first();
  635. if(!empty($other)){
  636. return Result::error("请选择已有的选项!",0);
  637. }
  638. $choice['other'] = ArticleSurvey::whereIn('id',$data['choice_id'])
  639. ->where('website_id',$data['website_id'])
  640. ->where('is_other',1)
  641. ->where('other_id','!=',0)
  642. ->first();
  643. // return Result::success($choice['other']);
  644. $choice_id = $data['choice_id'];
  645. if(!empty($choice['other'])){
  646. // array_push($data['choice_id'],$choice['other']['other_id']);
  647. if(!empty($choice_id)){
  648. $key = array_search($choice['other']['id'], $choice_id);
  649. if ($key!== false) {
  650. unset($choice_id[$key]);
  651. $choice_id = array_values($choice_id);
  652. }
  653. array_push($choice_id,$choice['other']['other_id']);
  654. }else{
  655. $choice_id[0] = $choice['other']['other_id'];
  656. }
  657. array_push($data['choice_id'],$choice['other']['other_id']);
  658. }
  659. // return Result::success($data);
  660. $choice = ArticleSurvey::whereIn('id',$data['choice_id'])
  661. ->where('website_id',$data['website_id'])
  662. ->increment('results', 1);
  663. if(empty($choice)){
  664. return Result::error("请选择已有的选项!",0);
  665. }
  666. $survey['data'] = ArticleSurvey::where('sur_id',$data['sur_id'])
  667. ->where('website_id',$data['website_id'])
  668. ->where('other_id', 0)
  669. ->get();
  670. $survey['choice'] = $choice_id;
  671. return Result::success($survey);
  672. }
  673. return Result::error("参数必填!");
  674. }
  675. return Result::error("此调查问卷不存在",0);
  676. }
  677. return Result::error("参数必填!");
  678. }
  679. /**
  680. * 后端-获取网站调查问卷列表
  681. * @param array $data
  682. * @return array
  683. */
  684. public function getSurveyList(array $data): array
  685. {
  686. $where = [];
  687. if(isset($data['survey_name']) &&!empty($data['survey_name'])){
  688. array_push($where,['survey_name','like','%'.$data['survey_name'].'%']);
  689. }
  690. if(isset($data['survey_type']) && $data['survey_type'] != null){
  691. array_push($where,['survey_type','=',$data['survey_type']]);
  692. }
  693. if(isset($data['is_survey']) && $data['is_survey'] != null){
  694. array_push($where,['is_survey','=',$data['is_survey']]);
  695. }
  696. // return Result::success($where);
  697. if (!empty($where)) {
  698. $query = Article::where($where)->where(function ($q) {
  699. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  700. });
  701. } else {
  702. $query = Article::where(function ($q) {
  703. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  704. });
  705. }
  706. $count = $query->count();
  707. $survey = $query->orderByDesc('id')
  708. ->limit($data['pageSize'])
  709. ->offset(($data['page']-1)*$data['pageSize'])
  710. ->get();
  711. if(empty($survey->toArray())){
  712. return Result::error("暂无调查问卷!",0);
  713. }
  714. $result = [
  715. 'rows'=>$survey,
  716. 'count'=>$count
  717. ];
  718. return Result::success($result);
  719. }
  720. /**
  721. * 后端-获取网站调查问卷详情
  722. * @param array $data
  723. * @return array
  724. */
  725. public function getSurveyInfo(array $data): array
  726. {
  727. if(isset($data['sur_id']) &&!empty($data['sur_id'])){
  728. $where = [ 'sur_id'=>$data['sur_id']];
  729. $choose = ArticleSurvey::where($where)->where('is_other',0)
  730. ->leftJoin('article','article_survey.art_id','article.id')
  731. ->select('article_survey.*','article.survey_type')
  732. ->get()->all();
  733. if(empty($choose)){
  734. return Result::error("此调查问卷不存在",0);
  735. }
  736. $resultsArray = array_column($choose, 'results');
  737. $total = array_sum($resultsArray);
  738. $other = ArticleSurvey::where($where)->where('is_other',1)->where('other_id',0)->first();
  739. $others = ArticleSurvey::where($where)->where('is_other',1)->where('other_id','!=',0)->orderByDesc('created_at')->get()->all();
  740. // $total = 0;
  741. if(!empty($other)){
  742. $total = $total + $other['results'];
  743. $other['choice_name'] ='(其他)';
  744. if(!empty($others)){
  745. $other['hasChildren'] = true;
  746. // array_push($other,['hasChildren','=',true]);
  747. $other['children'] = $others;
  748. $other_choices = [$other->toArray()];
  749. $mer_choice = array_merge($choose,$other_choices);
  750. $value_choice = array_values($mer_choice);
  751. }
  752. else{
  753. // return Result::error('1111');
  754. $other_choices = [$other->toArray()];
  755. $other_choices = array_merge($choose,$other_choices);
  756. $value_choice = array_values($other_choices);
  757. // return Result::success($result);
  758. }
  759. }else{
  760. $value_choice = $choose;
  761. }
  762. $result = [
  763. 'choose'=>$value_choice,
  764. 'total'=>$total
  765. ];
  766. }
  767. return Result::success($result);
  768. }
  769. /**
  770. * 前端-搜索新闻列表
  771. * @param array $data
  772. * @return array
  773. */
  774. public function selectWebsiteArticle(array $data): array
  775. {
  776. $where = [];
  777. // 初始化查询构造器
  778. $category = WebsiteCategory::where('website_id',$data['website_id'])->pluck('category_id');
  779. $query = Article::where('status', 1)
  780. ->whereIn('catid', $category)
  781. ->where(function ($query) use ($data) {
  782. $query->where(function ($subQuery) use ($data) {
  783. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0");
  784. })->orWhereNull("ignore_ids");
  785. });
  786. // return Result::success($all_articles);
  787. // 检查是否存在 cityid 参数
  788. if (isset($data['cityid']) && !empty($data['cityid'])) {
  789. $query->whereRaw("JSON_CONTAINS(city_arr_id, '".intval($data['cityid'])."')");
  790. }
  791. // 检查是否存在 department_id 参数
  792. if (isset($data['department_id']) && !empty($data['department_id'])) {
  793. $query->whereRaw("JSON_CONTAINS(department_arr_id, '".intval($data['department_id'])."')");
  794. }
  795. // 检查是否存在 keyword 参数
  796. if (isset($data['keyword']) && !empty($data['keyword'])) {
  797. $query->where('title', 'like', '%'.$data['keyword'].'%');
  798. }
  799. // 计算总数
  800. $count = $query->count();
  801. // 分页查询
  802. $articles = $query->orderBy("updated_at", "desc")
  803. ->limit($data['pageSize'])
  804. ->offset(($data['page'] - 1) * $data['pageSize'])
  805. ->get()->all();
  806. if (empty($articles)) {
  807. return Result::error("没有符合条件的资讯数据");
  808. }
  809. $data = [
  810. 'rows' => $articles,
  811. 'count' => $count
  812. ];
  813. return Result::success($data);
  814. }
  815. /**
  816. * 模块新闻加强版
  817. * @param array $data
  818. * @return array
  819. */
  820. public function getWebsiteCatidArticle(array $data): array
  821. {
  822. // return Result::success($data);
  823. $where = [
  824. // 'category.status' => 1,
  825. 'website_category.category_id' => $data['catid'],
  826. 'website_category.website_id' => $data['website_id'],
  827. // 'article.status' => 1,
  828. ];
  829. // $category = WebsiteCategory::where($where);
  830. if(isset($data['child_catnum']) && !empty($data['child_catnum'])){
  831. $child_catnum = $data['child_catnum']?? 1;
  832. $category['child'] = WebsiteCategory::where('pid',$data['catid'])->where('website_id',$data['website_id'])->select('category_id','alias')->limit($child_catnum)->get()->toArray();
  833. $childCategoryIds = array_column($category['child'], 'category_id');
  834. if(empty($childCategoryIds)){
  835. return Result::error("暂无子栏目",0);
  836. }
  837. $imgArticles = [];
  838. $textArticles = [];
  839. // return Result::success($childCategoryIds);
  840. if(isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum']!=0){
  841. // 初始化子分类图片新闻和文字新闻数组
  842. // 查询所有子级栏目的图文新闻
  843. $imgArticles = Article::where('catid', $childCategoryIds[0])
  844. ->where(function ($query) use ($data) {
  845. $query->where(function ($subQuery) use ($data) {
  846. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0");
  847. })->orWhereNull("ignore_ids");
  848. })
  849. ->where('status', 1)
  850. ->where('imgurl', '!=', '')
  851. ->select('*')
  852. ->orderBy('updated_at', 'desc')
  853. ->limit($data['child_imgnum'])
  854. ->get();
  855. }
  856. if( isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum']!=0){
  857. // 查询所有子级栏目的文字新闻
  858. $textArticles = Article::where('catid', $childCategoryIds[0])
  859. ->where('status', 1)
  860. ->where(function ($query) use ($data) {
  861. $query->where(function ($subQuery) use ($data) {
  862. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0");
  863. })->orWhereNull("ignore_ids");
  864. })
  865. // ->where(function ($query) {
  866. // $query->whereNull('imgurl')
  867. // ->orWhere('imgurl', '');
  868. // })
  869. ->select('*')
  870. ->orderBy('updated_at', 'desc')
  871. ->limit($data['child_textnum'])
  872. ->get();
  873. }
  874. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  875. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  876. $child['img'] = $imgArticles? $imgArticles->where('catid', $child['category_id']) : [];
  877. $child['text'] = $textArticles? $textArticles->where('catid', $child['category_id']) : [];
  878. return $child;
  879. }, $category['child']);
  880. }
  881. // }
  882. if (isset($data['img_num']) && !empty($data['img_num'])) {
  883. $category['img'] = WebsiteCategory::where($where)
  884. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  885. ->where('article.status', 1)
  886. ->where('article.imgurl', '!=', '')
  887. ->select('article.*','website_category.category_id','website_category.alias')
  888. ->orderBy('article.updated_at', 'desc')
  889. ->limit($data['img_num'])
  890. ->get();
  891. }
  892. if (isset($data['text_num']) && !empty($data['text_num'])) {
  893. $category['text'] = WebsiteCategory::where($where)
  894. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  895. ->where('article.status', 1)
  896. // ->where(function ($query) {
  897. // $query->whereNull('article.imgurl')
  898. // ->orWhere('article.imgurl', '');
  899. // })
  900. ->select('article.*','website_category.category_id','website_category.alias')
  901. ->orderBy('article.updated_at', 'desc')
  902. ->limit($data['text_num'])
  903. ->get();
  904. }
  905. // $category = $category->get();
  906. if(empty($category)){
  907. return Result::error("查询失败", 0);
  908. }
  909. return Result::success($category);
  910. }
  911. /**
  912. * 模块新闻加强plus版
  913. * @param array $data
  914. * @return array
  915. */
  916. public function getWebsiteAllArticle(array $data): array
  917. {
  918. // 修正传入的字符串,将单引号替换为双引号
  919. $input['id'] = $data['id'];
  920. $input['website_id'] = $data['website_id'];
  921. // 将 JSON 字符串转换为 PHP 数组
  922. $data = json_decode($input['id'], true);
  923. // 使用 array_map 处理每个元素
  924. $result = array_map(function ($item) use ($input) {
  925. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  926. $website = [
  927. 'website_id' => $input['website_id'],
  928. ];
  929. // 查询栏目名称
  930. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id','aLIas_pinyin']);
  931. if(empty($category)){
  932. $imgArticles = [];
  933. $textArticles = [];
  934. // return Result::error("暂无此栏目",0);
  935. }else{
  936. $parent_alias = $category->alias ?? '';
  937. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  938. // 查询图片新闻
  939. $imgArticles = Article::where('catid', $parentCatId)
  940. ->where('status', 1)
  941. ->where(function ($query) use ($website) {
  942. $query->where(function ($subQuery) use ($website) {
  943. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($website['website_id'])."') = 0");
  944. })->orWhereNull("ignore_ids");
  945. })
  946. ->where('imgurl', '!=', '')
  947. ->select(
  948. 'article.id',
  949. 'article.title',
  950. 'article.imgurl',
  951. 'article.author',
  952. 'article.updated_at',
  953. 'article.introduce',
  954. 'article.islink',
  955. 'article.linkurl',
  956. 'article.copyfrom',
  957. DB::raw("'$parent_pinyin' as pinyin") // 添加 pinyin 字段
  958. )
  959. ->orderBy('updated_at', 'desc')
  960. ->limit($parentImgNum)
  961. ->get()->all();
  962. // 查询文字新闻
  963. $textArticles = Article::where('catid', $parentCatId)
  964. ->where('status', 1)
  965. ->where(function ($query) use ($website) {
  966. $query->where(function ($subQuery) use ($website) {
  967. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($website['website_id'])."') = 0");
  968. })->orWhereNull("ignore_ids");
  969. })
  970. ->select(
  971. 'article.id',
  972. 'article.title',
  973. 'article.author',
  974. 'article.updated_at',
  975. 'article.introduce',
  976. 'article.islink',
  977. 'article.linkurl',
  978. 'article.copyfrom',
  979. DB::raw("'$parent_pinyin' as pinyin"))
  980. ->orderBy('updated_at', 'desc')
  981. ->limit($parentTextNum)
  982. ->get()->all();
  983. }
  984. $resultItem = [
  985. 'alias' => $parent_alias,
  986. 'category_id' => $parentCatId,
  987. 'pinyin' => $parent_pinyin,
  988. 'imgnum' => $imgArticles,
  989. 'textnum' => $textArticles,
  990. ];
  991. if (!empty($item['child']) && $item['child'] != "") {
  992. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin.'/' : '';
  993. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  994. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  995. ->get()->all();
  996. if ($childCategory) {
  997. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  998. // 查询子栏目名称
  999. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  1000. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  1001. ->first();
  1002. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  1003. if(empty($childCategoryInfo)){
  1004. $childImgArticles = [];
  1005. $childTextArticles = [];
  1006. }else{
  1007. // 查询子栏目图片新闻
  1008. $childImgArticles = Article::where('catid', $childCatId)
  1009. ->where('status', 1)
  1010. ->where(function ($query) use ($website) {
  1011. $query->where(function ($subQuery) use ($website) {
  1012. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($website['website_id'])."') = 0");
  1013. })->orWhereNull("ignore_ids");
  1014. })
  1015. ->select(
  1016. 'article.id',
  1017. 'article.title',
  1018. 'article.imgurl',
  1019. 'article.author',
  1020. 'article.updated_at',
  1021. 'article.introduce',
  1022. 'article.islink',
  1023. 'article.linkurl',
  1024. 'article.copyfrom',
  1025. DB::raw("'$child_pinyin' as pinyin"))
  1026. ->where('imgurl', '!=', '')
  1027. ->orderBy('updated_at', 'desc')
  1028. ->limit($childImgNum)
  1029. ->get()->all();
  1030. // 查询子栏目文字新闻
  1031. $childTextArticles = Article::where('catid', $childCatId)
  1032. ->where('status', 1)
  1033. ->where(function ($query) use ($website) {
  1034. $query->where(function ($subQuery) use ($website) {
  1035. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($website['website_id'])."') = 0");
  1036. })->orWhereNull("ignore_ids");
  1037. })
  1038. ->select(
  1039. 'article.id',
  1040. 'article.title',
  1041. 'article.author',
  1042. 'article.updated_at',
  1043. 'article.introduce',
  1044. 'article.islink',
  1045. 'article.linkurl',
  1046. 'article.copyfrom',
  1047. DB::raw("'$child_pinyin' as pinyin"))
  1048. ->orderBy('updated_at', 'desc')
  1049. ->limit($childTextNum)
  1050. ->get()->all();
  1051. }
  1052. $resultItem['child'] = [
  1053. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  1054. 'category_id' => $childCatId,
  1055. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  1056. 'all_childcat' => $childCategory,
  1057. 'imgnum' => $childImgArticles,
  1058. 'textnum' => $childTextArticles,
  1059. ];
  1060. // $resultItem['pinyin'] = $childCategoryInfo->aLIas_pinyin ?? '';
  1061. }
  1062. }
  1063. return $resultItem;
  1064. }, $data);
  1065. return Result::success($result);
  1066. // return Result::success($data);
  1067. }
  1068. /**
  1069. * 乡村网-获取特殊新闻模块
  1070. * @param array $data
  1071. * @return array
  1072. */
  1073. public function getWebsiteArticles(array $data): array
  1074. {
  1075. $input['id'] = $data['id'];
  1076. $input['website_id'] = $data['website_id'];
  1077. $data = json_decode($input['id'], true);
  1078. // 使用 array_map 处理每个元素
  1079. $result = array_map(function ($item) use ($input) {
  1080. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  1081. $website = [
  1082. 'website_id' => $input['website_id']
  1083. ];
  1084. // 查询栏目名称
  1085. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id','aLIas_pinyin']);
  1086. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  1087. if(empty($category)){
  1088. $imgArticles = [];
  1089. $textArticles = [];
  1090. // return Result::error("暂无此栏目",0);
  1091. }else{
  1092. $parent_alias = $category->aLIas_pinyin ? $category->aLIas_pinyin.'/' : null;
  1093. // return Result::success($website);
  1094. // 查询图片新闻
  1095. // 合并查询条件
  1096. $baseQuery = Article::where(function ($query) use ($website) {
  1097. $query->where(function ($subQuery) use ($website) {
  1098. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1099. })->orWhereNull("ignore_ids");
  1100. })
  1101. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($parentCatId) . "')")
  1102. ->leftJoin('website_category', 'website_category.category_id', 'article.catid')
  1103. ->where('website_category.website_id', $website['website_id'])
  1104. ->where('article.status', 1);
  1105. // 查询文字新闻
  1106. $textArticles = clone $baseQuery;
  1107. $textArticles = $textArticles
  1108. ->select(
  1109. 'article.id',
  1110. 'article.title',
  1111. // 'article.imgurl',
  1112. 'article.author',
  1113. 'article.updated_at',
  1114. 'article.introduce',
  1115. 'article.islink',
  1116. 'article.linkurl',
  1117. 'article.copyfrom',
  1118. 'website_category.category_id',
  1119. 'website_category.alias',
  1120. 'website_category.aLIas_pinyin'
  1121. )
  1122. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1123. ->orderBy('article.updated_at', 'desc')
  1124. ->limit($parentTextNum)
  1125. ->get()
  1126. ->all();
  1127. // 查询图片新闻
  1128. $imgArticles = clone $baseQuery;
  1129. $imgArticles = $imgArticles
  1130. ->select(
  1131. 'article.id',
  1132. 'article.title',
  1133. 'article.imgurl',
  1134. 'article.author',
  1135. 'article.updated_at',
  1136. 'article.introduce',
  1137. 'article.islink',
  1138. 'article.linkurl',
  1139. 'article.copyfrom',
  1140. 'website_category.category_id',
  1141. 'website_category.alias',
  1142. 'website_category.aLIas_pinyin'
  1143. )
  1144. ->selectRaw("CONCAT(?, aLIas_pinyin ) as aLIas_pinyin", [$parent_alias])
  1145. ->orderBy('article.updated_at', 'desc')
  1146. ->where('imgurl', '!=', '')
  1147. ->limit($parentImgNum)
  1148. ->get()
  1149. ->all();
  1150. }
  1151. $resultItem = [
  1152. 'alias' => $category ? $category->alias : null,
  1153. 'category_id' => $parentCatId,
  1154. 'pinyin' => $pinyin ? $pinyin : null,
  1155. 'imgnum' => $imgArticles ?? [],
  1156. 'textnum' => $textArticles ?? [],
  1157. ];
  1158. return $resultItem;
  1159. }, $data);
  1160. return Result::success($result);
  1161. }
  1162. /**
  1163. *获取头条类新闻模块-合集
  1164. * @param array $data
  1165. * @return array
  1166. */
  1167. public function getWebsiteAllArticlett(array $data): array
  1168. {
  1169. $input['id'] = $data['id'];
  1170. $input['website_id'] = $data['website_id'];
  1171. $data = json_decode($input['id'], true);
  1172. // 使用 array_map 处理每个元素
  1173. $result = array_map(function ($item) use ($input) {
  1174. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  1175. $website = [
  1176. 'website_id' => $input['website_id']
  1177. ];
  1178. $category = WebsiteCategory::where('website_id', $input['website_id'])->pluck('category_id');
  1179. $category = array_values(array_unique($category->toArray()));
  1180. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  1181. $where = [
  1182. 'status' => 1,
  1183. ];
  1184. return $category;
  1185. }, $data); // 添加第二个参数 $data,确保 array_map 函数有两个参数
  1186. return Result::success($result);
  1187. }
  1188. }