NewsService.php 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260
  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. // 企业会员
  1019. if($user['type_id'] == 3){
  1020. array_push($where,['user_id', $data['user_id']]);
  1021. }
  1022. $result = JobRecruiting::where($where)
  1023. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  1024. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  1025. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  1026. ->orderBy("updated_at", "desc")
  1027. ->offset(($data['page'] - 1) * $data['page_size'])
  1028. ->limit($data['page_size'])
  1029. ->get()
  1030. ->all();
  1031. if (empty($result)) {
  1032. return Result::error("暂无招聘信息", 0);
  1033. }
  1034. return Result::success($result);
  1035. }
  1036. /*
  1037. * 招聘信息详情
  1038. * */
  1039. public function getJobRecruitingInfo(array $data): array
  1040. {
  1041. $result = JobRecruiting::where('id', $data['id'])
  1042. ->leftJoin('user_info', 'job_recruiting.user_id', '=', 'user.id')
  1043. ->select('job_recruiting.*', 'user_info.*')
  1044. ->orderBy("updated_at", "desc")
  1045. ->first();
  1046. if (empty($result)) {
  1047. return Result::error("暂无招聘信息", 0);
  1048. }
  1049. return Result::success($result);
  1050. }
  1051. /*
  1052. * 招聘信息添加
  1053. * */
  1054. public function addJobRecruiting(array $data): array
  1055. {
  1056. // return Result::success($data);
  1057. $data['cat_arr_id'] = isset($data['cat_arr_id'])? json_encode($data['cat_arr_id']) : '';
  1058. $data['city_arr_id'] = isset($data['city_arr_id'])? json_encode($data['city_arr_id']) : '';
  1059. $result = JobRecruiting::insertGetId($data);
  1060. if (empty($result)) {
  1061. return Result::error("添加失败", 0);
  1062. }
  1063. return Result::success($result);
  1064. }
  1065. /*
  1066. * 招聘信息更新
  1067. * */
  1068. public function updateJobRecruiting(array $data): array
  1069. {
  1070. return Result::success($data);
  1071. }
  1072. /*
  1073. * 招聘信息删除
  1074. * */
  1075. public function delJobRecruiting(array $data): array
  1076. {
  1077. return Result::success($data);
  1078. }
  1079. /*
  1080. * 获取省-市
  1081. * */
  1082. public function getJobRecruitingArea(array $data): array
  1083. {
  1084. if(isset($data['province_id']) && $data['province_id']!=null){
  1085. $result = District::where('pid',$data['pid'])->get()->all();
  1086. }else{
  1087. $result = District::where('level',1)->get()->all();
  1088. }
  1089. if (empty($result)) {
  1090. return Result::error("暂无此省市", 0);
  1091. }
  1092. return Result::success($result);
  1093. }
  1094. /*
  1095. * 获取行业分类
  1096. * */
  1097. public function getIndustry(array $data): array
  1098. {
  1099. $result = JobIndustry::get()->all();
  1100. if (empty($result)) {
  1101. return Result::error("暂无行业分类", 0);
  1102. }
  1103. return Result::success($result);
  1104. }
  1105. /*
  1106. * 获取职位
  1107. * */
  1108. public function getPositionList(array $data): array
  1109. {
  1110. if(isset($data['zwpid']) && $data['zwpid']!=null){
  1111. $result = JobPosition::where('zwpid',$data['zwpid'])->get()->all();
  1112. }else{
  1113. $result = JobPosition::where('zwpid',0)->get()->all();
  1114. }
  1115. if (empty($result)) {
  1116. return Result::error("暂无此职位", 0);
  1117. }
  1118. return Result::success($result);
  1119. }
  1120. /*
  1121. * 获取工作性质-菜单
  1122. * */
  1123. public function getJobNature(array $data): array
  1124. {
  1125. $result = JobEnum::get('egroup','nature')->all();
  1126. if (empty($result)) {
  1127. return Result::error("暂无工作性质", 0);
  1128. }
  1129. return Result::success($result);
  1130. }
  1131. /*
  1132. * 获取工作经验-菜单
  1133. * */
  1134. public function getExperience(array $data): array
  1135. {
  1136. $result = JobEnum::where('egroup','years')->get()->all();
  1137. if (empty($result)) {
  1138. return Result::error("暂无工作经验", 0);
  1139. }
  1140. return Result::success($result);
  1141. }
  1142. /*
  1143. * 获取学历-菜单
  1144. * */
  1145. public function getEducation(array $data): array
  1146. {
  1147. $result = JobEnum::where('egroup','education')->get()->all();
  1148. if (empty($result)) {
  1149. return Result::error("暂无学历", 0);
  1150. }
  1151. return Result::success($result);
  1152. }
  1153. /*
  1154. * 获取薪资-菜单
  1155. * */
  1156. public function getSalary(array $data): array
  1157. {
  1158. $result = JobEnum::where('egroup','income')->get()->all();
  1159. if (empty($result)) {
  1160. return Result::error("暂无薪资", 0);
  1161. }
  1162. return Result::success($result);
  1163. }
  1164. /*
  1165. * 获取语言-菜单
  1166. * */
  1167. public function getLanguage(array $data): array
  1168. {
  1169. $result = JobEnum::where('egroup','language')->get()->all();
  1170. if (empty($result)) {
  1171. return Result::error("暂无语言", 0);
  1172. }
  1173. return Result::success($result);
  1174. }
  1175. /*
  1176. * 获取掌握程度-菜单
  1177. * */
  1178. public function getLevel(array $data): array
  1179. {
  1180. $result = JobEnum::where('egroup','languagetype')->get()->all();
  1181. if (empty($result)) {
  1182. return Result::error("暂无工作性质", 0);
  1183. }
  1184. return Result::success($result);
  1185. }
  1186. // 公司信息
  1187. /*
  1188. * 获取公司性质-菜单
  1189. * */
  1190. public function getCompanyNature(array $data): array
  1191. {
  1192. $result = JobNature::get()->all();
  1193. if (empty($result)) {
  1194. return Result::error("暂无公司性质", 0);
  1195. }
  1196. return Result::success($result);
  1197. }
  1198. /*
  1199. * 获取公司规模-菜单
  1200. * */
  1201. public function getCompanyScale(array $data): array
  1202. {
  1203. $result = JobEnum::get('egroup','cosize')->all();
  1204. if (empty($result)) {
  1205. return Result::error("暂无公司规模", 0);
  1206. }
  1207. return Result::success($result);
  1208. }
  1209. // 20250306 招聘
  1210. }