NewsService.php 47 KB

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