NewsService.php 52 KB

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