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