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