NewsService.php 53 KB

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