NewsService.php 46 KB

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