NewsService.php 51 KB

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