NewsService.php 58 KB

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