NewsService.php 53 KB

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