NewsService.php 76 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887
  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\WebsiteCategory;
  7. use App\Model\ArticleSurvey;
  8. use App\Model\jobHunting;
  9. use App\Model\JobEnum;
  10. use App\Model\JobIndustry;
  11. use App\Model\JobPosition;
  12. use App\Model\JobRecruiting;
  13. use App\Model\Good;
  14. use App\Model\JobNature;
  15. use App\Model\Website;
  16. use Hyperf\DbConnection\Db;
  17. use Hyperf\RpcServer\Annotation\RpcService;
  18. use App\Tools\Result;
  19. use Ramsey\Uuid\Uuid;
  20. use Hyperf\Utils\Random;
  21. use Fukuball\Jieba\Jieba;
  22. use Fukuball\Jieba\Finalseg;
  23. use App\Model\ChatRecords;
  24. use Hyperf\Utils\Collection;
  25. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  26. class NewsService implements NewsServiceInterface
  27. {
  28. /**
  29. * 获取导航池列表
  30. * @param array $data
  31. * @return array
  32. */
  33. public function getCategoryList(array $data): array
  34. {
  35. $page = (int) $data['page'] ?? 1;
  36. $perPage = (int) $data['pageSize'] ?? 10;
  37. $search = $data['name'] ?? '';
  38. // 查找所有匹配的分类
  39. $matchedCategories = $this->findMatchedCategories($search);
  40. // 查找所有匹配分类的父级分类
  41. $allRequiredCategories = $this->findAllParents($matchedCategories);
  42. // 提取一级分类
  43. $topLevelCategories = [];
  44. foreach ($allRequiredCategories as $category) {
  45. if ($category->pid === 0) {
  46. $topLevelCategories[] = $category;
  47. }
  48. }
  49. // 分页处理
  50. $offset = ($page - 1) * $perPage;
  51. $paginatedTopLevelCategories = array_slice($topLevelCategories, $offset, $perPage);
  52. $categoryTree = [];
  53. foreach ($paginatedTopLevelCategories as $category) {
  54. $categoryTree[] = $this->buildCategoryTree($category, $allRequiredCategories);
  55. }
  56. $return = [
  57. 'rows' => $categoryTree,
  58. 'total' => count($topLevelCategories),
  59. ];
  60. return Result::success($return);
  61. }
  62. private function findMatchedCategories($search)
  63. {
  64. if ($search) {
  65. return Category::where('name', 'like', "%{$search}%")
  66. ->orderBy('updated_at', 'desc')
  67. ->get();
  68. }
  69. return Category::orderBy('updated_at', 'desc') // 按 updated_at 字段倒序排序
  70. ->get();
  71. }
  72. private function findAllParents($categories)
  73. {
  74. $allCategories = [];
  75. foreach ($categories as $category) {
  76. $parentId = $category->pid;
  77. while ($parentId > 0) {
  78. $parent = Category::find($parentId);
  79. if ($parent) {
  80. $allCategories[$parent->id] = $parent;
  81. $parentId = $parent->pid;
  82. } else {
  83. break;
  84. }
  85. }
  86. $allCategories[$category->id] = $category;
  87. }
  88. return array_values($allCategories);
  89. }
  90. private function buildCategoryTree($category, $allRequiredCategories)
  91. {
  92. $categoryData = $category->toArray();
  93. $children = [];
  94. foreach ($allRequiredCategories as $c) {
  95. if ($c->pid === $category->id) {
  96. $children[] = $this->buildCategoryTree($c, $allRequiredCategories);
  97. }
  98. }
  99. if (!empty($children)) {
  100. $categoryData['children'] = $children;
  101. }
  102. return $categoryData;
  103. }
  104. public function myCategoryList(array $data): array
  105. {
  106. $sszq = $data['sszq'] ?? '';
  107. unset($data['sszq']);
  108. //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
  109. $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
  110. $where[] = [
  111. 'pid', '=', $data['pid'],
  112. ];
  113. if (isset($data['name'])) {
  114. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  115. }
  116. var_dump($where);
  117. //根据分类id,从category表中取出分类信息
  118. $result = Category::where($where)
  119. ->whereIn('category.id', $catorytids)
  120. ->select('category.*', 'category.id as category_id')->get();
  121. if (empty($result)) {
  122. return Result::error("没有栏目数据");
  123. }
  124. return Result::success($result);
  125. }
  126. /**
  127. * @param array $data
  128. * @return array
  129. */
  130. public function categoryList(array $data): array
  131. {
  132. $where[] = [
  133. 'pid', '=', $data['pid'],
  134. ];
  135. if (isset($data['name'])) {
  136. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  137. }
  138. var_dump($where);
  139. $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
  140. if (empty($result)) {
  141. return Result::error("没有栏目数据");
  142. }
  143. return Result::success($result);
  144. }
  145. /**
  146. * @param array $data
  147. * @return array
  148. */
  149. public function addCategory(array $data): array
  150. {
  151. if (isset($data['id'])) {
  152. unset($data['id']);
  153. }
  154. $id = Category::insertGetId($data);
  155. if (empty($id)) {
  156. return Result::error("添加失败");
  157. }
  158. return Result::success(['id' => $id]);
  159. }
  160. /**
  161. * @param array $data
  162. * @return array
  163. */
  164. public function delCategory(array $data): array
  165. {
  166. Db::beginTransaction();
  167. try {
  168. $categoryList = Category::where(['pid' => $data['id']])->get();
  169. if ($categoryList->toArray()) {
  170. Db::rollBack();
  171. return Result::error("分类下面有子分类不能删除");
  172. }
  173. $articleList = Article::where(['catid' => $data['id']])->get();
  174. if ($articleList->toArray()) {
  175. Db::rollBack();
  176. return Result::error("分类下面有资讯不能删除");
  177. }
  178. $result = Category::where($data)->delete();
  179. WebsiteCategory::where(['category_id' => $data['id']])->delete();
  180. if (!$result) {
  181. return Result::error("删除失败");
  182. }
  183. return Result::success($result);
  184. Db::commit();
  185. }catch (\Exception $e){
  186. Db::rollBack();
  187. return Result::error("删除失败");
  188. }
  189. }
  190. /**
  191. * @param array $data
  192. * @return array
  193. */
  194. public function updateCategory(array $data): array
  195. {
  196. $where = [
  197. 'id' => $data['id'],
  198. ];
  199. $result = Category::where($where)->update($data);
  200. if ($result) {
  201. return Result::success($result);
  202. } else {
  203. return Result::error("更新失败");
  204. }
  205. }
  206. /**
  207. * 获取导航池信息
  208. * @param array $data
  209. * @return array
  210. */
  211. public function getCategoryInfo(array $data): array
  212. {
  213. $where = [
  214. 'id' => $data['id'],
  215. ];
  216. $result = Category::where($where)->first();
  217. if ($result) {
  218. return Result::success($result);
  219. } else {
  220. return Result::error("更新失败");
  221. }
  222. }
  223. /**
  224. * @param array $data
  225. * @return array
  226. */
  227. public function getArticleList(array $data): array
  228. {
  229. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  230. $type_id = $data['type_id'];
  231. unset($data['type_id']);
  232. $user_id = $data['user_id'];
  233. unset($data['user_id']);
  234. $where = [];
  235. $status1 = [];
  236. if (isset($data['id']) && $data['id']) {
  237. array_push($where, ['article.id', '=', $data['id']]);
  238. }
  239. if (isset($data['title']) && $data['title']) {
  240. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  241. }
  242. if (isset($data['category_name']) && $data['category_name']) {
  243. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  244. }
  245. if (isset($data['author']) && $data['author']) {
  246. array_push($where, ['article.author', '=', $data['author']]);
  247. }
  248. if (isset($data['islink']) && $data['islink'] !== "") {
  249. array_push($where, ['article.islink', '=', $data['islink']]);
  250. }
  251. if (isset($data['status']) && $data['status'] !== "") {
  252. array_push($where, ['article.status', '=', $data['status']]);
  253. }
  254. if (isset($data['status1'])) {
  255. $status1 = json_decode(($data['status1']));
  256. }
  257. //不是管理员展示个人数据;
  258. if ($type_id != 10000) {
  259. $where[] = ['article.admin_user_id', '=', $user_id];
  260. }
  261. $rep = Article::where($where)
  262. ->whereNotIn('article.status', [404])
  263. ->when($status1, function ($query) use ($status1) {
  264. if (isset($status1) && $status1) {
  265. $query->whereIn('article.status', $status1);
  266. }
  267. })
  268. ->leftJoin('category', 'article.catid', 'category.id')
  269. ->select("article.*", "category.name as category_name")
  270. ->orderBy("article.updated_at", "desc")
  271. ->limit($data['pageSize'])
  272. ->offset(($data['page'] - 1) * $data['pageSize'])->get();
  273. $count = Article::where($where)->whereNotIn('article.status', [404])
  274. ->when($status1, function ($query) use ($status1) {
  275. if (isset($status1) && $status1) {
  276. $query->whereIn('article.status', $status1);
  277. }
  278. })
  279. ->leftJoin('category', 'article.catid', 'category.id')->count();
  280. $data = [
  281. 'rows' => $rep->toArray(),
  282. 'count' => $count,
  283. ];
  284. if (empty($rep)) {
  285. return Result::error("没有信息数据");
  286. }
  287. return Result::success($data);
  288. }
  289. /**
  290. * @param array $data
  291. * @return array
  292. */
  293. public function addArticle(array $data): array
  294. {
  295. var_dump($data, '----------12-----------1');
  296. unset($data['user_type']);
  297. unset($data['nav_add_pool_id']);
  298. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  299. Db::beginTransaction();
  300. try {
  301. //处理投票
  302. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  303. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  304. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  305. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  306. unset($data['is_survey']);
  307. unset($data['survey_name']);
  308. unset($data['suvey_array']);
  309. // unset($data['website_id']);
  310. // unset($data['web_site_id']);
  311. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  312. if ($data['hits'] == '') {
  313. $data['hits'] = 0;
  314. }
  315. if ($data['is_original'] == '') {
  316. $data['is_original'] = 0;
  317. }
  318. if ($data['status'] == '') {
  319. $data['status'] = 0;
  320. }
  321. $articleData = $data;
  322. unset($articleData['content']);
  323. //自动处理缩略图、关键字、描述
  324. if ($articleData['imgurl'] == '') {
  325. //如果没有图,设置level=0
  326. $levelArr = json_decode($articleData['level'], true);
  327. var_dump($levelArr, '----------levelArr-----------1');
  328. //content中提取图片第一个图,正则提取
  329. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  330. preg_match_all($reg, $data['content'], $matches);
  331. if (isset($matches[1][0])) {
  332. //截取varchar240
  333. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  334. //如果有图,设置level=3
  335. if (!in_array(3, $levelArr)) {$levelArr[] = 3;}
  336. $articleData['level'] = json_encode($levelArr);
  337. } else {
  338. if (!in_array(0, $levelArr)) {
  339. $levelArr[] = 0;
  340. }
  341. $articleData['level'] = json_encode($levelArr);
  342. }
  343. }
  344. var_dump($articleData['level'], '----------$articleData[level]----------1');
  345. if ($articleData['keyword'] == '') {
  346. //提取标题+内容中的关键词
  347. $articleData['keyword'] = $data['title'];
  348. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  349. Jieba::init(); // 初始化 jieba-php
  350. Finalseg::init();
  351. $segList = Jieba::cut($articleData['keyword']);
  352. $segList1 = array_slice($segList, 0, 8);
  353. $articleData['keyword'] = implode(',', $segList1);
  354. }
  355. if ($articleData['introduce'] == '') {
  356. //提取内容中的描述
  357. $articleData['introduce'] = substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
  358. }
  359. $id = Article::insertGetId($articleData);
  360. $articleDataContent = [
  361. 'article_id' => $id,
  362. 'content' => $data['content'],
  363. ];
  364. ArticleData::insertGetId($articleDataContent);
  365. //处理投票
  366. if ($is_survey == 1) {
  367. //生成年月日时分秒+8位随机数
  368. $uuid = date('YmdHis') . rand(10000000, 99999999);
  369. var_dump($suvey_array, 'suvey_array________');
  370. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  371. var_dump($suveys_array, '---------------------1');
  372. var_dump($suvey_array, '---------------------2');
  373. $suvey_data = [];
  374. foreach ($suveys_array as $key => $value) {
  375. if ($value == '') {
  376. continue;
  377. }
  378. if (is_array($value)) {
  379. $suvey_data[] = [
  380. 'sur_id' => $uuid,
  381. 'art_id' => $id,
  382. 'website_id' => $website_id ?? 2,
  383. 'survey_name' => $survey_name,
  384. 'choice_name' => $value[1],
  385. 'is_other' => 1,
  386. 'other_id' => 0,
  387. 'results' => 0,
  388. ];
  389. } else {
  390. $suvey_data[] = [
  391. 'sur_id' => $uuid,
  392. 'art_id' => $id,
  393. 'website_id' => $website_id ?? 2,
  394. 'survey_name' => $survey_name,
  395. 'choice_name' => $value,
  396. 'is_other' => 0,
  397. 'other_id' => 0,
  398. 'results' => 0,
  399. ];
  400. }
  401. if (empty($suvey_data)) {
  402. throw new \Exception("投票数据为空");
  403. }
  404. }
  405. $result = ArticleSurvey::insert($suvey_data);
  406. if (!$result) {
  407. throw new \Exception("投票失败,ArticleSurvey插入失败");
  408. }
  409. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  410. if (!$result) {
  411. throw new \Exception("投票失败,更新主表失败");
  412. }
  413. }
  414. Db::commit();
  415. return Result::success(['id' => $id]);
  416. } catch (\Throwable $ex) {
  417. Db::rollBack();
  418. var_dump($ex->getMessage());
  419. return Result::error("创建失败", 0);
  420. }
  421. }
  422. /**
  423. * @param array $data
  424. * @return array
  425. */
  426. public function delArticle(array $data): array
  427. {
  428. $result = Article::where($data)->delete();
  429. //survey投票删除
  430. articleSurvey::where(['art_id' => $data['id']])->delete();
  431. if (!$result) {
  432. return Result::error("删除失败");
  433. }
  434. return Result::success($result);
  435. }
  436. /**
  437. * @param array $data
  438. * @return array
  439. */
  440. public function updateArticle(array $data): array
  441. {
  442. var_dump($data, '----------12-----------1');
  443. Db::beginTransaction();
  444. unset($data['user_type']);
  445. // unset($data['web_site_id']);
  446. unset($data['nav_add_pool_id']);
  447. try {
  448. //处理投票
  449. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  450. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  451. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  452. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  453. unset($data['is_survey']);
  454. unset($data['survey_name']);
  455. unset($data['suvey_array']);
  456. unset($data['website_id']);
  457. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  458. if ($data['hits'] == '') {
  459. $data['hits'] = 0;
  460. }
  461. if ($data['is_original'] == '') {
  462. $data['is_original'] = 0;
  463. }
  464. if ($data['status'] == '') {
  465. $data['status'] = 0;
  466. }
  467. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  468. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  469. $articleData = $data;
  470. unset($articleData['content']);
  471. unset($articleData['status_name']);
  472. unset($articleData['name']);
  473. unset($articleData['content']);
  474. unset($articleData['pid_arr']);
  475. unset($articleData['pid']);
  476. //自动处理缩略图、关键字、描述
  477. if ($articleData['imgurl'] == '') {
  478. //如果没有图,设置level=0
  479. $levelArr = json_decode($articleData['level'], true);
  480. var_dump($levelArr, '----------levelArr-----------1');
  481. //content中提取图片第一个图,正则提取
  482. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  483. preg_match_all($reg, $data['content'], $matches);
  484. if (isset($matches[1][0])) {
  485. //截取varchar240
  486. // 截取到第一个<
  487. $articleData['imgurl'] = $matches[1][0];
  488. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  489. $pos = strpos($articleData['imgurl'], '"');
  490. if ($pos !== false) {
  491. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  492. }
  493. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  494. //如果有图,设置level=3
  495. if (!in_array(3, $levelArr)) {$levelArr[] = 3;}
  496. $articleData['level'] = json_encode($levelArr);
  497. } else {
  498. if (!in_array(0, $levelArr)) {
  499. $levelArr[] = 0;
  500. }
  501. $articleData['level'] = json_encode($levelArr);
  502. }
  503. }
  504. var_dump($articleData['level'], '----------$articleData[level]----------1');
  505. if ($articleData['keyword'] == '') {
  506. //提取标题+内容中的关键词
  507. $articleData['keyword'] = $data['title'];
  508. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  509. Jieba::init(); // 初始化 jieba-php
  510. Finalseg::init();
  511. $segList = Jieba::cut($articleData['keyword']);
  512. $segList1 = array_slice($segList, 0, 8);
  513. $articleData['keyword'] = implode(',', $segList1);
  514. }
  515. if ($articleData['introduce'] == '') {
  516. //提取内容中的描述
  517. $articleData['introduce'] = substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
  518. }
  519. $id = Article::where(['id' => $data['id']])->update($articleData);
  520. $articleDataContent = [
  521. 'content' => $data['content'],
  522. ];
  523. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  524. //处理投票
  525. $id = $data['id'];
  526. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  527. var_dump($suvey_array, 'suvey_array________delete');
  528. //处理投票
  529. if ($is_survey == 1) {
  530. //生成年月日时分秒+8位随机数
  531. $uuid = date('YmdHis') . rand(10000000, 99999999);
  532. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  533. var_dump($suveys_array, '---------------------1');
  534. $suvey_data = [];
  535. if (is_array($suveys_array)) {
  536. foreach ($suveys_array as $key => $value) {
  537. if ($value == '') {
  538. continue;
  539. }
  540. if (is_array($value)) {
  541. $suvey_data[] = [
  542. 'sur_id' => $uuid,
  543. 'art_id' => $id,
  544. 'website_id' => $website_id ?? 2,
  545. 'survey_name' => $survey_name,
  546. 'choice_name' => $value[1],
  547. 'is_other' => 1,
  548. 'other_id' => 0,
  549. 'results' => 0,
  550. ];
  551. } else {
  552. $suvey_data[] = [
  553. 'sur_id' => $uuid,
  554. 'art_id' => $id,
  555. 'website_id' => $website_id ?? 2,
  556. 'survey_name' => $survey_name,
  557. 'choice_name' => $value,
  558. 'is_other' => 0,
  559. 'other_id' => 0,
  560. 'results' => 0,
  561. ];
  562. }
  563. if (empty($suvey_data)) {
  564. throw new \Exception("投票数据为空");
  565. }
  566. }
  567. }
  568. $result = ArticleSurvey::insert($suvey_data);
  569. if (!$result) {
  570. throw new \Exception("投票失败");
  571. }
  572. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  573. if (!$result) {
  574. throw new \Exception("投票失败");
  575. }
  576. } else {
  577. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  578. }
  579. Db::commit();
  580. return Result::success([]);
  581. } catch (\Throwable $ex) {
  582. Db::rollBack();
  583. var_dump($ex->getMessage());
  584. return Result::error("更新失败" . $ex->getMessage(), 0);
  585. }
  586. }
  587. /**
  588. * 更新资讯状态
  589. * @param array $data
  590. * @return array
  591. */
  592. public function upArticleStatus(array $data): array
  593. {
  594. $result = Article::where(['id' => $data['id']])->update($data);
  595. if ($result) {
  596. return Result::success();
  597. } else {
  598. return Result::error("更新状态失败", 0);
  599. }
  600. }
  601. /**
  602. * @param array $data
  603. * @return array
  604. */
  605. public function getArticleInfo(array $data): array
  606. {
  607. $where = [
  608. 'article.id' => $data['id'],
  609. // 'article.status' => 1,
  610. ];
  611. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  612. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  613. $info = $result;
  614. // var_dump($info, 'info');
  615. $info['survey_array'] = $articleSurvey;
  616. if ($result) {
  617. return Result::success($info);
  618. } else {
  619. return Result::error("查询失败", 0);
  620. }
  621. }
  622. /**
  623. * 获取新闻
  624. * @param array $data
  625. * @return array
  626. */
  627. public function getWebsiteArticlett(array $data): array
  628. {
  629. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
  630. $result = [];
  631. if ($category) {
  632. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  633. $where = [
  634. 'status' => 1,
  635. ];
  636. var_dump($data, 'data-----------------');
  637. // level=7 根据文章key来匹配文章
  638. if (isset($data['level']) && $data['level'] == 7) {
  639. // 根据文章id获取key
  640. // $data['id'] = 50142;
  641. if (isset($data['id']) && !empty($data['id'])) {
  642. $keyword = Article::where('id', $data['id'])->value('keyword');
  643. $keywordArray = explode(',', $keyword);
  644. $whereL7 = [];
  645. foreach ($keywordArray as $k => $v) {
  646. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  647. }
  648. $result = Article::where($whereL7)
  649. ->offset($placeid)
  650. ->limit($data['pageSize'])
  651. ->orderBy('updated_at', 'desc')
  652. ->get();
  653. if (empty($result)) {
  654. return Result::success([]);
  655. }
  656. return Result::success($result);
  657. } else {
  658. return Result::error("参数错误level=7,id不能为空", 0);
  659. }
  660. }
  661. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  662. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  663. var_dump($where, 'where-----------------');
  664. $result = Article::where($where)
  665. ->whereIn("catid", $category)
  666. ->where(function ($query) use ($data) {
  667. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  668. ->orWhereNull("ignore_ids");
  669. })
  670. //$data['level'] == 4 || $data['level'] == 5 查询随机
  671. ->when($data['level'] == 5, function ($query) {
  672. $query->inRandomOrder()
  673. //updated_at最近三十天;
  674. ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  675. })
  676. ->when($data['level'] == 4, function ($query) {
  677. $query->orderBy("updated_at", "desc");
  678. })
  679. ->when(!empty($data['level']), function ($query) use ($data) {
  680. if ($data['level'] != 4 && $data['level'] != 5) {
  681. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  682. ->orderBy("updated_at", "desc");
  683. }
  684. })
  685. ->offset($placeid)
  686. ->limit($data['pageSize'])
  687. ->get();
  688. if (empty($result)) {
  689. return Result::error("暂无头条新闻", 0);
  690. }
  691. return Result::success($result);
  692. } else {
  693. return Result::error("本网站下暂无相关栏目", 0);
  694. }
  695. }
  696. /**
  697. * 获取模块新闻
  698. * @param array $data
  699. * @return array
  700. */
  701. public function getWebsiteModelArticles(array $data): array
  702. {
  703. $catid = $data['catid'];
  704. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  705. $category = $category->toArray();
  706. if (!empty($category)) {
  707. $where = [
  708. 'status' => 1,
  709. 'catid' => $catid,
  710. ];
  711. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  712. // 1:文字新闻;2:轮播图;3:图文;
  713. // 级别:0:未分类
  714. // 3:推荐图片
  715. if ($data['level'] == 1) {
  716. $data['level'] = 0;
  717. }
  718. $result = Article::where($where)
  719. ->where(function ($query) use ($data) {
  720. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  721. ->orWhereNull("level")
  722. ->orWhereRaw("level = '[]'");
  723. })
  724. ->where(function ($query) use ($data) {
  725. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  726. ->orWhereNull("ignore_ids");
  727. })
  728. ->orderBy("updated_at", "desc")
  729. ->offset($placeid)
  730. ->limit($data['pagesize'])
  731. ->get();
  732. if (empty($result)) {
  733. return Result::error("此栏目暂无相关新闻", 0);
  734. }
  735. } else {
  736. return Result::error("此网站暂无此栏目", 0);
  737. }
  738. return Result::success($result);
  739. }
  740. /**
  741. *获取新闻列表
  742. * @param array $data
  743. * @return array
  744. */
  745. public function getWebsiteArticleList(array $data): array
  746. {
  747. $where[] = ['status', '=', 1];
  748. if (isset($data['keyword']) && !empty($data['keyword'])) {
  749. array_push($where, ['article.title', 'like', '%' . $data['keyword'] . '%']);
  750. }
  751. if (isset($data['catid']) && !empty($data['catid'])) {
  752. if (is_array($data['catid'])) {
  753. $category = WebsiteCategory::where('website_id', $data['website_id'])->whereIn('category_id', $data['catid'])->pluck('category_id');
  754. array_push($where, ['catid', 'in', $data['catid']]);
  755. } else {
  756. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  757. array_push($where, ['catid', '=', $data['catid']]);
  758. }
  759. if (empty($category)) {
  760. return Result::error("此网站暂无此栏目", 0);
  761. }
  762. }
  763. // return Result::success($where);
  764. $rep = Article::where(function ($query) use ($where) {
  765. foreach ($where as $condition) {
  766. if ($condition[1] === 'in') {
  767. $query->whereIn($condition[0], $condition[2]);
  768. } else {
  769. $query->where($condition[0], $condition[1], $condition[2]);
  770. }
  771. }
  772. })
  773. ->where(function ($query) use ($data) {
  774. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  775. ->orWhereNull("ignore_ids");
  776. })
  777. ->orderBy("updated_at", "desc")
  778. ->limit($data['pageSize'])
  779. ->offset(($data['page'] - 1) * $data['pageSize'])
  780. ->get();
  781. $count = Article::where(function ($query) use ($where) {
  782. foreach ($where as $condition) {
  783. if ($condition[1] === 'in') {
  784. $query->whereIn($condition[0], $condition[2]);
  785. } else {
  786. $query->where($condition[0], $condition[1], $condition[2]);
  787. }
  788. }
  789. })->count();
  790. $data = [
  791. 'rows' => $rep->toArray(),
  792. 'count' => $count,
  793. ];
  794. if (empty($rep)) {
  795. return Result::error("没有信息数据");
  796. }
  797. return Result::success($data);
  798. }
  799. /**
  800. * 前端-获取新闻详情
  801. * @param array $data
  802. * @return array
  803. */
  804. public function selectWebsiteArticleInfo(array $data): array
  805. {
  806. $where = [
  807. 'article.id' => $data['id'],
  808. 'article.status' => 1,
  809. ];
  810. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")
  811. ->where(function ($query) use ($data) {
  812. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  813. ->orWhereNull("ignore_ids");
  814. })
  815. ->first();
  816. if (empty($result)) {
  817. return Result::error("暂无此新闻!", 0);
  818. }
  819. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  820. ->select('website_category.*', 'website.website_name', 'website.suffix')
  821. ->where('website_category.website_id', $data['website_id'])
  822. ->where(['website_category.category_id' => $result['catid']])
  823. ->first();
  824. if (empty($category)) {
  825. return Result::error("查询失败", 0);
  826. }
  827. //手动推荐文章
  828. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  829. $commendArticle = Article::whereIn('id', $commend_ids)
  830. ->where('status', 1)
  831. ->select('id', 'title', 'catid', 'imgurl', 'hits', 'created_at')
  832. ->orderBy('updated_at', 'desc')
  833. ->limit(5)
  834. ->get();
  835. $result['category_id'] = $category['category_id'];
  836. $result['cat_name'] = $category['alias'];
  837. $result['website_name'] = $category['website_name'] ?? "";
  838. $result['suffix'] = $category['suffix'] ?? "";
  839. $result['commendArticle'] = $commendArticle;
  840. return Result::success($result);
  841. }
  842. /**
  843. * 前端-获取网站调查问卷
  844. * @param array $data
  845. * @return array
  846. */
  847. public function getWebsiteSurvey(array $data): array
  848. {
  849. if (isset($data['website_id']) && !empty($data['website_id'])) {
  850. $website = Website::where('id', $data['website_id'])->first();
  851. if (empty($website)) {
  852. return Result::error("暂无此网站", 0);
  853. }
  854. }
  855. if (isset($data['art_id']) && !empty($data['art_id'])) {
  856. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  857. if (empty($article)) {
  858. return Result::error("暂无此文章", 0);
  859. }
  860. // return Result::error($data,0);
  861. $where['art_id'] = $data['art_id'];
  862. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  863. } else {
  864. $survey = Article::where(function ($query) {
  865. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  866. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  867. })
  868. ->where('status', 1)
  869. ->where('is_survey', 1)
  870. ->select('survey_id')
  871. ->orderBy('updated_at', 'desc')
  872. ->first();
  873. if (empty($survey)) {
  874. return Result::error("暂无调查问卷", 0);
  875. }
  876. $where['sur_id'] = $survey['survey_id'];
  877. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  878. }
  879. // return Result::success($where);
  880. $result = ArticleSurvey::where($where)
  881. ->where(function ($query) {
  882. $query->where('is_other', 0)
  883. ->orWhere(function ($subQuery) {
  884. $subQuery->where('is_other', 1)
  885. ->where('other_id', 0);
  886. });
  887. })
  888. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  889. ->select('article_survey.*', 'article.survey_type')
  890. ->get()->all();
  891. if (empty($result)) {
  892. return Result::error("此文章暂无调查问卷", 0);
  893. }
  894. return Result::success($result);
  895. }
  896. /**
  897. * 前端-添加网站调查问卷选项
  898. * @param array $data
  899. * @return array
  900. */
  901. public function addWebsiteSurveyOption(array $data): array
  902. {
  903. if (isset($data['website_id']) && !empty($data['website_id'])) {
  904. $website = Website::where('id', $data['website_id'])->first();
  905. if (empty($website)) {
  906. return Result::error("暂无此网站", 0);
  907. }
  908. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  909. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('website_id', $data['website_id'])->where('is_other', 1)->where('other_id', 0)->first();
  910. if (empty($survey)) {
  911. return Result::error("此调查问卷不可添加选项", 0);
  912. }
  913. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  914. $choice = [
  915. 'art_id' => $survey['art_id'],
  916. 'website_id' => $data['website_id'],
  917. 'survey_name' => $survey['survey_name'],
  918. 'choice_name' => $data['choice_name'],
  919. 'sur_id' => $survey['sur_id'],
  920. 'is_other' => 1,
  921. 'other_id' => $survey['id'],
  922. ];
  923. $result = ArticleSurvey::insertGetId($choice);
  924. if (empty($result)) {
  925. return Result::error("添加失败", 0);
  926. }
  927. return Result::success($result);
  928. }
  929. }
  930. return Result::error("添加失败", 0);
  931. }
  932. return Result::error("添加失败", 0);
  933. }
  934. /**
  935. * 前端-调查问卷投票
  936. * @param array $data
  937. * @return array
  938. */
  939. public function addWebsiteSurveyVote(array $data): array
  940. {
  941. // return Result::success($data);
  942. if (isset($data['website_id']) && !empty($data['website_id'])) {
  943. $website = Website::where('id', $data['website_id'])->first();
  944. if (empty($website)) {
  945. return Result::error("暂无此网站", 0);
  946. }
  947. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  948. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  949. // return Result::success($survey);
  950. if (empty($is_survey)) {
  951. return Result::error("此调查问卷不存在", 0);
  952. }
  953. // return Result::success($survey);
  954. // 调查问卷类型
  955. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  956. //多选 若是json型则转化成数组类型
  957. if (strpos($data['choice_id'], '[') === 0) {
  958. $data['choice_id'] = json_decode($data['choice_id'], true);
  959. } else {
  960. // 单选 也转换成数组
  961. $data['choice_id'] = [$data['choice_id']];
  962. }
  963. $data['choice_id'] = array_map('intval', $data['choice_id']);
  964. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  965. ->where('website_id', $data['website_id'])
  966. ->where('is_other', 1)
  967. ->where('other_id', 0)
  968. ->first();
  969. if (!empty($other)) {
  970. return Result::error("请选择已有的选项!", 0);
  971. }
  972. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  973. ->where('website_id', $data['website_id'])
  974. ->where('is_other', 1)
  975. ->where('other_id', '!=', 0)
  976. ->first();
  977. // return Result::success($choice['other']);
  978. $choice_id = $data['choice_id'];
  979. if (!empty($choice['other'])) {
  980. // array_push($data['choice_id'],$choice['other']['other_id']);
  981. if (!empty($choice_id)) {
  982. $key = array_search($choice['other']['id'], $choice_id);
  983. if ($key !== false) {
  984. unset($choice_id[$key]);
  985. $choice_id = array_values($choice_id);
  986. }
  987. array_push($choice_id, $choice['other']['other_id']);
  988. } else {
  989. $choice_id[0] = $choice['other']['other_id'];
  990. }
  991. array_push($data['choice_id'], $choice['other']['other_id']);
  992. }
  993. // return Result::success($data);
  994. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  995. ->where('website_id', $data['website_id'])
  996. ->increment('results', 1);
  997. if (empty($choice)) {
  998. return Result::error("请选择已有的选项!", 0);
  999. }
  1000. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1001. ->where('website_id', $data['website_id'])
  1002. ->where('other_id', 0)
  1003. ->get();
  1004. $survey['choice'] = $choice_id;
  1005. return Result::success($survey);
  1006. }
  1007. return Result::error("参数必填!");
  1008. }
  1009. return Result::error("此调查问卷不存在", 0);
  1010. }
  1011. return Result::error("参数必填!");
  1012. }
  1013. /**
  1014. * 后端-获取网站调查问卷列表
  1015. * @param array $data
  1016. * @return array
  1017. */
  1018. public function getSurveyList(array $data): array
  1019. {
  1020. $where = [];
  1021. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1022. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1023. }
  1024. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  1025. array_push($where, ['survey_type', '=', $data['survey_type']]);
  1026. }
  1027. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  1028. array_push($where, ['is_survey', '=', $data['is_survey']]);
  1029. }
  1030. // return Result::success($where);
  1031. if (!empty($where)) {
  1032. $query = Article::where($where)->where(function ($q) {
  1033. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1034. });
  1035. } else {
  1036. $query = Article::where(function ($q) {
  1037. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1038. });
  1039. }
  1040. $count = $query->count();
  1041. $survey = $query->orderByDesc('id')
  1042. ->limit($data['pageSize'])
  1043. ->offset(($data['page'] - 1) * $data['pageSize'])
  1044. ->get();
  1045. if (empty($survey->toArray())) {
  1046. return Result::error("暂无调查问卷!", 0);
  1047. }
  1048. $result = [
  1049. 'rows' => $survey,
  1050. 'count' => $count,
  1051. ];
  1052. return Result::success($result);
  1053. }
  1054. /**
  1055. * 后端-获取网站调查问卷详情
  1056. * @param array $data
  1057. * @return array
  1058. */
  1059. public function getSurveyInfo(array $data): array
  1060. {
  1061. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1062. $where = ['sur_id' => $data['sur_id']];
  1063. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1064. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1065. ->select('article_survey.*', 'article.survey_type')
  1066. ->get()->all();
  1067. if (empty($choose)) {
  1068. return Result::error("此调查问卷不存在", 0);
  1069. }
  1070. $resultsArray = array_column($choose, 'results');
  1071. $total = array_sum($resultsArray);
  1072. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1073. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1074. // $total = 0;
  1075. if (!empty($other)) {
  1076. $total = $total + $other['results'];
  1077. $other['choice_name'] = '(其他)';
  1078. if (!empty($others)) {
  1079. $other['hasChildren'] = true;
  1080. // array_push($other,['hasChildren','=',true]);
  1081. $other['children'] = $others;
  1082. $other_choices = [$other->toArray()];
  1083. $mer_choice = array_merge($choose, $other_choices);
  1084. $value_choice = array_values($mer_choice);
  1085. } else {
  1086. // return Result::error('1111');
  1087. $other_choices = [$other->toArray()];
  1088. $other_choices = array_merge($choose, $other_choices);
  1089. $value_choice = array_values($other_choices);
  1090. // return Result::success($result);
  1091. }
  1092. } else {
  1093. $value_choice = $choose;
  1094. }
  1095. $result = [
  1096. 'choose' => $value_choice,
  1097. 'total' => $total,
  1098. ];
  1099. }
  1100. return Result::success($result);
  1101. }
  1102. /**
  1103. * 前端-搜索新闻列表
  1104. * @param array $data
  1105. * @return array
  1106. */
  1107. public function selectWebsiteArticle(array $data): array
  1108. {
  1109. $where = [];
  1110. // 初始化查询构造器
  1111. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
  1112. $query = Article::where('status', 1)
  1113. ->whereIn('catid', $category)
  1114. ->where(function ($query) use ($data) {
  1115. $query->where(function ($subQuery) use ($data) {
  1116. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1117. })->orWhereNull("ignore_ids");
  1118. });
  1119. // return Result::success($all_articles);
  1120. // 检查是否存在 cityid 参数
  1121. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1122. $query->whereRaw("JSON_CONTAINS(city_arr_id, '" . intval($data['cityid']) . "')");
  1123. }
  1124. // 检查是否存在 department_id 参数
  1125. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1126. $query->whereRaw("JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "')");
  1127. }
  1128. // 检查是否存在 keyword 参数
  1129. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1130. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  1131. }
  1132. // 计算总数
  1133. $count = $query->count();
  1134. // 分页查询
  1135. $articles = $query->orderBy("updated_at", "desc")
  1136. ->limit($data['pageSize'])
  1137. ->offset(($data['page'] - 1) * $data['pageSize'])
  1138. ->get()->all();
  1139. if (empty($articles)) {
  1140. return Result::error("没有符合条件的资讯数据");
  1141. }
  1142. $data = [
  1143. 'rows' => $articles,
  1144. 'count' => $count,
  1145. ];
  1146. return Result::success($data);
  1147. }
  1148. /**
  1149. * 模块新闻加强版
  1150. * @param array $data
  1151. * @return array
  1152. */
  1153. public function getWebsiteCatidArticle(array $data): array
  1154. {
  1155. // return Result::success($data);
  1156. $where = [
  1157. // 'category.status' => 1,
  1158. 'website_category.category_id' => $data['catid'],
  1159. 'website_category.website_id' => $data['website_id'],
  1160. // 'article.status' => 1,
  1161. ];
  1162. // $category = WebsiteCategory::where($where);
  1163. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  1164. $child_catnum = $data['child_catnum'] ?? 1;
  1165. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  1166. $childCategoryIds = array_column($category['child'], 'category_id');
  1167. if (empty($childCategoryIds)) {
  1168. return Result::error("暂无子栏目", 0);
  1169. }
  1170. $imgArticles = [];
  1171. $textArticles = [];
  1172. // return Result::success($childCategoryIds);
  1173. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  1174. // 初始化子分类图片新闻和文字新闻数组
  1175. // 查询所有子级栏目的图文新闻
  1176. $imgArticles = Article::where('catid', $childCategoryIds[0])
  1177. ->where(function ($query) use ($data) {
  1178. $query->where(function ($subQuery) use ($data) {
  1179. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0");
  1180. })->orWhereNull("ignore_ids");
  1181. })
  1182. ->where('status', 1)
  1183. ->where('imgurl', '!=', '')
  1184. ->select('*')
  1185. ->orderBy('updated_at', 'desc')
  1186. ->limit($data['child_imgnum'])
  1187. ->get();
  1188. }
  1189. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  1190. // 查询所有子级栏目的文字新闻
  1191. $textArticles = Article::where('catid', $childCategoryIds[0])
  1192. ->where('status', 1)
  1193. ->where(function ($query) use ($data) {
  1194. $query->where(function ($subQuery) use ($data) {
  1195. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0");
  1196. })->orWhereNull("ignore_ids");
  1197. })
  1198. // ->where(function ($query) {
  1199. // $query->whereNull('imgurl')
  1200. // ->orWhere('imgurl', '');
  1201. // })
  1202. ->select('*')
  1203. ->orderBy('updated_at', 'desc')
  1204. ->limit($data['child_textnum'])
  1205. ->get();
  1206. }
  1207. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  1208. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  1209. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  1210. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  1211. return $child;
  1212. }, $category['child']);
  1213. }
  1214. // }
  1215. if (isset($data['img_num']) && !empty($data['img_num'])) {
  1216. $category['img'] = WebsiteCategory::where($where)
  1217. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1218. ->where('article.status', 1)
  1219. ->where('article.imgurl', '!=', '')
  1220. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1221. ->orderBy('article.updated_at', 'desc')
  1222. ->limit($data['img_num'])
  1223. ->get();
  1224. }
  1225. if (isset($data['text_num']) && !empty($data['text_num'])) {
  1226. $category['text'] = WebsiteCategory::where($where)
  1227. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1228. ->where('article.status', 1)
  1229. // ->where(function ($query) {
  1230. // $query->whereNull('article.imgurl')
  1231. // ->orWhere('article.imgurl', '');
  1232. // })
  1233. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1234. ->orderBy('article.updated_at', 'desc')
  1235. ->limit($data['text_num'])
  1236. ->get();
  1237. }
  1238. // $category = $category->get();
  1239. if (empty($category)) {
  1240. return Result::error("查询失败", 0);
  1241. }
  1242. return Result::success($category);
  1243. }
  1244. /**
  1245. * 模块新闻加强plus版
  1246. * @param array $data
  1247. * @return array
  1248. */
  1249. public function getWebsiteAllArticle(array $data): array
  1250. {
  1251. // 修正传入的字符串,将单引号替换为双引号
  1252. $input['id'] = $data['id'];
  1253. $input['website_id'] = $data['website_id'];
  1254. // 将 JSON 字符串转换为 PHP 数组
  1255. $data = json_decode($input['id'], true);
  1256. // 使用 array_map 处理每个元素
  1257. $result = array_map(function ($item) use ($input) {
  1258. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  1259. $website = [
  1260. 'website_id' => $input['website_id'],
  1261. ];
  1262. // 查询栏目名称
  1263. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id','aLIas_pinyin']);
  1264. if(empty($category)){
  1265. $imgArticles = [];
  1266. $textArticles = [];
  1267. // return Result::error("暂无此栏目",0);
  1268. }else{
  1269. // 查询图片新闻
  1270. $imgArticles = Article::where('catid', $parentCatId)
  1271. ->where('status', 1)
  1272. ->where(function ($query) use ($website) {
  1273. $query->where(function ($subQuery) use ($website) {
  1274. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($website['website_id'])."') = 0");
  1275. })->orWhereNull("ignore_ids");
  1276. })
  1277. ->where('imgurl', '!=', '')
  1278. ->orderBy('updated_at', 'desc')
  1279. ->limit($parentImgNum)
  1280. ->get()->all();
  1281. // 查询文字新闻
  1282. $textArticles = Article::where('catid', $parentCatId)
  1283. ->where('status', 1)
  1284. ->where(function ($query) use ($website) {
  1285. $query->where(function ($subQuery) use ($website) {
  1286. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($website['website_id'])."') = 0");
  1287. })->orWhereNull("ignore_ids");
  1288. })
  1289. ->orderBy('updated_at', 'desc')
  1290. ->limit($parentTextNum)
  1291. ->get()->all();
  1292. }
  1293. $resultItem = [
  1294. 'alias' => $category ? $category->alias : null,
  1295. 'category_id' => $parentCatId,
  1296. 'pinyin' => $category->aLIas_pinyin ?? '',
  1297. 'imgnum' => $imgArticles,
  1298. 'textnum' => $textArticles,
  1299. ];
  1300. if (!empty($item['child']) && $item['child'] != "") {
  1301. // 查询第一个pid等于parent中第一个参数的category来获取child的category_id
  1302. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)->select('category_id','alias','aLIas_pinyin')->get()->all();
  1303. if ($childCategory) {
  1304. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  1305. // 查询子栏目名称
  1306. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)->first(['alias', 'category_id','aLIas_pinyin']);
  1307. // $childAllCartegory = WebsiteCategory::where('pid', $childCatId)->where($website)->first(['category_id']);
  1308. if(empty($childCategoryInfo)){
  1309. $childImgArticles = [];
  1310. $childTextArticles = [];
  1311. }else{
  1312. // 查询子栏目图片新闻
  1313. $childImgArticles = Article::where('catid', $childCatId)
  1314. ->where('status', 1)
  1315. ->where(function ($query) use ($website) {
  1316. $query->where(function ($subQuery) use ($website) {
  1317. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($website['website_id'])."') = 0");
  1318. })->orWhereNull("ignore_ids");
  1319. })
  1320. ->where('imgurl', '!=', '')
  1321. ->orderBy('updated_at', 'desc')
  1322. ->limit($childImgNum)
  1323. ->get()->all();
  1324. // 查询子栏目文字新闻
  1325. $childTextArticles = Article::where('catid', $childCatId)
  1326. ->where('status', 1)
  1327. ->where(function ($query) use ($website) {
  1328. $query->where(function ($subQuery) use ($website) {
  1329. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($website['website_id'])."') = 0");
  1330. })->orWhereNull("ignore_ids");
  1331. })
  1332. ->orderBy('updated_at', 'desc')
  1333. ->limit($childTextNum)
  1334. ->get()->all();
  1335. }
  1336. $resultItem['child'] = [
  1337. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  1338. 'category_id' => $childCatId,
  1339. 'pinyin' => $childCategoryInfo->aLIas_pinyin?? '',
  1340. 'all_childcat' => $childCategory,
  1341. 'imgnum' => $childImgArticles,
  1342. 'textnum' => $childTextArticles,
  1343. ];
  1344. // $resultItem['pinyin'] = $childCategoryInfo->aLIas_pinyin ?? '';
  1345. }
  1346. }
  1347. return $resultItem;
  1348. }, $data);
  1349. return Result::success($result);
  1350. // return Result::success($data);
  1351. }
  1352. /**
  1353. * 乡村网-获取特殊新闻模块
  1354. * @param array $data
  1355. * @return array
  1356. */
  1357. public function getWebsiteArticles(array $data): array
  1358. {
  1359. $web = Website::where('id',$data['website_id'])->first();
  1360. if(empty($web)){
  1361. return Result::error("暂无此网站",0);
  1362. }
  1363. $where = [
  1364. // 'article.catid' => $data['catid'],
  1365. 'article.status' => 1,
  1366. ];
  1367. $articles['img'] = Article::where($where)
  1368. ->where('imgurl', '!=', '')
  1369. ->whereNotNull('imgurl')
  1370. ->whereRaw("JSON_CONTAINS(category_arr_id, '".intval($data['catid'])."')")
  1371. ->leftJoin('website_category', 'website_category.category_id', 'article.catid','website_category.aLIas_pinyin')
  1372. ->select('article.*','website_category.category_id','website_category.alias')
  1373. ->orderBy('updated_at', 'desc')
  1374. ->limit($data['img_num'])
  1375. ->get()->all();
  1376. $articles['text'] = Article::where($where)
  1377. ->whereRaw("JSON_CONTAINS(category_arr_id, '".intval($data['catid'])."')")
  1378. ->leftJoin('website_category', 'website_category.category_id', 'article.catid')
  1379. ->select('article.*','website_category.category_id','website_category.alias','website_category.aLIas_pinyin')
  1380. ->orderBy('updated_at', 'desc')
  1381. ->limit($data['text_num'])
  1382. ->get()->all();
  1383. if(empty($articles)){
  1384. return Result::error("暂无此栏目",0);
  1385. }
  1386. return Result::success($articles);
  1387. }
  1388. /**
  1389. * 验证导航名称是否重复
  1390. * @return void
  1391. */
  1392. public function checkCategoryName(array $data): array
  1393. {
  1394. $result = Category::when($data, function ($query) use ($data) {
  1395. if (isset($data['name']) && $data['name']) {
  1396. $query->where("name", $data['name']);
  1397. }
  1398. if (isset($data['id']) && $data['id']) {
  1399. $query->where("id", "!=", $data['id']);
  1400. }
  1401. })->first();
  1402. if ($result) {
  1403. return Result::error("已存在");
  1404. } else {
  1405. return Result::success();
  1406. }
  1407. }
  1408. //20250226 产品列表
  1409. public function getGoodList(array $data): array
  1410. {
  1411. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  1412. unset($data['type_id']);
  1413. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  1414. $where = [];
  1415. if ($type_id != '10000') {
  1416. $where = [
  1417. 'good.user_id' => $user_id,
  1418. ];
  1419. }
  1420. //类型
  1421. if (isset($data['type_id']) && $data['type_id']) {
  1422. $where = [
  1423. 'type_id' => $data['type_id'],
  1424. ];
  1425. }
  1426. //名称
  1427. if (isset($data['name']) && $data['name']) {
  1428. $where = [
  1429. 'good.name' => $data['name'],
  1430. ];
  1431. }
  1432. $where1 = [];
  1433. //website_id
  1434. // if (isset($data['website_id']) && $data['website_id']) {
  1435. // $where1 = [
  1436. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  1437. // ];
  1438. // }
  1439. // website_name
  1440. if (isset($data['website_name']) && $data['website_name']) {
  1441. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  1442. }
  1443. // catid
  1444. if (isset($data['category_name']) && $data['category_name']) {
  1445. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  1446. }
  1447. // $result = Good::where($where)
  1448. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  1449. $result = Good::where($where)
  1450. ->when(!empty($where1), function ($query) use ($where1) {
  1451. return $query->where($where1);
  1452. })
  1453. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  1454. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  1455. ->leftJoin('category', 'good.catid', '=', 'category.id')
  1456. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  1457. ->orderBy("id", "desc")
  1458. ->limit($data['page_size'])
  1459. ->offset(($data['page'] - 1) * $data['page_size'])
  1460. ->get();
  1461. $count = Good::where($where)
  1462. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  1463. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  1464. ->leftJoin('category', 'good.catid', '=', 'category.id')
  1465. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  1466. ->orderBy("updated_at", "desc")->count();
  1467. $data = [
  1468. 'rows' => $result->toArray(),
  1469. 'count' => $count,
  1470. ];
  1471. if (empty($result)) {
  1472. return Result::error("此栏目暂无相关产品", 0);
  1473. }
  1474. return Result::success($data);
  1475. }
  1476. public function getGoodInfo(array $data): array
  1477. {
  1478. $result = Good::where('id', $data['id'])->first();
  1479. if (empty($result)) {
  1480. return Result::error("此产品不存在", 0);
  1481. }
  1482. return Result::success($result);
  1483. }
  1484. public function addGood(array $data): array
  1485. {
  1486. // unset($data['city_arr_id']);
  1487. // unset($data['cat_arr_id']);
  1488. $data['city_id'] = end($data['city_arr_id']);
  1489. $data['catid'] = end($data['cat_arr_id']);
  1490. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  1491. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  1492. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  1493. unset($data['imgUrl']);
  1494. $result = Good::insert($data);
  1495. if (empty($result)) {
  1496. return Result::error("添加失败", 0);
  1497. }
  1498. return Result::success($result);
  1499. }
  1500. public function updateGood(array $data): array
  1501. {
  1502. $data['city_id'] = end($data['city_arr_id']);
  1503. $data['catid'] = end($data['cat_arr_id']);
  1504. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  1505. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  1506. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  1507. //设置东八区
  1508. date_default_timezone_set('Asia/Shanghai');
  1509. $data['updated_at'] = date('Y-m-d H:i:s');
  1510. $result = Good::where('id', $data['id'])->update($data);
  1511. if (empty($result)) {
  1512. return Result::error("更新失败", 0);
  1513. }
  1514. return Result::success($result);
  1515. }
  1516. public function delGood(array $data): array
  1517. {
  1518. $result = Good::where('id', $data['id'])->delete();
  1519. if (empty($result)) {
  1520. return Result::error("删除失败", 0);
  1521. }
  1522. return Result::success($result);
  1523. }
  1524. //20250226 产品列表
  1525. //20250306 求职信息
  1526. public function getJobHuntingList(array $data): array
  1527. {
  1528. $where = [];
  1529. if (isset($data['username']) && !empty($data['username'])) {
  1530. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  1531. }
  1532. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  1533. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  1534. unset($data['type_id']);
  1535. if ($type_id != '10000') {
  1536. $where[] = ['job_hunting.user_id', '=', $user_id];
  1537. }
  1538. $result = JobHunting::where($where)
  1539. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  1540. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  1541. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  1542. ->orderBy("id", "desc")
  1543. ->limit($data['page_size'])
  1544. ->offset(($data['page'] - 1) * $data['page_size'])
  1545. ->get();
  1546. if (empty($result)) {
  1547. return Result::error("查询失败", 0);
  1548. }
  1549. $count = JobHunting::where($where)
  1550. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  1551. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  1552. ->count();
  1553. $data = [
  1554. 'rows' => $result->toArray(),
  1555. 'count' => $count,
  1556. ];
  1557. return Result::success($data);
  1558. }
  1559. public function addJobHunting(array $data): array
  1560. {
  1561. date_default_timezone_set('Asia/Shanghai');
  1562. unset($data['company_name']);
  1563. unset($data['job_industry']);
  1564. unset($data['job_name']);
  1565. unset($data['department']);
  1566. unset($data['job_timeList']);
  1567. unset($data['job_content']);
  1568. $data['created_at'] = date('Y-m-d H:i:s');
  1569. $data['updated_at'] = date('Y-m-d H:i:s');
  1570. var_dump($data, '-----------------test---------');
  1571. $result = JobHunting::create($data);
  1572. if (empty($result)) {
  1573. return Result::error("添加失败", 0);
  1574. }
  1575. return Result::success($result);
  1576. }
  1577. public function delJobHunting(array $data): array
  1578. {
  1579. $result = JobHunting::where('id', $data['id'])->delete();
  1580. if (empty($result)) {
  1581. return Result::error("删除失败", 0);
  1582. }
  1583. return Result::success($result);
  1584. }
  1585. public function updateJobHunting(array $data): array
  1586. {
  1587. //设置东八区
  1588. date_default_timezone_set('Asia/Shanghai');
  1589. unset($data['company_name']);
  1590. unset($data['job_industry']);
  1591. unset($data['job_name']);
  1592. unset($data['department']);
  1593. unset($data['job_timeList']);
  1594. unset($data['job_content']);
  1595. $data['created_at'] = date('Y-m-d H:i:s');
  1596. $data['updated_at'] = date('Y-m-d H:i:s');
  1597. $result = JobHunting::where('id', $data['id'])->update($data);
  1598. if (empty($result)) {
  1599. return Result::error("更新失败", 0);
  1600. }
  1601. return Result::success($result);
  1602. }
  1603. public function getJobHuntingInfo(array $data): array
  1604. {
  1605. $result = JobHunting::where('id', $data['id'])->first();
  1606. if (empty($result)) {
  1607. return Result::error("查询失败", 0);
  1608. }
  1609. return Result::success($result);
  1610. }
  1611. public function getJobHuntingData(array $data): array
  1612. {
  1613. $jobEnum = JobEnum::get();
  1614. $jobIndustry = JobIndustry::get();
  1615. $jobNature = JobNature::get();
  1616. $jobPosition = JobPosition::get();
  1617. $data = [
  1618. 'jobEnum' => $jobEnum,
  1619. 'jobIndustry' => $jobIndustry,
  1620. 'jobNature' => $jobNature,
  1621. 'jobPosition' => $jobPosition,
  1622. ];
  1623. return Result::success($data);
  1624. }
  1625. public function delJobHuntingInfo(array $data): array
  1626. {
  1627. $result = JobHunting::where('id', $data['id'])->delete();
  1628. return Result::success();
  1629. }
  1630. //20250324 通知,公告,消息
  1631. public function delNotice(array $data): array
  1632. {
  1633. return Result::success();
  1634. }
  1635. public function getNoticeInfo(array $data): array
  1636. {
  1637. $result = Notice::where('id', $data['id'])->first();
  1638. if (empty($result)) {
  1639. return Result::error("查询失败", 0);
  1640. }
  1641. return Result::success($result);
  1642. }
  1643. public function addNotice(array $data): array
  1644. {
  1645. $result = Notice::create($data);
  1646. return Result::success($result);
  1647. }
  1648. public function updateNotice(array $data): array
  1649. {
  1650. $result = Notice::where('id', $data['id'])->update($data);
  1651. return Result::success($result);
  1652. }
  1653. public function getNoticeList(array $data): array
  1654. {
  1655. $result = Notice::where('status', 1)->get();
  1656. return Result::success($result);
  1657. }
  1658. public function getNoticeDetail(array $data): array
  1659. {
  1660. $result = Notice::where('id', $data['id'])->first();
  1661. if (empty($result)) {
  1662. return Result::error("查询失败", 0);
  1663. }
  1664. return Result::success($result);
  1665. }
  1666. public function deleteNotice(array $data): array
  1667. {
  1668. $result = Notice::where('id', $data['id'])->delete();
  1669. return Result::success($result);
  1670. }
  1671. public function getMSG(array $data): array
  1672. {
  1673. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  1674. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  1675. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  1676. $result = [];
  1677. if ($type_id == 1) {
  1678. //最近的5篇已审的文章
  1679. $apply_articale = Article::where('status', 1)
  1680. ->orderBy('updated_at', 'desc')
  1681. ->limit(5)->get();
  1682. //获取5条单聊未读聊天消息
  1683. $chat = ChatRecords::where('is_read', 0)
  1684. ->where('user_id', $user_id)
  1685. ->where('talk_type', 1)
  1686. ->orderBy('created_at', 'desc')
  1687. ->limit(5)->get();
  1688. //获取5条未读群聊信息
  1689. $chat_group = ChatRecords::where('is_read', 0)
  1690. ->where('user_id', $user_id)
  1691. ->where('talk_type', 2)
  1692. ->orderBy('created_at', 'desc')
  1693. ->limit(5)->get();
  1694. $count = count($chat) + count($chat_group) + count($apply_articale);
  1695. $result = [
  1696. 'apply_articale' => $apply_articale,
  1697. 'chat' => $chat,
  1698. 'chat_group' => $chat_group,
  1699. 'count' => $count,
  1700. ];
  1701. } elseif ($type_id == 2) {
  1702. //最近的5篇已审的文章
  1703. $apply_articale = Article::where('status', 1)->limit(5)->get();
  1704. //获取5条单聊未读聊天消息
  1705. $chat = ChatRecords::where('is_read', 0)
  1706. ->where('user_id', $user_id)
  1707. ->where('talk_type', 1)
  1708. ->orderBy('created_at', 'desc')
  1709. ->limit(5)->get();
  1710. //获取5条未读群聊信息
  1711. $chat_group = ChatRecords::where('is_read', 0)
  1712. ->where('user_id', $user_id)
  1713. ->where('talk_type', 2)
  1714. ->orderBy('created_at', 'desc')
  1715. ->limit(5)->get();
  1716. $count = count($chat) + count($chat_group) + count($apply_articale);
  1717. $result = [
  1718. 'apply_articale' => $apply_articale,
  1719. 'chat' => $chat,
  1720. 'chat_group' => $chat_group,
  1721. 'count' => $count,
  1722. ];
  1723. } elseif ($type_id == 3) {
  1724. //最近的5篇已审的文章
  1725. $apply_articale = Article::where('status', 1)->limit(5)->get();
  1726. //获取5条单聊未读聊天消息
  1727. $chat = ChatRecords::where('is_read', 0)
  1728. ->where('user_id', $user_id)
  1729. ->where('talk_type', 1)
  1730. ->orderBy('created_at', 'desc')
  1731. ->limit(5)->get();
  1732. //获取5条未读群聊信息
  1733. $chat_group = ChatRecords::where('is_read', 0)
  1734. ->where('user_id', $user_id)
  1735. ->where('talk_type', 2)
  1736. ->orderBy('created_at', 'desc')
  1737. ->limit(5)->get();
  1738. $count = count($chat) + count($chat_group) + count($apply_articale);
  1739. $result = [
  1740. 'apply_articale' => $apply_articale,
  1741. 'chat' => $chat,
  1742. 'chat_group' => $chat_group,
  1743. 'count' => $count,
  1744. ];
  1745. } elseif ($type_id == 4) {
  1746. //最近的5篇已审的文章
  1747. $apply_articale = Article::where('status', 1)->limit(5)->get();
  1748. $count = count($apply_articale);
  1749. $result = [
  1750. 'count' => $count,
  1751. ];
  1752. } elseif ($type_id == 10000) {
  1753. //获取未审核的5篇文章
  1754. $apply_articale = Article::where('status', 0)
  1755. ->orderBy('updated_at', 'desc')
  1756. ->limit(5)->get();
  1757. //获取5条单聊未读聊天消息
  1758. $chat = ChatRecords::where('is_read', 0)
  1759. ->where('user_id', $user_id)
  1760. ->where('talk_type', 1)
  1761. ->orderBy('created_at', 'desc')
  1762. ->limit(5)->get();
  1763. //获取5条未读群聊信息
  1764. $chat_group = ChatRecords::where('is_read', 0)
  1765. ->where('user_id', $user_id)
  1766. ->where('talk_type', 2)
  1767. ->orderBy('created_at', 'desc')
  1768. ->limit(5)->get();
  1769. $count = count($chat) + count($chat_group) + count($apply_articale);
  1770. $result = [
  1771. 'apply_articale' => $apply_articale,
  1772. 'chat' => $chat,
  1773. 'chat_group' => $chat_group,
  1774. 'count' => $count,
  1775. ];
  1776. } elseif ($type_id == 20000) {
  1777. }
  1778. var_dump($type_id, '-----------------test---------');
  1779. return Result::success($result);
  1780. }
  1781. public function getComplaintList(array $data): array
  1782. {
  1783. $result = Notice::where('status', 1)->get();
  1784. return Result::success($result);
  1785. }
  1786. public function getComplaintInfo(array $data): array
  1787. {
  1788. $result = Notice::where('id', $data['id'])->first();
  1789. if (empty($result)) {
  1790. return Result::error("查询失败", 0);
  1791. }
  1792. return Result::success($result);
  1793. }
  1794. public function addComplaint(array $data): array
  1795. {
  1796. $result = Notice::create($data);
  1797. return Result::success($result);
  1798. }
  1799. public function updateComplaint(array $data): array
  1800. {
  1801. $result = Notice::where('id', $data['id'])->update($data);
  1802. return Result::success($result);
  1803. }
  1804. public function deleteComplaint(array $data): array
  1805. {
  1806. $result = Notice::where('id', $data['id'])->delete();
  1807. return Result::success($result);
  1808. }
  1809. public function getComplainInfo(array $data): array
  1810. {
  1811. $result = Notice::where('id', $data['id'])->first();
  1812. if (empty($result)) {
  1813. return Result::error("查询失败", 0);
  1814. }
  1815. return Result::success($result);
  1816. }
  1817. //20250324 通知,公告,消息
  1818. }