NewsService.php 82 KB

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