NewsService.php 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195
  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\Good;
  10. use App\Model\Website;
  11. use Hyperf\DbConnection\Db;
  12. use Hyperf\RpcServer\Annotation\RpcService;
  13. use App\Tools\Result;
  14. use Ramsey\Uuid\Uuid;
  15. use Hyperf\Utils\Random;
  16. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  17. class NewsService implements NewsServiceInterface
  18. {
  19. /**
  20. * 获取导航池列表
  21. * @param array $data
  22. * @return array
  23. */
  24. public function getCategoryList(array $data): array
  25. {
  26. $where = [];
  27. if (isset($data['name']) && $data['name']) {
  28. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  29. }
  30. if (isset($data['department_id']) && $data['department_id']) {
  31. array_push($where, ['category.department_id', '=', $data['department_id']]);
  32. }
  33. $city_id = '';
  34. if (isset($data['city_id']) && $data['city_id']) {
  35. $city_id = intval($data['city_id']);
  36. }
  37. $rep = Category::where($where)
  38. ->when($city_id, function ($query) use ($city_id) {
  39. if (isset($city_id) && $city_id) {
  40. $query->whereJsonContains("category.city_arr_id", $city_id);
  41. }
  42. })
  43. ->leftJoin('district', 'category.city_id', 'district.id')
  44. ->leftJoin('department', 'category.department_id', 'department.id')
  45. ->select("category.*", "district.name as city_name", "department.name as department_name")
  46. ->limit($data['pageSize'])->orderByDesc('category.updated_at')->offset(($data['page'] - 1) * $data['pageSize'])->get();
  47. $count = Category::where($where)->when($city_id, function ($query) use ($city_id) {
  48. if (isset($city_id) && $city_id) {
  49. $query->whereJsonContains("category.city_arr_id", $city_id);
  50. }
  51. })->count();
  52. $data = [
  53. 'rows' => $rep->toArray(),
  54. 'count' => $count,
  55. ];
  56. if (empty($rep->toArray())) {
  57. return Result::error("没有导航池数据");
  58. }
  59. return Result::success($data);
  60. }
  61. public function myCategoryList(array $data): array
  62. {
  63. $sszq = $data['sszq'] ?? '';
  64. unset($data['sszq']);
  65. //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
  66. $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
  67. $where[] = [
  68. 'pid', '=', $data['pid'],
  69. ];
  70. if (isset($data['name'])) {
  71. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  72. }
  73. var_dump($where);
  74. //根据分类id,从category表中取出分类信息
  75. $result = Category::where($where)
  76. ->whereIn('category.id', $catorytids)
  77. ->select('category.*', 'category.id as category_id')->get();
  78. if (empty($result)) {
  79. return Result::error("没有栏目数据");
  80. }
  81. return Result::success($result);
  82. }
  83. /**
  84. * @param array $data
  85. * @return array
  86. */
  87. public function categoryList(array $data): array
  88. {
  89. $where[] = [
  90. 'pid', '=', $data['pid'],
  91. ];
  92. if (isset($data['name'])) {
  93. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  94. }
  95. var_dump($where);
  96. $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
  97. if (empty($result)) {
  98. return Result::error("没有栏目数据");
  99. }
  100. return Result::success($result);
  101. }
  102. /**
  103. * @param array $data
  104. * @return array
  105. */
  106. public function addCategory(array $data): array
  107. {
  108. $id = Category::insertGetId($data);
  109. if (empty($id)) {
  110. return Result::error("添加失败");
  111. }
  112. return Result::success(['id' => $id]);
  113. }
  114. /**
  115. * @param array $data
  116. * @return array
  117. */
  118. public function delCategory(array $data): array
  119. {
  120. $categoryList = Category::where(['pid' => $data['id']])->get();
  121. var_dump("分类列表:", $data, $categoryList);
  122. if ($categoryList->toArray()) {
  123. return Result::error("分类下面有子分类不能删除");
  124. }
  125. $articleList = Article::where(['catid' => $data['id']])->get();
  126. var_dump("文章列表:", $articleList);
  127. if ($articleList->toArray()) {
  128. return Result::error("分类下面有资讯不能删除");
  129. }
  130. $result = Category::where($data)->delete();
  131. if (!$result) {
  132. return Result::error("删除失败");
  133. }
  134. return Result::success($result);
  135. }
  136. /**
  137. * @param array $data
  138. * @return array
  139. */
  140. public function updateCategory(array $data): array
  141. {
  142. $where = [
  143. 'id' => $data['id'],
  144. ];
  145. $result = Category::where($where)->update($data);
  146. if ($result) {
  147. return Result::success($result);
  148. } else {
  149. return Result::error("更新失败");
  150. }
  151. }
  152. /**
  153. * 获取导航池信息
  154. * @param array $data
  155. * @return array
  156. */
  157. public function getCategoryInfo(array $data): array
  158. {
  159. $where = [
  160. 'id' => $data['id'],
  161. ];
  162. $result = Category::where($where)->first();
  163. if ($result) {
  164. return Result::success($result);
  165. } else {
  166. return Result::error("更新失败");
  167. }
  168. }
  169. /**
  170. * @param array $data
  171. * @return array
  172. */
  173. public function getArticleList(array $data): array
  174. {
  175. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  176. $type_id = $data['type_id'];
  177. unset($data['type_id']);
  178. $user_id = $data['user_id'];
  179. unset($data['user_id']);
  180. $where = [];
  181. $status1 = [];
  182. if (isset($data['title']) && $data['title']) {
  183. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  184. }
  185. if (isset($data['category_name']) && $data['category_name']) {
  186. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  187. }
  188. if (isset($data['author']) && $data['author']) {
  189. array_push($where, ['article.author', '=', $data['author']]);
  190. }
  191. if (isset($data['islink']) && $data['islink'] !== "") {
  192. array_push($where, ['article.islink', '=', $data['islink']]);
  193. }
  194. if (isset($data['status']) && $data['status'] !== "") {
  195. array_push($where, ['article.status', '=', $data['status']]);
  196. }
  197. if (isset($data['status1'])) {
  198. $status1 = json_decode(($data['status1']));
  199. }
  200. //不是管理员展示个人数据;
  201. if ($type_id != 10000) {
  202. $where[] = ['article.admin_user_id', '=', $user_id];
  203. }
  204. $rep = Article::where($where)
  205. ->whereNotIn('article.status', [404])
  206. ->when($status1, function ($query) use ($status1) {
  207. if (isset($status1) && $status1) {
  208. $query->whereIn('article.status', $status1);
  209. }
  210. })
  211. ->leftJoin('category', 'article.catid', 'category.id')
  212. ->select("article.*", "category.name as category_name")
  213. ->orderBy("article.id", "desc")
  214. ->limit($data['pageSize'])
  215. ->offset(($data['page'] - 1) * $data['pageSize'])->get();
  216. $count = Article::where($where)->whereNotIn('article.status', [404])
  217. ->when($status1, function ($query) use ($status1) {
  218. if (isset($status1) && $status1) {
  219. $query->whereIn('article.status', $status1);
  220. }
  221. })
  222. ->leftJoin('category', 'article.catid', 'category.id')->count();
  223. $data = [
  224. 'rows' => $rep->toArray(),
  225. 'count' => $count,
  226. ];
  227. if (empty($rep)) {
  228. return Result::error("没有信息数据");
  229. }
  230. return Result::success($data);
  231. }
  232. /**
  233. * @param array $data
  234. * @return array
  235. */
  236. public function addArticle(array $data): array
  237. {
  238. var_dump($data, '----------12-----------1');
  239. unset($data['user_type']);
  240. // unset($data['web_site_id']);
  241. unset($data['nav_add_pool_id']);
  242. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  243. Db::beginTransaction();
  244. try {
  245. //处理投票
  246. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  247. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  248. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  249. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  250. unset($data['is_survey']);
  251. unset($data['survey_name']);
  252. unset($data['suvey_array']);
  253. unset($data['website_id']);
  254. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  255. if ($data['hits'] == '') {
  256. $data['hits'] = 0;
  257. }
  258. if ($data['is_original'] == '') {
  259. $data['is_original'] = 0;
  260. }
  261. if ($data['status'] == '') {
  262. $data['status'] = 0;
  263. }
  264. $articleData = $data;
  265. unset($articleData['content']);
  266. $id = Article::insertGetId($articleData);
  267. $articleDataContent = [
  268. 'article_id' => $id,
  269. 'content' => $data['content'],
  270. ];
  271. ArticleData::insertGetId($articleDataContent);
  272. //处理投票
  273. if ($is_survey == 1) {
  274. //生成年月日时分秒+8位随机数
  275. $uuid = date('YmdHis') . rand(10000000, 99999999);
  276. var_dump($suvey_array, 'suvey_array________');
  277. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  278. var_dump($suveys_array, '---------------------1');
  279. var_dump($suvey_array, '---------------------2');
  280. $suvey_data = [];
  281. foreach ($suveys_array as $key => $value) {
  282. if ($value == '') {
  283. continue;
  284. }
  285. if (is_array($value)) {
  286. $suvey_data[] = [
  287. 'sur_id' => $uuid,
  288. 'art_id' => $id,
  289. 'website_id' => $website_id ?? 2,
  290. 'survey_name' => $survey_name,
  291. 'choice_name' => $value[1],
  292. 'is_other' => 1,
  293. 'other_id' => 0,
  294. 'results' => 0,
  295. ];
  296. } else {
  297. $suvey_data[] = [
  298. 'sur_id' => $uuid,
  299. 'art_id' => $id,
  300. 'website_id' => $website_id ?? 2,
  301. 'survey_name' => $survey_name,
  302. 'choice_name' => $value,
  303. 'is_other' => 0,
  304. 'other_id' => 0,
  305. 'results' => 0,
  306. ];
  307. }
  308. if (empty($suvey_data)) {
  309. throw new \Exception("投票数据为空");
  310. }
  311. }
  312. $result = ArticleSurvey::insert($suvey_data);
  313. if (!$result) {
  314. throw new \Exception("投票失败,ArticleSurvey插入失败");
  315. }
  316. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  317. if (!$result) {
  318. throw new \Exception("投票失败,更新主表失败");
  319. }
  320. }
  321. Db::commit();
  322. return Result::success(['id' => $id]);
  323. } catch (\Throwable $ex) {
  324. Db::rollBack();
  325. var_dump($ex->getMessage());
  326. return Result::error("创建失败", 0);
  327. }
  328. }
  329. /**
  330. * @param array $data
  331. * @return array
  332. */
  333. public function delArticle(array $data): array
  334. {
  335. $result = Article::where($data)->delete();
  336. //survey投票删除
  337. articleSurvey::where(['art_id' => $data['id']])->delete();
  338. if (!$result) {
  339. return Result::error("删除失败");
  340. }
  341. return Result::success($result);
  342. }
  343. /**
  344. * @param array $data
  345. * @return array
  346. */
  347. public function updateArticle(array $data): array
  348. {
  349. var_dump($data, '----------12-----------1');
  350. Db::beginTransaction();
  351. unset($data['user_type']);
  352. // unset($data['web_site_id']);
  353. unset($data['nav_add_pool_id']);
  354. try {
  355. //处理投票
  356. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  357. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  358. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  359. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  360. unset($data['is_survey']);
  361. unset($data['survey_name']);
  362. unset($data['suvey_array']);
  363. unset($data['website_id']);
  364. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  365. if ($data['hits'] == '') {
  366. $data['hits'] = 0;
  367. }
  368. if ($data['is_original'] == '') {
  369. $data['is_original'] = 0;
  370. }
  371. if ($data['status'] == '') {
  372. $data['status'] = 0;
  373. }
  374. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  375. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  376. $articleData = $data;
  377. unset($articleData['content']);
  378. unset($articleData['status_name']);
  379. unset($articleData['name']);
  380. unset($articleData['content']);
  381. unset($articleData['pid_arr']);
  382. unset($articleData['pid']);
  383. $id = Article::where(['id' => $data['id']])->update($articleData);
  384. $articleDataContent = [
  385. 'content' => $data['content'],
  386. ];
  387. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  388. //处理投票
  389. $id = $data['id'];
  390. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  391. var_dump($suvey_array, 'suvey_array________delete');
  392. //处理投票
  393. if ($is_survey == 1) {
  394. //生成年月日时分秒+8位随机数
  395. $uuid = date('YmdHis') . rand(10000000, 99999999);
  396. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  397. var_dump($suveys_array, '---------------------1');
  398. var_dump($suvey_array, '---------------------2');
  399. $suvey_data = [];
  400. if (is_array($suveys_array)) {
  401. foreach ($suveys_array as $key => $value) {
  402. if ($value == '') {
  403. continue;
  404. }
  405. if (is_array($value)) {
  406. $suvey_data[] = [
  407. 'sur_id' => $uuid,
  408. 'art_id' => $id,
  409. 'website_id' => $website_id ?? 2,
  410. 'survey_name' => $survey_name,
  411. 'choice_name' => $value[1],
  412. 'is_other' => 1,
  413. 'other_id' => 0,
  414. 'results' => 0,
  415. ];
  416. } else {
  417. $suvey_data[] = [
  418. 'sur_id' => $uuid,
  419. 'art_id' => $id,
  420. 'website_id' => $website_id ?? 2,
  421. 'survey_name' => $survey_name,
  422. 'choice_name' => $value,
  423. 'is_other' => 0,
  424. 'other_id' => 0,
  425. 'results' => 0,
  426. ];
  427. }
  428. if (empty($suvey_data)) {
  429. throw new \Exception("投票数据为空");
  430. }
  431. }
  432. }
  433. $result = ArticleSurvey::insert($suvey_data);
  434. if (!$result) {
  435. throw new \Exception("投票失败");
  436. }
  437. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  438. if (!$result) {
  439. throw new \Exception("投票失败");
  440. }
  441. } else {
  442. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  443. }
  444. Db::commit();
  445. return Result::success([]);
  446. } catch (\Throwable $ex) {
  447. Db::rollBack();
  448. var_dump($ex->getMessage());
  449. return Result::error("更新失败1" . $ex->getMessage(), 0);
  450. }
  451. }
  452. /**
  453. * 更新资讯状态
  454. * @param array $data
  455. * @return array
  456. */
  457. public function upArticleStatus(array $data): array
  458. {
  459. $result = Article::where(['id' => $data['id']])->update($data);
  460. if ($result) {
  461. return Result::success();
  462. } else {
  463. return Result::error("更新状态失败", 0);
  464. }
  465. }
  466. /**
  467. * @param array $data
  468. * @return array
  469. */
  470. public function getArticleInfo(array $data): array
  471. {
  472. $where = [
  473. 'article.id' => $data['id'],
  474. // 'article.status' => 1,
  475. ];
  476. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  477. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  478. $info = $result;
  479. // var_dump($info, 'info');
  480. $info['survey_array'] = $articleSurvey;
  481. if ($result) {
  482. return Result::success($info);
  483. } else {
  484. return Result::error("查询失败", 0);
  485. }
  486. }
  487. /**
  488. * 获取新闻
  489. * @param array $data
  490. * @return array
  491. */
  492. public function getWebsiteArticlett(array $data): array
  493. {
  494. $category = WebsiteCategory::where('website_id',$data['website_id'])->pluck('category_id');
  495. $result= [];
  496. if($category){
  497. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  498. $where = [
  499. 'status' => 1,
  500. 'level' => $data['level'],
  501. ];
  502. $result = Article::where($where)
  503. ->whereIn("catid", $category)
  504. ->where(function ($query) use ($data) {
  505. $query->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0")
  506. ->orWhereNull("ignore_ids");
  507. })
  508. ->orderBy("updated_at", "desc")
  509. ->offset($placeid)
  510. ->limit($data['pageSize'])
  511. ->get();
  512. if(empty($result)){
  513. return Result::error("暂无头条新闻",0);
  514. }
  515. return Result::success($result);
  516. }else{
  517. return Result::error("本网站下暂无相关栏目",0);
  518. }
  519. }
  520. /**
  521. * 获取模块新闻
  522. * @param array $data
  523. * @return array
  524. */
  525. public function getWebsiteModelArticles(array $data): array
  526. {
  527. $catid = $data['catid'];
  528. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  529. $category = $category->toArray();
  530. if (!empty($category)) {
  531. $where = [
  532. 'status' => 1,
  533. 'catid' => $catid,
  534. ];
  535. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  536. // 级别:0:未分类 1:头条 2:轮播图 3:推荐图 4:热点资讯 5:资讯推荐
  537. if ($data['level'] == 1) {
  538. $level = [
  539. 0 => '1',
  540. 1 => '4',
  541. 2 => '5',
  542. 3 => '0',
  543. ];
  544. $result = Article::where($where)
  545. ->whereIn('level',$level)
  546. ->where(function ($query) use ($data) {
  547. $query->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0")
  548. ->orWhereNull("ignore_ids");
  549. })
  550. ->orderBy("updated_at","desc")
  551. ->offset($placeid)
  552. ->limit($data['pagesize'])
  553. ->get();
  554. }elseif($data['level']==2){
  555. $level='2';
  556. $result = Article::where($where)
  557. ->where('level',$level)
  558. ->where(function ($query) use ($data) {
  559. $query->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0")
  560. ->orWhereNull("ignore_ids");
  561. })
  562. ->orderBy("updated_at","desc")
  563. ->offset($placeid)
  564. ->limit($data['pagesize'])
  565. ->get();
  566. }else{
  567. $level='3';
  568. $result = Article::where($where)
  569. ->where('level',$level)
  570. ->where(function ($query) use ($data) {
  571. $query->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0")
  572. ->orWhereNull("ignore_ids");
  573. })
  574. ->orderBy("updated_at","desc")
  575. ->offset($placeid)
  576. ->limit($data['pagesize'])
  577. ->get();
  578. }
  579. if (empty($result)) {
  580. return Result::error("此栏目暂无相关新闻", 0);
  581. }
  582. } else {
  583. return Result::error("此网站暂无此栏目", 0);
  584. }
  585. return Result::success($result);
  586. }
  587. /**
  588. *获取新闻列表
  589. * @param array $data
  590. * @return array
  591. */
  592. public function getWebsiteArticleList(array $data): array
  593. {
  594. $where[] = ['status', '=', 1];
  595. if (isset($data['keyword']) && !empty($data['keyword'])) {
  596. array_push($where, ['article.title', 'like', '%' . $data['keyword'] . '%']);
  597. }
  598. if (isset($data['catid']) && !empty($data['catid'])) {
  599. if (is_array($data['catid'])) {
  600. $category = WebsiteCategory::where('website_id', $data['website_id'])->whereIn('category_id', $data['catid'])->pluck('category_id');
  601. array_push($where, ['catid', 'in', $data['catid']]);
  602. } else {
  603. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  604. array_push($where, ['catid', '=', $data['catid']]);
  605. }
  606. if (empty($category)) {
  607. return Result::error("此网站暂无此栏目", 0);
  608. }
  609. }
  610. // return Result::success($where);
  611. $rep = Article::where(function ($query) use ($where) {
  612. foreach ($where as $condition) {
  613. if ($condition[1] === 'in') {
  614. $query->whereIn($condition[0], $condition[2]);
  615. } else {
  616. $query->where($condition[0], $condition[1], $condition[2]);
  617. }
  618. }
  619. })
  620. ->where(function ($query) use ($data) {
  621. $query->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0")
  622. ->orWhereNull("ignore_ids");
  623. })
  624. ->orderBy("updated_at", "desc")
  625. ->limit($data['pageSize'])
  626. ->offset(($data['page'] - 1) * $data['pageSize'])
  627. ->get();
  628. $count = Article::where(function ($query) use ($where) {
  629. foreach ($where as $condition) {
  630. if ($condition[1] === 'in') {
  631. $query->whereIn($condition[0], $condition[2]);
  632. } else {
  633. $query->where($condition[0], $condition[1], $condition[2]);
  634. }
  635. }
  636. })->count();
  637. $data = [
  638. 'rows' => $rep->toArray(),
  639. 'count' => $count,
  640. ];
  641. if (empty($rep)) {
  642. return Result::error("没有信息数据");
  643. }
  644. return Result::success($data);
  645. }
  646. /**
  647. * 前端-获取新闻详情
  648. * @param array $data
  649. * @return array
  650. */
  651. public function selectWebsiteArticleInfo(array $data): array
  652. {
  653. $where = [
  654. 'article.id' => $data['id'],
  655. 'article.status' => 1,
  656. ];
  657. $result = Article::where($where)->leftJoin("article_data","article.id","article_data.article_id")
  658. ->where(function ($query) use ($data) {
  659. $query->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0")
  660. ->orWhereNull("ignore_ids");
  661. })
  662. ->first();
  663. if(empty($result)){
  664. return Result::error("暂无此新闻!",0);
  665. }
  666. $category = WebsiteCategory::where('website_id', $data['website_id'])->where(['category_id' => $result['catid']])->first();
  667. if (empty($category)) {
  668. return Result::error("查询失败", 0);
  669. }
  670. $result['category_id'] = $category['category_id'];
  671. $result['cat_name'] = $category['alias'];
  672. return Result::success($result);
  673. }
  674. /**
  675. * 前端-获取网站调查问卷
  676. * @param array $data
  677. * @return array
  678. */
  679. public function getWebsiteSurvey(array $data): array
  680. {
  681. if (isset($data['website_id']) && !empty($data['website_id'])) {
  682. $website = Website::where('id', $data['website_id'])->first();
  683. if (empty($website)) {
  684. return Result::error("暂无此网站", 0);
  685. }
  686. }
  687. if (isset($data['art_id']) && !empty($data['art_id'])) {
  688. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  689. if (empty($article)) {
  690. return Result::error("暂无此文章", 0);
  691. }
  692. // return Result::error($data,0);
  693. $where['art_id'] = $data['art_id'];
  694. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  695. } else {
  696. $survey = ArticleSurvey::where('website_id', $data['website_id'])->orderBy('created_at')->first();
  697. if (empty($survey)) {
  698. return Result::error("暂无调查问卷", 0);
  699. }
  700. $where['sur_id'] = $survey['sur_id'];
  701. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  702. }
  703. $result['survey'] = ArticleSurvey::where($where)->where('is_other', 0)
  704. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  705. ->select('article_survey.*', 'article.survey_type')
  706. ->get()->all();
  707. $result['other'] = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  708. $result['others'] = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->first();
  709. if (empty($result)) {
  710. return Result::error("此文章暂无调查问卷", 0);
  711. }
  712. return Result::success($result);
  713. }
  714. /**
  715. * 前端-添加网站调查问卷选项
  716. * @param array $data
  717. * @return array
  718. */
  719. public function addWebsiteSurveyOption(array $data): array
  720. {
  721. if (isset($data['website_id']) && !empty($data['website_id'])) {
  722. $website = Website::where('id', $data['website_id'])->first();
  723. if (empty($website)) {
  724. return Result::error("暂无此网站", 0);
  725. }
  726. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  727. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('website_id', $data['website_id'])->where('is_other', 1)->where('other_id', 0)->first();
  728. if (empty($survey)) {
  729. return Result::error("此调查问卷不可添加选项", 0);
  730. }
  731. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  732. $choice = [
  733. 'art_id' => $survey['art_id'],
  734. 'website_id' => $data['website_id'],
  735. 'survey_name' => $survey['survey_name'],
  736. 'choice_name' => $data['choice_name'],
  737. 'sur_id' => $survey['sur_id'],
  738. 'is_other' => 1,
  739. 'other_id' => $survey['id'],
  740. ];
  741. $result = ArticleSurvey::insertGetId($choice);
  742. if (empty($result)) {
  743. return Result::error("添加失败", 0);
  744. }
  745. return Result::success($result);
  746. }
  747. }
  748. return Result::error("添加失败", 0);
  749. }
  750. return Result::error("添加失败", 0);
  751. }
  752. /**
  753. * 前端-调查问卷投票
  754. * @param array $data
  755. * @return array
  756. */
  757. public function addWebsiteSurveyVote(array $data): array
  758. {
  759. if (isset($data['website_id']) && !empty($data['website_id'])) {
  760. $website = Website::where('id', $data['website_id'])->first();
  761. if (empty($website)) {
  762. return Result::error("暂无此网站", 0);
  763. }
  764. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  765. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('website_id', $data['website_id'])->pluck('sur_id');
  766. if (empty($survey)) {
  767. return Result::error("此调查问卷不存在", 0);
  768. }
  769. // return Result::success($survey);
  770. // 调查问卷类型 0:单选 1:多选
  771. $type = Article::where('survey_id', $data['sur_id'])->pluck('survey_type');
  772. // return Result::success($type);
  773. if (empty($type) || ($type[0] != 1 && $type[0] != 0)) {
  774. return Result::error("此调查问卷不可投票", 0);
  775. }
  776. // return Result::success($type[0]);
  777. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  778. if ($type[0] == 0) {
  779. if (is_array($data['choice_id'])) {
  780. return Result::error("请选择一个选项!", 0);
  781. }
  782. $data['choice_id'] = [$data['choice_id']];
  783. } else {
  784. if (!is_array($data['choice_id'])) {
  785. return Result::error("请传递数组!", 0);
  786. }
  787. }
  788. // return Result::success($data['choice_id']);
  789. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  790. ->where('website_id', $data['website_id'])
  791. ->where('is_other', 1)
  792. ->where('other_id', 0)
  793. ->first();
  794. if (!empty($other)) {
  795. return Result::error("请选择已有的选项!", 0);
  796. }
  797. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  798. ->where('website_id', $data['website_id'])
  799. ->where('is_other', 1)
  800. ->where('other_id', '!=', 0)
  801. ->first();
  802. // return Result::success($data);
  803. if (!empty($choice['other'])) {
  804. array_push($data['choice_id'], $choice['other']['other_id']);
  805. // return Result::success($data['choice_id']);
  806. }
  807. // return Result::success($data);
  808. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  809. ->where('website_id', $data['website_id'])
  810. ->increment('results', 1);
  811. if (empty($choice)) {
  812. return Result::error("请选择已有的选项!", 0);
  813. }
  814. return Result::success($choice);
  815. }
  816. return Result::error("参数必填!");
  817. // if(isset($data['choice_id']) && !empty($data['choice_id'])){
  818. // $choice = ArticleSurvey::whereIn('id',$data['choice_id'])->where('website_id',$data['website_id'])->where('is_other',1)->where('other_id',0)->first();
  819. // }
  820. }
  821. return Result::error("此调查问卷不存在", 0);
  822. }
  823. return Result::error("参数必填!");
  824. }
  825. /**
  826. * 后端-获取网站调查问卷列表
  827. * @param array $data
  828. * @return array
  829. */
  830. public function getSurveyList(array $data): array
  831. {
  832. $where = [];
  833. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  834. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  835. }
  836. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  837. array_push($where, ['survey_type', '=', $data['survey_type']]);
  838. }
  839. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  840. array_push($where, ['is_survey', '=', $data['is_survey']]);
  841. }
  842. // return Result::success($where);
  843. if (!empty($where)) {
  844. $query = Article::where($where)->whereNotNull('survey_name');
  845. } else {
  846. $query = Article::whereNotNull('survey_name');
  847. }
  848. $count = $query->count();
  849. $survey = $query->orderByDesc('id')
  850. ->limit($data['pageSize'])
  851. ->offset(($data['page'] - 1) * $data['pageSize'])
  852. ->get();
  853. if (empty($survey->toArray())) {
  854. return Result::error("暂无调查问卷!", 0);
  855. }
  856. $result = [
  857. 'rows' => $survey,
  858. 'count' => $count,
  859. ];
  860. return Result::success($result);
  861. }
  862. /**
  863. * 后端-获取网站调查问卷详情
  864. * @param array $data
  865. * @return array
  866. */
  867. public function getSurveyInfo(array $data): array
  868. {
  869. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  870. $where = ['sur_id' => $data['sur_id']];
  871. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  872. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  873. ->select('article_survey.*', 'article.survey_type')
  874. ->get()->all();
  875. if (empty($choose)) {
  876. return Result::error("此调查问卷不存在", 0);
  877. }
  878. $resultsArray = array_column($choose, 'results');
  879. $total = array_sum($resultsArray);
  880. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  881. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  882. // $total = 0;
  883. if (!empty($other)) {
  884. $total = $total + $other['results'];
  885. $other['choice_name'] = $other['choice_name'] . '(其他)';
  886. if (!empty($others)) {
  887. $other['hasChildren'] = true;
  888. // array_push($other,['hasChildren','=',true]);
  889. $other['children'] = $others;
  890. $other_choices = [$other->toArray()];
  891. $mer_choice = array_merge($choose, $other_choices);
  892. $value_choice = array_values($mer_choice);
  893. } else {
  894. // return Result::error('1111');
  895. $other_choices = [$other->toArray()];
  896. $other_choices = array_merge($choose, $other_choices);
  897. $value_choice = array_values($other_choices);
  898. // return Result::success($result);
  899. }
  900. } else {
  901. $value_choice = $choose;
  902. }
  903. $result = [
  904. 'choose' => $value_choice,
  905. 'total' => $total,
  906. ];
  907. }
  908. return Result::success($result);
  909. }
  910. /**
  911. * 前端-搜索新闻列表
  912. * @param array $data
  913. * @return array
  914. */
  915. public function selectWebsiteArticle(array $data): array
  916. {
  917. $where = [];
  918. // 初始化查询构造器
  919. $category = WebsiteCategory::where('website_id',$data['website_id'])->pluck('category_id');
  920. $query = Article::where('status', 1)
  921. ->whereIn('catid', $category)
  922. ->where(function ($query) use ($data) {
  923. $query->where(function ($subQuery) use ($data) {
  924. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($data['website_id'])."') = 0");
  925. })->orWhereNull("ignore_ids");
  926. });
  927. // return Result::success($all_articles);
  928. // 检查是否存在 cityid 参数
  929. if (isset($data['cityid']) && !empty($data['cityid'])) {
  930. $query->whereRaw("JSON_CONTAINS(city_arr_id, '".intval($data['cityid'])."')");
  931. }
  932. // 检查是否存在 department_id 参数
  933. if (isset($data['department_id']) && !empty($data['department_id'])) {
  934. $query->whereRaw("JSON_CONTAINS(department_arr_id, '".intval($data['department_id'])."')");
  935. }
  936. // 检查是否存在 keyword 参数
  937. if (isset($data['keyword']) && !empty($data['keyword'])) {
  938. $query->where('title', 'like', '%'.$data['keyword'].'%');
  939. }
  940. // 计算总数
  941. $count = $query->count();
  942. // 分页查询
  943. $articles = $query->orderBy("updated_at", "desc")
  944. ->limit($data['pageSize'])
  945. ->offset(($data['page'] - 1) * $data['pageSize'])
  946. ->get()->all();
  947. if (empty($articles)) {
  948. return Result::error("没有符合条件的资讯数据");
  949. }
  950. $data = [
  951. 'rows' => $articles,
  952. 'count' => $count
  953. ];
  954. return Result::success($data);
  955. }
  956. /**
  957. * 验证导航名称是否重复
  958. * @return void
  959. */
  960. public function checkCategoryName(array $data): array
  961. {
  962. $result = Category::when($data, function ($query) use ($data) {
  963. if (isset($data['name']) && $data['name']) {
  964. $query->where("name", $data['name']);
  965. }
  966. if (isset($data['id']) && $data['id']) {
  967. $query->where("id", "!=", $data['id']);
  968. }
  969. })->first();
  970. if ($result) {
  971. return Result::error("已存在");
  972. } else {
  973. return Result::success();
  974. }
  975. }
  976. //20250226 产品列表
  977. public function getGoodList(array $data): array
  978. {
  979. $where = [];
  980. //类型
  981. if (isset($data['type_id']) && $data['type_id']) {
  982. $where = [
  983. 'type_id' => $data['type_id'],
  984. ];
  985. }
  986. //名称
  987. if (isset($data['name']) && $data['name']) {
  988. $where = [
  989. 'good.name' => $data['name'],
  990. ];
  991. }
  992. $where1 = [];
  993. //website_id
  994. // if (isset($data['website_id']) && $data['website_id']) {
  995. // $where1 = [
  996. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  997. // ];
  998. // }
  999. // website_name
  1000. if (isset($data['website_name']) && $data['website_name']) {
  1001. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  1002. }
  1003. // catid
  1004. if (isset($data['category_name']) && $data['category_name']) {
  1005. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  1006. }
  1007. // $result = Good::where($where)
  1008. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  1009. $result = Good::where($where)
  1010. ->when(!empty($where1), function ($query) use ($where1) {
  1011. return $query->where($where1);
  1012. })
  1013. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  1014. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  1015. ->leftJoin('category', 'good.catid', '=', 'category.id')
  1016. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  1017. ->orderBy("id", "desc")
  1018. ->limit($data['page_size'])
  1019. ->offset(($data['page'] - 1) * $data['page_size'])
  1020. ->get();
  1021. $count = Good::where($where)
  1022. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  1023. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  1024. ->leftJoin('category', 'good.catid', '=', 'category.id')
  1025. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  1026. ->orderBy("updated_at", "desc")->count();
  1027. $data = [
  1028. 'rows' => $result->toArray(),
  1029. 'count' => $count,
  1030. ];
  1031. if (empty($result)) {
  1032. return Result::error("此栏目暂无相关产品", 0);
  1033. }
  1034. return Result::success($data);
  1035. }
  1036. public function getGoodInfo(array $data): array
  1037. {
  1038. $result = Good::where('id', $data['id'])->first();
  1039. if (empty($result)) {
  1040. return Result::error("此产品不存在", 0);
  1041. }
  1042. return Result::success($result);
  1043. }
  1044. public function addGood(array $data): array
  1045. {
  1046. // unset($data['city_arr_id']);
  1047. // unset($data['cat_arr_id']);
  1048. $data['city_id'] = end($data['city_arr_id']);
  1049. $data['catid'] = end($data['cat_arr_id']);
  1050. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  1051. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  1052. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  1053. unset($data['imgUrl']);
  1054. $result = Good::insert($data);
  1055. if (empty($result)) {
  1056. return Result::error("添加失败", 0);
  1057. }
  1058. return Result::success($result);
  1059. }
  1060. public function updateGood(array $data): array
  1061. {
  1062. $data['city_id'] = end($data['city_arr_id']);
  1063. $data['catid'] = end($data['cat_arr_id']);
  1064. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  1065. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  1066. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  1067. //设置东八区
  1068. date_default_timezone_set('Asia/Shanghai');
  1069. $data['updated_at'] = date('Y-m-d H:i:s');
  1070. $result = Good::where('id', $data['id'])->update($data);
  1071. if (empty($result)) {
  1072. return Result::error("更新失败", 0);
  1073. }
  1074. return Result::success($result);
  1075. }
  1076. public function delGood(array $data): array
  1077. {
  1078. $result = Good::where('id', $data['id'])->delete();
  1079. if (empty($result)) {
  1080. return Result::error("删除失败", 0);
  1081. }
  1082. return Result::success($result);
  1083. }
  1084. //20250226 产品列表
  1085. //20250306 求职信息
  1086. public function getJobHuntingList(array $data): array
  1087. {
  1088. $where = [];
  1089. if (isset($data['name']) && !empty($data['name'])) {
  1090. $where[] = ['name', 'like', '%' . $data['name'] . '%'];
  1091. }
  1092. $result = JobHunting::where($where)
  1093. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  1094. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  1095. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  1096. ->orderBy("updated_at", "desc")
  1097. ->limit($data['page_size'])
  1098. ->offset(($data['page'] - 1) * $data['page_size'])
  1099. ->get();
  1100. if (empty($result)) {
  1101. return Result::error("查询失败", 0);
  1102. }
  1103. $count = JobHunting::where($where)->count();
  1104. $data = [
  1105. 'rows' => $result->toArray(),
  1106. 'count' => $count,
  1107. ];
  1108. return Result::success($data);
  1109. }
  1110. public function addJobHunting(array $data): array
  1111. {
  1112. $data['created_at'] = date('Y-m-d H:i:s');
  1113. $data['updated_at'] = date('Y-m-d H:i:s');
  1114. $result = JobHunting::create($data);
  1115. if (empty($result)) {
  1116. return Result::error("添加失败", 0);
  1117. }
  1118. return Result::success($result);
  1119. }
  1120. public function delJobHunting(array $data): array
  1121. {
  1122. $result = JobHunting::where('id', $data['id'])->delete();
  1123. if (empty($result)) {
  1124. return Result::error("删除失败", 0);
  1125. }
  1126. return Result::success($result);
  1127. }
  1128. public function updateJobHunting(array $data): array
  1129. {
  1130. $result = JobHunting::where('id', $data['id'])->update($data);
  1131. if (empty($result)) {
  1132. return Result::error("更新失败", 0);
  1133. }
  1134. return Result::success($result);
  1135. }
  1136. public function getJobHuntingInfo(array $data): array
  1137. {
  1138. $result = JobHunting::where('id', $data['id'])->first();
  1139. if (empty($result)) {
  1140. return Result::error("查询失败", 0);
  1141. }
  1142. return Result::success($result);
  1143. }
  1144. }