NewsService.php 84 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043
  1. <?php
  2. namespace App\JsonRpc;
  3. use App\Model\Article;
  4. use App\Model\ArticleData;
  5. use App\Model\Category;
  6. use App\Model\WebsiteCategory;
  7. use App\Model\ArticleSurvey;
  8. use App\Model\jobHunting;
  9. use App\Model\JobEnum;
  10. use App\Model\JobIndustry;
  11. use App\Model\JobPosition;
  12. use App\Model\JobRecruiting;
  13. use App\Model\Good;
  14. use App\Model\JobNature;
  15. use App\Model\Website;
  16. use Hyperf\DbConnection\Db;
  17. use Hyperf\RpcServer\Annotation\RpcService;
  18. use App\Tools\Result;
  19. use Ramsey\Uuid\Uuid;
  20. use Hyperf\Utils\Random;
  21. use Fukuball\Jieba\Jieba;
  22. use Fukuball\Jieba\Finalseg;
  23. use App\Model\ChatRecords;
  24. use Hyperf\Utils\Collection;
  25. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  26. class NewsService implements NewsServiceInterface
  27. {
  28. /**
  29. * 获取导航池列表
  30. * @param array $data
  31. * @return array
  32. */
  33. public function getCategoryList(array $data): array
  34. {
  35. $page = (int) $data['page'] ?? 1;
  36. $perPage = (int) $data['pageSize'] ?? 10;
  37. $search = $data['name'] ?? '';
  38. // 查找所有匹配的分类
  39. $matchedCategories = $this->findMatchedCategories($search);
  40. // 查找所有匹配分类的父级分类
  41. $allRequiredCategories = $this->findAllParents($matchedCategories);
  42. // 提取一级分类
  43. $topLevelCategories = [];
  44. foreach ($allRequiredCategories as $category) {
  45. if ($category->pid === 0) {
  46. $topLevelCategories[] = $category;
  47. }
  48. }
  49. // 分页处理
  50. $offset = ($page - 1) * $perPage;
  51. $paginatedTopLevelCategories = array_slice($topLevelCategories, $offset, $perPage);
  52. $categoryTree = [];
  53. foreach ($paginatedTopLevelCategories as $category) {
  54. $categoryTree[] = $this->buildCategoryTree($category, $allRequiredCategories);
  55. }
  56. $return = [
  57. 'rows' => $categoryTree,
  58. 'total' => count($topLevelCategories),
  59. ];
  60. return Result::success($return);
  61. }
  62. private function findMatchedCategories($search)
  63. {
  64. if ($search) {
  65. return Category::where('name', 'like', "%{$search}%")
  66. ->orderBy('updated_at', 'desc')
  67. ->get();
  68. }
  69. return Category::orderBy('updated_at', 'desc') // 按 updated_at 字段倒序排序
  70. ->get();
  71. }
  72. private function findAllParents($categories)
  73. {
  74. $allCategories = [];
  75. foreach ($categories as $category) {
  76. $parentId = $category->pid;
  77. while ($parentId > 0) {
  78. $parent = Category::find($parentId);
  79. if ($parent) {
  80. $allCategories[$parent->id] = $parent;
  81. $parentId = $parent->pid;
  82. } else {
  83. break;
  84. }
  85. }
  86. $allCategories[$category->id] = $category;
  87. }
  88. return array_values($allCategories);
  89. }
  90. private function buildCategoryTree($category, $allRequiredCategories)
  91. {
  92. $categoryData = $category->toArray();
  93. $children = [];
  94. foreach ($allRequiredCategories as $c) {
  95. if ($c->pid === $category->id) {
  96. $children[] = $this->buildCategoryTree($c, $allRequiredCategories);
  97. }
  98. }
  99. if (!empty($children)) {
  100. $categoryData['children'] = $children;
  101. }
  102. return $categoryData;
  103. }
  104. public function myCategoryList(array $data): array
  105. {
  106. $sszq = $data['sszq'] ?? '';
  107. unset($data['sszq']);
  108. //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
  109. $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
  110. $where[] = [
  111. 'pid', '=', $data['pid'],
  112. ];
  113. if (isset($data['name'])) {
  114. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  115. }
  116. var_dump($where);
  117. //根据分类id,从category表中取出分类信息
  118. $result = Category::where($where)
  119. ->whereIn('category.id', $catorytids)
  120. ->select('category.*', 'category.id as category_id')->get();
  121. if (empty($result)) {
  122. return Result::error("没有栏目数据");
  123. }
  124. return Result::success($result);
  125. }
  126. /**
  127. * @param array $data
  128. * @return array
  129. */
  130. public function categoryList(array $data): array
  131. {
  132. $where[] = [
  133. 'pid', '=', $data['pid'],
  134. ];
  135. if (isset($data['name'])) {
  136. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  137. }
  138. var_dump($where);
  139. $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
  140. if (empty($result)) {
  141. return Result::error("没有栏目数据");
  142. }
  143. return Result::success($result);
  144. }
  145. /**
  146. * @param array $data
  147. * @return array
  148. */
  149. public function addCategory(array $data): array
  150. {
  151. if (isset($data['id'])) {
  152. unset($data['id']);
  153. }
  154. $id = Category::insertGetId($data);
  155. if (empty($id)) {
  156. return Result::error("添加失败");
  157. }
  158. return Result::success(['id' => $id]);
  159. }
  160. /**
  161. * @param array $data
  162. * @return array
  163. */
  164. public function delCategory(array $data): array
  165. {
  166. Db::beginTransaction();
  167. try {
  168. $categoryList = Category::where(['pid' => $data['id']])->get();
  169. if ($categoryList->toArray()) {
  170. Db::rollBack();
  171. return Result::error("分类下面有子分类不能删除");
  172. }
  173. $articleList = Article::where(['catid' => $data['id']])->get();
  174. if ($articleList->toArray()) {
  175. Db::rollBack();
  176. return Result::error("分类下面有资讯不能删除");
  177. }
  178. $result = Category::where($data)->delete();
  179. WebsiteCategory::where(['category_id' => $data['id']])->delete();
  180. if (!$result) {
  181. return Result::error("删除失败");
  182. }
  183. return Result::success($result);
  184. Db::commit();
  185. } catch (\Exception $e) {
  186. Db::rollBack();
  187. return Result::error("删除失败");
  188. }
  189. }
  190. /**
  191. * @param array $data
  192. * @return array
  193. */
  194. public function updateCategory(array $data): array
  195. {
  196. $where = [
  197. 'id' => $data['id'],
  198. ];
  199. $result = Category::where($where)->update($data);
  200. if ($result) {
  201. return Result::success($result);
  202. } else {
  203. return Result::error("更新失败");
  204. }
  205. }
  206. /**
  207. * 获取导航池信息
  208. * @param array $data
  209. * @return array
  210. */
  211. public function getCategoryInfo(array $data): array
  212. {
  213. $where = [
  214. 'id' => $data['id'],
  215. ];
  216. $result = Category::where($where)->first();
  217. if ($result) {
  218. return Result::success($result);
  219. } else {
  220. return Result::error("更新失败");
  221. }
  222. }
  223. /**
  224. * @param array $data
  225. * @return array
  226. */
  227. public function getArticleList(array $data): array
  228. {
  229. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  230. $type_id = $data['type_id'];
  231. unset($data['type_id']);
  232. $user_id = $data['user_id'];
  233. unset($data['user_id']);
  234. $where = [];
  235. $status1 = [];
  236. if (isset($data['id']) && $data['id']) {
  237. array_push($where, ['article.id', '=', $data['id']]);
  238. }
  239. if (isset($data['title']) && $data['title']) {
  240. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  241. }
  242. if (isset($data['category_name']) && $data['category_name']) {
  243. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  244. }
  245. if (isset($data['author']) && $data['author']) {
  246. array_push($where, ['article.author', '=', $data['author']]);
  247. }
  248. if (isset($data['islink']) && $data['islink'] !== "") {
  249. array_push($where, ['article.islink', '=', $data['islink']]);
  250. }
  251. if (isset($data['status']) && $data['status'] !== "") {
  252. array_push($where, ['article.status', '=', $data['status']]);
  253. }
  254. if (isset($data['status1'])) {
  255. $status1 = json_decode(($data['status1']));
  256. }
  257. //不是管理员展示个人数据;
  258. if ($type_id != 10000) {
  259. $where[] = ['article.admin_user_id', '=', $user_id];
  260. }
  261. $rep = Article::where($where)
  262. ->whereNotIn('article.status', [404])
  263. ->when($status1, function ($query) use ($status1) {
  264. if (isset($status1) && $status1) {
  265. $query->whereIn('article.status', $status1);
  266. }
  267. })
  268. ->leftJoin('category', 'article.catid', 'category.id')
  269. ->select("article.*", "category.name as category_name")
  270. ->orderBy("article.updated_at", "desc")
  271. ->limit($data['pageSize'])
  272. ->offset(($data['page'] - 1) * $data['pageSize'])->get();
  273. $count = Article::where($where)->whereNotIn('article.status', [404])
  274. ->when($status1, function ($query) use ($status1) {
  275. if (isset($status1) && $status1) {
  276. $query->whereIn('article.status', $status1);
  277. }
  278. })
  279. ->leftJoin('category', 'article.catid', 'category.id')->count();
  280. $data = [
  281. 'rows' => $rep->toArray(),
  282. 'count' => $count,
  283. ];
  284. if (empty($rep)) {
  285. return Result::error("没有信息数据");
  286. }
  287. return Result::success($data);
  288. }
  289. /**
  290. * @param array $data
  291. * @return array
  292. */
  293. public function addArticle(array $data): array
  294. {
  295. var_dump($data, '----------12-----------1');
  296. unset($data['user_type']);
  297. unset($data['nav_add_pool_id']);
  298. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  299. Db::beginTransaction();
  300. try {
  301. //处理投票
  302. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  303. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  304. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  305. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  306. unset($data['is_survey']);
  307. unset($data['survey_name']);
  308. unset($data['suvey_array']);
  309. // unset($data['website_id']);
  310. // unset($data['web_site_id']);
  311. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  312. if ($data['hits'] == '') {
  313. $data['hits'] = 0;
  314. }
  315. if ($data['is_original'] == '') {
  316. $data['is_original'] = 0;
  317. }
  318. if ($data['status'] == '') {
  319. $data['status'] = 0;
  320. }
  321. $articleData = $data;
  322. unset($articleData['content']);
  323. //自动处理缩略图、关键字、描述
  324. if ($articleData['imgurl'] == '') {
  325. //如果没有图,设置level=0
  326. $levelArr = json_decode($articleData['level'], true);
  327. var_dump($levelArr, '----------levelArr-----------1');
  328. //content中提取图片第一个图,正则提取
  329. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  330. preg_match_all($reg, $data['content'], $matches);
  331. if (isset($matches[1][0])) {
  332. //截取varchar240
  333. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  334. //如果有图,设置level=3
  335. if (!in_array(3, $levelArr)) {$levelArr[] = 3;}
  336. $articleData['level'] = json_encode($levelArr);
  337. } else {
  338. if (!in_array(0, $levelArr)) {
  339. $levelArr[] = 0;
  340. }
  341. $articleData['level'] = json_encode($levelArr);
  342. }
  343. }
  344. var_dump($articleData['level'], '----------$articleData[level]----------1');
  345. if ($articleData['keyword'] == '') {
  346. //提取标题+内容中的关键词
  347. $articleData['keyword'] = $data['title'];
  348. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  349. Jieba::init(); // 初始化 jieba-php
  350. Finalseg::init();
  351. $segList = Jieba::cut($articleData['keyword']);
  352. $segList1 = array_slice($segList, 0, 8);
  353. $articleData['keyword'] = implode(',', $segList1);
  354. }
  355. if ($articleData['introduce'] == '') {
  356. //提取内容中的描述
  357. $articleData['introduce'] = substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
  358. }
  359. $id = Article::insertGetId($articleData);
  360. $articleDataContent = [
  361. 'article_id' => $id,
  362. 'content' => $data['content'],
  363. ];
  364. ArticleData::insertGetId($articleDataContent);
  365. //处理投票
  366. if ($is_survey == 1) {
  367. //生成年月日时分秒+8位随机数
  368. $uuid = date('YmdHis') . rand(10000000, 99999999);
  369. var_dump($suvey_array, 'suvey_array________');
  370. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  371. var_dump($suveys_array, '---------------------1');
  372. var_dump($suvey_array, '---------------------2');
  373. $suvey_data = [];
  374. foreach ($suveys_array as $key => $value) {
  375. if ($value == '') {
  376. continue;
  377. }
  378. if (is_array($value)) {
  379. $suvey_data[] = [
  380. 'sur_id' => $uuid,
  381. 'art_id' => $id,
  382. 'website_id' => $website_id ?? 2,
  383. 'survey_name' => $survey_name,
  384. 'choice_name' => $value[1],
  385. 'is_other' => 1,
  386. 'other_id' => 0,
  387. 'results' => 0,
  388. ];
  389. } else {
  390. $suvey_data[] = [
  391. 'sur_id' => $uuid,
  392. 'art_id' => $id,
  393. 'website_id' => $website_id ?? 2,
  394. 'survey_name' => $survey_name,
  395. 'choice_name' => $value,
  396. 'is_other' => 0,
  397. 'other_id' => 0,
  398. 'results' => 0,
  399. ];
  400. }
  401. if (empty($suvey_data)) {
  402. throw new \Exception("投票数据为空");
  403. }
  404. }
  405. $result = ArticleSurvey::insert($suvey_data);
  406. if (!$result) {
  407. throw new \Exception("投票失败,ArticleSurvey插入失败");
  408. }
  409. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  410. if (!$result) {
  411. throw new \Exception("投票失败,更新主表失败");
  412. }
  413. }
  414. Db::commit();
  415. return Result::success(['id' => $id]);
  416. } catch (\Throwable $ex) {
  417. Db::rollBack();
  418. var_dump($ex->getMessage());
  419. return Result::error("创建失败", 0);
  420. }
  421. }
  422. /**
  423. * @param array $data
  424. * @return array
  425. */
  426. public function delArticle(array $data): array
  427. {
  428. $result = Article::where($data)->delete();
  429. //survey投票删除
  430. articleSurvey::where(['art_id' => $data['id']])->delete();
  431. if (!$result) {
  432. return Result::error("删除失败");
  433. }
  434. return Result::success($result);
  435. }
  436. /**
  437. * @param array $data
  438. * @return array
  439. */
  440. public function updateArticle(array $data): array
  441. {
  442. var_dump($data, '----------12-----------1');
  443. Db::beginTransaction();
  444. unset($data['user_type']);
  445. // unset($data['web_site_id']);
  446. unset($data['nav_add_pool_id']);
  447. try {
  448. //处理投票
  449. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  450. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  451. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  452. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  453. unset($data['is_survey']);
  454. unset($data['survey_name']);
  455. unset($data['suvey_array']);
  456. unset($data['website_id']);
  457. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  458. if ($data['hits'] == '') {
  459. $data['hits'] = 0;
  460. }
  461. if ($data['is_original'] == '') {
  462. $data['is_original'] = 0;
  463. }
  464. if ($data['status'] == '') {
  465. $data['status'] = 0;
  466. }
  467. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  468. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  469. $articleData = $data;
  470. unset($articleData['content']);
  471. unset($articleData['status_name']);
  472. unset($articleData['name']);
  473. unset($articleData['content']);
  474. unset($articleData['pid_arr']);
  475. unset($articleData['pid']);
  476. //自动处理缩略图、关键字、描述
  477. if ($articleData['imgurl'] == '') {
  478. //如果没有图,设置level=0
  479. $levelArr = json_decode($articleData['level'], true);
  480. var_dump($levelArr, '----------levelArr-----------1');
  481. //content中提取图片第一个图,正则提取
  482. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  483. preg_match_all($reg, $data['content'], $matches);
  484. if (isset($matches[1][0])) {
  485. //截取varchar240
  486. // 截取到第一个<
  487. $articleData['imgurl'] = $matches[1][0];
  488. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  489. $pos = strpos($articleData['imgurl'], '"');
  490. if ($pos !== false) {
  491. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  492. }
  493. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  494. //如果有图,设置level=3
  495. if (!in_array(3, $levelArr)) {$levelArr[] = 3;}
  496. $articleData['level'] = json_encode($levelArr);
  497. } else {
  498. if (!in_array(0, $levelArr)) {
  499. $levelArr[] = 0;
  500. }
  501. $articleData['level'] = json_encode($levelArr);
  502. }
  503. }
  504. var_dump($articleData['level'], '----------$articleData[level]----------1');
  505. if ($articleData['keyword'] == '') {
  506. //提取标题+内容中的关键词
  507. $articleData['keyword'] = $data['title'];
  508. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  509. Jieba::init(); // 初始化 jieba-php
  510. Finalseg::init();
  511. $segList = Jieba::cut($articleData['keyword']);
  512. $segList1 = array_slice($segList, 0, 8);
  513. $articleData['keyword'] = implode(',', $segList1);
  514. }
  515. if ($articleData['introduce'] == '') {
  516. //提取内容中的描述
  517. $articleData['introduce'] = substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
  518. }
  519. $id = Article::where(['id' => $data['id']])->update($articleData);
  520. $articleDataContent = [
  521. 'content' => $data['content'],
  522. ];
  523. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  524. //处理投票
  525. $id = $data['id'];
  526. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  527. var_dump($suvey_array, 'suvey_array________delete');
  528. //处理投票
  529. if ($is_survey == 1) {
  530. //生成年月日时分秒+8位随机数
  531. $uuid = date('YmdHis') . rand(10000000, 99999999);
  532. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  533. var_dump($suveys_array, '---------------------1');
  534. $suvey_data = [];
  535. if (is_array($suveys_array)) {
  536. foreach ($suveys_array as $key => $value) {
  537. if ($value == '') {
  538. continue;
  539. }
  540. if (is_array($value)) {
  541. $suvey_data[] = [
  542. 'sur_id' => $uuid,
  543. 'art_id' => $id,
  544. 'website_id' => $website_id ?? 2,
  545. 'survey_name' => $survey_name,
  546. 'choice_name' => $value[1],
  547. 'is_other' => 1,
  548. 'other_id' => 0,
  549. 'results' => 0,
  550. ];
  551. } else {
  552. $suvey_data[] = [
  553. 'sur_id' => $uuid,
  554. 'art_id' => $id,
  555. 'website_id' => $website_id ?? 2,
  556. 'survey_name' => $survey_name,
  557. 'choice_name' => $value,
  558. 'is_other' => 0,
  559. 'other_id' => 0,
  560. 'results' => 0,
  561. ];
  562. }
  563. if (empty($suvey_data)) {
  564. throw new \Exception("投票数据为空");
  565. }
  566. }
  567. }
  568. $result = ArticleSurvey::insert($suvey_data);
  569. if (!$result) {
  570. throw new \Exception("投票失败");
  571. }
  572. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  573. if (!$result) {
  574. throw new \Exception("投票失败");
  575. }
  576. } else {
  577. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  578. }
  579. Db::commit();
  580. return Result::success([]);
  581. } catch (\Throwable $ex) {
  582. Db::rollBack();
  583. var_dump($ex->getMessage());
  584. return Result::error("更新失败" . $ex->getMessage(), 0);
  585. }
  586. }
  587. /**
  588. * 更新资讯状态
  589. * @param array $data
  590. * @return array
  591. */
  592. public function upArticleStatus(array $data): array
  593. {
  594. $result = Article::where(['id' => $data['id']])->update($data);
  595. if ($result) {
  596. return Result::success();
  597. } else {
  598. return Result::error("更新状态失败", 0);
  599. }
  600. }
  601. /**
  602. * @param array $data
  603. * @return array
  604. */
  605. public function getArticleInfo(array $data): array
  606. {
  607. $where = [
  608. 'article.id' => $data['id'],
  609. // 'article.status' => 1,
  610. ];
  611. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  612. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  613. $info = $result;
  614. // var_dump($info, 'info');
  615. $info['survey_array'] = $articleSurvey;
  616. if ($result) {
  617. return Result::success($info);
  618. } else {
  619. return Result::error("查询失败", 0);
  620. }
  621. }
  622. /**
  623. * 获取新闻
  624. * @param array $data
  625. * @return array
  626. */
  627. public function getWebsiteArticlett(array $data): array
  628. {
  629. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
  630. $category = array_values(array_unique($category->toArray()));
  631. $result = [];
  632. if ($category) {
  633. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  634. $where = [
  635. 'status' => 1,
  636. ];
  637. var_dump($data, 'data-----------------');
  638. // level=7 根据文章key来匹配文章
  639. if (isset($data['level']) && $data['level'] == 7) {
  640. // 根据文章id获取key
  641. // $data['id'] = 50142;
  642. if (isset($data['id']) && !empty($data['id'])) {
  643. $keyword = Article::where('id', $data['id'])->value('keyword');
  644. $keywordArray = explode(',', $keyword);
  645. $whereL7 = [];
  646. foreach ($keywordArray as $k => $v) {
  647. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  648. }
  649. // 原始查询
  650. $result = Article::where($whereL7)
  651. ->offset($placeid)
  652. ->limit($data['pageSize'])
  653. ->orderBy('updated_at', 'desc')
  654. ->get()
  655. ->map(function ($article ) use ($data) {
  656. $catid = $article->catid;
  657. $pinyin = '';
  658. $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
  659. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  660. if ($category->pid != 0 && !empty($category->aLIas_pinyin)) {
  661. $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
  662. $pinyin = $childCategory->aLIas_pinyin ? $childCategory->aLIas_pinyin.'/'. $category->aLIas_pinyin : null;
  663. }
  664. $article->pinyin = $pinyin;
  665. return $article;
  666. });
  667. if (empty($result)) {
  668. return Result::success([]);
  669. }
  670. return Result::success($result);
  671. } else {
  672. return Result::error("参数错误level=7,id不能为空", 0);
  673. }
  674. }
  675. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  676. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  677. var_dump($where, 'where-----------------');
  678. $result = Article::where($where)
  679. ->whereIn("catid", $category)
  680. // ->leftJoin('website_category', 'article.catid', 'website_category.category_id')
  681. // ->where('website_category.website_id', $data['website_id'])
  682. ->where(function ($query) use ($data) {
  683. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  684. ->orWhereNull("ignore_ids");
  685. })
  686. //$data['level'] == 4 || $data['level'] == 5 查询随机
  687. ->when($data['level'] == 5, function ($query) {
  688. $query->inRandomOrder()
  689. //updated_at最近三十天;
  690. ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  691. })
  692. ->when($data['level'] == 4, function ($query) {
  693. $query->orderBy("article.updated_at", "desc");
  694. })
  695. ->when(!empty($data['level']), function ($query) use ($data) {
  696. if ($data['level'] != 4 && $data['level'] != 5) {
  697. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  698. ->orderBy("article.updated_at", "desc");
  699. }
  700. })
  701. ->select('article.*')
  702. ->offset($placeid)
  703. ->limit($data['pageSize'])
  704. ->get()
  705. ->map(function ($article ) use ($data) {
  706. $catid = $article->catid;
  707. $pinyin = '';
  708. // $category = WebsiteCategory::whereIn('category_id', $catArrId)->where('website_category.website_id', $data['website_id'])->get()->all();
  709. // if ($catArrId) {
  710. // foreach ($catArrId as $categoryId) {
  711. $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
  712. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  713. if ($category->pid != 0 && !empty($category->aLIas_pinyin)) {
  714. $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
  715. $pinyin = $childCategory->aLIas_pinyin ? $childCategory->aLIas_pinyin.'/'. $category->aLIas_pinyin : null;
  716. }
  717. // }
  718. // }
  719. $article->pinyin = $pinyin;
  720. return $article;
  721. });
  722. if (empty($result)) {
  723. return Result::error("暂无头条新闻", 0);
  724. }
  725. return Result::success($result);
  726. } else {
  727. return Result::error("本网站下暂无相关栏目", 0);
  728. }
  729. }
  730. /**
  731. * 获取模块新闻
  732. * @param array $data
  733. * @return array
  734. */
  735. public function getWebsiteModelArticles(array $data): array
  736. {
  737. $catid = $data['catid'];
  738. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  739. $category = $category->toArray();
  740. if (!empty($category)) {
  741. $where = [
  742. 'status' => 1,
  743. 'catid' => $catid,
  744. ];
  745. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  746. // 1:文字新闻;2:轮播图;3:图文;
  747. // 级别:0:未分类
  748. // 3:推荐图片
  749. if ($data['level'] == 1) {
  750. $data['level'] = 0;
  751. }
  752. $result = Article::where($where)
  753. ->where(function ($query) use ($data) {
  754. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  755. ->orWhereNull("level")
  756. ->orWhereRaw("level = '[]'");
  757. })
  758. ->where(function ($query) use ($data) {
  759. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  760. ->orWhereNull("ignore_ids");
  761. })
  762. ->orderBy("updated_at", "desc")
  763. ->offset($placeid)
  764. ->limit($data['pagesize'])
  765. ->get();
  766. if (empty($result)) {
  767. return Result::error("此栏目暂无相关新闻", 0);
  768. }
  769. } else {
  770. return Result::error("此网站暂无此栏目", 0);
  771. }
  772. return Result::success($result);
  773. }
  774. /**
  775. *获取新闻列表
  776. * @param array $data
  777. * @return array
  778. */
  779. public function getWebsiteArticleList(array $data): array
  780. {
  781. $where[] = ['status', '=', 1];
  782. if (isset($data['keyword']) && !empty($data['keyword'])) {
  783. array_push($where, ['article.title', 'like', '%' . $data['keyword'] . '%']);
  784. }
  785. if (isset($data['catid']) && !empty($data['catid'])) {
  786. if (is_array($data['catid'])) {
  787. $category = WebsiteCategory::where('website_id', $data['website_id'])->whereIn('category_id', $data['catid'])->pluck('category_id');
  788. array_push($where, ['catid', 'in', $data['catid']]);
  789. } else {
  790. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  791. array_push($where, ['catid', '=', $data['catid']]);
  792. }
  793. if (empty($category)) {
  794. return Result::error("此网站暂无此栏目", 0);
  795. }
  796. }
  797. // return Result::success($where);
  798. $rep = Article::where(function ($query) use ($where) {
  799. foreach ($where as $condition) {
  800. if ($condition[1] === 'in') {
  801. $query->whereIn($condition[0], $condition[2]);
  802. } else {
  803. $query->where($condition[0], $condition[1], $condition[2]);
  804. }
  805. }
  806. })
  807. ->where(function ($query) use ($data) {
  808. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  809. ->orWhereNull("ignore_ids");
  810. })
  811. ->orderBy("updated_at", "desc")
  812. ->limit($data['pageSize'])
  813. ->offset(($data['page'] - 1) * $data['pageSize'])
  814. ->get();
  815. $count = Article::where(function ($query) use ($where) {
  816. foreach ($where as $condition) {
  817. if ($condition[1] === 'in') {
  818. $query->whereIn($condition[0], $condition[2]);
  819. } else {
  820. $query->where($condition[0], $condition[1], $condition[2]);
  821. }
  822. }
  823. })->count();
  824. $data = [
  825. 'rows' => $rep->toArray(),
  826. 'count' => $count,
  827. ];
  828. if (empty($rep)) {
  829. return Result::error("没有信息数据");
  830. }
  831. return Result::success($data);
  832. }
  833. /**
  834. * 前端-获取新闻详情
  835. * @param array $data
  836. * @return array
  837. */
  838. public function selectWebsiteArticleInfo(array $data): array
  839. {
  840. $where = [
  841. 'article.id' => $data['id'],
  842. 'article.status' => 1,
  843. ];
  844. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")
  845. ->where(function ($query) use ($data) {
  846. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  847. ->orWhereNull("ignore_ids");
  848. })
  849. ->first();
  850. if (empty($result)) {
  851. return Result::error("暂无此新闻!", 0);
  852. }
  853. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  854. ->select('website_category.*', 'website.website_name', 'website.suffix')
  855. ->where('website_category.website_id', $data['website_id'])
  856. ->where(['website_category.category_id' => $result['catid']])
  857. ->first();
  858. if (empty($category)) {
  859. return Result::error("查询失败", 0);
  860. }
  861. //手动推荐文章
  862. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  863. $commendArticle = Article::whereIn('id', $commend_ids)
  864. ->where('status', 1)
  865. ->select('id', 'title', 'catid', 'imgurl', 'hits', 'created_at')
  866. ->orderBy('updated_at', 'desc')
  867. ->limit(5)
  868. ->get();
  869. $result['category_id'] = $category['category_id'];
  870. $result['cat_name'] = $category['alias'];
  871. $result['website_name'] = $category['website_name'] ?? "";
  872. $result['suffix'] = $category['suffix'] ?? "";
  873. $result['commendArticle'] = $commendArticle;
  874. return Result::success($result);
  875. }
  876. /**
  877. * 前端-获取网站调查问卷
  878. * @param array $data
  879. * @return array
  880. */
  881. public function getWebsiteSurvey(array $data): array
  882. {
  883. if (isset($data['website_id']) && !empty($data['website_id'])) {
  884. $website = Website::where('id', $data['website_id'])->first();
  885. if (empty($website)) {
  886. return Result::error("暂无此网站", 0);
  887. }
  888. }
  889. if (isset($data['art_id']) && !empty($data['art_id'])) {
  890. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  891. if (empty($article)) {
  892. return Result::error("暂无此文章", 0);
  893. }
  894. // return Result::error($data,0);
  895. $where['art_id'] = $data['art_id'];
  896. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  897. } else {
  898. $survey = Article::where(function ($query) {
  899. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  900. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  901. })
  902. ->where('status', 1)
  903. ->where('is_survey', 1)
  904. ->select('survey_id')
  905. ->orderBy('updated_at', 'desc')
  906. ->first();
  907. if (empty($survey)) {
  908. return Result::error("暂无调查问卷", 0);
  909. }
  910. $where['sur_id'] = $survey['survey_id'];
  911. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  912. }
  913. // return Result::success($where);
  914. $result = ArticleSurvey::where($where)
  915. ->where(function ($query) {
  916. $query->where('is_other', 0)
  917. ->orWhere(function ($subQuery) {
  918. $subQuery->where('is_other', 1)
  919. ->where('other_id', 0);
  920. });
  921. })
  922. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  923. ->select('article_survey.*', 'article.survey_type')
  924. ->get()->all();
  925. if (empty($result)) {
  926. return Result::error("此文章暂无调查问卷", 0);
  927. }
  928. return Result::success($result);
  929. }
  930. /**
  931. * 前端-添加网站调查问卷选项
  932. * @param array $data
  933. * @return array
  934. */
  935. public function addWebsiteSurveyOption(array $data): array
  936. {
  937. if (isset($data['website_id']) && !empty($data['website_id'])) {
  938. $website = Website::where('id', $data['website_id'])->first();
  939. if (empty($website)) {
  940. return Result::error("暂无此网站", 0);
  941. }
  942. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  943. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('website_id', $data['website_id'])->where('is_other', 1)->where('other_id', 0)->first();
  944. if (empty($survey)) {
  945. return Result::error("此调查问卷不可添加选项", 0);
  946. }
  947. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  948. $choice = [
  949. 'art_id' => $survey['art_id'],
  950. 'website_id' => $data['website_id'],
  951. 'survey_name' => $survey['survey_name'],
  952. 'choice_name' => $data['choice_name'],
  953. 'sur_id' => $survey['sur_id'],
  954. 'is_other' => 1,
  955. 'other_id' => $survey['id'],
  956. ];
  957. $result = ArticleSurvey::insertGetId($choice);
  958. if (empty($result)) {
  959. return Result::error("添加失败", 0);
  960. }
  961. return Result::success($result);
  962. }
  963. }
  964. return Result::error("添加失败", 0);
  965. }
  966. return Result::error("添加失败", 0);
  967. }
  968. /**
  969. * 前端-调查问卷投票
  970. * @param array $data
  971. * @return array
  972. */
  973. public function addWebsiteSurveyVote(array $data): array
  974. {
  975. // return Result::success($data);
  976. if (isset($data['website_id']) && !empty($data['website_id'])) {
  977. $website = Website::where('id', $data['website_id'])->first();
  978. if (empty($website)) {
  979. return Result::error("暂无此网站", 0);
  980. }
  981. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  982. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  983. // return Result::success($survey);
  984. if (empty($is_survey)) {
  985. return Result::error("此调查问卷不存在", 0);
  986. }
  987. // return Result::success($survey);
  988. // 调查问卷类型
  989. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  990. //多选 若是json型则转化成数组类型
  991. if (strpos($data['choice_id'], '[') === 0) {
  992. $data['choice_id'] = json_decode($data['choice_id'], true);
  993. } else {
  994. // 单选 也转换成数组
  995. $data['choice_id'] = [$data['choice_id']];
  996. }
  997. $data['choice_id'] = array_map('intval', $data['choice_id']);
  998. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  999. ->where('website_id', $data['website_id'])
  1000. ->where('is_other', 1)
  1001. ->where('other_id', 0)
  1002. ->first();
  1003. if (!empty($other)) {
  1004. return Result::error("请选择已有的选项!", 0);
  1005. }
  1006. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1007. ->where('website_id', $data['website_id'])
  1008. ->where('is_other', 1)
  1009. ->where('other_id', '!=', 0)
  1010. ->first();
  1011. // return Result::success($choice['other']);
  1012. $choice_id = $data['choice_id'];
  1013. if (!empty($choice['other'])) {
  1014. // array_push($data['choice_id'],$choice['other']['other_id']);
  1015. if (!empty($choice_id)) {
  1016. $key = array_search($choice['other']['id'], $choice_id);
  1017. if ($key !== false) {
  1018. unset($choice_id[$key]);
  1019. $choice_id = array_values($choice_id);
  1020. }
  1021. array_push($choice_id, $choice['other']['other_id']);
  1022. } else {
  1023. $choice_id[0] = $choice['other']['other_id'];
  1024. }
  1025. array_push($data['choice_id'], $choice['other']['other_id']);
  1026. }
  1027. // return Result::success($data);
  1028. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1029. ->where('website_id', $data['website_id'])
  1030. ->increment('results', 1);
  1031. if (empty($choice)) {
  1032. return Result::error("请选择已有的选项!", 0);
  1033. }
  1034. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1035. ->where('website_id', $data['website_id'])
  1036. ->where('other_id', 0)
  1037. ->get();
  1038. $survey['choice'] = $choice_id;
  1039. return Result::success($survey);
  1040. }
  1041. return Result::error("参数必填!");
  1042. }
  1043. return Result::error("此调查问卷不存在", 0);
  1044. }
  1045. return Result::error("参数必填!");
  1046. }
  1047. /**
  1048. * 后端-获取网站调查问卷列表
  1049. * @param array $data
  1050. * @return array
  1051. */
  1052. public function getSurveyList(array $data): array
  1053. {
  1054. $where = [];
  1055. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1056. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1057. }
  1058. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  1059. array_push($where, ['survey_type', '=', $data['survey_type']]);
  1060. }
  1061. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  1062. array_push($where, ['is_survey', '=', $data['is_survey']]);
  1063. }
  1064. // return Result::success($where);
  1065. if (!empty($where)) {
  1066. $query = Article::where($where)->where(function ($q) {
  1067. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1068. });
  1069. } else {
  1070. $query = Article::where(function ($q) {
  1071. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1072. });
  1073. }
  1074. $count = $query->count();
  1075. $survey = $query->orderByDesc('id')
  1076. ->limit($data['pageSize'])
  1077. ->offset(($data['page'] - 1) * $data['pageSize'])
  1078. ->get();
  1079. if (empty($survey->toArray())) {
  1080. return Result::error("暂无调查问卷!", 0);
  1081. }
  1082. $result = [
  1083. 'rows' => $survey,
  1084. 'count' => $count,
  1085. ];
  1086. return Result::success($result);
  1087. }
  1088. /**
  1089. * 后端-获取网站调查问卷详情
  1090. * @param array $data
  1091. * @return array
  1092. */
  1093. public function getSurveyInfo(array $data): array
  1094. {
  1095. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1096. $where = ['sur_id' => $data['sur_id']];
  1097. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1098. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1099. ->select('article_survey.*', 'article.survey_type')
  1100. ->get()->all();
  1101. if (empty($choose)) {
  1102. return Result::error("此调查问卷不存在", 0);
  1103. }
  1104. $resultsArray = array_column($choose, 'results');
  1105. $total = array_sum($resultsArray);
  1106. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1107. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1108. // $total = 0;
  1109. if (!empty($other)) {
  1110. $total = $total + $other['results'];
  1111. $other['choice_name'] = '(其他)';
  1112. if (!empty($others)) {
  1113. $other['hasChildren'] = true;
  1114. // array_push($other,['hasChildren','=',true]);
  1115. $other['children'] = $others;
  1116. $other_choices = [$other->toArray()];
  1117. $mer_choice = array_merge($choose, $other_choices);
  1118. $value_choice = array_values($mer_choice);
  1119. } else {
  1120. // return Result::error('1111');
  1121. $other_choices = [$other->toArray()];
  1122. $other_choices = array_merge($choose, $other_choices);
  1123. $value_choice = array_values($other_choices);
  1124. // return Result::success($result);
  1125. }
  1126. } else {
  1127. $value_choice = $choose;
  1128. }
  1129. $result = [
  1130. 'choose' => $value_choice,
  1131. 'total' => $total,
  1132. ];
  1133. }
  1134. return Result::success($result);
  1135. }
  1136. /**
  1137. * 前端-搜索新闻列表
  1138. * @param array $data
  1139. * @return array
  1140. */
  1141. public function selectWebsiteArticle(array $data): array
  1142. {
  1143. $where = [];
  1144. // 初始化查询构造器
  1145. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
  1146. $query = Article::where('status', 1)
  1147. ->whereIn('catid', $category)
  1148. ->where(function ($query) use ($data) {
  1149. $query->where(function ($subQuery) use ($data) {
  1150. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1151. })->orWhereNull("ignore_ids");
  1152. });
  1153. // return Result::success($all_articles);
  1154. // 检查是否存在 cityid 参数
  1155. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1156. $query->whereRaw("JSON_CONTAINS(city_arr_id, '" . intval($data['cityid']) . "')");
  1157. }
  1158. // 检查是否存在 department_id 参数
  1159. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1160. $query->whereRaw("JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "')");
  1161. }
  1162. // 检查是否存在 keyword 参数
  1163. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1164. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  1165. }
  1166. // 计算总数
  1167. $count = $query->count();
  1168. // 分页查询
  1169. $articles = $query->orderBy("updated_at", "desc")
  1170. ->limit($data['pageSize'])
  1171. ->offset(($data['page'] - 1) * $data['pageSize'])
  1172. ->get()->all();
  1173. if (empty($articles)) {
  1174. return Result::error("没有符合条件的资讯数据");
  1175. }
  1176. $data = [
  1177. 'rows' => $articles,
  1178. 'count' => $count,
  1179. ];
  1180. return Result::success($data);
  1181. }
  1182. /**
  1183. * 模块新闻加强版
  1184. * @param array $data
  1185. * @return array
  1186. */
  1187. public function getWebsiteCatidArticle(array $data): array
  1188. {
  1189. // return Result::success($data);
  1190. $where = [
  1191. // 'category.status' => 1,
  1192. 'website_category.category_id' => $data['catid'],
  1193. 'website_category.website_id' => $data['website_id'],
  1194. // 'article.status' => 1,
  1195. ];
  1196. // $category = WebsiteCategory::where($where);
  1197. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  1198. $child_catnum = $data['child_catnum'] ?? 1;
  1199. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  1200. $childCategoryIds = array_column($category['child'], 'category_id');
  1201. if (empty($childCategoryIds)) {
  1202. return Result::error("暂无子栏目", 0);
  1203. }
  1204. $imgArticles = [];
  1205. $textArticles = [];
  1206. // return Result::success($childCategoryIds);
  1207. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  1208. // 初始化子分类图片新闻和文字新闻数组
  1209. // 查询所有子级栏目的图文新闻
  1210. $imgArticles = Article::where('catid', $childCategoryIds[0])
  1211. ->where(function ($query) use ($data) {
  1212. $query->where(function ($subQuery) use ($data) {
  1213. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1214. })->orWhereNull("ignore_ids");
  1215. })
  1216. ->where('status', 1)
  1217. ->where('imgurl', '!=', '')
  1218. ->select('*')
  1219. ->orderBy('updated_at', 'desc')
  1220. ->limit($data['child_imgnum'])
  1221. ->get();
  1222. }
  1223. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  1224. // 查询所有子级栏目的文字新闻
  1225. $textArticles = Article::where('catid', $childCategoryIds[0])
  1226. ->where('status', 1)
  1227. ->where(function ($query) use ($data) {
  1228. $query->where(function ($subQuery) use ($data) {
  1229. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1230. })->orWhereNull("ignore_ids");
  1231. })
  1232. // ->where(function ($query) {
  1233. // $query->whereNull('imgurl')
  1234. // ->orWhere('imgurl', '');
  1235. // })
  1236. ->select('*')
  1237. ->orderBy('updated_at', 'desc')
  1238. ->limit($data['child_textnum'])
  1239. ->get();
  1240. }
  1241. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  1242. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  1243. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  1244. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  1245. return $child;
  1246. }, $category['child']);
  1247. }
  1248. // }
  1249. if (isset($data['img_num']) && !empty($data['img_num'])) {
  1250. $category['img'] = WebsiteCategory::where($where)
  1251. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1252. ->where('article.status', 1)
  1253. ->where('article.imgurl', '!=', '')
  1254. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1255. ->orderBy('article.updated_at', 'desc')
  1256. ->limit($data['img_num'])
  1257. ->get();
  1258. }
  1259. if (isset($data['text_num']) && !empty($data['text_num'])) {
  1260. $category['text'] = WebsiteCategory::where($where)
  1261. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1262. ->where('article.status', 1)
  1263. // ->where(function ($query) {
  1264. // $query->whereNull('article.imgurl')
  1265. // ->orWhere('article.imgurl', '');
  1266. // })
  1267. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1268. ->orderBy('article.updated_at', 'desc')
  1269. ->limit($data['text_num'])
  1270. ->get();
  1271. }
  1272. // $category = $category->get();
  1273. if (empty($category)) {
  1274. return Result::error("查询失败", 0);
  1275. }
  1276. return Result::success($category);
  1277. }
  1278. /**
  1279. * 模块新闻加强plus版
  1280. * @param array $data
  1281. * @return array
  1282. */
  1283. public function getWebsiteAllArticle(array $data): array
  1284. {
  1285. // 修正传入的字符串,将单引号替换为双引号
  1286. $input['id'] = $data['id'];
  1287. $input['website_id'] = $data['website_id'];
  1288. // 将 JSON 字符串转换为 PHP 数组
  1289. $data = json_decode($input['id'], true);
  1290. // 使用 array_map 处理每个元素
  1291. $result = array_map(function ($item) use ($input) {
  1292. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  1293. $website = [
  1294. 'website_id' => $input['website_id'],
  1295. ];
  1296. // 查询栏目名称
  1297. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  1298. if (empty($category)) {
  1299. $imgArticles = [];
  1300. $textArticles = [];
  1301. // return Result::error("暂无此栏目",0);
  1302. }else{
  1303. $parent_alias = $category->alias ?? '';
  1304. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  1305. // 查询图片新闻
  1306. $imgArticles = Article::where('catid', $parentCatId)
  1307. ->where('status', 1)
  1308. ->where(function ($query) use ($website) {
  1309. $query->where(function ($subQuery) use ($website) {
  1310. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '".intval($website['website_id'])."') = 0");
  1311. })->orWhereNull("ignore_ids");
  1312. })
  1313. ->where('imgurl', '!=', '')
  1314. ->select(
  1315. 'article.id',
  1316. 'article.title',
  1317. 'article.imgurl',
  1318. 'article.author',
  1319. 'article.updated_at',
  1320. 'article.introduce',
  1321. 'article.islink',
  1322. 'article.linkurl',
  1323. 'article.copyfrom',
  1324. DB::raw("'$parent_pinyin' as pinyin") // 添加 pinyin 字段
  1325. )
  1326. ->orderBy('updated_at', 'desc')
  1327. ->limit($parentImgNum)
  1328. ->get()->all();
  1329. // 查询文字新闻
  1330. $textArticles = Article::where('catid', $parentCatId)
  1331. ->where('status', 1)
  1332. ->where(function ($query) use ($website) {
  1333. $query->where(function ($subQuery) use ($website) {
  1334. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1335. })->orWhereNull("ignore_ids");
  1336. })
  1337. ->select(
  1338. 'article.id',
  1339. 'article.title',
  1340. 'article.author',
  1341. 'article.updated_at',
  1342. 'article.introduce',
  1343. 'article.islink',
  1344. 'article.linkurl',
  1345. 'article.copyfrom',
  1346. DB::raw("'$parent_pinyin' as pinyin"))
  1347. ->orderBy('updated_at', 'desc')
  1348. ->limit($parentTextNum)
  1349. ->get()->all();
  1350. }
  1351. $resultItem = [
  1352. 'alias' => $parent_alias,
  1353. 'category_id' => $parentCatId,
  1354. 'pinyin' => $parent_pinyin,
  1355. 'imgnum' => $imgArticles,
  1356. 'textnum' => $textArticles,
  1357. ];
  1358. if (!empty($item['child']) && $item['child'] != "") {
  1359. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin.'/' : '';
  1360. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  1361. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  1362. ->get()->all();
  1363. if ($childCategory) {
  1364. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  1365. // 查询子栏目名称
  1366. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  1367. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  1368. ->first();
  1369. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  1370. if(empty($childCategoryInfo)){
  1371. $childImgArticles = [];
  1372. $childTextArticles = [];
  1373. } else {
  1374. // 查询子栏目图片新闻
  1375. $childImgArticles = Article::where('catid', $childCatId)
  1376. ->where('status', 1)
  1377. ->where(function ($query) use ($website) {
  1378. $query->where(function ($subQuery) use ($website) {
  1379. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1380. })->orWhereNull("ignore_ids");
  1381. })
  1382. ->select(
  1383. 'article.id',
  1384. 'article.title',
  1385. 'article.imgurl',
  1386. 'article.author',
  1387. 'article.updated_at',
  1388. 'article.introduce',
  1389. 'article.islink',
  1390. 'article.linkurl',
  1391. 'article.copyfrom',
  1392. DB::raw("'$child_pinyin' as pinyin"))
  1393. ->where('imgurl', '!=', '')
  1394. ->orderBy('updated_at', 'desc')
  1395. ->limit($childImgNum)
  1396. ->get()->all();
  1397. // 查询子栏目文字新闻
  1398. $childTextArticles = Article::where('catid', $childCatId)
  1399. ->where('status', 1)
  1400. ->where(function ($query) use ($website) {
  1401. $query->where(function ($subQuery) use ($website) {
  1402. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1403. })->orWhereNull("ignore_ids");
  1404. })
  1405. ->select(
  1406. 'article.id',
  1407. 'article.title',
  1408. 'article.author',
  1409. 'article.updated_at',
  1410. 'article.introduce',
  1411. 'article.islink',
  1412. 'article.linkurl',
  1413. 'article.copyfrom',
  1414. DB::raw("'$child_pinyin' as pinyin"))
  1415. ->orderBy('updated_at', 'desc')
  1416. ->limit($childTextNum)
  1417. ->get()->all();
  1418. }
  1419. $resultItem['child'] = [
  1420. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  1421. 'category_id' => $childCatId,
  1422. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  1423. 'all_childcat' => $childCategory,
  1424. 'imgnum' => $childImgArticles,
  1425. 'textnum' => $childTextArticles,
  1426. ];
  1427. // $resultItem['pinyin'] = $childCategoryInfo->aLIas_pinyin ?? '';
  1428. }
  1429. }
  1430. return $resultItem;
  1431. }, $data);
  1432. return Result::success($result);
  1433. // return Result::success($data);
  1434. }
  1435. /**
  1436. * 乡村网-获取特殊新闻模块
  1437. * @param array $data
  1438. * @return array
  1439. */
  1440. public function getWebsiteArticles(array $data): array
  1441. {
  1442. $input['id'] = $data['id'];
  1443. $input['website_id'] = $data['website_id'];
  1444. $data = json_decode($input['id'], true);
  1445. // 使用 array_map 处理每个元素
  1446. $result = array_map(function ($item) use ($input) {
  1447. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  1448. $website = [
  1449. 'website_id' => $input['website_id']
  1450. ];
  1451. // 查询栏目名称
  1452. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id','aLIas_pinyin']);
  1453. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  1454. if(empty($category)){
  1455. $imgArticles = [];
  1456. $textArticles = [];
  1457. // return Result::error("暂无此栏目",0);
  1458. }else{
  1459. // return Result::success($website);
  1460. // 查询图片新闻
  1461. // 合并查询条件
  1462. $baseQuery = Article::where(function ($query) use ($website) {
  1463. $query->where(function ($subQuery) use ($website) {
  1464. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1465. })->orWhereNull("ignore_ids");
  1466. })
  1467. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($parentCatId) . "')")
  1468. ->leftJoin('website_category', 'website_category.category_id', 'article.catid')
  1469. ->where('website_category.website_id', $website['website_id'])
  1470. ->where('article.status', 1);
  1471. // 查询文字新闻
  1472. $textArticles = clone $baseQuery;
  1473. $textArticles = $textArticles
  1474. ->select(
  1475. 'article.id',
  1476. 'article.title',
  1477. // 'article.imgurl',
  1478. 'article.author',
  1479. 'article.updated_at',
  1480. 'article.introduce',
  1481. 'article.islink',
  1482. 'article.linkurl',
  1483. 'article.copyfrom',
  1484. 'website_category.category_id',
  1485. 'website_category.alias',
  1486. 'website_category.aLIas_pinyin'
  1487. )
  1488. ->selectRaw("CONCAT(?, aLIas_pinyin, '/') as aLIas_pinyin", [$pinyin])
  1489. ->orderBy('article.updated_at', 'desc')
  1490. ->limit($parentTextNum)
  1491. ->get()
  1492. ->all();
  1493. // 查询图片新闻
  1494. $imgArticles = clone $baseQuery;
  1495. $imgArticles = $imgArticles
  1496. ->select(
  1497. 'article.id',
  1498. 'article.title',
  1499. 'article.imgurl',
  1500. 'article.author',
  1501. 'article.updated_at',
  1502. 'article.introduce',
  1503. 'article.islink',
  1504. 'article.linkurl',
  1505. 'article.copyfrom',
  1506. 'website_category.category_id',
  1507. 'website_category.alias',
  1508. 'website_category.aLIas_pinyin'
  1509. )
  1510. ->selectRaw("CONCAT(?, aLIas_pinyin, '/') as aLIas_pinyin", [$pinyin])
  1511. ->orderBy('article.updated_at', 'desc')
  1512. ->where('imgurl', '!=', '')
  1513. ->limit($parentImgNum)
  1514. ->get()
  1515. ->all();
  1516. }
  1517. $resultItem = [
  1518. 'alias' => $category ? $category->alias : null,
  1519. 'category_id' => $parentCatId,
  1520. 'pinyin' => $pinyin ? $pinyin : null,
  1521. 'imgnum' => $imgArticles ?? [],
  1522. 'textnum' => $textArticles ?? [],
  1523. ];
  1524. return $resultItem;
  1525. }, $data);
  1526. return Result::success($result);
  1527. }
  1528. /**
  1529. * 验证导航名称是否重复
  1530. * @return void
  1531. */
  1532. public function checkCategoryName(array $data): array
  1533. {
  1534. $result = Category::when($data, function ($query) use ($data) {
  1535. if (isset($data['name']) && $data['name']) {
  1536. $query->where("name", $data['name']);
  1537. }
  1538. if (isset($data['id']) && $data['id']) {
  1539. $query->where("id", "!=", $data['id']);
  1540. }
  1541. })->first();
  1542. if ($result) {
  1543. return Result::error("已存在");
  1544. } else {
  1545. return Result::success();
  1546. }
  1547. }
  1548. //20250226 产品列表
  1549. public function getGoodList(array $data): array
  1550. {
  1551. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  1552. unset($data['type_id']);
  1553. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  1554. $where = [];
  1555. if ($type_id != '10000') {
  1556. $where = [
  1557. 'good.user_id' => $user_id,
  1558. ];
  1559. }
  1560. //类型
  1561. if (isset($data['type_id']) && $data['type_id']) {
  1562. $where = [
  1563. 'type_id' => $data['type_id'],
  1564. ];
  1565. }
  1566. //名称
  1567. if (isset($data['name']) && $data['name']) {
  1568. $where = [
  1569. 'good.name' => $data['name'],
  1570. ];
  1571. }
  1572. $where1 = [];
  1573. //website_id
  1574. // if (isset($data['website_id']) && $data['website_id']) {
  1575. // $where1 = [
  1576. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  1577. // ];
  1578. // }
  1579. // website_name
  1580. if (isset($data['website_name']) && $data['website_name']) {
  1581. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  1582. }
  1583. // catid
  1584. if (isset($data['category_name']) && $data['category_name']) {
  1585. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  1586. }
  1587. // $result = Good::where($where)
  1588. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  1589. $result = Good::where($where)
  1590. ->when(!empty($where1), function ($query) use ($where1) {
  1591. return $query->where($where1);
  1592. })
  1593. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  1594. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  1595. ->leftJoin('category', 'good.catid', '=', 'category.id')
  1596. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  1597. ->orderBy("id", "desc")
  1598. ->limit($data['page_size'])
  1599. ->offset(($data['page'] - 1) * $data['page_size'])
  1600. ->get();
  1601. $count = Good::where($where)
  1602. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  1603. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  1604. ->leftJoin('category', 'good.catid', '=', 'category.id')
  1605. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  1606. ->orderBy("updated_at", "desc")->count();
  1607. $data = [
  1608. 'rows' => $result->toArray(),
  1609. 'count' => $count,
  1610. ];
  1611. if (empty($result)) {
  1612. return Result::error("此栏目暂无相关产品", 0);
  1613. }
  1614. return Result::success($data);
  1615. }
  1616. public function getGoodInfo(array $data): array
  1617. {
  1618. $result = Good::where('id', $data['id'])->first();
  1619. if (empty($result)) {
  1620. return Result::error("此产品不存在", 0);
  1621. }
  1622. return Result::success($result);
  1623. }
  1624. public function addGood(array $data): array
  1625. {
  1626. // unset($data['city_arr_id']);
  1627. // unset($data['cat_arr_id']);
  1628. $data['city_id'] = end($data['city_arr_id']);
  1629. $data['catid'] = end($data['cat_arr_id']);
  1630. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  1631. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  1632. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  1633. unset($data['imgUrl']);
  1634. $result = Good::insert($data);
  1635. if (empty($result)) {
  1636. return Result::error("添加失败", 0);
  1637. }
  1638. return Result::success($result);
  1639. }
  1640. public function updateGood(array $data): array
  1641. {
  1642. $data['city_id'] = end($data['city_arr_id']);
  1643. $data['catid'] = end($data['cat_arr_id']);
  1644. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  1645. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  1646. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  1647. //设置东八区
  1648. date_default_timezone_set('Asia/Shanghai');
  1649. $data['updated_at'] = date('Y-m-d H:i:s');
  1650. $result = Good::where('id', $data['id'])->update($data);
  1651. if (empty($result)) {
  1652. return Result::error("更新失败", 0);
  1653. }
  1654. return Result::success($result);
  1655. }
  1656. public function delGood(array $data): array
  1657. {
  1658. $result = Good::where('id', $data['id'])->delete();
  1659. if (empty($result)) {
  1660. return Result::error("删除失败", 0);
  1661. }
  1662. return Result::success($result);
  1663. }
  1664. //20250226 产品列表
  1665. //20250306 求职信息
  1666. public function getJobHuntingList(array $data): array
  1667. {
  1668. $where = [];
  1669. if (isset($data['username']) && !empty($data['username'])) {
  1670. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  1671. }
  1672. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  1673. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  1674. unset($data['type_id']);
  1675. if ($type_id != '10000') {
  1676. $where[] = ['job_hunting.user_id', '=', $user_id];
  1677. }
  1678. $result = JobHunting::where($where)
  1679. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  1680. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  1681. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  1682. ->orderBy("id", "desc")
  1683. ->limit($data['page_size'])
  1684. ->offset(($data['page'] - 1) * $data['page_size'])
  1685. ->get();
  1686. if (empty($result)) {
  1687. return Result::error("查询失败", 0);
  1688. }
  1689. $count = JobHunting::where($where)
  1690. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  1691. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  1692. ->count();
  1693. $data = [
  1694. 'rows' => $result->toArray(),
  1695. 'count' => $count,
  1696. ];
  1697. return Result::success($data);
  1698. }
  1699. public function addJobHunting(array $data): array
  1700. {
  1701. date_default_timezone_set('Asia/Shanghai');
  1702. unset($data['company_name']);
  1703. unset($data['job_industry']);
  1704. unset($data['job_name']);
  1705. unset($data['department']);
  1706. unset($data['job_timeList']);
  1707. unset($data['job_content']);
  1708. $data['created_at'] = date('Y-m-d H:i:s');
  1709. $data['updated_at'] = date('Y-m-d H:i:s');
  1710. var_dump($data, '-----------------test---------');
  1711. $result = JobHunting::create($data);
  1712. if (empty($result)) {
  1713. return Result::error("添加失败", 0);
  1714. }
  1715. return Result::success($result);
  1716. }
  1717. public function delJobHunting(array $data): array
  1718. {
  1719. $result = JobHunting::where('id', $data['id'])->delete();
  1720. if (empty($result)) {
  1721. return Result::error("删除失败", 0);
  1722. }
  1723. return Result::success($result);
  1724. }
  1725. public function updateJobHunting(array $data): array
  1726. {
  1727. //设置东八区
  1728. date_default_timezone_set('Asia/Shanghai');
  1729. unset($data['company_name']);
  1730. unset($data['job_industry']);
  1731. unset($data['job_name']);
  1732. unset($data['department']);
  1733. unset($data['job_timeList']);
  1734. unset($data['job_content']);
  1735. $data['created_at'] = date('Y-m-d H:i:s');
  1736. $data['updated_at'] = date('Y-m-d H:i:s');
  1737. $result = JobHunting::where('id', $data['id'])->update($data);
  1738. if (empty($result)) {
  1739. return Result::error("更新失败", 0);
  1740. }
  1741. return Result::success($result);
  1742. }
  1743. public function getJobHuntingInfo(array $data): array
  1744. {
  1745. $result = JobHunting::where('id', $data['id'])->first();
  1746. if (empty($result)) {
  1747. return Result::error("查询失败", 0);
  1748. }
  1749. return Result::success($result);
  1750. }
  1751. public function getJobHuntingData(array $data): array
  1752. {
  1753. $jobEnum = JobEnum::get();
  1754. $jobIndustry = JobIndustry::get();
  1755. $jobNature = JobNature::get();
  1756. $jobPosition = JobPosition::get();
  1757. $data = [
  1758. 'jobEnum' => $jobEnum,
  1759. 'jobIndustry' => $jobIndustry,
  1760. 'jobNature' => $jobNature,
  1761. 'jobPosition' => $jobPosition,
  1762. ];
  1763. return Result::success($data);
  1764. }
  1765. public function delJobHuntingInfo(array $data): array
  1766. {
  1767. $result = JobHunting::where('id', $data['id'])->delete();
  1768. return Result::success();
  1769. }
  1770. //20250324 通知,公告,消息
  1771. public function delNotice(array $data): array
  1772. {
  1773. return Result::success();
  1774. }
  1775. public function getNoticeInfo(array $data): array
  1776. {
  1777. $result = Notice::where('id', $data['id'])->first();
  1778. if (empty($result)) {
  1779. return Result::error("查询失败", 0);
  1780. }
  1781. return Result::success($result);
  1782. }
  1783. public function addNotice(array $data): array
  1784. {
  1785. $result = Notice::create($data);
  1786. return Result::success($result);
  1787. }
  1788. public function updateNotice(array $data): array
  1789. {
  1790. $result = Notice::where('id', $data['id'])->update($data);
  1791. return Result::success($result);
  1792. }
  1793. public function getNoticeList(array $data): array
  1794. {
  1795. $result = Notice::where('status', 1)->get();
  1796. return Result::success($result);
  1797. }
  1798. public function getNoticeDetail(array $data): array
  1799. {
  1800. $result = Notice::where('id', $data['id'])->first();
  1801. if (empty($result)) {
  1802. return Result::error("查询失败", 0);
  1803. }
  1804. return Result::success($result);
  1805. }
  1806. public function deleteNotice(array $data): array
  1807. {
  1808. $result = Notice::where('id', $data['id'])->delete();
  1809. return Result::success($result);
  1810. }
  1811. public function getMSG(array $data): array
  1812. {
  1813. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  1814. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  1815. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  1816. $result = [];
  1817. if ($type_id == 1) {
  1818. //最近的5篇已审的文章
  1819. $apply_articale = Article::where('status', 1)
  1820. ->where('admin_user_id', $user_id)
  1821. ->orderBy('updated_at', 'desc')
  1822. ->limit(5)->get();
  1823. //获取5条单聊未读聊天消息
  1824. $chat = ChatRecords::where('is_read', 0)
  1825. ->where('user_id', $user_id)
  1826. ->where('talk_type', 1)
  1827. ->orderBy('created_at', 'desc')
  1828. ->limit(5)->get();
  1829. //获取5条未读群聊信息
  1830. $chat_group = ChatRecords::where('is_read', 0)
  1831. ->where('user_id', $user_id)
  1832. ->where('talk_type', 2)
  1833. ->orderBy('created_at', 'desc')
  1834. ->limit(5)->get();
  1835. $count = count($chat) + count($chat_group) + count($apply_articale);
  1836. $result = [
  1837. 'apply_articale' => $apply_articale,
  1838. 'chat' => $chat,
  1839. 'chat_group' => $chat_group,
  1840. 'count' => $count,
  1841. ];
  1842. } elseif ($type_id == 2) {
  1843. //最近的5篇已审的文章
  1844. $apply_articale = Article::where('status', 1)
  1845. ->where('admin_user_id', $user_id)
  1846. ->limit(5)->get();
  1847. //获取5条单聊未读聊天消息
  1848. $chat = ChatRecords::where('is_read', 0)
  1849. ->where('user_id', $user_id)
  1850. ->where('talk_type', 1)
  1851. ->orderBy('created_at', 'desc')
  1852. ->limit(5)->get();
  1853. //获取5条未读群聊信息
  1854. $chat_group = ChatRecords::where('is_read', 0)
  1855. ->where('user_id', $user_id)
  1856. ->where('talk_type', 2)
  1857. ->orderBy('created_at', 'desc')
  1858. ->limit(5)->get();
  1859. $count = count($chat) + count($chat_group) + count($apply_articale);
  1860. $result = [
  1861. 'apply_articale' => $apply_articale,
  1862. 'chat' => $chat,
  1863. 'chat_group' => $chat_group,
  1864. 'count' => $count,
  1865. ];
  1866. } elseif ($type_id == 3) {
  1867. //最近的5篇已审的文章
  1868. $apply_articale = Article::where('status', 1)
  1869. ->where('admin_user_id', $user_id)
  1870. ->limit(5)->get();
  1871. //获取5条单聊未读聊天消息
  1872. $chat = ChatRecords::where('is_read', 0)
  1873. ->where('user_id', $user_id)
  1874. ->where('talk_type', 1)
  1875. ->orderBy('created_at', 'desc')
  1876. ->limit(5)->get();
  1877. //获取5条未读群聊信息
  1878. $chat_group = ChatRecords::where('is_read', 0)
  1879. ->where('user_id', $user_id)
  1880. ->where('talk_type', 2)
  1881. ->orderBy('created_at', 'desc')
  1882. ->limit(5)->get();
  1883. $count = count($chat) + count($chat_group) + count($apply_articale);
  1884. $result = [
  1885. 'apply_articale' => $apply_articale,
  1886. 'chat' => $chat,
  1887. 'chat_group' => $chat_group,
  1888. 'count' => $count,
  1889. ];
  1890. } elseif ($type_id == 4) {
  1891. //最近的5篇已审的文章
  1892. $apply_articale = Article::where('status', 1)
  1893. ->where('admin_user_id', $user_id)
  1894. ->limit(5)->get();
  1895. $count = count($apply_articale);
  1896. $result = [
  1897. 'apply_articale' => $apply_articale,
  1898. 'count' => $count,
  1899. ];
  1900. } elseif ($type_id == 10000) {
  1901. //获取未审核的5篇文章
  1902. $apply_articale = Article::where('status', 0)
  1903. ->orderBy('updated_at', 'desc')
  1904. ->limit(5)->get();
  1905. //获取5条单聊未读聊天消息
  1906. $chat = ChatRecords::where('is_read', 0)
  1907. ->where('user_id', $user_id)
  1908. ->where('talk_type', 1)
  1909. ->orderBy('created_at', 'desc')
  1910. ->limit(5)->get();
  1911. //获取5条未读群聊信息
  1912. $chat_group = ChatRecords::where('is_read', 0)
  1913. ->where('user_id', $user_id)
  1914. ->where('talk_type', 2)
  1915. ->orderBy('created_at', 'desc')
  1916. ->limit(5)->get();
  1917. $count = count($chat) + count($chat_group) + count($apply_articale);
  1918. $result = [
  1919. 'apply_articale' => $apply_articale,
  1920. 'chat' => $chat,
  1921. 'chat_group' => $chat_group,
  1922. 'count' => $count,
  1923. ];
  1924. } elseif ($type_id == 20000) {
  1925. }
  1926. var_dump($type_id, '-----------------test---------');
  1927. return Result::success($result);
  1928. }
  1929. public function getComplaintList(array $data): array
  1930. {
  1931. $result = Notice::where('status', 1)->get();
  1932. return Result::success($result);
  1933. }
  1934. public function getComplaintInfo(array $data): array
  1935. {
  1936. $result = Notice::where('id', $data['id'])->first();
  1937. if (empty($result)) {
  1938. return Result::error("查询失败", 0);
  1939. }
  1940. return Result::success($result);
  1941. }
  1942. public function addComplaint(array $data): array
  1943. {
  1944. $result = Notice::create($data);
  1945. return Result::success($result);
  1946. }
  1947. public function updateComplaint(array $data): array
  1948. {
  1949. $result = Notice::where('id', $data['id'])->update($data);
  1950. return Result::success($result);
  1951. }
  1952. public function deleteComplaint(array $data): array
  1953. {
  1954. $result = Notice::where('id', $data['id'])->delete();
  1955. return Result::success($result);
  1956. }
  1957. public function getComplainInfo(array $data): array
  1958. {
  1959. $result = Notice::where('id', $data['id'])->first();
  1960. if (empty($result)) {
  1961. return Result::error("查询失败", 0);
  1962. }
  1963. return Result::success($result);
  1964. }
  1965. //20250324 通知,公告,消息
  1966. }