NewsService.php 51 KB

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