NewsService.php 72 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814
  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('status', 1)
  1178. ->where('imgurl', '!=', '')
  1179. ->select('*')
  1180. ->orderBy('updated_at', 'desc')
  1181. ->limit($data['child_imgnum'])
  1182. ->get();
  1183. }
  1184. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  1185. // 查询所有子级栏目的文字新闻
  1186. $textArticles = Article::where('catid', $childCategoryIds[0])
  1187. ->where('status', 1)
  1188. // ->where(function ($query) {
  1189. // $query->whereNull('imgurl')
  1190. // ->orWhere('imgurl', '');
  1191. // })
  1192. ->select('*')
  1193. ->orderBy('updated_at', 'desc')
  1194. ->limit($data['child_textnum'])
  1195. ->get();
  1196. }
  1197. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  1198. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  1199. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  1200. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  1201. return $child;
  1202. }, $category['child']);
  1203. }
  1204. // }
  1205. if (isset($data['img_num']) && !empty($data['img_num'])) {
  1206. $category['img'] = WebsiteCategory::where($where)
  1207. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1208. ->where('article.status', 1)
  1209. ->where('article.imgurl', '!=', '')
  1210. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1211. ->orderBy('article.updated_at', 'desc')
  1212. ->limit($data['img_num'])
  1213. ->get();
  1214. }
  1215. if (isset($data['text_num']) && !empty($data['text_num'])) {
  1216. $category['text'] = WebsiteCategory::where($where)
  1217. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1218. ->where('article.status', 1)
  1219. // ->where(function ($query) {
  1220. // $query->whereNull('article.imgurl')
  1221. // ->orWhere('article.imgurl', '');
  1222. // })
  1223. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1224. ->orderBy('article.updated_at', 'desc')
  1225. ->limit($data['text_num'])
  1226. ->get();
  1227. }
  1228. // $category = $category->get();
  1229. if (empty($category)) {
  1230. return Result::error("查询失败", 0);
  1231. }
  1232. return Result::success($category);
  1233. }
  1234. /**
  1235. * 模块新闻加强plus版
  1236. * @param array $data
  1237. * @return array
  1238. */
  1239. public function getWebsiteAllArticle(array $data): array
  1240. {
  1241. // 修正传入的字符串,将单引号替换为双引号
  1242. $input['id'] = $data['id'];
  1243. $input['website_id'] = $data['website_id'];
  1244. // 将 JSON 字符串转换为 PHP 数组
  1245. $data = json_decode($input['id'], true);
  1246. // 使用 array_map 处理每个元素
  1247. $result = array_map(function ($item) use ($input) {
  1248. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  1249. $website = [
  1250. 'website_id' => $input['website_id'],
  1251. ];
  1252. // 查询栏目名称
  1253. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id']);
  1254. if(empty($category)){
  1255. $imgArticles = [];
  1256. $textArticles = [];
  1257. // return Result::error("暂无此栏目",0);
  1258. }else{
  1259. // 查询图片新闻
  1260. $imgArticles = Article::where('catid', $parentCatId)
  1261. ->where('imgurl', '!=', '')
  1262. // ->where($website)
  1263. ->limit($parentImgNum)
  1264. ->get()->all();
  1265. // 查询文字新闻
  1266. $textArticles = Article::where('catid', $parentCatId)
  1267. // ->where($website)
  1268. ->limit($parentTextNum)
  1269. ->get()->all();
  1270. }
  1271. $resultItem = [
  1272. 'alias' => $category ? $category->alias : null,
  1273. 'category_id' => $parentCatId,
  1274. 'imgnum' => $imgArticles,
  1275. 'textnum' => $textArticles
  1276. ];
  1277. if (!empty($item['child']) && $item['child'] != "") {
  1278. // 查询第一个pid等于parent中第一个参数的category来获取child的category_id
  1279. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)->first();
  1280. if ($childCategory) {
  1281. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  1282. // 查询子栏目名称
  1283. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)->first(['alias', 'category_id']);
  1284. if(empty($childCategoryInfo)){
  1285. $childImgArticles = [];
  1286. $childTextArticles = [];
  1287. }else{
  1288. // 查询子栏目图片新闻
  1289. $childImgArticles = Article::where('catid', $childCatId)
  1290. ->where('imgurl', '!=', '')
  1291. // ->where($website)
  1292. ->limit($childImgNum)
  1293. ->get()->all();
  1294. // 查询子栏目文字新闻
  1295. $childTextArticles = Article::where('catid', $childCatId)
  1296. // ->where($website)
  1297. ->limit($childTextNum)
  1298. ->get()->all();
  1299. }
  1300. $resultItem['child'] = [
  1301. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  1302. 'category_id' => $childCatId,
  1303. 'imgnum' => $childImgArticles,
  1304. 'textnum' => $childTextArticles
  1305. ];
  1306. }
  1307. }
  1308. return $resultItem;
  1309. }, $data);
  1310. return Result::success($result);
  1311. // return Result::success($data);
  1312. }
  1313. /**
  1314. * 验证导航名称是否重复
  1315. * @return void
  1316. */
  1317. public function checkCategoryName(array $data): array
  1318. {
  1319. $result = Category::when($data, function ($query) use ($data) {
  1320. if (isset($data['name']) && $data['name']) {
  1321. $query->where("name", $data['name']);
  1322. }
  1323. if (isset($data['id']) && $data['id']) {
  1324. $query->where("id", "!=", $data['id']);
  1325. }
  1326. })->first();
  1327. if ($result) {
  1328. return Result::error("已存在");
  1329. } else {
  1330. return Result::success();
  1331. }
  1332. }
  1333. //20250226 产品列表
  1334. public function getGoodList(array $data): array
  1335. {
  1336. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  1337. unset($data['type_id']);
  1338. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  1339. $where = [];
  1340. if ($type_id != '10000') {
  1341. $where = [
  1342. 'good.user_id' => $user_id,
  1343. ];
  1344. }
  1345. //类型
  1346. if (isset($data['type_id']) && $data['type_id']) {
  1347. $where = [
  1348. 'type_id' => $data['type_id'],
  1349. ];
  1350. }
  1351. //名称
  1352. if (isset($data['name']) && $data['name']) {
  1353. $where = [
  1354. 'good.name' => $data['name'],
  1355. ];
  1356. }
  1357. $where1 = [];
  1358. //website_id
  1359. // if (isset($data['website_id']) && $data['website_id']) {
  1360. // $where1 = [
  1361. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  1362. // ];
  1363. // }
  1364. // website_name
  1365. if (isset($data['website_name']) && $data['website_name']) {
  1366. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  1367. }
  1368. // catid
  1369. if (isset($data['category_name']) && $data['category_name']) {
  1370. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  1371. }
  1372. // $result = Good::where($where)
  1373. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  1374. $result = Good::where($where)
  1375. ->when(!empty($where1), function ($query) use ($where1) {
  1376. return $query->where($where1);
  1377. })
  1378. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  1379. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  1380. ->leftJoin('category', 'good.catid', '=', 'category.id')
  1381. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  1382. ->orderBy("id", "desc")
  1383. ->limit($data['page_size'])
  1384. ->offset(($data['page'] - 1) * $data['page_size'])
  1385. ->get();
  1386. $count = Good::where($where)
  1387. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  1388. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  1389. ->leftJoin('category', 'good.catid', '=', 'category.id')
  1390. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  1391. ->orderBy("updated_at", "desc")->count();
  1392. $data = [
  1393. 'rows' => $result->toArray(),
  1394. 'count' => $count,
  1395. ];
  1396. if (empty($result)) {
  1397. return Result::error("此栏目暂无相关产品", 0);
  1398. }
  1399. return Result::success($data);
  1400. }
  1401. public function getGoodInfo(array $data): array
  1402. {
  1403. $result = Good::where('id', $data['id'])->first();
  1404. if (empty($result)) {
  1405. return Result::error("此产品不存在", 0);
  1406. }
  1407. return Result::success($result);
  1408. }
  1409. public function addGood(array $data): array
  1410. {
  1411. // unset($data['city_arr_id']);
  1412. // unset($data['cat_arr_id']);
  1413. $data['city_id'] = end($data['city_arr_id']);
  1414. $data['catid'] = end($data['cat_arr_id']);
  1415. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  1416. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  1417. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  1418. unset($data['imgUrl']);
  1419. $result = Good::insert($data);
  1420. if (empty($result)) {
  1421. return Result::error("添加失败", 0);
  1422. }
  1423. return Result::success($result);
  1424. }
  1425. public function updateGood(array $data): array
  1426. {
  1427. $data['city_id'] = end($data['city_arr_id']);
  1428. $data['catid'] = end($data['cat_arr_id']);
  1429. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  1430. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  1431. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  1432. //设置东八区
  1433. date_default_timezone_set('Asia/Shanghai');
  1434. $data['updated_at'] = date('Y-m-d H:i:s');
  1435. $result = Good::where('id', $data['id'])->update($data);
  1436. if (empty($result)) {
  1437. return Result::error("更新失败", 0);
  1438. }
  1439. return Result::success($result);
  1440. }
  1441. public function delGood(array $data): array
  1442. {
  1443. $result = Good::where('id', $data['id'])->delete();
  1444. if (empty($result)) {
  1445. return Result::error("删除失败", 0);
  1446. }
  1447. return Result::success($result);
  1448. }
  1449. //20250226 产品列表
  1450. //20250306 求职信息
  1451. public function getJobHuntingList(array $data): array
  1452. {
  1453. $where = [];
  1454. if (isset($data['username']) && !empty($data['username'])) {
  1455. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  1456. }
  1457. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  1458. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  1459. unset($data['type_id']);
  1460. if ($type_id != '10000') {
  1461. $where[] = ['job_hunting.user_id', '=', $user_id];
  1462. }
  1463. $result = JobHunting::where($where)
  1464. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  1465. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  1466. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  1467. ->orderBy("id", "desc")
  1468. ->limit($data['page_size'])
  1469. ->offset(($data['page'] - 1) * $data['page_size'])
  1470. ->get();
  1471. if (empty($result)) {
  1472. return Result::error("查询失败", 0);
  1473. }
  1474. $count = JobHunting::where($where)
  1475. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  1476. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  1477. ->count();
  1478. $data = [
  1479. 'rows' => $result->toArray(),
  1480. 'count' => $count,
  1481. ];
  1482. return Result::success($data);
  1483. }
  1484. public function addJobHunting(array $data): array
  1485. {
  1486. date_default_timezone_set('Asia/Shanghai');
  1487. unset($data['company_name']);
  1488. unset($data['job_industry']);
  1489. unset($data['job_name']);
  1490. unset($data['department']);
  1491. unset($data['job_timeList']);
  1492. unset($data['job_content']);
  1493. $data['created_at'] = date('Y-m-d H:i:s');
  1494. $data['updated_at'] = date('Y-m-d H:i:s');
  1495. var_dump($data, '-----------------test---------');
  1496. $result = JobHunting::create($data);
  1497. if (empty($result)) {
  1498. return Result::error("添加失败", 0);
  1499. }
  1500. return Result::success($result);
  1501. }
  1502. public function delJobHunting(array $data): array
  1503. {
  1504. $result = JobHunting::where('id', $data['id'])->delete();
  1505. if (empty($result)) {
  1506. return Result::error("删除失败", 0);
  1507. }
  1508. return Result::success($result);
  1509. }
  1510. public function updateJobHunting(array $data): array
  1511. {
  1512. //设置东八区
  1513. date_default_timezone_set('Asia/Shanghai');
  1514. unset($data['company_name']);
  1515. unset($data['job_industry']);
  1516. unset($data['job_name']);
  1517. unset($data['department']);
  1518. unset($data['job_timeList']);
  1519. unset($data['job_content']);
  1520. $data['created_at'] = date('Y-m-d H:i:s');
  1521. $data['updated_at'] = date('Y-m-d H:i:s');
  1522. $result = JobHunting::where('id', $data['id'])->update($data);
  1523. if (empty($result)) {
  1524. return Result::error("更新失败", 0);
  1525. }
  1526. return Result::success($result);
  1527. }
  1528. public function getJobHuntingInfo(array $data): array
  1529. {
  1530. $result = JobHunting::where('id', $data['id'])->first();
  1531. if (empty($result)) {
  1532. return Result::error("查询失败", 0);
  1533. }
  1534. return Result::success($result);
  1535. }
  1536. public function getJobHuntingData(array $data): array
  1537. {
  1538. $jobEnum = JobEnum::get();
  1539. $jobIndustry = JobIndustry::get();
  1540. $jobNature = JobNature::get();
  1541. $jobPosition = JobPosition::get();
  1542. $data = [
  1543. 'jobEnum' => $jobEnum,
  1544. 'jobIndustry' => $jobIndustry,
  1545. 'jobNature' => $jobNature,
  1546. 'jobPosition' => $jobPosition,
  1547. ];
  1548. return Result::success($data);
  1549. }
  1550. public function delJobHuntingInfo(array $data): array
  1551. {
  1552. $result = JobHunting::where('id', $data['id'])->delete();
  1553. return Result::success();
  1554. }
  1555. //20250324 通知,公告,消息
  1556. public function delNotice(array $data): array
  1557. {
  1558. return Result::success();
  1559. }
  1560. public function getNoticeInfo(array $data): array
  1561. {
  1562. $result = Notice::where('id', $data['id'])->first();
  1563. if (empty($result)) {
  1564. return Result::error("查询失败", 0);
  1565. }
  1566. return Result::success($result);
  1567. }
  1568. public function addNotice(array $data): array
  1569. {
  1570. $result = Notice::create($data);
  1571. return Result::success($result);
  1572. }
  1573. public function updateNotice(array $data): array
  1574. {
  1575. $result = Notice::where('id', $data['id'])->update($data);
  1576. return Result::success($result);
  1577. }
  1578. public function getNoticeList(array $data): array
  1579. {
  1580. $result = Notice::where('status', 1)->get();
  1581. return Result::success($result);
  1582. }
  1583. public function getNoticeDetail(array $data): array
  1584. {
  1585. $result = Notice::where('id', $data['id'])->first();
  1586. if (empty($result)) {
  1587. return Result::error("查询失败", 0);
  1588. }
  1589. return Result::success($result);
  1590. }
  1591. public function deleteNotice(array $data): array
  1592. {
  1593. $result = Notice::where('id', $data['id'])->delete();
  1594. return Result::success($result);
  1595. }
  1596. public function getMSG(array $data): array
  1597. {
  1598. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  1599. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  1600. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  1601. $result = [];
  1602. if ($type_id == 1) {
  1603. //最近的5篇已审的文章
  1604. $apply_articale = Article::where('status', 1)
  1605. ->orderBy('updated_at', 'desc')
  1606. ->limit(5)->get();
  1607. //获取5条单聊未读聊天消息
  1608. $chat = ChatRecords::where('is_read', 0)
  1609. ->where('user_id', $user_id)
  1610. ->where('talk_type', 1)
  1611. ->orderBy('created_at', 'desc')
  1612. ->limit(5)->get();
  1613. //获取5条未读群聊信息
  1614. $chat_group = ChatRecords::where('is_read', 0)
  1615. ->where('user_id', $user_id)
  1616. ->where('talk_type', 2)
  1617. ->orderBy('created_at', 'desc')
  1618. ->limit(5)->get();
  1619. $count = count($chat) + count($chat_group) + count($apply_articale);
  1620. $result = [
  1621. 'apply_articale' => $apply_articale,
  1622. 'chat' => $chat,
  1623. 'chat_group' => $chat_group,
  1624. 'count' => $count,
  1625. ];
  1626. } elseif ($type_id == 2) {
  1627. //最近的5篇已审的文章
  1628. $apply_articale = Article::where('status', 1)->limit(5)->get();
  1629. //获取5条单聊未读聊天消息
  1630. $chat = ChatRecords::where('is_read', 0)
  1631. ->where('user_id', $user_id)
  1632. ->where('talk_type', 1)
  1633. ->orderBy('created_at', 'desc')
  1634. ->limit(5)->get();
  1635. //获取5条未读群聊信息
  1636. $chat_group = ChatRecords::where('is_read', 0)
  1637. ->where('user_id', $user_id)
  1638. ->where('talk_type', 2)
  1639. ->orderBy('created_at', 'desc')
  1640. ->limit(5)->get();
  1641. $count = count($chat) + count($chat_group) + count($apply_articale);
  1642. $result = [
  1643. 'apply_articale' => $apply_articale,
  1644. 'chat' => $chat,
  1645. 'chat_group' => $chat_group,
  1646. 'count' => $count,
  1647. ];
  1648. } elseif ($type_id == 3) {
  1649. //最近的5篇已审的文章
  1650. $apply_articale = Article::where('status', 1)->limit(5)->get();
  1651. //获取5条单聊未读聊天消息
  1652. $chat = ChatRecords::where('is_read', 0)
  1653. ->where('user_id', $user_id)
  1654. ->where('talk_type', 1)
  1655. ->orderBy('created_at', 'desc')
  1656. ->limit(5)->get();
  1657. //获取5条未读群聊信息
  1658. $chat_group = ChatRecords::where('is_read', 0)
  1659. ->where('user_id', $user_id)
  1660. ->where('talk_type', 2)
  1661. ->orderBy('created_at', 'desc')
  1662. ->limit(5)->get();
  1663. $count = count($chat) + count($chat_group) + count($apply_articale);
  1664. $result = [
  1665. 'apply_articale' => $apply_articale,
  1666. 'chat' => $chat,
  1667. 'chat_group' => $chat_group,
  1668. 'count' => $count,
  1669. ];
  1670. } elseif ($type_id == 4) {
  1671. //最近的5篇已审的文章
  1672. $apply_articale = Article::where('status', 1)->limit(5)->get();
  1673. $count = count($apply_articale);
  1674. $result = [
  1675. 'count' => $count,
  1676. ];
  1677. } elseif ($type_id == 10000) {
  1678. //获取未审核的5篇文章
  1679. $apply_articale = Article::where('status', 0)
  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 == 20000) {
  1702. }
  1703. var_dump($type_id, '-----------------test---------');
  1704. return Result::success($result);
  1705. }
  1706. public function getComplaintList(array $data): array
  1707. {
  1708. $result = Notice::where('status', 1)->get();
  1709. return Result::success($result);
  1710. }
  1711. public function getComplaintInfo(array $data): array
  1712. {
  1713. $result = Notice::where('id', $data['id'])->first();
  1714. if (empty($result)) {
  1715. return Result::error("查询失败", 0);
  1716. }
  1717. return Result::success($result);
  1718. }
  1719. public function addComplaint(array $data): array
  1720. {
  1721. $result = Notice::create($data);
  1722. return Result::success($result);
  1723. }
  1724. public function updateComplaint(array $data): array
  1725. {
  1726. $result = Notice::where('id', $data['id'])->update($data);
  1727. return Result::success($result);
  1728. }
  1729. public function deleteComplaint(array $data): array
  1730. {
  1731. $result = Notice::where('id', $data['id'])->delete();
  1732. return Result::success($result);
  1733. }
  1734. public function getComplainInfo(array $data): array
  1735. {
  1736. $result = Notice::where('id', $data['id'])->first();
  1737. if (empty($result)) {
  1738. return Result::error("查询失败", 0);
  1739. }
  1740. return Result::success($result);
  1741. }
  1742. //20250324 通知,公告,消息
  1743. }