NewsService.php 79 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948
  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. // 修正传入的字符串,将单引号替换为双引号
  1360. $input['id'] = $data['id'];
  1361. $input['website_id'] = $data['website_id'];
  1362. // 将 JSON 字符串转换为 PHP 数组
  1363. $data = json_decode($input['id'], true);
  1364. // 使用 array_map 处理每个元素
  1365. $result = array_map(function ($item) use ($input) {
  1366. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  1367. $website = [
  1368. 'website_id' => $input['website_id'],
  1369. ];
  1370. // 查询栏目名称
  1371. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id','aLIas_pinyin']);
  1372. if(empty($category)){
  1373. $imgArticles = [];
  1374. $textArticles = [];
  1375. // return Result::error("暂无此栏目",0);
  1376. }else{
  1377. // 查询图片新闻
  1378. $imgArticles = Article::where('status',1)
  1379. ->where(function ($query) use ($website) {
  1380. $query->where(function ($subQuery) use ($website) {
  1381. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($website['website_id'])."') = 0");
  1382. })->orWhereNull("ignore_ids");
  1383. })
  1384. ->where('imgurl', '!=', '')
  1385. ->whereRaw("JSON_CONTAINS(category_arr_id, '".intval($parentCatId)."')")
  1386. ->leftJoin('website_category', 'website_category.category_id', 'article.catid','website_category.aLIas_pinyin')
  1387. ->select('article.*','website_category.category_id','website_category.alias')
  1388. ->orderBy('updated_at', 'desc')
  1389. ->limit($parentImgNum)
  1390. ->get()->all();
  1391. // 查询文字新闻
  1392. $textArticles = Article::where('status',1)
  1393. ->where(function ($query) use ($website) {
  1394. $query->where(function ($subQuery) use ($website) {
  1395. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($website['website_id'])."') = 0");
  1396. })->orWhereNull("ignore_ids");
  1397. })
  1398. ->whereRaw("JSON_CONTAINS(category_arr_id, '".intval($parentCatId)."')")
  1399. ->leftJoin('website_category', 'website_category.category_id', 'article.catid','website_category.aLIas_pinyin')
  1400. ->select('article.*','website_category.category_id','website_category.alias','website_category.aLIas_pinyin')
  1401. ->orderBy('updated_at', 'desc')
  1402. ->limit($parentTextNum)
  1403. ->get()->all();
  1404. }
  1405. $resultItem = [
  1406. 'alias' => $category ? $category->alias : null,
  1407. 'category_id' => $parentCatId,
  1408. 'pinyin' => $category->aLIas_pinyin ?? '',
  1409. 'imgnum' => $imgArticles,
  1410. 'textnum' => $textArticles,
  1411. ];
  1412. return $resultItem;
  1413. }, $data);
  1414. $web = Website::where('id',$data['website_id'])->first();
  1415. if(empty($web)){
  1416. return Result::error("暂无此网站",0);
  1417. }
  1418. $where = [
  1419. // 'article.catid' => $data['catid'],
  1420. 'article.status' => 1,
  1421. ];
  1422. $articles['img'] = Article::where($where)
  1423. ->where('imgurl', '!=', '')
  1424. ->whereNotNull('imgurl')
  1425. ->whereRaw("JSON_CONTAINS(category_arr_id, '".intval($data['catid'])."')")
  1426. ->leftJoin('website_category', 'website_category.category_id', 'article.catid','website_category.aLIas_pinyin')
  1427. ->select('article.*','website_category.category_id','website_category.alias')
  1428. ->orderBy('updated_at', 'desc')
  1429. ->limit($data['img_num'])
  1430. ->get()->all();
  1431. $articles['text'] = Article::where($where)
  1432. ->whereRaw("JSON_CONTAINS(category_arr_id, '".intval($data['catid'])."')")
  1433. ->leftJoin('website_category', 'website_category.category_id', 'article.catid')
  1434. ->select('article.*','website_category.category_id','website_category.alias','website_category.aLIas_pinyin')
  1435. ->orderBy('updated_at', 'desc')
  1436. ->limit($data['text_num'])
  1437. ->get()->all();
  1438. if(empty($articles)){
  1439. return Result::error("暂无此栏目",0);
  1440. }
  1441. return Result::success($articles);
  1442. }
  1443. /**
  1444. * 验证导航名称是否重复
  1445. * @return void
  1446. */
  1447. public function checkCategoryName(array $data): array
  1448. {
  1449. $result = Category::when($data, function ($query) use ($data) {
  1450. if (isset($data['name']) && $data['name']) {
  1451. $query->where("name", $data['name']);
  1452. }
  1453. if (isset($data['id']) && $data['id']) {
  1454. $query->where("id", "!=", $data['id']);
  1455. }
  1456. })->first();
  1457. if ($result) {
  1458. return Result::error("已存在");
  1459. } else {
  1460. return Result::success();
  1461. }
  1462. }
  1463. //20250226 产品列表
  1464. public function getGoodList(array $data): array
  1465. {
  1466. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  1467. unset($data['type_id']);
  1468. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  1469. $where = [];
  1470. if ($type_id != '10000') {
  1471. $where = [
  1472. 'good.user_id' => $user_id,
  1473. ];
  1474. }
  1475. //类型
  1476. if (isset($data['type_id']) && $data['type_id']) {
  1477. $where = [
  1478. 'type_id' => $data['type_id'],
  1479. ];
  1480. }
  1481. //名称
  1482. if (isset($data['name']) && $data['name']) {
  1483. $where = [
  1484. 'good.name' => $data['name'],
  1485. ];
  1486. }
  1487. $where1 = [];
  1488. //website_id
  1489. // if (isset($data['website_id']) && $data['website_id']) {
  1490. // $where1 = [
  1491. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  1492. // ];
  1493. // }
  1494. // website_name
  1495. if (isset($data['website_name']) && $data['website_name']) {
  1496. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  1497. }
  1498. // catid
  1499. if (isset($data['category_name']) && $data['category_name']) {
  1500. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  1501. }
  1502. // $result = Good::where($where)
  1503. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  1504. $result = Good::where($where)
  1505. ->when(!empty($where1), function ($query) use ($where1) {
  1506. return $query->where($where1);
  1507. })
  1508. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  1509. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  1510. ->leftJoin('category', 'good.catid', '=', 'category.id')
  1511. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  1512. ->orderBy("id", "desc")
  1513. ->limit($data['page_size'])
  1514. ->offset(($data['page'] - 1) * $data['page_size'])
  1515. ->get();
  1516. $count = Good::where($where)
  1517. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  1518. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  1519. ->leftJoin('category', 'good.catid', '=', 'category.id')
  1520. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  1521. ->orderBy("updated_at", "desc")->count();
  1522. $data = [
  1523. 'rows' => $result->toArray(),
  1524. 'count' => $count,
  1525. ];
  1526. if (empty($result)) {
  1527. return Result::error("此栏目暂无相关产品", 0);
  1528. }
  1529. return Result::success($data);
  1530. }
  1531. public function getGoodInfo(array $data): array
  1532. {
  1533. $result = Good::where('id', $data['id'])->first();
  1534. if (empty($result)) {
  1535. return Result::error("此产品不存在", 0);
  1536. }
  1537. return Result::success($result);
  1538. }
  1539. public function addGood(array $data): array
  1540. {
  1541. // unset($data['city_arr_id']);
  1542. // unset($data['cat_arr_id']);
  1543. $data['city_id'] = end($data['city_arr_id']);
  1544. $data['catid'] = end($data['cat_arr_id']);
  1545. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  1546. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  1547. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  1548. unset($data['imgUrl']);
  1549. $result = Good::insert($data);
  1550. if (empty($result)) {
  1551. return Result::error("添加失败", 0);
  1552. }
  1553. return Result::success($result);
  1554. }
  1555. public function updateGood(array $data): array
  1556. {
  1557. $data['city_id'] = end($data['city_arr_id']);
  1558. $data['catid'] = end($data['cat_arr_id']);
  1559. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  1560. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  1561. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  1562. //设置东八区
  1563. date_default_timezone_set('Asia/Shanghai');
  1564. $data['updated_at'] = date('Y-m-d H:i:s');
  1565. $result = Good::where('id', $data['id'])->update($data);
  1566. if (empty($result)) {
  1567. return Result::error("更新失败", 0);
  1568. }
  1569. return Result::success($result);
  1570. }
  1571. public function delGood(array $data): array
  1572. {
  1573. $result = Good::where('id', $data['id'])->delete();
  1574. if (empty($result)) {
  1575. return Result::error("删除失败", 0);
  1576. }
  1577. return Result::success($result);
  1578. }
  1579. //20250226 产品列表
  1580. //20250306 求职信息
  1581. public function getJobHuntingList(array $data): array
  1582. {
  1583. $where = [];
  1584. if (isset($data['username']) && !empty($data['username'])) {
  1585. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  1586. }
  1587. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  1588. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  1589. unset($data['type_id']);
  1590. if ($type_id != '10000') {
  1591. $where[] = ['job_hunting.user_id', '=', $user_id];
  1592. }
  1593. $result = JobHunting::where($where)
  1594. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  1595. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  1596. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  1597. ->orderBy("id", "desc")
  1598. ->limit($data['page_size'])
  1599. ->offset(($data['page'] - 1) * $data['page_size'])
  1600. ->get();
  1601. if (empty($result)) {
  1602. return Result::error("查询失败", 0);
  1603. }
  1604. $count = JobHunting::where($where)
  1605. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  1606. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  1607. ->count();
  1608. $data = [
  1609. 'rows' => $result->toArray(),
  1610. 'count' => $count,
  1611. ];
  1612. return Result::success($data);
  1613. }
  1614. public function addJobHunting(array $data): array
  1615. {
  1616. date_default_timezone_set('Asia/Shanghai');
  1617. unset($data['company_name']);
  1618. unset($data['job_industry']);
  1619. unset($data['job_name']);
  1620. unset($data['department']);
  1621. unset($data['job_timeList']);
  1622. unset($data['job_content']);
  1623. $data['created_at'] = date('Y-m-d H:i:s');
  1624. $data['updated_at'] = date('Y-m-d H:i:s');
  1625. var_dump($data, '-----------------test---------');
  1626. $result = JobHunting::create($data);
  1627. if (empty($result)) {
  1628. return Result::error("添加失败", 0);
  1629. }
  1630. return Result::success($result);
  1631. }
  1632. public function delJobHunting(array $data): array
  1633. {
  1634. $result = JobHunting::where('id', $data['id'])->delete();
  1635. if (empty($result)) {
  1636. return Result::error("删除失败", 0);
  1637. }
  1638. return Result::success($result);
  1639. }
  1640. public function updateJobHunting(array $data): array
  1641. {
  1642. //设置东八区
  1643. date_default_timezone_set('Asia/Shanghai');
  1644. unset($data['company_name']);
  1645. unset($data['job_industry']);
  1646. unset($data['job_name']);
  1647. unset($data['department']);
  1648. unset($data['job_timeList']);
  1649. unset($data['job_content']);
  1650. $data['created_at'] = date('Y-m-d H:i:s');
  1651. $data['updated_at'] = date('Y-m-d H:i:s');
  1652. $result = JobHunting::where('id', $data['id'])->update($data);
  1653. if (empty($result)) {
  1654. return Result::error("更新失败", 0);
  1655. }
  1656. return Result::success($result);
  1657. }
  1658. public function getJobHuntingInfo(array $data): array
  1659. {
  1660. $result = JobHunting::where('id', $data['id'])->first();
  1661. if (empty($result)) {
  1662. return Result::error("查询失败", 0);
  1663. }
  1664. return Result::success($result);
  1665. }
  1666. public function getJobHuntingData(array $data): array
  1667. {
  1668. $jobEnum = JobEnum::get();
  1669. $jobIndustry = JobIndustry::get();
  1670. $jobNature = JobNature::get();
  1671. $jobPosition = JobPosition::get();
  1672. $data = [
  1673. 'jobEnum' => $jobEnum,
  1674. 'jobIndustry' => $jobIndustry,
  1675. 'jobNature' => $jobNature,
  1676. 'jobPosition' => $jobPosition,
  1677. ];
  1678. return Result::success($data);
  1679. }
  1680. public function delJobHuntingInfo(array $data): array
  1681. {
  1682. $result = JobHunting::where('id', $data['id'])->delete();
  1683. return Result::success();
  1684. }
  1685. //20250324 通知,公告,消息
  1686. public function delNotice(array $data): array
  1687. {
  1688. return Result::success();
  1689. }
  1690. public function getNoticeInfo(array $data): array
  1691. {
  1692. $result = Notice::where('id', $data['id'])->first();
  1693. if (empty($result)) {
  1694. return Result::error("查询失败", 0);
  1695. }
  1696. return Result::success($result);
  1697. }
  1698. public function addNotice(array $data): array
  1699. {
  1700. $result = Notice::create($data);
  1701. return Result::success($result);
  1702. }
  1703. public function updateNotice(array $data): array
  1704. {
  1705. $result = Notice::where('id', $data['id'])->update($data);
  1706. return Result::success($result);
  1707. }
  1708. public function getNoticeList(array $data): array
  1709. {
  1710. $result = Notice::where('status', 1)->get();
  1711. return Result::success($result);
  1712. }
  1713. public function getNoticeDetail(array $data): array
  1714. {
  1715. $result = Notice::where('id', $data['id'])->first();
  1716. if (empty($result)) {
  1717. return Result::error("查询失败", 0);
  1718. }
  1719. return Result::success($result);
  1720. }
  1721. public function deleteNotice(array $data): array
  1722. {
  1723. $result = Notice::where('id', $data['id'])->delete();
  1724. return Result::success($result);
  1725. }
  1726. public function getMSG(array $data): array
  1727. {
  1728. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  1729. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  1730. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  1731. $result = [];
  1732. if ($type_id == 1) {
  1733. //最近的5篇已审的文章
  1734. $apply_articale = Article::where('status', 1)
  1735. ->orderBy('updated_at', 'desc')
  1736. ->limit(5)->get();
  1737. //获取5条单聊未读聊天消息
  1738. $chat = ChatRecords::where('is_read', 0)
  1739. ->where('user_id', $user_id)
  1740. ->where('talk_type', 1)
  1741. ->orderBy('created_at', 'desc')
  1742. ->limit(5)->get();
  1743. //获取5条未读群聊信息
  1744. $chat_group = ChatRecords::where('is_read', 0)
  1745. ->where('user_id', $user_id)
  1746. ->where('talk_type', 2)
  1747. ->orderBy('created_at', 'desc')
  1748. ->limit(5)->get();
  1749. $count = count($chat) + count($chat_group) + count($apply_articale);
  1750. $result = [
  1751. 'apply_articale' => $apply_articale,
  1752. 'chat' => $chat,
  1753. 'chat_group' => $chat_group,
  1754. 'count' => $count,
  1755. ];
  1756. } elseif ($type_id == 2) {
  1757. //最近的5篇已审的文章
  1758. $apply_articale = Article::where('status', 1)->limit(5)->get();
  1759. //获取5条单聊未读聊天消息
  1760. $chat = ChatRecords::where('is_read', 0)
  1761. ->where('user_id', $user_id)
  1762. ->where('talk_type', 1)
  1763. ->orderBy('created_at', 'desc')
  1764. ->limit(5)->get();
  1765. //获取5条未读群聊信息
  1766. $chat_group = ChatRecords::where('is_read', 0)
  1767. ->where('user_id', $user_id)
  1768. ->where('talk_type', 2)
  1769. ->orderBy('created_at', 'desc')
  1770. ->limit(5)->get();
  1771. $count = count($chat) + count($chat_group) + count($apply_articale);
  1772. $result = [
  1773. 'apply_articale' => $apply_articale,
  1774. 'chat' => $chat,
  1775. 'chat_group' => $chat_group,
  1776. 'count' => $count,
  1777. ];
  1778. } elseif ($type_id == 3) {
  1779. //最近的5篇已审的文章
  1780. $apply_articale = Article::where('status', 1)->limit(5)->get();
  1781. //获取5条单聊未读聊天消息
  1782. $chat = ChatRecords::where('is_read', 0)
  1783. ->where('user_id', $user_id)
  1784. ->where('talk_type', 1)
  1785. ->orderBy('created_at', 'desc')
  1786. ->limit(5)->get();
  1787. //获取5条未读群聊信息
  1788. $chat_group = ChatRecords::where('is_read', 0)
  1789. ->where('user_id', $user_id)
  1790. ->where('talk_type', 2)
  1791. ->orderBy('created_at', 'desc')
  1792. ->limit(5)->get();
  1793. $count = count($chat) + count($chat_group) + count($apply_articale);
  1794. $result = [
  1795. 'apply_articale' => $apply_articale,
  1796. 'chat' => $chat,
  1797. 'chat_group' => $chat_group,
  1798. 'count' => $count,
  1799. ];
  1800. } elseif ($type_id == 4) {
  1801. //最近的5篇已审的文章
  1802. $apply_articale = Article::where('status', 1)->limit(5)->get();
  1803. $count = count($apply_articale);
  1804. $result = [
  1805. 'count' => $count,
  1806. ];
  1807. } elseif ($type_id == 10000) {
  1808. //获取未审核的5篇文章
  1809. $apply_articale = Article::where('status', 0)
  1810. ->orderBy('updated_at', 'desc')
  1811. ->limit(5)->get();
  1812. //获取5条单聊未读聊天消息
  1813. $chat = ChatRecords::where('is_read', 0)
  1814. ->where('user_id', $user_id)
  1815. ->where('talk_type', 1)
  1816. ->orderBy('created_at', 'desc')
  1817. ->limit(5)->get();
  1818. //获取5条未读群聊信息
  1819. $chat_group = ChatRecords::where('is_read', 0)
  1820. ->where('user_id', $user_id)
  1821. ->where('talk_type', 2)
  1822. ->orderBy('created_at', 'desc')
  1823. ->limit(5)->get();
  1824. $count = count($chat) + count($chat_group) + count($apply_articale);
  1825. $result = [
  1826. 'apply_articale' => $apply_articale,
  1827. 'chat' => $chat,
  1828. 'chat_group' => $chat_group,
  1829. 'count' => $count,
  1830. ];
  1831. } elseif ($type_id == 20000) {
  1832. }
  1833. var_dump($type_id, '-----------------test---------');
  1834. return Result::success($result);
  1835. }
  1836. public function getComplaintList(array $data): array
  1837. {
  1838. $result = Notice::where('status', 1)->get();
  1839. return Result::success($result);
  1840. }
  1841. public function getComplaintInfo(array $data): array
  1842. {
  1843. $result = Notice::where('id', $data['id'])->first();
  1844. if (empty($result)) {
  1845. return Result::error("查询失败", 0);
  1846. }
  1847. return Result::success($result);
  1848. }
  1849. public function addComplaint(array $data): array
  1850. {
  1851. $result = Notice::create($data);
  1852. return Result::success($result);
  1853. }
  1854. public function updateComplaint(array $data): array
  1855. {
  1856. $result = Notice::where('id', $data['id'])->update($data);
  1857. return Result::success($result);
  1858. }
  1859. public function deleteComplaint(array $data): array
  1860. {
  1861. $result = Notice::where('id', $data['id'])->delete();
  1862. return Result::success($result);
  1863. }
  1864. public function getComplainInfo(array $data): array
  1865. {
  1866. $result = Notice::where('id', $data['id'])->first();
  1867. if (empty($result)) {
  1868. return Result::error("查询失败", 0);
  1869. }
  1870. return Result::success($result);
  1871. }
  1872. //20250324 通知,公告,消息
  1873. }