NewsService.php 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091
  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. if (isset($data['title']) && $data['title']) {
  182. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  183. }
  184. if (isset($data['category_name']) && $data['category_name']) {
  185. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  186. }
  187. if (isset($data['author']) && $data['author']) {
  188. array_push($where, ['article.author', '=', $data['author']]);
  189. }
  190. if (isset($data['islink']) && $data['islink'] !== "") {
  191. array_push($where, ['article.islink', '=', $data['islink']]);
  192. }
  193. if (isset($data['status']) && $data['status'] !== "") {
  194. array_push($where, ['article.status', '=', $data['status']]);
  195. }
  196. //不是管理员展示个人数据;
  197. if ($type_id != 10000) {
  198. $where[] = ['article.admin_user_id', '=', $user_id];
  199. }
  200. $rep = Article::where($where)
  201. ->whereNotIn('article.status', [404])
  202. ->leftJoin('category', 'article.catid', 'category.id')
  203. ->select("article.*", "category.name as category_name")
  204. ->orderBy("article.id", "desc")
  205. ->limit($data['pageSize'])
  206. ->offset(($data['page'] - 1) * $data['pageSize'])->get();
  207. $count = Article::where($where)->whereNotIn('article.status', [404])
  208. ->leftJoin('category', 'article.catid', 'category.id')->count();
  209. $data = [
  210. 'rows' => $rep->toArray(),
  211. 'count' => $count,
  212. ];
  213. if (empty($rep)) {
  214. return Result::error("没有信息数据");
  215. }
  216. return Result::success($data);
  217. }
  218. /**
  219. * @param array $data
  220. * @return array
  221. */
  222. public function addArticle(array $data): array
  223. {
  224. var_dump($data, '----------12-----------1');
  225. unset($data['user_type']);
  226. // unset($data['web_site_id']);
  227. unset($data['nav_add_pool_id']);
  228. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  229. Db::beginTransaction();
  230. try {
  231. //处理投票
  232. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  233. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  234. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  235. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  236. unset($data['is_survey']);
  237. unset($data['survey_name']);
  238. unset($data['suvey_array']);
  239. unset($data['website_id']);
  240. $articleData = $data;
  241. unset($articleData['content']);
  242. $id = Article::insertGetId($articleData);
  243. $articleDataContent = [
  244. 'article_id' => $id,
  245. 'content' => $data['content'],
  246. ];
  247. ArticleData::insertGetId($articleDataContent);
  248. //处理投票
  249. if ($is_survey == 1) {
  250. //生成年月日时分秒+8位随机数
  251. $uuid = date('YmdHis') . rand(10000000, 99999999);
  252. var_dump($suvey_array, 'suvey_array________');
  253. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  254. var_dump($suveys_array, '---------------------1');
  255. var_dump($suvey_array, '---------------------2');
  256. $suvey_data = [];
  257. foreach ($suveys_array as $key => $value) {
  258. if ($value == '') {
  259. continue;
  260. }
  261. if (is_array($value)) {
  262. $suvey_data[] = [
  263. 'sur_id' => $uuid,
  264. 'art_id' => $id,
  265. 'website_id' => $website_id ?? 2,
  266. 'survey_name' => $survey_name,
  267. 'choice_name' => $value[1],
  268. 'is_other' => 1,
  269. 'other_id' => 0,
  270. 'results' => 0,
  271. ];
  272. } else {
  273. $suvey_data[] = [
  274. 'sur_id' => $uuid,
  275. 'art_id' => $id,
  276. 'website_id' => $website_id ?? 2,
  277. 'survey_name' => $survey_name,
  278. 'choice_name' => $value,
  279. 'is_other' => 0,
  280. 'other_id' => 0,
  281. 'results' => 0,
  282. ];
  283. }
  284. if (empty($suvey_data)) {
  285. throw new \Exception("投票数据为空");
  286. }
  287. }
  288. $result = ArticleSurvey::insert($suvey_data);
  289. if (!$result) {
  290. throw new \Exception("投票失败,ArticleSurvey插入失败");
  291. }
  292. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  293. if (!$result) {
  294. throw new \Exception("投票失败,更新主表失败");
  295. }
  296. }
  297. Db::commit();
  298. return Result::success(['id' => $id]);
  299. } catch (\Throwable $ex) {
  300. Db::rollBack();
  301. var_dump($ex->getMessage());
  302. return Result::error("创建失败", 0);
  303. }
  304. }
  305. /**
  306. * @param array $data
  307. * @return array
  308. */
  309. public function delArticle(array $data): array
  310. {
  311. $result = Article::where($data)->delete();
  312. //survey投票删除
  313. articleSurvey::where(['art_id' => $data['id']])->delete();
  314. if (!$result) {
  315. return Result::error("删除失败");
  316. }
  317. return Result::success($result);
  318. }
  319. /**
  320. * @param array $data
  321. * @return array
  322. */
  323. public function updateArticle(array $data): array
  324. {
  325. var_dump($data, '----------12-----------1');
  326. Db::beginTransaction();
  327. unset($data['user_type']);
  328. // unset($data['web_site_id']);
  329. unset($data['nav_add_pool_id']);
  330. try {
  331. //处理投票
  332. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  333. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  334. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  335. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  336. unset($data['is_survey']);
  337. unset($data['survey_name']);
  338. unset($data['suvey_array']);
  339. unset($data['website_id']);
  340. if ($data['hits'] == '') {
  341. $data['hits'] = 0;
  342. }
  343. if ($data['is_original'] == '') {
  344. $data['is_original'] = 0;
  345. }
  346. if ($data['status'] == '') {
  347. $data['status'] = 0;
  348. }
  349. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  350. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  351. $articleData = $data;
  352. unset($articleData['content']);
  353. unset($articleData['status_name']);
  354. unset($articleData['name']);
  355. unset($articleData['content']);
  356. unset($articleData['pid_arr']);
  357. unset($articleData['pid']);
  358. $id = Article::where(['id' => $data['id']])->update($articleData);
  359. $articleDataContent = [
  360. 'content' => $data['content'],
  361. ];
  362. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  363. //处理投票
  364. $id = $data['id'];
  365. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  366. var_dump($suvey_array, 'suvey_array________delete');
  367. //处理投票
  368. if ($is_survey == 1) {
  369. //生成年月日时分秒+8位随机数
  370. $uuid = date('YmdHis') . rand(10000000, 99999999);
  371. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  372. var_dump($suveys_array, '---------------------1');
  373. var_dump($suvey_array, '---------------------2');
  374. $suvey_data = [];
  375. if (is_array($suveys_array)) {
  376. foreach ($suveys_array as $key => $value) {
  377. if ($value == '') {
  378. continue;
  379. }
  380. if (is_array($value)) {
  381. $suvey_data[] = [
  382. 'sur_id' => $uuid,
  383. 'art_id' => $id,
  384. 'website_id' => $website_id ?? 2,
  385. 'survey_name' => $survey_name,
  386. 'choice_name' => $value[1],
  387. 'is_other' => 1,
  388. 'other_id' => 0,
  389. 'results' => 0,
  390. ];
  391. } else {
  392. $suvey_data[] = [
  393. 'sur_id' => $uuid,
  394. 'art_id' => $id,
  395. 'website_id' => $website_id ?? 2,
  396. 'survey_name' => $survey_name,
  397. 'choice_name' => $value,
  398. 'is_other' => 0,
  399. 'other_id' => 0,
  400. 'results' => 0,
  401. ];
  402. }
  403. if (empty($suvey_data)) {
  404. throw new \Exception("投票数据为空");
  405. }
  406. }
  407. }
  408. $result = ArticleSurvey::insert($suvey_data);
  409. if (!$result) {
  410. throw new \Exception("投票失败");
  411. }
  412. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  413. if (!$result) {
  414. throw new \Exception("投票失败");
  415. }
  416. } else {
  417. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  418. }
  419. Db::commit();
  420. return Result::success([]);
  421. } catch (\Throwable $ex) {
  422. Db::rollBack();
  423. var_dump($ex->getMessage());
  424. return Result::error("更新失败1" . $ex->getMessage(), 0);
  425. }
  426. }
  427. /**
  428. * 更新资讯状态
  429. * @param array $data
  430. * @return array
  431. */
  432. public function upArticleStatus(array $data): array
  433. {
  434. $result = Article::where(['id' => $data['id']])->update($data);
  435. if ($result) {
  436. return Result::success();
  437. } else {
  438. return Result::error("更新状态失败", 0);
  439. }
  440. }
  441. /**
  442. * @param array $data
  443. * @return array
  444. */
  445. public function getArticleInfo(array $data): array
  446. {
  447. $where = [
  448. 'article.id' => $data['id'],
  449. // 'article.status' => 1,
  450. ];
  451. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  452. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get()->all();
  453. var_dump($articleSurvey, 'articleSurvey');
  454. $info = $result;
  455. var_dump($info, 'info');
  456. // $info['survey_array'] = $articleSurvey == null ? [] : $info['survey_array'];
  457. if ($result) {
  458. return Result::success($info);
  459. } else {
  460. return Result::error("查询失败", 0);
  461. }
  462. }
  463. /**
  464. * 获取新闻
  465. * @param array $data
  466. * @return array
  467. */
  468. public function getWebsiteArticlett(array $data): array
  469. {
  470. $category = WebsiteCategory::where('website_id', $data['website_id'])->select('category_id')->get();
  471. $category = $category->toArray();
  472. $result = [];
  473. if ($category) {
  474. $category_ids = [];
  475. foreach ($category as $val) {
  476. array_push($category_ids, $val['category_id']);
  477. }
  478. if (isset($data['placeid'])) {
  479. $placeid = $data['placeid'] - 1;
  480. $result = Article::where('status', 1)->where('level', $data['level'])->whereIn("catid", $category_ids)->orderBy("updated_at", "desc")->offset($placeid)->limit($data['pageSize'])->get();
  481. } else {
  482. $result = Article::where('status', 1)->where('level', $data['level'])->whereIn("catid", $category_ids)->orderBy("updated_at", "desc")->offset(0)->limit($data['pageSize'])->get();
  483. }
  484. if (empty($result)) {
  485. return Result::error("暂无头条新闻", 0);
  486. }
  487. return Result::success($result);
  488. } else {
  489. return Result::error("本网站下暂无相关栏目", 0);
  490. }
  491. }
  492. /**
  493. * 获取模块新闻
  494. * @param array $data
  495. * @return array
  496. */
  497. public function getWebsiteModelArticles(array $data): array
  498. {
  499. $catid = $data['catid'];
  500. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  501. $category = $category->toArray();
  502. if (!empty($category)) {
  503. $where = [
  504. 'status' => 1,
  505. 'catid' => $catid,
  506. ];
  507. if ($data['level'] == 1) {
  508. $level = [
  509. 0 => '1',
  510. 1 => '4',
  511. 2 => '5',
  512. 3 => '0',
  513. ];
  514. $result = Article::where($where)->whereIn('level', $level)->orderBy("updated_at", "desc")->limit($data['pagesize'])->get();
  515. } elseif ($data['level'] == 2) {
  516. $level = '2';
  517. $result = Article::where($where)->where('level', $level)->orderBy("updated_at", "desc")->limit($data['pagesize'])->get();
  518. } else {
  519. $level = '3';
  520. $result = Article::where($where)->where('level', $level)->orderBy("updated_at", "desc")->limit($data['pagesize'])->get();
  521. }
  522. $result = $result->toArray();
  523. if (!empty($result) && isset($data['placeid']) && !empty($data['placeid'])) {
  524. $placeid = $data['placeid'] - 1;
  525. if ($level == 2 || $level == 3) {
  526. $where = [
  527. 'level' => $level,
  528. ];
  529. $result = Article::where($where)
  530. ->orderBy("updated_at", "desc")
  531. ->offset($placeid)
  532. ->limit($data['pagesize'])->get();
  533. } else {
  534. $result = Article::where($where)
  535. ->whereIn('level', $level)
  536. ->offset($placeid)
  537. ->orderBy("updated_at", "desc")
  538. ->limit($data['pagesize'])->get();
  539. }
  540. }
  541. if (empty($result)) {
  542. return Result::error("此栏目暂无相关新闻", 0);
  543. }
  544. } else {
  545. return Result::error("此网站暂无此栏目", 0);
  546. }
  547. return Result::success($result);
  548. }
  549. /**
  550. *获取新闻列表
  551. * @param array $data
  552. * @return array
  553. */
  554. public function getWebsiteArticleList(array $data): array
  555. {
  556. $where[] = ['status', '=', 1];
  557. if (isset($data['keyword']) && !empty($data['keyword'])) {
  558. array_push($where, ['article.title', 'like', '%' . $data['keyword'] . '%']);
  559. }
  560. if (isset($data['catid']) && !empty($data['catid'])) {
  561. if (is_array($data['catid'])) {
  562. $category = WebsiteCategory::where('website_id', $data['website_id'])->whereIn('category_id', $data['catid'])->pluck('category_id');
  563. array_push($where, ['catid', 'in', $data['catid']]);
  564. } else {
  565. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  566. array_push($where, ['catid', '=', $data['catid']]);
  567. }
  568. if (empty($category)) {
  569. return Result::error("此网站暂无此栏目", 0);
  570. }
  571. }
  572. // return Result::success($where);
  573. $rep = Article::where(function ($query) use ($where) {
  574. foreach ($where as $condition) {
  575. if ($condition[1] === 'in') {
  576. $query->whereIn($condition[0], $condition[2]);
  577. } else {
  578. $query->where($condition[0], $condition[1], $condition[2]);
  579. }
  580. }
  581. })
  582. ->orderBy("updated_at", "desc")
  583. ->limit($data['pageSize'])
  584. ->offset(($data['page'] - 1) * $data['pageSize'])
  585. ->get();
  586. $count = Article::where(function ($query) use ($where) {
  587. foreach ($where as $condition) {
  588. if ($condition[1] === 'in') {
  589. $query->whereIn($condition[0], $condition[2]);
  590. } else {
  591. $query->where($condition[0], $condition[1], $condition[2]);
  592. }
  593. }
  594. })->count();
  595. $data = [
  596. 'rows' => $rep->toArray(),
  597. 'count' => $count,
  598. ];
  599. if (empty($rep)) {
  600. return Result::error("没有信息数据");
  601. }
  602. return Result::success($data);
  603. }
  604. /**
  605. * 前端-获取新闻详情
  606. * @param array $data
  607. * @return array
  608. */
  609. public function selectWebsiteArticleInfo(array $data): array
  610. {
  611. $where = [
  612. 'article.id' => $data['id'],
  613. 'article.status' => 1,
  614. ];
  615. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  616. if (empty($result)) {
  617. return Result::error("查询失败", 0);
  618. }
  619. $category = WebsiteCategory::where('website_id', $data['website_id'])->where(['category_id' => $result['catid']])->first();
  620. if (empty($category)) {
  621. return Result::error("查询失败", 0);
  622. }
  623. $result['category_id'] = $category['category_id'];
  624. $result['cat_name'] = $category['alias'];
  625. return Result::success($result);
  626. }
  627. /**
  628. * 前端-获取网站调查问卷
  629. * @param array $data
  630. * @return array
  631. */
  632. public function getWebsiteSurvey(array $data): array
  633. {
  634. if (isset($data['website_id']) && !empty($data['website_id'])) {
  635. $website = Website::where('id', $data['website_id'])->first();
  636. if (empty($website)) {
  637. return Result::error("暂无此网站", 0);
  638. }
  639. }
  640. if (isset($data['art_id']) && !empty($data['art_id'])) {
  641. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  642. if (empty($article)) {
  643. return Result::error("暂无此文章", 0);
  644. }
  645. // return Result::error($data,0);
  646. $where['art_id'] = $data['art_id'];
  647. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  648. } else {
  649. $survey = ArticleSurvey::where('website_id', $data['website_id'])->orderBy('created_at')->first();
  650. if (empty($survey)) {
  651. return Result::error("暂无调查问卷", 0);
  652. }
  653. $where['sur_id'] = $survey['sur_id'];
  654. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  655. }
  656. $result['survey'] = ArticleSurvey::where($where)->where('is_other', 0)
  657. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  658. ->select('article_survey.*', 'article.survey_type')
  659. ->get()->all();
  660. $result['other'] = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  661. $result['others'] = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->first();
  662. if (empty($result)) {
  663. return Result::error("此文章暂无调查问卷", 0);
  664. }
  665. return Result::success($result);
  666. }
  667. /**
  668. * 前端-添加网站调查问卷选项
  669. * @param array $data
  670. * @return array
  671. */
  672. public function addWebsiteSurveyOption(array $data): array
  673. {
  674. if (isset($data['website_id']) && !empty($data['website_id'])) {
  675. $website = Website::where('id', $data['website_id'])->first();
  676. if (empty($website)) {
  677. return Result::error("暂无此网站", 0);
  678. }
  679. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  680. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('website_id', $data['website_id'])->where('is_other', 1)->where('other_id', 0)->first();
  681. if (empty($survey)) {
  682. return Result::error("此调查问卷不可添加选项", 0);
  683. }
  684. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  685. $choice = [
  686. 'art_id' => $survey['art_id'],
  687. 'website_id' => $data['website_id'],
  688. 'survey_name' => $survey['survey_name'],
  689. 'choice_name' => $data['choice_name'],
  690. 'sur_id' => $survey['sur_id'],
  691. 'is_other' => 1,
  692. 'other_id' => $survey['id'],
  693. ];
  694. $result = ArticleSurvey::insertGetId($choice);
  695. if (empty($result)) {
  696. return Result::error("添加失败", 0);
  697. }
  698. return Result::success($result);
  699. }
  700. }
  701. return Result::error("添加失败", 0);
  702. }
  703. return Result::error("添加失败", 0);
  704. }
  705. /**
  706. * 前端-调查问卷投票
  707. * @param array $data
  708. * @return array
  709. */
  710. public function addWebsiteSurveyVote(array $data): array
  711. {
  712. if (isset($data['website_id']) && !empty($data['website_id'])) {
  713. $website = Website::where('id', $data['website_id'])->first();
  714. if (empty($website)) {
  715. return Result::error("暂无此网站", 0);
  716. }
  717. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  718. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('website_id', $data['website_id'])->pluck('sur_id');
  719. if (empty($survey)) {
  720. return Result::error("此调查问卷不存在", 0);
  721. }
  722. // return Result::success($survey);
  723. // 调查问卷类型 0:单选 1:多选
  724. $type = Article::where('survey_id', $data['sur_id'])->pluck('survey_type');
  725. // return Result::success($type);
  726. if (empty($type) || ($type[0] != 1 && $type[0] != 0)) {
  727. return Result::error("此调查问卷不可投票", 0);
  728. }
  729. // return Result::success($type[0]);
  730. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  731. if ($type[0] == 0) {
  732. if (is_array($data['choice_id'])) {
  733. return Result::error("请选择一个选项!", 0);
  734. }
  735. $data['choice_id'] = [$data['choice_id']];
  736. } else {
  737. if (!is_array($data['choice_id'])) {
  738. return Result::error("请传递数组!", 0);
  739. }
  740. }
  741. // return Result::success($data['choice_id']);
  742. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  743. ->where('website_id', $data['website_id'])
  744. ->where('is_other', 1)
  745. ->where('other_id', 0)
  746. ->first();
  747. if (!empty($other)) {
  748. return Result::error("请选择已有的选项!", 0);
  749. }
  750. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  751. ->where('website_id', $data['website_id'])
  752. ->where('is_other', 1)
  753. ->where('other_id', '!=', 0)
  754. ->first();
  755. // return Result::success($data);
  756. if (!empty($choice['other'])) {
  757. array_push($data['choice_id'], $choice['other']['other_id']);
  758. // return Result::success($data['choice_id']);
  759. }
  760. // return Result::success($data);
  761. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  762. ->where('website_id', $data['website_id'])
  763. ->increment('results', 1);
  764. if (empty($choice)) {
  765. return Result::error("请选择已有的选项!", 0);
  766. }
  767. return Result::success($choice);
  768. }
  769. return Result::error("参数必填!");
  770. // if(isset($data['choice_id']) && !empty($data['choice_id'])){
  771. // $choice = ArticleSurvey::whereIn('id',$data['choice_id'])->where('website_id',$data['website_id'])->where('is_other',1)->where('other_id',0)->first();
  772. // }
  773. }
  774. return Result::error("此调查问卷不存在", 0);
  775. }
  776. return Result::error("参数必填!");
  777. }
  778. /**
  779. * 后端-获取网站调查问卷列表
  780. * @param array $data
  781. * @return array
  782. */
  783. public function getSurveyList(array $data): array
  784. {
  785. $where = [];
  786. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  787. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  788. }
  789. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  790. array_push($where, ['survey_type', '=', $data['survey_type']]);
  791. }
  792. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  793. array_push($where, ['is_survey', '=', $data['is_survey']]);
  794. }
  795. // return Result::success($where);
  796. if (!empty($where)) {
  797. $query = Article::where($where)->whereNotNull('survey_name');
  798. } else {
  799. $query = Article::whereNotNull('survey_name');
  800. }
  801. $count = $query->count();
  802. $survey = $query->orderByDesc('id')
  803. ->limit($data['pageSize'])
  804. ->offset(($data['page'] - 1) * $data['pageSize'])
  805. ->get();
  806. if (empty($survey->toArray())) {
  807. return Result::error("暂无调查问卷!", 0);
  808. }
  809. $result = [
  810. 'rows' => $survey,
  811. 'count' => $count,
  812. ];
  813. return Result::success($result);
  814. }
  815. /**
  816. * 后端-获取网站调查问卷详情
  817. * @param array $data
  818. * @return array
  819. */
  820. public function getSurveyInfo(array $data): array
  821. {
  822. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  823. $where = ['sur_id' => $data['sur_id']];
  824. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  825. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  826. ->select('article_survey.*', 'article.survey_type')
  827. ->get()->all();
  828. if (empty($choose)) {
  829. return Result::error("此调查问卷不存在", 0);
  830. }
  831. $resultsArray = array_column($choose, 'results');
  832. $total = array_sum($resultsArray);
  833. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  834. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  835. // $total = 0;
  836. if (!empty($other)) {
  837. $total = $total + $other['results'];
  838. $other['choice_name'] = $other['choice_name'] . '(其他)';
  839. if (!empty($others)) {
  840. $other['hasChildren'] = true;
  841. // array_push($other,['hasChildren','=',true]);
  842. $other['children'] = $others;
  843. $other_choices = [$other->toArray()];
  844. $mer_choice = array_merge($choose, $other_choices);
  845. $value_choice = array_values($mer_choice);
  846. } else {
  847. // return Result::error('1111');
  848. $other_choices = [$other->toArray()];
  849. $other_choices = array_merge($choose, $other_choices);
  850. $value_choice = array_values($other_choices);
  851. // return Result::success($result);
  852. }
  853. } else {
  854. $value_choice = $choose;
  855. }
  856. $result = [
  857. 'choose' => $value_choice,
  858. 'total' => $total,
  859. ];
  860. }
  861. return Result::success($result);
  862. }
  863. /**
  864. * 验证导航名称是否重复
  865. * @return void
  866. */
  867. public function checkCategoryName(array $data): array
  868. {
  869. $result = Category::when($data, function ($query) use ($data) {
  870. if (isset($data['name']) && $data['name']) {
  871. $query->where("name", $data['name']);
  872. }
  873. if (isset($data['id']) && $data['id']) {
  874. $query->where("id", "!=", $data['id']);
  875. }
  876. })->first();
  877. if ($result) {
  878. return Result::error("已存在");
  879. } else {
  880. return Result::success();
  881. }
  882. }
  883. //20250226 产品列表
  884. public function getGoodList(array $data): array
  885. {
  886. $where = [];
  887. //类型
  888. if (isset($data['type_id']) && $data['type_id']) {
  889. $where = [
  890. 'type_id' => $data['type_id'],
  891. ];
  892. }
  893. //名称
  894. if (isset($data['name']) && $data['name']) {
  895. $where = [
  896. 'good.name' => $data['name'],
  897. ];
  898. }
  899. $where1 = [];
  900. //website_id
  901. // if (isset($data['website_id']) && $data['website_id']) {
  902. // $where1 = [
  903. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  904. // ];
  905. // }
  906. // website_name
  907. if (isset($data['website_name']) && $data['website_name']) {
  908. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  909. }
  910. // catid
  911. if (isset($data['category_name']) && $data['category_name']) {
  912. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  913. }
  914. // $result = Good::where($where)
  915. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  916. $result = Good::where($where)
  917. ->when(!empty($where1), function ($query) use ($where1) {
  918. return $query->where($where1);
  919. })
  920. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  921. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  922. ->leftJoin('category', 'good.catid', '=', 'category.id')
  923. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  924. ->orderBy("id", "desc")
  925. ->limit($data['page_size'])
  926. ->offset(($data['page'] - 1) * $data['page_size'])
  927. ->get();
  928. $count = Good::where($where)
  929. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  930. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  931. ->leftJoin('category', 'good.catid', '=', 'category.id')
  932. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  933. ->orderBy("updated_at", "desc")->count();
  934. $data = [
  935. 'rows' => $result->toArray(),
  936. 'count' => $count,
  937. ];
  938. if (empty($result)) {
  939. return Result::error("此栏目暂无相关产品", 0);
  940. }
  941. return Result::success($data);
  942. }
  943. public function getGoodInfo(array $data): array
  944. {
  945. $result = Good::where('id', $data['id'])->first();
  946. if (empty($result)) {
  947. return Result::error("此产品不存在", 0);
  948. }
  949. return Result::success($result);
  950. }
  951. public function addGood(array $data): array
  952. {
  953. // unset($data['city_arr_id']);
  954. // unset($data['cat_arr_id']);
  955. $data['city_id'] = end($data['city_arr_id']);
  956. $data['catid'] = end($data['cat_arr_id']);
  957. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  958. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  959. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  960. unset($data['imgUrl']);
  961. $result = Good::insert($data);
  962. if (empty($result)) {
  963. return Result::error("添加失败", 0);
  964. }
  965. return Result::success($result);
  966. }
  967. public function updateGood(array $data): array
  968. {
  969. $data['city_id'] = end($data['city_arr_id']);
  970. $data['catid'] = end($data['cat_arr_id']);
  971. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  972. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  973. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  974. //设置东八区
  975. date_default_timezone_set('Asia/Shanghai');
  976. $data['updated_at'] = date('Y-m-d H:i:s');
  977. $result = Good::where('id', $data['id'])->update($data);
  978. if (empty($result)) {
  979. return Result::error("更新失败", 0);
  980. }
  981. return Result::success($result);
  982. }
  983. public function delGood(array $data): array
  984. {
  985. $result = Good::where('id', $data['id'])->delete();
  986. if (empty($result)) {
  987. return Result::error("删除失败", 0);
  988. }
  989. return Result::success($result);
  990. }
  991. //20250226 产品列表
  992. //20250306 求职信息
  993. public function getJobHuntingList(array $data): array
  994. {
  995. $where = [];
  996. if (isset($data['name']) && !empty($data['name'])) {
  997. $where[] = ['name', 'like', '%' . $data['name'] . '%'];
  998. }
  999. $result = JobHunting::where($where)->
  1000. orderBy("updated_at", "desc")
  1001. ->limit($data['page_size'])
  1002. ->offset(($data['page'] - 1) * $data['page_size'])
  1003. ->get();
  1004. if (empty($result)) {
  1005. return Result::error("查询失败", 0);
  1006. }
  1007. return Result::success($result);
  1008. }
  1009. public function addJobHunting(array $data): array
  1010. {
  1011. $data['created_at'] = date('Y-m-d H:i:s');
  1012. $data['updated_at'] = date('Y-m-d H:i:s');
  1013. $result = JobHunting::create($data);
  1014. if (empty($result)) {
  1015. return Result::error("添加失败", 0);
  1016. }
  1017. return Result::success($result);
  1018. }
  1019. public function delJobHunting(array $data): array
  1020. {
  1021. $result = JobHunting::where('id', $data['id'])->delete();
  1022. if (empty($result)) {
  1023. return Result::error("删除失败", 0);
  1024. }
  1025. return Result::success($result);
  1026. }
  1027. public function updateJobHunting(array $data): array
  1028. {
  1029. $result = JobHunting::where('id', $data['id'])->update($data);
  1030. if (empty($result)) {
  1031. return Result::error("更新失败", 0);
  1032. }
  1033. return Result::success($result);
  1034. }
  1035. public function getJobHuntingInfo(array $data): array
  1036. {
  1037. $result = JobHunting::where('id', $data['id'])->first();
  1038. if (empty($result)) {
  1039. return Result::error("查询失败", 0);
  1040. }
  1041. return Result::success($result);
  1042. }
  1043. }