NewsService.php 45 KB

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