NewsService.php 43 KB

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