NewsService.php 47 KB

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