NewsService.php 81 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003
  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. $parent_alias = $category->alias ?? '';
  1270. $parent_pinyin = $category->aLIas_pinyin ?'/'.$category->aLIas_pinyin.'/' : null;
  1271. // 查询图片新闻
  1272. $imgArticles = Article::where('catid', $parentCatId)
  1273. ->where('status', 1)
  1274. ->where(function ($query) use ($website) {
  1275. $query->where(function ($subQuery) use ($website) {
  1276. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($website['website_id'])."') = 0");
  1277. })->orWhereNull("ignore_ids");
  1278. })
  1279. ->where('imgurl', '!=', '')
  1280. ->select(
  1281. 'article.id',
  1282. 'article.title',
  1283. 'article.imgurl',
  1284. 'article.author',
  1285. 'article.updated_at',
  1286. 'article.introduce',
  1287. 'article.islink',
  1288. 'article.linkurl',
  1289. 'article.copyfrom')
  1290. ->orderBy('updated_at', 'desc')
  1291. ->limit($parentImgNum)
  1292. ->get()->all();
  1293. // 查询文字新闻
  1294. $textArticles = Article::where('catid', $parentCatId)
  1295. ->where('status', 1)
  1296. ->where(function ($query) use ($website) {
  1297. $query->where(function ($subQuery) use ($website) {
  1298. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1299. })->orWhereNull("ignore_ids");
  1300. })
  1301. ->select(
  1302. 'article.id',
  1303. 'article.title',
  1304. 'article.author',
  1305. 'article.updated_at',
  1306. 'article.introduce',
  1307. 'article.islink',
  1308. 'article.linkurl',
  1309. 'article.copyfrom')
  1310. ->orderBy('updated_at', 'desc')
  1311. ->limit($parentTextNum)
  1312. ->get()->all();
  1313. }
  1314. $resultItem = [
  1315. 'alias' => $parent_alias,
  1316. 'category_id' => $parentCatId,
  1317. 'pinyin' => $parent_pinyin,
  1318. 'imgnum' => $imgArticles,
  1319. 'textnum' => $textArticles,
  1320. ];
  1321. if (!empty($item['child']) && $item['child'] != "") {
  1322. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin : '';
  1323. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  1324. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin, '/') as aLIas_pinyin", [$parent_pinyin_str])
  1325. ->get()->all();
  1326. if ($childCategory) {
  1327. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  1328. // 查询子栏目名称
  1329. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  1330. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin, '/') as aLIas_pinyin", [$parent_pinyin])
  1331. ->first();
  1332. if(empty($childCategoryInfo)){
  1333. $childImgArticles = [];
  1334. $childTextArticles = [];
  1335. } else {
  1336. // 查询子栏目图片新闻
  1337. $childImgArticles = Article::where('catid', $childCatId)
  1338. ->where('status', 1)
  1339. ->where(function ($query) use ($website) {
  1340. $query->where(function ($subQuery) use ($website) {
  1341. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1342. })->orWhereNull("ignore_ids");
  1343. })
  1344. ->select(
  1345. 'article.id',
  1346. 'article.title',
  1347. 'article.imgurl',
  1348. 'article.author',
  1349. 'article.updated_at',
  1350. 'article.introduce',
  1351. 'article.islink',
  1352. 'article.linkurl',
  1353. 'article.copyfrom')
  1354. ->where('imgurl', '!=', '')
  1355. ->orderBy('updated_at', 'desc')
  1356. ->limit($childImgNum)
  1357. ->get()->all();
  1358. // 查询子栏目文字新闻
  1359. $childTextArticles = Article::where('catid', $childCatId)
  1360. ->where('status', 1)
  1361. ->where(function ($query) use ($website) {
  1362. $query->where(function ($subQuery) use ($website) {
  1363. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1364. })->orWhereNull("ignore_ids");
  1365. })
  1366. ->select(
  1367. 'article.id',
  1368. 'article.title',
  1369. 'article.author',
  1370. 'article.updated_at',
  1371. 'article.introduce',
  1372. 'article.islink',
  1373. 'article.linkurl',
  1374. 'article.copyfrom')
  1375. ->orderBy('updated_at', 'desc')
  1376. ->limit($childTextNum)
  1377. ->get()->all();
  1378. }
  1379. $resultItem['child'] = [
  1380. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  1381. 'category_id' => $childCatId,
  1382. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  1383. 'all_childcat' => $childCategory,
  1384. 'imgnum' => $childImgArticles,
  1385. 'textnum' => $childTextArticles,
  1386. ];
  1387. // $resultItem['pinyin'] = $childCategoryInfo->aLIas_pinyin ?? '';
  1388. }
  1389. }
  1390. return $resultItem;
  1391. }, $data);
  1392. return Result::success($result);
  1393. // return Result::success($data);
  1394. }
  1395. /**
  1396. * 乡村网-获取特殊新闻模块
  1397. * @param array $data
  1398. * @return array
  1399. */
  1400. public function getWebsiteArticles(array $data): array
  1401. {
  1402. $input['id'] = $data['id'];
  1403. $input['website_id'] = $data['website_id'];
  1404. $data = json_decode($input['id'], true);
  1405. // 使用 array_map 处理每个元素
  1406. $result = array_map(function ($item) use ($input) {
  1407. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  1408. $website = [
  1409. 'website_id' => $input['website_id']
  1410. ];
  1411. // 查询栏目名称
  1412. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id','aLIas_pinyin']);
  1413. $pinyin = $category->aLIas_pinyin ? '/'.$category->aLIas_pinyin.'/' : null;
  1414. if(empty($category)){
  1415. $imgArticles = [];
  1416. $textArticles = [];
  1417. // return Result::error("暂无此栏目",0);
  1418. }else{
  1419. // return Result::success($website);
  1420. // 查询图片新闻
  1421. // 合并查询条件
  1422. $baseQuery = Article::where(function ($query) use ($website) {
  1423. $query->where(function ($subQuery) use ($website) {
  1424. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1425. })->orWhereNull("ignore_ids");
  1426. })
  1427. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($parentCatId) . "')")
  1428. ->leftJoin('website_category', 'website_category.category_id', 'article.catid')
  1429. ->where('website_category.website_id', $website['website_id'])
  1430. ->where('article.status', 1);
  1431. // 查询文字新闻
  1432. $textArticles = clone $baseQuery;
  1433. $textArticles = $textArticles
  1434. ->select(
  1435. 'article.id',
  1436. 'article.title',
  1437. // 'article.imgurl',
  1438. 'article.author',
  1439. 'article.updated_at',
  1440. 'article.introduce',
  1441. 'article.islink',
  1442. 'article.linkurl',
  1443. 'article.copyfrom',
  1444. 'website_category.category_id',
  1445. 'website_category.alias',
  1446. 'website_category.aLIas_pinyin'
  1447. )
  1448. ->selectRaw("CONCAT(?, aLIas_pinyin, '/') as aLIas_pinyin", [$pinyin])
  1449. ->orderBy('article.updated_at', 'desc')
  1450. ->limit($parentTextNum)
  1451. ->get()
  1452. ->all();
  1453. // 查询图片新闻
  1454. $imgArticles = clone $baseQuery;
  1455. $imgArticles = $imgArticles
  1456. ->select(
  1457. 'article.id',
  1458. 'article.title',
  1459. 'article.imgurl',
  1460. 'article.author',
  1461. 'article.updated_at',
  1462. 'article.introduce',
  1463. 'article.islink',
  1464. 'article.linkurl',
  1465. 'article.copyfrom',
  1466. 'website_category.category_id',
  1467. 'website_category.alias',
  1468. 'website_category.aLIas_pinyin'
  1469. )
  1470. ->selectRaw("CONCAT(?, aLIas_pinyin, '/') as aLIas_pinyin", [$pinyin])
  1471. ->orderBy('article.updated_at', 'desc')
  1472. ->where('imgurl', '!=', '')
  1473. ->limit($parentImgNum)
  1474. ->get()
  1475. ->all();
  1476. }
  1477. $resultItem = [
  1478. 'alias' => $category ? $category->alias : null,
  1479. 'category_id' => $parentCatId,
  1480. 'pinyin' => $pinyin ? $pinyin : null,
  1481. 'imgnum' => $imgArticles ?? [],
  1482. 'textnum' => $textArticles ?? [],
  1483. ];
  1484. return $resultItem;
  1485. }, $data);
  1486. return Result::success($result);
  1487. }
  1488. /**
  1489. * 验证导航名称是否重复
  1490. * @return void
  1491. */
  1492. public function checkCategoryName(array $data): array
  1493. {
  1494. $result = Category::when($data, function ($query) use ($data) {
  1495. if (isset($data['name']) && $data['name']) {
  1496. $query->where("name", $data['name']);
  1497. }
  1498. if (isset($data['id']) && $data['id']) {
  1499. $query->where("id", "!=", $data['id']);
  1500. }
  1501. })->first();
  1502. if ($result) {
  1503. return Result::error("已存在");
  1504. } else {
  1505. return Result::success();
  1506. }
  1507. }
  1508. //20250226 产品列表
  1509. public function getGoodList(array $data): array
  1510. {
  1511. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  1512. unset($data['type_id']);
  1513. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  1514. $where = [];
  1515. if ($type_id != '10000') {
  1516. $where = [
  1517. 'good.user_id' => $user_id,
  1518. ];
  1519. }
  1520. //类型
  1521. if (isset($data['type_id']) && $data['type_id']) {
  1522. $where = [
  1523. 'type_id' => $data['type_id'],
  1524. ];
  1525. }
  1526. //名称
  1527. if (isset($data['name']) && $data['name']) {
  1528. $where = [
  1529. 'good.name' => $data['name'],
  1530. ];
  1531. }
  1532. $where1 = [];
  1533. //website_id
  1534. // if (isset($data['website_id']) && $data['website_id']) {
  1535. // $where1 = [
  1536. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  1537. // ];
  1538. // }
  1539. // website_name
  1540. if (isset($data['website_name']) && $data['website_name']) {
  1541. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  1542. }
  1543. // catid
  1544. if (isset($data['category_name']) && $data['category_name']) {
  1545. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  1546. }
  1547. // $result = Good::where($where)
  1548. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  1549. $result = Good::where($where)
  1550. ->when(!empty($where1), function ($query) use ($where1) {
  1551. return $query->where($where1);
  1552. })
  1553. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  1554. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  1555. ->leftJoin('category', 'good.catid', '=', 'category.id')
  1556. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  1557. ->orderBy("id", "desc")
  1558. ->limit($data['page_size'])
  1559. ->offset(($data['page'] - 1) * $data['page_size'])
  1560. ->get();
  1561. $count = Good::where($where)
  1562. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  1563. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  1564. ->leftJoin('category', 'good.catid', '=', 'category.id')
  1565. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  1566. ->orderBy("updated_at", "desc")->count();
  1567. $data = [
  1568. 'rows' => $result->toArray(),
  1569. 'count' => $count,
  1570. ];
  1571. if (empty($result)) {
  1572. return Result::error("此栏目暂无相关产品", 0);
  1573. }
  1574. return Result::success($data);
  1575. }
  1576. public function getGoodInfo(array $data): array
  1577. {
  1578. $result = Good::where('id', $data['id'])->first();
  1579. if (empty($result)) {
  1580. return Result::error("此产品不存在", 0);
  1581. }
  1582. return Result::success($result);
  1583. }
  1584. public function addGood(array $data): array
  1585. {
  1586. // unset($data['city_arr_id']);
  1587. // unset($data['cat_arr_id']);
  1588. $data['city_id'] = end($data['city_arr_id']);
  1589. $data['catid'] = end($data['cat_arr_id']);
  1590. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  1591. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  1592. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  1593. unset($data['imgUrl']);
  1594. $result = Good::insert($data);
  1595. if (empty($result)) {
  1596. return Result::error("添加失败", 0);
  1597. }
  1598. return Result::success($result);
  1599. }
  1600. public function updateGood(array $data): array
  1601. {
  1602. $data['city_id'] = end($data['city_arr_id']);
  1603. $data['catid'] = end($data['cat_arr_id']);
  1604. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  1605. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  1606. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  1607. //设置东八区
  1608. date_default_timezone_set('Asia/Shanghai');
  1609. $data['updated_at'] = date('Y-m-d H:i:s');
  1610. $result = Good::where('id', $data['id'])->update($data);
  1611. if (empty($result)) {
  1612. return Result::error("更新失败", 0);
  1613. }
  1614. return Result::success($result);
  1615. }
  1616. public function delGood(array $data): array
  1617. {
  1618. $result = Good::where('id', $data['id'])->delete();
  1619. if (empty($result)) {
  1620. return Result::error("删除失败", 0);
  1621. }
  1622. return Result::success($result);
  1623. }
  1624. //20250226 产品列表
  1625. //20250306 求职信息
  1626. public function getJobHuntingList(array $data): array
  1627. {
  1628. $where = [];
  1629. if (isset($data['username']) && !empty($data['username'])) {
  1630. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  1631. }
  1632. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  1633. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  1634. unset($data['type_id']);
  1635. if ($type_id != '10000') {
  1636. $where[] = ['job_hunting.user_id', '=', $user_id];
  1637. }
  1638. $result = JobHunting::where($where)
  1639. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  1640. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  1641. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  1642. ->orderBy("id", "desc")
  1643. ->limit($data['page_size'])
  1644. ->offset(($data['page'] - 1) * $data['page_size'])
  1645. ->get();
  1646. if (empty($result)) {
  1647. return Result::error("查询失败", 0);
  1648. }
  1649. $count = JobHunting::where($where)
  1650. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  1651. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  1652. ->count();
  1653. $data = [
  1654. 'rows' => $result->toArray(),
  1655. 'count' => $count,
  1656. ];
  1657. return Result::success($data);
  1658. }
  1659. public function addJobHunting(array $data): array
  1660. {
  1661. date_default_timezone_set('Asia/Shanghai');
  1662. unset($data['company_name']);
  1663. unset($data['job_industry']);
  1664. unset($data['job_name']);
  1665. unset($data['department']);
  1666. unset($data['job_timeList']);
  1667. unset($data['job_content']);
  1668. $data['created_at'] = date('Y-m-d H:i:s');
  1669. $data['updated_at'] = date('Y-m-d H:i:s');
  1670. var_dump($data, '-----------------test---------');
  1671. $result = JobHunting::create($data);
  1672. if (empty($result)) {
  1673. return Result::error("添加失败", 0);
  1674. }
  1675. return Result::success($result);
  1676. }
  1677. public function delJobHunting(array $data): array
  1678. {
  1679. $result = JobHunting::where('id', $data['id'])->delete();
  1680. if (empty($result)) {
  1681. return Result::error("删除失败", 0);
  1682. }
  1683. return Result::success($result);
  1684. }
  1685. public function updateJobHunting(array $data): array
  1686. {
  1687. //设置东八区
  1688. date_default_timezone_set('Asia/Shanghai');
  1689. unset($data['company_name']);
  1690. unset($data['job_industry']);
  1691. unset($data['job_name']);
  1692. unset($data['department']);
  1693. unset($data['job_timeList']);
  1694. unset($data['job_content']);
  1695. $data['created_at'] = date('Y-m-d H:i:s');
  1696. $data['updated_at'] = date('Y-m-d H:i:s');
  1697. $result = JobHunting::where('id', $data['id'])->update($data);
  1698. if (empty($result)) {
  1699. return Result::error("更新失败", 0);
  1700. }
  1701. return Result::success($result);
  1702. }
  1703. public function getJobHuntingInfo(array $data): array
  1704. {
  1705. $result = JobHunting::where('id', $data['id'])->first();
  1706. if (empty($result)) {
  1707. return Result::error("查询失败", 0);
  1708. }
  1709. return Result::success($result);
  1710. }
  1711. public function getJobHuntingData(array $data): array
  1712. {
  1713. $jobEnum = JobEnum::get();
  1714. $jobIndustry = JobIndustry::get();
  1715. $jobNature = JobNature::get();
  1716. $jobPosition = JobPosition::get();
  1717. $data = [
  1718. 'jobEnum' => $jobEnum,
  1719. 'jobIndustry' => $jobIndustry,
  1720. 'jobNature' => $jobNature,
  1721. 'jobPosition' => $jobPosition,
  1722. ];
  1723. return Result::success($data);
  1724. }
  1725. public function delJobHuntingInfo(array $data): array
  1726. {
  1727. $result = JobHunting::where('id', $data['id'])->delete();
  1728. return Result::success();
  1729. }
  1730. //20250324 通知,公告,消息
  1731. public function delNotice(array $data): array
  1732. {
  1733. return Result::success();
  1734. }
  1735. public function getNoticeInfo(array $data): array
  1736. {
  1737. $result = Notice::where('id', $data['id'])->first();
  1738. if (empty($result)) {
  1739. return Result::error("查询失败", 0);
  1740. }
  1741. return Result::success($result);
  1742. }
  1743. public function addNotice(array $data): array
  1744. {
  1745. $result = Notice::create($data);
  1746. return Result::success($result);
  1747. }
  1748. public function updateNotice(array $data): array
  1749. {
  1750. $result = Notice::where('id', $data['id'])->update($data);
  1751. return Result::success($result);
  1752. }
  1753. public function getNoticeList(array $data): array
  1754. {
  1755. $result = Notice::where('status', 1)->get();
  1756. return Result::success($result);
  1757. }
  1758. public function getNoticeDetail(array $data): array
  1759. {
  1760. $result = Notice::where('id', $data['id'])->first();
  1761. if (empty($result)) {
  1762. return Result::error("查询失败", 0);
  1763. }
  1764. return Result::success($result);
  1765. }
  1766. public function deleteNotice(array $data): array
  1767. {
  1768. $result = Notice::where('id', $data['id'])->delete();
  1769. return Result::success($result);
  1770. }
  1771. public function getMSG(array $data): array
  1772. {
  1773. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  1774. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  1775. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  1776. $result = [];
  1777. if ($type_id == 1) {
  1778. //最近的5篇已审的文章
  1779. $apply_articale = Article::where('status', 1)
  1780. ->where('admin_user_id', $user_id)
  1781. ->orderBy('updated_at', 'desc')
  1782. ->limit(5)->get();
  1783. //获取5条单聊未读聊天消息
  1784. $chat = ChatRecords::where('is_read', 0)
  1785. ->where('user_id', $user_id)
  1786. ->where('talk_type', 1)
  1787. ->orderBy('created_at', 'desc')
  1788. ->limit(5)->get();
  1789. //获取5条未读群聊信息
  1790. $chat_group = ChatRecords::where('is_read', 0)
  1791. ->where('user_id', $user_id)
  1792. ->where('talk_type', 2)
  1793. ->orderBy('created_at', 'desc')
  1794. ->limit(5)->get();
  1795. $count = count($chat) + count($chat_group) + count($apply_articale);
  1796. $result = [
  1797. 'apply_articale' => $apply_articale,
  1798. 'chat' => $chat,
  1799. 'chat_group' => $chat_group,
  1800. 'count' => $count,
  1801. ];
  1802. } elseif ($type_id == 2) {
  1803. //最近的5篇已审的文章
  1804. $apply_articale = Article::where('status', 1)
  1805. ->where('admin_user_id', $user_id)
  1806. ->limit(5)->get();
  1807. //获取5条单聊未读聊天消息
  1808. $chat = ChatRecords::where('is_read', 0)
  1809. ->where('user_id', $user_id)
  1810. ->where('talk_type', 1)
  1811. ->orderBy('created_at', 'desc')
  1812. ->limit(5)->get();
  1813. //获取5条未读群聊信息
  1814. $chat_group = ChatRecords::where('is_read', 0)
  1815. ->where('user_id', $user_id)
  1816. ->where('talk_type', 2)
  1817. ->orderBy('created_at', 'desc')
  1818. ->limit(5)->get();
  1819. $count = count($chat) + count($chat_group) + count($apply_articale);
  1820. $result = [
  1821. 'apply_articale' => $apply_articale,
  1822. 'chat' => $chat,
  1823. 'chat_group' => $chat_group,
  1824. 'count' => $count,
  1825. ];
  1826. } elseif ($type_id == 3) {
  1827. //最近的5篇已审的文章
  1828. $apply_articale = Article::where('status', 1)
  1829. ->where('admin_user_id', $user_id)
  1830. ->limit(5)->get();
  1831. //获取5条单聊未读聊天消息
  1832. $chat = ChatRecords::where('is_read', 0)
  1833. ->where('user_id', $user_id)
  1834. ->where('talk_type', 1)
  1835. ->orderBy('created_at', 'desc')
  1836. ->limit(5)->get();
  1837. //获取5条未读群聊信息
  1838. $chat_group = ChatRecords::where('is_read', 0)
  1839. ->where('user_id', $user_id)
  1840. ->where('talk_type', 2)
  1841. ->orderBy('created_at', 'desc')
  1842. ->limit(5)->get();
  1843. $count = count($chat) + count($chat_group) + count($apply_articale);
  1844. $result = [
  1845. 'apply_articale' => $apply_articale,
  1846. 'chat' => $chat,
  1847. 'chat_group' => $chat_group,
  1848. 'count' => $count,
  1849. ];
  1850. } elseif ($type_id == 4) {
  1851. //最近的5篇已审的文章
  1852. $apply_articale = Article::where('status', 1)
  1853. ->where('admin_user_id', $user_id)
  1854. ->limit(5)->get();
  1855. $count = count($apply_articale);
  1856. $result = [
  1857. 'apply_articale' => $apply_articale,
  1858. 'count' => $count,
  1859. ];
  1860. } elseif ($type_id == 10000) {
  1861. //获取未审核的5篇文章
  1862. $apply_articale = Article::where('status', 0)
  1863. ->orderBy('updated_at', 'desc')
  1864. ->limit(5)->get();
  1865. //获取5条单聊未读聊天消息
  1866. $chat = ChatRecords::where('is_read', 0)
  1867. ->where('user_id', $user_id)
  1868. ->where('talk_type', 1)
  1869. ->orderBy('created_at', 'desc')
  1870. ->limit(5)->get();
  1871. //获取5条未读群聊信息
  1872. $chat_group = ChatRecords::where('is_read', 0)
  1873. ->where('user_id', $user_id)
  1874. ->where('talk_type', 2)
  1875. ->orderBy('created_at', 'desc')
  1876. ->limit(5)->get();
  1877. $count = count($chat) + count($chat_group) + count($apply_articale);
  1878. $result = [
  1879. 'apply_articale' => $apply_articale,
  1880. 'chat' => $chat,
  1881. 'chat_group' => $chat_group,
  1882. 'count' => $count,
  1883. ];
  1884. } elseif ($type_id == 20000) {
  1885. }
  1886. var_dump($type_id, '-----------------test---------');
  1887. return Result::success($result);
  1888. }
  1889. public function getComplaintList(array $data): array
  1890. {
  1891. $result = Notice::where('status', 1)->get();
  1892. return Result::success($result);
  1893. }
  1894. public function getComplaintInfo(array $data): array
  1895. {
  1896. $result = Notice::where('id', $data['id'])->first();
  1897. if (empty($result)) {
  1898. return Result::error("查询失败", 0);
  1899. }
  1900. return Result::success($result);
  1901. }
  1902. public function addComplaint(array $data): array
  1903. {
  1904. $result = Notice::create($data);
  1905. return Result::success($result);
  1906. }
  1907. public function updateComplaint(array $data): array
  1908. {
  1909. $result = Notice::where('id', $data['id'])->update($data);
  1910. return Result::success($result);
  1911. }
  1912. public function deleteComplaint(array $data): array
  1913. {
  1914. $result = Notice::where('id', $data['id'])->delete();
  1915. return Result::success($result);
  1916. }
  1917. public function getComplainInfo(array $data): array
  1918. {
  1919. $result = Notice::where('id', $data['id'])->first();
  1920. if (empty($result)) {
  1921. return Result::error("查询失败", 0);
  1922. }
  1923. return Result::success($result);
  1924. }
  1925. //20250324 通知,公告,消息
  1926. }