NewsService.php 51 KB

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