NewsService.php 51 KB

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