NewsService.php 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309
  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(function ($query) {
  734. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  735. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  736. })
  737. ->where('status',1)
  738. ->where('is_survey',1)
  739. ->select('survey_id')
  740. ->orderBy('updated_at','desc')
  741. ->first();
  742. if(empty($survey)){
  743. return Result::error("暂无调查问卷",0);
  744. }
  745. $where['sur_id'] = $survey['survey_id'];
  746. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  747. }
  748. return Result::success($where);
  749. $result = ArticleSurvey::where($where)
  750. ->where(function ($query) {
  751. $query->where('is_other', 0)
  752. ->orWhere(function ($subQuery) {
  753. $subQuery->where('is_other', 1)
  754. ->where('other_id', 0);
  755. });
  756. })
  757. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  758. ->select('article_survey.*', 'article.survey_type')
  759. ->get()->all();
  760. if(empty($result)){
  761. return Result::error("此文章暂无调查问卷",0);
  762. }
  763. return Result::success($result);
  764. }
  765. /**
  766. * 前端-添加网站调查问卷选项
  767. * @param array $data
  768. * @return array
  769. */
  770. public function addWebsiteSurveyOption(array $data): array
  771. {
  772. if (isset($data['website_id']) && !empty($data['website_id'])) {
  773. $website = Website::where('id', $data['website_id'])->first();
  774. if (empty($website)) {
  775. return Result::error("暂无此网站", 0);
  776. }
  777. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  778. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('website_id', $data['website_id'])->where('is_other', 1)->where('other_id', 0)->first();
  779. if (empty($survey)) {
  780. return Result::error("此调查问卷不可添加选项", 0);
  781. }
  782. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  783. $choice = [
  784. 'art_id' => $survey['art_id'],
  785. 'website_id' => $data['website_id'],
  786. 'survey_name' => $survey['survey_name'],
  787. 'choice_name' => $data['choice_name'],
  788. 'sur_id' => $survey['sur_id'],
  789. 'is_other' => 1,
  790. 'other_id' => $survey['id'],
  791. ];
  792. $result = ArticleSurvey::insertGetId($choice);
  793. if (empty($result)) {
  794. return Result::error("添加失败", 0);
  795. }
  796. return Result::success($result);
  797. }
  798. }
  799. return Result::error("添加失败", 0);
  800. }
  801. return Result::error("添加失败", 0);
  802. }
  803. /**
  804. * 前端-调查问卷投票
  805. * @param array $data
  806. * @return array
  807. */
  808. public function addWebsiteSurveyVote(array $data): array
  809. {
  810. // return Result::success($data);
  811. if(isset($data['website_id']) && !empty($data['website_id'])){
  812. $website = Website::where('id',$data['website_id'])->first();
  813. if(empty($website)){
  814. return Result::error("暂无此网站",0);
  815. }
  816. if(isset($data['sur_id']) && !empty($data['sur_id'])){
  817. $is_survey = ArticleSurvey::where('sur_id',$data['sur_id'])->first();
  818. // return Result::success($survey);
  819. if(empty($is_survey)){
  820. return Result::error("此调查问卷不存在",0);
  821. }
  822. // return Result::success($survey);
  823. // 调查问卷类型
  824. if(isset($data['choice_id']) &&!empty($data['choice_id'])){
  825. //多选 若是json型则转化成数组类型
  826. if (strpos($data['choice_id'], '[') === 0) {
  827. $data['choice_id'] = json_decode($data['choice_id'], true);
  828. } else {
  829. // 单选 也转换成数组
  830. $data['choice_id'] = [$data['choice_id']];
  831. }
  832. $data['choice_id'] = array_map('intval', $data['choice_id']);
  833. $other = ArticleSurvey::whereIn('id',$data['choice_id'])
  834. ->where('website_id',$data['website_id'])
  835. ->where('is_other',1)
  836. ->where('other_id',0)
  837. ->first();
  838. if(!empty($other)){
  839. return Result::error("请选择已有的选项!",0);
  840. }
  841. $choice['other'] = ArticleSurvey::whereIn('id',$data['choice_id'])
  842. ->where('website_id',$data['website_id'])
  843. ->where('is_other',1)
  844. ->where('other_id','!=',0)
  845. ->first();
  846. // return Result::success($choice['other']);
  847. $choice_id = $data['choice_id'];
  848. if(!empty($choice['other'])){
  849. // array_push($data['choice_id'],$choice['other']['other_id']);
  850. if(!empty($choice_id)){
  851. $key = array_search($choice['other']['id'], $choice_id);
  852. if ($key!== false) {
  853. unset($choice_id[$key]);
  854. $choice_id = array_values($choice_id);
  855. }
  856. array_push($choice_id,$choice['other']['other_id']);
  857. }else{
  858. $choice_id[0] = $choice['other']['other_id'];
  859. }
  860. // return Result::success($data['choice_id']);
  861. }
  862. // return Result::success($data);
  863. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  864. ->where('website_id', $data['website_id'])
  865. ->increment('results', 1);
  866. if (empty($choice)) {
  867. return Result::error("请选择已有的选项!", 0);
  868. }
  869. $survey['data'] = ArticleSurvey::where('sur_id',$data['sur_id'])
  870. ->where('website_id',$data['website_id'])
  871. ->where('other_id', 0)
  872. ->get();
  873. $survey['choice'] = $choice_id;
  874. return Result::success($survey);
  875. }
  876. return Result::error("参数必填!");
  877. }
  878. return Result::error("此调查问卷不存在", 0);
  879. }
  880. return Result::error("参数必填!");
  881. }
  882. /**
  883. * 后端-获取网站调查问卷列表
  884. * @param array $data
  885. * @return array
  886. */
  887. public function getSurveyList(array $data): array
  888. {
  889. $where = [];
  890. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  891. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  892. }
  893. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  894. array_push($where, ['survey_type', '=', $data['survey_type']]);
  895. }
  896. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  897. array_push($where, ['is_survey', '=', $data['is_survey']]);
  898. }
  899. // return Result::success($where);
  900. if (!empty($where)) {
  901. $query = Article::where($where)->where(function ($q) {
  902. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  903. });
  904. } else {
  905. $query = Article::where(function ($q) {
  906. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  907. });
  908. }
  909. $count = $query->count();
  910. $survey = $query->orderByDesc('id')
  911. ->limit($data['pageSize'])
  912. ->offset(($data['page'] - 1) * $data['pageSize'])
  913. ->get();
  914. if (empty($survey->toArray())) {
  915. return Result::error("暂无调查问卷!", 0);
  916. }
  917. $result = [
  918. 'rows' => $survey,
  919. 'count' => $count,
  920. ];
  921. return Result::success($result);
  922. }
  923. /**
  924. * 后端-获取网站调查问卷详情
  925. * @param array $data
  926. * @return array
  927. */
  928. public function getSurveyInfo(array $data): array
  929. {
  930. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  931. $where = ['sur_id' => $data['sur_id']];
  932. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  933. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  934. ->select('article_survey.*', 'article.survey_type')
  935. ->get()->all();
  936. if (empty($choose)) {
  937. return Result::error("此调查问卷不存在", 0);
  938. }
  939. $resultsArray = array_column($choose, 'results');
  940. $total = array_sum($resultsArray);
  941. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  942. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  943. // $total = 0;
  944. if (!empty($other)) {
  945. $total = $total + $other['results'];
  946. $other['choice_name'] = $other['choice_name'] . '(其他)';
  947. if (!empty($others)) {
  948. $other['hasChildren'] = true;
  949. // array_push($other,['hasChildren','=',true]);
  950. $other['children'] = $others;
  951. $other_choices = [$other->toArray()];
  952. $mer_choice = array_merge($choose, $other_choices);
  953. $value_choice = array_values($mer_choice);
  954. } else {
  955. // return Result::error('1111');
  956. $other_choices = [$other->toArray()];
  957. $other_choices = array_merge($choose, $other_choices);
  958. $value_choice = array_values($other_choices);
  959. // return Result::success($result);
  960. }
  961. } else {
  962. $value_choice = $choose;
  963. }
  964. $result = [
  965. 'choose' => $value_choice,
  966. 'total' => $total,
  967. ];
  968. }
  969. return Result::success($result);
  970. }
  971. /**
  972. * 前端-搜索新闻列表
  973. * @param array $data
  974. * @return array
  975. */
  976. public function selectWebsiteArticle(array $data): array
  977. {
  978. $where = [];
  979. // 初始化查询构造器
  980. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
  981. $query = Article::where('status', 1)
  982. ->whereIn('catid', $category)
  983. ->where(function ($query) use ($data) {
  984. $query->where(function ($subQuery) use ($data) {
  985. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  986. })->orWhereNull("ignore_ids");
  987. });
  988. // return Result::success($all_articles);
  989. // 检查是否存在 cityid 参数
  990. if (isset($data['cityid']) && !empty($data['cityid'])) {
  991. $query->whereRaw("JSON_CONTAINS(city_arr_id, '" . intval($data['cityid']) . "')");
  992. }
  993. // 检查是否存在 department_id 参数
  994. if (isset($data['department_id']) && !empty($data['department_id'])) {
  995. $query->whereRaw("JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "')");
  996. }
  997. // 检查是否存在 keyword 参数
  998. if (isset($data['keyword']) && !empty($data['keyword'])) {
  999. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  1000. }
  1001. // 计算总数
  1002. $count = $query->count();
  1003. // 分页查询
  1004. $articles = $query->orderBy("updated_at", "desc")
  1005. ->limit($data['pageSize'])
  1006. ->offset(($data['page'] - 1) * $data['pageSize'])
  1007. ->get()->all();
  1008. if (empty($articles)) {
  1009. return Result::error("没有符合条件的资讯数据");
  1010. }
  1011. $data = [
  1012. 'rows' => $articles,
  1013. 'count' => $count,
  1014. ];
  1015. return Result::success($data);
  1016. }
  1017. /**
  1018. * 验证导航名称是否重复
  1019. * @return void
  1020. */
  1021. public function checkCategoryName(array $data): array
  1022. {
  1023. $result = Category::when($data, function ($query) use ($data) {
  1024. if (isset($data['name']) && $data['name']) {
  1025. $query->where("name", $data['name']);
  1026. }
  1027. if (isset($data['id']) && $data['id']) {
  1028. $query->where("id", "!=", $data['id']);
  1029. }
  1030. })->first();
  1031. if ($result) {
  1032. return Result::error("已存在");
  1033. } else {
  1034. return Result::success();
  1035. }
  1036. }
  1037. //20250226 产品列表
  1038. public function getGoodList(array $data): array
  1039. {
  1040. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  1041. unset($data['type_id']);
  1042. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  1043. $where = [];
  1044. if ($type_id != '10000') {
  1045. $where = [
  1046. 'good.user_id' => $user_id,
  1047. ];
  1048. }
  1049. //类型
  1050. if (isset($data['type_id']) && $data['type_id']) {
  1051. $where = [
  1052. 'type_id' => $data['type_id'],
  1053. ];
  1054. }
  1055. //名称
  1056. if (isset($data['name']) && $data['name']) {
  1057. $where = [
  1058. 'good.name' => $data['name'],
  1059. ];
  1060. }
  1061. $where1 = [];
  1062. //website_id
  1063. // if (isset($data['website_id']) && $data['website_id']) {
  1064. // $where1 = [
  1065. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  1066. // ];
  1067. // }
  1068. // website_name
  1069. if (isset($data['website_name']) && $data['website_name']) {
  1070. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  1071. }
  1072. // catid
  1073. if (isset($data['category_name']) && $data['category_name']) {
  1074. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  1075. }
  1076. // $result = Good::where($where)
  1077. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  1078. $result = Good::where($where)
  1079. ->when(!empty($where1), function ($query) use ($where1) {
  1080. return $query->where($where1);
  1081. })
  1082. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  1083. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  1084. ->leftJoin('category', 'good.catid', '=', 'category.id')
  1085. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  1086. ->orderBy("id", "desc")
  1087. ->limit($data['page_size'])
  1088. ->offset(($data['page'] - 1) * $data['page_size'])
  1089. ->get();
  1090. $count = Good::where($where)
  1091. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  1092. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  1093. ->leftJoin('category', 'good.catid', '=', 'category.id')
  1094. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  1095. ->orderBy("updated_at", "desc")->count();
  1096. $data = [
  1097. 'rows' => $result->toArray(),
  1098. 'count' => $count,
  1099. ];
  1100. if (empty($result)) {
  1101. return Result::error("此栏目暂无相关产品", 0);
  1102. }
  1103. return Result::success($data);
  1104. }
  1105. public function getGoodInfo(array $data): array
  1106. {
  1107. $result = Good::where('id', $data['id'])->first();
  1108. if (empty($result)) {
  1109. return Result::error("此产品不存在", 0);
  1110. }
  1111. return Result::success($result);
  1112. }
  1113. public function addGood(array $data): array
  1114. {
  1115. // unset($data['city_arr_id']);
  1116. // unset($data['cat_arr_id']);
  1117. $data['city_id'] = end($data['city_arr_id']);
  1118. $data['catid'] = end($data['cat_arr_id']);
  1119. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  1120. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  1121. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  1122. unset($data['imgUrl']);
  1123. $result = Good::insert($data);
  1124. if (empty($result)) {
  1125. return Result::error("添加失败", 0);
  1126. }
  1127. return Result::success($result);
  1128. }
  1129. public function updateGood(array $data): array
  1130. {
  1131. $data['city_id'] = end($data['city_arr_id']);
  1132. $data['catid'] = end($data['cat_arr_id']);
  1133. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  1134. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  1135. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  1136. //设置东八区
  1137. date_default_timezone_set('Asia/Shanghai');
  1138. $data['updated_at'] = date('Y-m-d H:i:s');
  1139. $result = Good::where('id', $data['id'])->update($data);
  1140. if (empty($result)) {
  1141. return Result::error("更新失败", 0);
  1142. }
  1143. return Result::success($result);
  1144. }
  1145. public function delGood(array $data): array
  1146. {
  1147. $result = Good::where('id', $data['id'])->delete();
  1148. if (empty($result)) {
  1149. return Result::error("删除失败", 0);
  1150. }
  1151. return Result::success($result);
  1152. }
  1153. //20250226 产品列表
  1154. //20250306 求职信息
  1155. public function getJobHuntingList(array $data): array
  1156. {
  1157. $where = [];
  1158. if (isset($data['username']) && !empty($data['username'])) {
  1159. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  1160. }
  1161. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  1162. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  1163. unset($data['type_id']);
  1164. if ($type_id != '10000') {
  1165. $where[] = ['job_hunting.user_id', '=', $user_id];
  1166. }
  1167. $result = JobHunting::where($where)
  1168. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  1169. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  1170. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  1171. ->orderBy("id", "desc")
  1172. ->limit($data['page_size'])
  1173. ->offset(($data['page'] - 1) * $data['page_size'])
  1174. ->get();
  1175. if (empty($result)) {
  1176. return Result::error("查询失败", 0);
  1177. }
  1178. $count = JobHunting::where($where)
  1179. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  1180. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  1181. ->count();
  1182. $data = [
  1183. 'rows' => $result->toArray(),
  1184. 'count' => $count,
  1185. ];
  1186. return Result::success($data);
  1187. }
  1188. public function addJobHunting(array $data): array
  1189. {
  1190. date_default_timezone_set('Asia/Shanghai');
  1191. unset($data['company_name']);
  1192. unset($data['job_industry']);
  1193. unset($data['job_name']);
  1194. unset($data['department']);
  1195. unset($data['job_timeList']);
  1196. unset($data['job_content']);
  1197. $data['created_at'] = date('Y-m-d H:i:s');
  1198. $data['updated_at'] = date('Y-m-d H:i:s');
  1199. var_dump($data, '-----------------test---------');
  1200. $result = JobHunting::create($data);
  1201. if (empty($result)) {
  1202. return Result::error("添加失败", 0);
  1203. }
  1204. return Result::success($result);
  1205. }
  1206. public function delJobHunting(array $data): array
  1207. {
  1208. $result = JobHunting::where('id', $data['id'])->delete();
  1209. if (empty($result)) {
  1210. return Result::error("删除失败", 0);
  1211. }
  1212. return Result::success($result);
  1213. }
  1214. public function updateJobHunting(array $data): array
  1215. {
  1216. //设置东八区
  1217. date_default_timezone_set('Asia/Shanghai');
  1218. unset($data['company_name']);
  1219. unset($data['job_industry']);
  1220. unset($data['job_name']);
  1221. unset($data['department']);
  1222. unset($data['job_timeList']);
  1223. unset($data['job_content']);
  1224. $data['created_at'] = date('Y-m-d H:i:s');
  1225. $data['updated_at'] = date('Y-m-d H:i:s');
  1226. $result = JobHunting::where('id', $data['id'])->update($data);
  1227. if (empty($result)) {
  1228. return Result::error("更新失败", 0);
  1229. }
  1230. return Result::success($result);
  1231. }
  1232. public function getJobHuntingInfo(array $data): array
  1233. {
  1234. $result = JobHunting::where('id', $data['id'])->first();
  1235. if (empty($result)) {
  1236. return Result::error("查询失败", 0);
  1237. }
  1238. return Result::success($result);
  1239. }
  1240. public function getJobHuntingData(array $data): array
  1241. {
  1242. $jobEnum = JobEnum::get();
  1243. $jobIndustry = JobIndustry::get();
  1244. $jobNature = JobNature::get();
  1245. $jobPosition = JobPosition::get();
  1246. $data = [
  1247. 'jobEnum' => $jobEnum,
  1248. 'jobIndustry' => $jobIndustry,
  1249. 'jobNature' => $jobNature,
  1250. 'jobPosition' => $jobPosition,
  1251. ];
  1252. return Result::success($data);
  1253. }
  1254. public function delJobHuntingInfo(array $data): array
  1255. {
  1256. $result = JobHunting::where('id', $data['id'])->delete();
  1257. return Result::success();
  1258. }
  1259. }