NewsService.php 52 KB

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