NewsService.php 51 KB

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