NewsService.php 62 KB

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