NewsService.php 49 KB

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