NewsService.php 115 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801
  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\District;
  10. use App\Model\Good;
  11. use App\Model\JobCompany;
  12. use App\Model\Website;
  13. use App\Model\JobRecruiting;
  14. use App\Model\JobIndustry;
  15. use App\Model\JobPosition;
  16. use App\Model\Notice;
  17. use App\Model\JobNature;
  18. use App\Model\JobEnum;
  19. use App\Model\User;
  20. use App\Model\UserRole;
  21. use App\Model\News;
  22. use App\Model\UserInfo;
  23. use App\Model\WebsiteGroup;;
  24. use Hyperf\DbConnection\Db;
  25. use Hyperf\RpcServer\Annotation\RpcService;
  26. use App\Tools\Result;
  27. use Directory;
  28. use Ramsey\Uuid\Uuid;
  29. use Hyperf\Utils\Random;
  30. use Fukuball\Jieba\Jieba;
  31. use Fukuball\Jieba\Finalseg;
  32. use Hyperf\Utils\Collection;
  33. use function Hyperf\Support\retry;
  34. use App\Tools\PublicData;
  35. use App\Model\ChatGroups;
  36. use App\Model\ChatGroupsMember;
  37. use App\Model\ChatRecords;
  38. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  39. class NewsService implements NewsServiceInterface
  40. {
  41. /**
  42. * 获取导航池列表
  43. * @param array $data
  44. * @return array
  45. */
  46. public function getCategoryList(array $data): array
  47. {
  48. $page = (int) $data['page'] ?? 1;
  49. $perPage = (int) $data['pageSize'] ?? 10;
  50. $search = $data['name'] ?? '';
  51. // 查找所有匹配的分类
  52. $matchedCategories = $this->findMatchedCategories($search);
  53. // 查找所有匹配分类的父级分类
  54. $allRequiredCategories = $this->findAllParents($matchedCategories);
  55. // 提取一级分类
  56. $topLevelCategories = [];
  57. foreach ($allRequiredCategories as $category) {
  58. if ($category->pid === 0) {
  59. $topLevelCategories[] = $category;
  60. }
  61. }
  62. // 分页处理
  63. $offset = ($page - 1) * $perPage;
  64. $paginatedTopLevelCategories = array_slice($topLevelCategories, $offset, $perPage);
  65. $categoryTree = [];
  66. foreach ($paginatedTopLevelCategories as $category) {
  67. $categoryTree[] = $this->buildCategoryTree($category, $allRequiredCategories);
  68. }
  69. $return = [
  70. 'rows' => $categoryTree,
  71. 'total' => count($topLevelCategories),
  72. ];
  73. return Result::success($return);
  74. }
  75. private function findMatchedCategories($search)
  76. {
  77. if ($search) {
  78. return Category::where('name', 'like', "%{$search}%")
  79. ->orderBy('updated_at', 'desc')
  80. ->get();
  81. }
  82. return Category::orderBy('updated_at', 'desc') // 按 updated_at 字段倒序排序
  83. ->get();
  84. }
  85. private function findAllParents($categories)
  86. {
  87. $allCategories = [];
  88. foreach ($categories as $category) {
  89. $parentId = $category->pid;
  90. while ($parentId > 0) {
  91. $parent = Category::find($parentId);
  92. if ($parent) {
  93. $allCategories[$parent->id] = $parent;
  94. $parentId = $parent->pid;
  95. } else {
  96. break;
  97. }
  98. }
  99. $allCategories[$category->id] = $category;
  100. }
  101. return array_values($allCategories);
  102. }
  103. private function buildCategoryTree($category, $allRequiredCategories)
  104. {
  105. $categoryData = $category->toArray();
  106. $children = [];
  107. foreach ($allRequiredCategories as $c) {
  108. if ($c->pid === $category->id) {
  109. $children[] = $this->buildCategoryTree($c, $allRequiredCategories);
  110. }
  111. }
  112. if (!empty($children)) {
  113. $categoryData['children'] = $children;
  114. }
  115. return $categoryData;
  116. }
  117. public function myCategoryList(array $data): array
  118. {
  119. $sszq = $data['sszq'] ?? '';
  120. unset($data['sszq']);
  121. //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
  122. $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
  123. $where[] = [
  124. 'pid',
  125. '=',
  126. $data['pid'],
  127. ];
  128. if (isset($data['name'])) {
  129. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  130. }
  131. var_dump($where);
  132. //根据分类id,从category表中取出分类信息
  133. $result = Category::where($where)
  134. ->whereIn('category.id', $catorytids)
  135. ->select('category.*', 'category.id as category_id')->get();
  136. if (empty($result)) {
  137. return Result::error("没有栏目数据");
  138. }
  139. return Result::success($result);
  140. }
  141. /**
  142. * @param array $data
  143. * @return array
  144. */
  145. public function categoryList(array $data): array
  146. {
  147. $where[] = [
  148. 'pid',
  149. '=',
  150. $data['pid'],
  151. ];
  152. if (isset($data['name'])) {
  153. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  154. }
  155. var_dump($where);
  156. $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
  157. if (empty($result)) {
  158. return Result::error("没有栏目数据");
  159. }
  160. return Result::success($result);
  161. }
  162. /**
  163. * @param array $data
  164. * @return array
  165. */
  166. public function addCategory(array $data): array
  167. {
  168. if (isset($data['id'])) {
  169. unset($data['id']);
  170. }
  171. $id = Category::insertGetId($data);
  172. if (empty($id)) {
  173. return Result::error("添加失败");
  174. }
  175. return Result::success(['id' => $id]);
  176. }
  177. /**
  178. * @param array $data
  179. * @return array
  180. */
  181. public function delCategory(array $data): array
  182. {
  183. Db::beginTransaction();
  184. try {
  185. $categoryList = Category::where(['pid' => $data['id']])->get();
  186. if ($categoryList->toArray()) {
  187. Db::rollBack();
  188. return Result::error("分类下面有子分类不能删除");
  189. }
  190. $articleList = Article::where(['catid' => $data['id']])->get();
  191. if ($articleList->toArray()) {
  192. Db::rollBack();
  193. return Result::error("分类下面有资讯不能删除");
  194. }
  195. $result = Category::where($data)->delete();
  196. WebsiteCategory::where(['category_id' => $data['id']])->delete();
  197. if (!$result) {
  198. return Result::error("删除失败");
  199. }
  200. return Result::success($result);
  201. Db::commit();
  202. } catch (\Exception $e) {
  203. Db::rollBack();
  204. return Result::error("删除失败");
  205. }
  206. }
  207. /**
  208. * @param array $data
  209. * @return array
  210. */
  211. public function updateCategory(array $data): array
  212. {
  213. $where = [
  214. 'id' => $data['id'],
  215. ];
  216. $result = Category::where($where)->update($data);
  217. if ($result) {
  218. return Result::success($result);
  219. } else {
  220. return Result::error("更新失败");
  221. }
  222. }
  223. /**
  224. * 获取导航池信息
  225. * @param array $data
  226. * @return array
  227. */
  228. public function getCategoryInfo(array $data): array
  229. {
  230. $where = [
  231. 'id' => $data['id'],
  232. ];
  233. $result = Category::where($where)->first();
  234. if ($result) {
  235. return Result::success($result);
  236. } else {
  237. return Result::error("更新失败");
  238. }
  239. }
  240. /**
  241. * @param array $data
  242. * @return array
  243. */
  244. public function getArticleList(array $data): array
  245. {
  246. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  247. $type_id = $data['type_id'];
  248. unset($data['type_id']);
  249. $user_id = $data['user_id'];
  250. unset($data['user_id']);
  251. $where = [];
  252. $status1 = [];
  253. if (isset($data['id']) && $data['id']) {
  254. array_push($where, ['article.id', '=', $data['id']]);
  255. }
  256. if (isset($data['title']) && $data['title']) {
  257. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  258. }
  259. if (isset($data['category_name']) && $data['category_name']) {
  260. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  261. }
  262. if (isset($data['author']) && $data['author']) {
  263. array_push($where, ['article.author', '=', $data['author']]);
  264. }
  265. if (isset($data['islink']) && $data['islink'] !== "") {
  266. array_push($where, ['article.islink', '=', $data['islink']]);
  267. }
  268. if (isset($data['status']) && $data['status'] !== "") {
  269. array_push($where, ['article.status', '=', $data['status']]);
  270. }
  271. if (isset($data['status1'])) {
  272. $status1 = json_decode(($data['status1']));
  273. }
  274. //不是管理员展示个人数据;
  275. if ($type_id != 10000) {
  276. $where[] = ['article.admin_user_id', '=', $user_id];
  277. }
  278. $rep = Article::where($where)
  279. ->whereNotIn('article.status', [404])
  280. ->when($status1, function ($query) use ($status1) {
  281. if (isset($status1) && $status1) {
  282. $query->whereIn('article.status', $status1);
  283. }
  284. })
  285. ->leftJoin('category', 'article.catid', 'category.id')
  286. ->leftJoin('website_category', function ($join) {
  287. $join->on('article.web_site_id', '=', 'website_category.website_id')
  288. ->on('article.catid', '=', 'website_category.category_id');
  289. })
  290. ->select("article.*", "category.name as category_name", "website_category.alias")
  291. ->orderBy("article.updated_at", "desc")
  292. ->limit($data['pageSize'])
  293. ->offset(($data['page'] - 1) * $data['pageSize'])->get();
  294. $count = Article::where($where)->whereNotIn('article.status', [404])
  295. ->when($status1, function ($query) use ($status1) {
  296. if (isset($status1) && $status1) {
  297. $query->whereIn('article.status', $status1);
  298. }
  299. })
  300. ->leftJoin('category', 'article.catid', 'category.id')->count();
  301. $data = [
  302. 'rows' => $rep->toArray(),
  303. 'count' => $count,
  304. ];
  305. if (empty($rep)) {
  306. return Result::error("没有信息数据");
  307. }
  308. return Result::success($data);
  309. }
  310. /**
  311. * @param array $data
  312. * @return array
  313. */
  314. public function addArticle(array $data): array
  315. {
  316. var_dump($data, '----------12-----------1');
  317. unset($data['user_type']);
  318. unset($data['nav_add_pool_id']);
  319. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  320. Db::beginTransaction();
  321. try {
  322. //处理投票
  323. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  324. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  325. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  326. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  327. unset($data['is_survey']);
  328. unset($data['survey_name']);
  329. unset($data['suvey_array']);
  330. // unset($data['website_id']);
  331. // unset($data['web_site_id']);
  332. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  333. if ($data['hits'] == '') {
  334. $data['hits'] = 0;
  335. }
  336. if ($data['is_original'] == '') {
  337. $data['is_original'] = 0;
  338. }
  339. if ($data['status'] == '') {
  340. $data['status'] = 0;
  341. }
  342. $articleData = $data;
  343. unset($articleData['content']);
  344. //自动处理缩略图、关键字、描述
  345. if ($articleData['imgurl'] == '') {
  346. //如果没有图,设置level=0
  347. $levelArr = json_decode($articleData['level'], true);
  348. var_dump($levelArr, '----------levelArr-----------1');
  349. //content中提取图片第一个图,正则提取
  350. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  351. preg_match_all($reg, $data['content'], $matches);
  352. if (isset($matches[1][0])) {
  353. //截取varchar240
  354. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  355. //如果有图,设置level=3
  356. if (!in_array(3, $levelArr)) {
  357. $levelArr[] = 3;
  358. }
  359. $articleData['level'] = json_encode($levelArr);
  360. } else {
  361. if (!in_array(0, $levelArr)) {
  362. $levelArr[] = 0;
  363. }
  364. $articleData['level'] = json_encode($levelArr);
  365. }
  366. }
  367. var_dump($articleData['level'], '----------$articleData[level]----------1');
  368. if ($articleData['keyword'] == '') {
  369. //提取标题+内容中的关键词
  370. $articleData['keyword'] = $data['title'];
  371. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  372. Jieba::init(); // 初始化 jieba-php
  373. Finalseg::init();
  374. $segList = Jieba::cut($articleData['keyword']);
  375. $segList1 = array_slice($segList, 0, 8);
  376. $articleData['keyword'] = implode(',', $segList1);
  377. }
  378. if ($articleData['introduce'] == '') {
  379. //提取内容中的描述
  380. $articleData['introduce'] = substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
  381. }
  382. $id = Article::insertGetId($articleData);
  383. $articleDataContent = [
  384. 'article_id' => $id,
  385. 'content' => $data['content'],
  386. ];
  387. ArticleData::insertGetId($articleDataContent);
  388. //处理投票
  389. if ($is_survey == 1) {
  390. //生成年月日时分秒+8位随机数
  391. $uuid = date('YmdHis') . rand(10000000, 99999999);
  392. var_dump($suvey_array, 'suvey_array________');
  393. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  394. var_dump($suveys_array, '---------------------1');
  395. var_dump($suvey_array, '---------------------2');
  396. $suvey_data = [];
  397. foreach ($suveys_array as $key => $value) {
  398. if ($value == '') {
  399. continue;
  400. }
  401. if (is_array($value)) {
  402. $suvey_data[] = [
  403. 'sur_id' => $uuid,
  404. 'art_id' => $id,
  405. 'website_id' => $website_id ?? 2,
  406. 'survey_name' => $survey_name,
  407. 'choice_name' => $value[1],
  408. 'is_other' => 1,
  409. 'other_id' => 0,
  410. 'results' => 0,
  411. ];
  412. } else {
  413. $suvey_data[] = [
  414. 'sur_id' => $uuid,
  415. 'art_id' => $id,
  416. 'website_id' => $website_id ?? 2,
  417. 'survey_name' => $survey_name,
  418. 'choice_name' => $value,
  419. 'is_other' => 0,
  420. 'other_id' => 0,
  421. 'results' => 0,
  422. ];
  423. }
  424. if (empty($suvey_data)) {
  425. throw new \Exception("投票数据为空");
  426. }
  427. }
  428. $result = ArticleSurvey::insert($suvey_data);
  429. if (!$result) {
  430. throw new \Exception("投票失败,ArticleSurvey插入失败");
  431. }
  432. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  433. if (!$result) {
  434. throw new \Exception("投票失败,更新主表失败");
  435. }
  436. }
  437. Db::commit();
  438. return Result::success(['id' => $id]);
  439. } catch (\Throwable $ex) {
  440. Db::rollBack();
  441. var_dump($ex->getMessage());
  442. return Result::error("创建失败", 0);
  443. }
  444. }
  445. /**
  446. * @param array $data
  447. * @return array
  448. */
  449. public function delArticle(array $data): array
  450. {
  451. $result = Article::where($data)->delete();
  452. //survey投票删除
  453. articleSurvey::where(['art_id' => $data['id']])->delete();
  454. if (!$result) {
  455. return Result::error("删除失败");
  456. }
  457. return Result::success($result);
  458. }
  459. /**
  460. * @param array $data
  461. * @return array
  462. */
  463. public function updateArticle(array $data): array
  464. {
  465. var_dump($data, '----------12-----------1');
  466. Db::beginTransaction();
  467. unset($data['user_type']);
  468. // unset($data['web_site_id']);
  469. unset($data['nav_add_pool_id']);
  470. try {
  471. //处理投票
  472. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  473. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  474. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  475. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  476. unset($data['is_survey']);
  477. unset($data['survey_name']);
  478. unset($data['suvey_array']);
  479. unset($data['website_id']);
  480. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  481. if ($data['hits'] == '') {
  482. $data['hits'] = 0;
  483. }
  484. if ($data['is_original'] == '') {
  485. $data['is_original'] = 0;
  486. }
  487. if ($data['status'] == '') {
  488. $data['status'] = 0;
  489. }
  490. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  491. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  492. $articleData = $data;
  493. unset($articleData['content']);
  494. unset($articleData['status_name']);
  495. unset($articleData['name']);
  496. unset($articleData['content']);
  497. unset($articleData['pid_arr']);
  498. unset($articleData['pid']);
  499. //自动处理缩略图、关键字、描述
  500. if ($articleData['imgurl'] == '') {
  501. //如果没有图,设置level=0
  502. $levelArr = json_decode($articleData['level'], true);
  503. var_dump($levelArr, '----------levelArr-----------1');
  504. //content中提取图片第一个图,正则提取
  505. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  506. preg_match_all($reg, $data['content'], $matches);
  507. if (isset($matches[1][0])) {
  508. //截取varchar240
  509. // 截取到第一个<
  510. $articleData['imgurl'] = $matches[1][0];
  511. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  512. $pos = strpos($articleData['imgurl'], '"');
  513. if ($pos !== false) {
  514. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  515. }
  516. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  517. //如果有图,设置level=3
  518. if (!in_array(3, $levelArr)) {
  519. $levelArr[] = 3;
  520. }
  521. $articleData['level'] = json_encode($levelArr);
  522. } else {
  523. if (!in_array(0, $levelArr)) {
  524. $levelArr[] = 0;
  525. }
  526. $articleData['level'] = json_encode($levelArr);
  527. }
  528. }
  529. var_dump($articleData['level'], '----------$articleData[level]----------1');
  530. if ($articleData['keyword'] == '') {
  531. //提取标题+内容中的关键词
  532. $articleData['keyword'] = $data['title'];
  533. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  534. Jieba::init(); // 初始化 jieba-php
  535. Finalseg::init();
  536. $segList = Jieba::cut($articleData['keyword']);
  537. $segList1 = array_slice($segList, 0, 8);
  538. $articleData['keyword'] = implode(',', $segList1);
  539. }
  540. if ($articleData['introduce'] == '') {
  541. //提取内容中的描述
  542. $articleData['introduce'] = substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
  543. }
  544. $id = Article::where(['id' => $data['id']])->update($articleData);
  545. $articleDataContent = [
  546. 'content' => $data['content'],
  547. ];
  548. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  549. //处理投票
  550. $id = $data['id'];
  551. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  552. var_dump($suvey_array, 'suvey_array________delete');
  553. //处理投票
  554. if ($is_survey == 1) {
  555. //生成年月日时分秒+8位随机数
  556. $uuid = date('YmdHis') . rand(10000000, 99999999);
  557. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  558. var_dump($suveys_array, '---------------------1');
  559. $suvey_data = [];
  560. if (is_array($suveys_array)) {
  561. foreach ($suveys_array as $key => $value) {
  562. if ($value == '') {
  563. continue;
  564. }
  565. if (is_array($value)) {
  566. $suvey_data[] = [
  567. 'sur_id' => $uuid,
  568. 'art_id' => $id,
  569. 'website_id' => $website_id ?? 2,
  570. 'survey_name' => $survey_name,
  571. 'choice_name' => $value[1],
  572. 'is_other' => 1,
  573. 'other_id' => 0,
  574. 'results' => 0,
  575. ];
  576. } else {
  577. $suvey_data[] = [
  578. 'sur_id' => $uuid,
  579. 'art_id' => $id,
  580. 'website_id' => $website_id ?? 2,
  581. 'survey_name' => $survey_name,
  582. 'choice_name' => $value,
  583. 'is_other' => 0,
  584. 'other_id' => 0,
  585. 'results' => 0,
  586. ];
  587. }
  588. if (empty($suvey_data)) {
  589. throw new \Exception("投票数据为空");
  590. }
  591. }
  592. }
  593. $result = ArticleSurvey::insert($suvey_data);
  594. if (!$result) {
  595. throw new \Exception("投票失败");
  596. }
  597. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  598. if (!$result) {
  599. throw new \Exception("投票失败");
  600. }
  601. } else {
  602. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  603. }
  604. Db::commit();
  605. return Result::success([]);
  606. } catch (\Throwable $ex) {
  607. Db::rollBack();
  608. var_dump($ex->getMessage());
  609. return Result::error("更新失败" . $ex->getMessage(), 0);
  610. }
  611. }
  612. /**
  613. * 更新资讯状态
  614. * @param array $data
  615. * @return array
  616. */
  617. public function upArticleStatus(array $data): array
  618. {
  619. $result = Article::where(['id' => $data['id']])->update($data);
  620. if ($result) {
  621. return Result::success();
  622. } else {
  623. return Result::error("更新状态失败", 0);
  624. }
  625. }
  626. /**
  627. * @param array $data
  628. * @return array
  629. */
  630. public function getArticleInfo(array $data): array
  631. {
  632. $where = [
  633. 'article.id' => $data['id'],
  634. // 'article.status' => 1,
  635. ];
  636. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  637. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  638. $info = $result;
  639. // var_dump($info, 'info');
  640. $info['survey_array'] = $articleSurvey;
  641. if ($result) {
  642. return Result::success($info);
  643. } else {
  644. return Result::error("查询失败", 0);
  645. }
  646. }
  647. /**
  648. * 获取新闻
  649. * @param array $data
  650. * @return array
  651. */
  652. public function getWebsiteArticlett(array $data): array
  653. {
  654. // return Result::success($data['website_id']);
  655. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
  656. $category = array_values(array_unique($category->toArray()));
  657. $result = [];
  658. if ($category) {
  659. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  660. $where = [
  661. 'status' => 1,
  662. ];
  663. var_dump($data, 'data-----------------');
  664. // level=7 根据文章key来匹配文章
  665. if (isset($data['level']) && $data['level'] == 7) {
  666. // 根据文章id获取key
  667. // $data['id'] = 50142;
  668. if (isset($data['id']) && !empty($data['id'])) {
  669. $keyword = Article::where('id', $data['id'])->value('keyword');
  670. $keywordArray = explode(',', $keyword);
  671. $whereL7 = [];
  672. foreach ($keywordArray as $k => $v) {
  673. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  674. }
  675. // 原始查询
  676. $result = Article::where($whereL7)
  677. ->offset($placeid)
  678. ->limit($data['pageSize'])
  679. ->orderBy('updated_at', 'desc')
  680. ->get()
  681. ->map(function ($article) use ($data) {
  682. $catid = $article->catid;
  683. $pinyin = '';
  684. $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
  685. if (!empty($category->aLIas_pinyin) && $category->pid != 0) {
  686. $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
  687. if ($childCategory && !empty($childCategory->aLIas_pinyin)) {
  688. $pinyin = $childCategory->aLIas_pinyin ? $childCategory->aLIas_pinyin.'/'. $category->aLIas_pinyin : null;
  689. }
  690. } else {
  691. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  692. }
  693. $article->pinyin = $pinyin;
  694. return $article;
  695. });
  696. if (empty($result)) {
  697. return Result::success([]);
  698. }
  699. return Result::success($result);
  700. } else {
  701. return Result::error("参数错误level=7,id不能为空", 0);
  702. }
  703. }
  704. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  705. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  706. var_dump($where, 'where-----------------');
  707. $result = Article::where($where)
  708. ->whereIn("catid", $category)
  709. // ->leftJoin('website_category', 'article.catid', 'website_category.category_id')
  710. // ->where('website_category.website_id', $data['website_id'])
  711. ->where(function ($query) use ($data) {
  712. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  713. ->orWhereNull("ignore_ids");
  714. })
  715. //$data['level'] == 4 || $data['level'] == 5 查询随机
  716. ->when($data['level'] == 5, function ($query) {
  717. $query->inRandomOrder()
  718. //updated_at最近三十天;
  719. ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  720. })
  721. ->when($data['level'] == 4, function ($query) {
  722. $query->orderBy("article.updated_at", "desc");
  723. })
  724. ->when(!empty($data['level']), function ($query) use ($data) {
  725. if ($data['level'] != 4 && $data['level'] != 5) {
  726. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  727. ->orderBy("article.updated_at", "desc");
  728. }
  729. })
  730. ->select('article.*')
  731. ->offset($placeid)
  732. ->limit($data['pageSize'])
  733. ->get()
  734. ->map(function ($article) use ($data) {
  735. $catid = $article->catid;
  736. $pinyin = '';
  737. $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
  738. if (!empty($category->aLIas_pinyin) && $category->pid != 0) {
  739. $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
  740. if ($childCategory && !empty($childCategory->aLIas_pinyin)) {
  741. $pinyin = $childCategory->aLIas_pinyin ? $childCategory->aLIas_pinyin.'/'. $category->aLIas_pinyin : null;
  742. }
  743. } else {
  744. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  745. }
  746. $article->pinyin = $pinyin;
  747. return $article;
  748. });
  749. if (empty($result)) {
  750. return Result::error("暂无头条新闻", 0);
  751. }
  752. return Result::success($result);
  753. } else {
  754. return Result::error("本网站下暂无相关栏目", 0);
  755. }
  756. }
  757. /**
  758. * 获取模块新闻
  759. * @param array $data
  760. * @return array
  761. */
  762. public function getWebsiteModelArticles(array $data): array
  763. {
  764. $catid = $data['catid'];
  765. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  766. $category = $category->toArray();
  767. if (!empty($category)) {
  768. $where = [
  769. 'status' => 1,
  770. 'catid' => $catid,
  771. ];
  772. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  773. // 1:文字新闻;2:轮播图;3:图文;
  774. // 级别:0:未分类
  775. // 3:推荐图片
  776. if ($data['level'] == 1) {
  777. $data['level'] = 0;
  778. }
  779. $result = Article::where($where)
  780. ->where(function ($query) use ($data) {
  781. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  782. ->orWhereNull("level")
  783. ->orWhereRaw("level = '[]'");
  784. })
  785. ->where(function ($query) use ($data) {
  786. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  787. ->orWhereNull("ignore_ids");
  788. })
  789. ->orderBy("updated_at", "desc")
  790. ->offset($placeid)
  791. ->limit($data['pagesize'])
  792. ->get();
  793. if (empty($result)) {
  794. return Result::error("此栏目暂无相关新闻", 0);
  795. }
  796. } else {
  797. return Result::error("此网站暂无此栏目", 0);
  798. }
  799. return Result::success($result);
  800. }
  801. /**
  802. *获取新闻列表
  803. * @param array $data
  804. * @return array
  805. */
  806. public function getWebsiteArticleList(array $data): array
  807. {
  808. // return Result::success($data);
  809. $where[] = ['status', '=', 1];
  810. if (isset($data['catid']) && !empty($data['catid'])) {
  811. if (is_array($data['catid'])) {
  812. $category = WebsiteCategory::where('website_id', $data['website_id'])->whereIn('category_id', $data['catid'])->pluck('category_id');
  813. array_push($where, ['catid', 'in', $data['catid']]);
  814. } else {
  815. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  816. array_push($where, ['catid', '=', $data['catid']]);
  817. }
  818. if (empty($category)) {
  819. return Result::error("此网站暂无此栏目", 0);
  820. }
  821. }
  822. // return Result::success($where);
  823. $rep = Article::where(function ($query) use ($where) {
  824. foreach ($where as $condition) {
  825. if ($condition[1] === 'in') {
  826. $query->whereIn($condition[0], $condition[2]);
  827. } else {
  828. $query->where($condition[0], $condition[1], $condition[2]);
  829. }
  830. }
  831. })
  832. ->where(function ($query) use ($data) {
  833. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  834. ->orWhereNull("ignore_ids");
  835. })
  836. ->select(
  837. 'article.id',
  838. 'article.title',
  839. 'article.imgurl',
  840. 'article.author',
  841. 'article.updated_at',
  842. 'article.introduce',
  843. 'article.islink',
  844. 'article.linkurl',
  845. 'article.copyfrom',
  846. 'article.catid'
  847. )
  848. ->orderBy("updated_at", "desc")
  849. ->limit($data['pageSize'])
  850. ->offset(($data['page'] - 1) * $data['pageSize'])
  851. ->get()
  852. ->map(function ($article) use ($data) {
  853. $catid = $article->catid ?? 0;
  854. $pinyin = '';
  855. $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
  856. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  857. if ($category->pid != 0 && !empty($category->aLIas_pinyin)) {
  858. $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
  859. $pinyin = $childCategory->aLIas_pinyin ? $childCategory->aLIas_pinyin . '/' . $category->aLIas_pinyin : null;
  860. }
  861. $article->pinyin = $pinyin;
  862. return $article;
  863. });
  864. $count = Article::where(function ($query) use ($where) {
  865. foreach ($where as $condition) {
  866. if ($condition[1] === 'in') {
  867. $query->whereIn($condition[0], $condition[2]);
  868. } else {
  869. $query->where($condition[0], $condition[1], $condition[2]);
  870. }
  871. }
  872. })->count();
  873. $data = [
  874. 'rows' => $rep->toArray(),
  875. 'count' => $count,
  876. ];
  877. if (empty($rep)) {
  878. return Result::error("没有信息数据");
  879. }
  880. return Result::success($data);
  881. }
  882. /**
  883. * 前端-获取新闻详情
  884. * @param array $data
  885. * @return array
  886. */
  887. public function selectWebsiteArticleInfo(array $data): array
  888. {
  889. $where = [
  890. 'article.id' => $data['id'],
  891. 'article.status' => 1,
  892. ];
  893. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")
  894. ->where(function ($query) use ($data) {
  895. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  896. ->orWhereNull("ignore_ids");
  897. })
  898. ->first();
  899. if (empty($result)) {
  900. return Result::error("暂无此新闻!", 0);
  901. }
  902. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  903. ->select('website_category.*', 'website.website_name', 'website.suffix')
  904. ->where('website_category.website_id', $data['website_id'])
  905. ->where(['website_category.category_id' => $result['catid']])
  906. ->first();
  907. if (empty($category)) {
  908. return Result::error("查询失败", 0);
  909. }
  910. //手动推荐文章
  911. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  912. $commendArticle = Article::whereIn('id', $commend_ids)
  913. ->where('status', 1)
  914. ->select('id', 'title', 'catid', 'imgurl', 'hits', 'created_at')
  915. ->orderBy('updated_at', 'desc')
  916. ->limit(5)
  917. ->get();
  918. $result['category_id'] = $category['category_id'];
  919. $result['cat_name'] = $category['alias'];
  920. $result['website_name'] = $category['website_name'] ?? "";
  921. $result['suffix'] = $category['suffix'] ?? "";
  922. $result['commendArticle'] = $commendArticle;
  923. return Result::success($result);
  924. }
  925. /**
  926. * 前端-获取网站调查问卷
  927. * @param array $data
  928. * @return array
  929. */
  930. public function getWebsiteSurvey(array $data): array
  931. {
  932. if (isset($data['website_id']) && !empty($data['website_id'])) {
  933. $website = Website::where('id', $data['website_id'])->first();
  934. if (empty($website)) {
  935. return Result::error("暂无此网站", 0);
  936. }
  937. }
  938. if (isset($data['art_id']) && !empty($data['art_id'])) {
  939. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  940. if (empty($article)) {
  941. return Result::error("暂无此文章", 0);
  942. }
  943. // return Result::error($data,0);
  944. $where['art_id'] = $data['art_id'];
  945. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  946. } else {
  947. $survey = Article::where(function ($query) {
  948. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  949. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  950. })
  951. ->where('status', 1)
  952. ->where('is_survey', 1)
  953. ->select('survey_id')
  954. ->orderBy('updated_at', 'desc')
  955. ->first();
  956. if (empty($survey)) {
  957. return Result::error("暂无调查问卷", 0);
  958. }
  959. $where['sur_id'] = $survey['survey_id'];
  960. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  961. }
  962. // return Result::success($where);
  963. $result = ArticleSurvey::where($where)
  964. ->where(function ($query) {
  965. $query->where('is_other', 0)
  966. ->orWhere(function ($subQuery) {
  967. $subQuery->where('is_other', 1)
  968. ->where('other_id', 0);
  969. });
  970. })
  971. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  972. ->select('article_survey.*', 'article.survey_type')
  973. ->get()->all();
  974. if (empty($result)) {
  975. return Result::error("此文章暂无调查问卷", 0);
  976. }
  977. return Result::success($result);
  978. }
  979. /**
  980. * 前端-添加网站调查问卷选项
  981. * @param array $data
  982. * @return array
  983. */
  984. public function addWebsiteSurveyOption(array $data): array
  985. {
  986. if (isset($data['website_id']) && !empty($data['website_id'])) {
  987. $website = Website::where('id', $data['website_id'])->first();
  988. if (empty($website)) {
  989. return Result::error("暂无此网站", 0);
  990. }
  991. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  992. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('website_id', $data['website_id'])->where('is_other', 1)->where('other_id', 0)->first();
  993. if (empty($survey)) {
  994. return Result::error("此调查问卷不可添加选项", 0);
  995. }
  996. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  997. $choice = [
  998. 'art_id' => $survey['art_id'],
  999. 'website_id' => $data['website_id'],
  1000. 'survey_name' => $survey['survey_name'],
  1001. 'choice_name' => $data['choice_name'],
  1002. 'sur_id' => $survey['sur_id'],
  1003. 'is_other' => 1,
  1004. 'other_id' => $survey['id'],
  1005. ];
  1006. $result = ArticleSurvey::insertGetId($choice);
  1007. if (empty($result)) {
  1008. return Result::error("添加失败", 0);
  1009. }
  1010. return Result::success($result);
  1011. }
  1012. }
  1013. return Result::error("添加失败", 0);
  1014. }
  1015. return Result::error("添加失败", 0);
  1016. }
  1017. /**
  1018. * 前端-调查问卷投票
  1019. * @param array $data
  1020. * @return array
  1021. */
  1022. public function addWebsiteSurveyVote(array $data): array
  1023. {
  1024. // return Result::success($data);
  1025. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1026. $website = Website::where('id', $data['website_id'])->first();
  1027. if (empty($website)) {
  1028. return Result::error("暂无此网站", 0);
  1029. }
  1030. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1031. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1032. // return Result::success($survey);
  1033. if (empty($is_survey)) {
  1034. return Result::error("此调查问卷不存在", 0);
  1035. }
  1036. // return Result::success($survey);
  1037. // 调查问卷类型
  1038. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1039. //多选 若是json型则转化成数组类型
  1040. if (strpos($data['choice_id'], '[') === 0) {
  1041. $data['choice_id'] = json_decode($data['choice_id'], true);
  1042. } else {
  1043. // 单选 也转换成数组
  1044. $data['choice_id'] = [$data['choice_id']];
  1045. }
  1046. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1047. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1048. ->where('website_id', $data['website_id'])
  1049. ->where('is_other', 1)
  1050. ->where('other_id', 0)
  1051. ->first();
  1052. if (!empty($other)) {
  1053. return Result::error("请选择已有的选项!", 0);
  1054. }
  1055. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1056. ->where('website_id', $data['website_id'])
  1057. ->where('is_other', 1)
  1058. ->where('other_id', '!=', 0)
  1059. ->first();
  1060. // return Result::success($choice['other']);
  1061. $choice_id = $data['choice_id'];
  1062. if (!empty($choice['other'])) {
  1063. // array_push($data['choice_id'],$choice['other']['other_id']);
  1064. if (!empty($choice_id)) {
  1065. $key = array_search($choice['other']['id'], $choice_id);
  1066. if ($key !== false) {
  1067. unset($choice_id[$key]);
  1068. $choice_id = array_values($choice_id);
  1069. }
  1070. array_push($choice_id, $choice['other']['other_id']);
  1071. } else {
  1072. $choice_id[0] = $choice['other']['other_id'];
  1073. }
  1074. array_push($data['choice_id'], $choice['other']['other_id']);
  1075. }
  1076. // return Result::success($data);
  1077. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1078. ->where('website_id', $data['website_id'])
  1079. ->increment('results', 1);
  1080. if (empty($choice)) {
  1081. return Result::error("请选择已有的选项!", 0);
  1082. }
  1083. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1084. ->where('website_id', $data['website_id'])
  1085. ->where('other_id', 0)
  1086. ->get();
  1087. $survey['choice'] = $choice_id;
  1088. return Result::success($survey);
  1089. }
  1090. return Result::error("参数必填!");
  1091. }
  1092. return Result::error("此调查问卷不存在", 0);
  1093. }
  1094. return Result::error("参数必填!");
  1095. }
  1096. /**
  1097. * 后端-获取网站调查问卷列表
  1098. * @param array $data
  1099. * @return array
  1100. */
  1101. public function getSurveyList(array $data): array
  1102. {
  1103. $where = [];
  1104. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1105. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1106. }
  1107. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  1108. array_push($where, ['survey_type', '=', $data['survey_type']]);
  1109. }
  1110. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  1111. array_push($where, ['is_survey', '=', $data['is_survey']]);
  1112. }
  1113. // return Result::success($where);
  1114. if (!empty($where)) {
  1115. $query = Article::where($where)->where(function ($q) {
  1116. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1117. });
  1118. } else {
  1119. $query = Article::where(function ($q) {
  1120. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1121. });
  1122. }
  1123. $count = $query->count();
  1124. $survey = $query->orderByDesc('id')
  1125. ->limit($data['pageSize'])
  1126. ->offset(($data['page'] - 1) * $data['pageSize'])
  1127. ->get();
  1128. if (empty($survey->toArray())) {
  1129. return Result::error("暂无调查问卷!", 0);
  1130. }
  1131. $result = [
  1132. 'rows' => $survey,
  1133. 'count' => $count,
  1134. ];
  1135. return Result::success($result);
  1136. }
  1137. /**
  1138. * 后端-获取网站调查问卷详情
  1139. * @param array $data
  1140. * @return array
  1141. */
  1142. public function getSurveyInfo(array $data): array
  1143. {
  1144. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1145. $where = ['sur_id' => $data['sur_id']];
  1146. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1147. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1148. ->select('article_survey.*', 'article.survey_type')
  1149. ->get()->all();
  1150. if (empty($choose)) {
  1151. return Result::error("此调查问卷不存在", 0);
  1152. }
  1153. $resultsArray = array_column($choose, 'results');
  1154. $total = array_sum($resultsArray);
  1155. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1156. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1157. // $total = 0;
  1158. if (!empty($other)) {
  1159. $total = $total + $other['results'];
  1160. $other['choice_name'] = '(其他)';
  1161. if (!empty($others)) {
  1162. $other['hasChildren'] = true;
  1163. // array_push($other,['hasChildren','=',true]);
  1164. $other['children'] = $others;
  1165. $other_choices = [$other->toArray()];
  1166. $mer_choice = array_merge($choose, $other_choices);
  1167. $value_choice = array_values($mer_choice);
  1168. } else {
  1169. // return Result::error('1111');
  1170. $other_choices = [$other->toArray()];
  1171. $other_choices = array_merge($choose, $other_choices);
  1172. $value_choice = array_values($other_choices);
  1173. // return Result::success($result);
  1174. }
  1175. } else {
  1176. $value_choice = $choose;
  1177. }
  1178. $result = [
  1179. 'choose' => $value_choice,
  1180. 'total' => $total,
  1181. ];
  1182. }
  1183. return Result::success($result);
  1184. }
  1185. /**
  1186. * 前端-搜索新闻列表
  1187. * @param array $data
  1188. * @return array
  1189. */
  1190. public function selectWebsiteArticle(array $data): array
  1191. {
  1192. $where = [];
  1193. // 初始化查询构造器
  1194. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
  1195. $query = Article::where('status', 1)
  1196. ->whereIn('catid', $category)
  1197. ->where(function ($query) use ($data) {
  1198. $query->where(function ($subQuery) use ($data) {
  1199. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1200. })->orWhereNull("ignore_ids");
  1201. });
  1202. // return Result::success($all_articles);
  1203. // 检查是否存在 cityid 参数
  1204. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1205. $query->whereRaw("JSON_CONTAINS(city_arr_id, '" . intval($data['cityid']) . "')");
  1206. }
  1207. // 检查是否存在 department_id 参数
  1208. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1209. $query->whereRaw("JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "')");
  1210. }
  1211. // 检查是否存在 keyword 参数
  1212. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1213. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  1214. }
  1215. // 计算总数
  1216. $count = $query->count();
  1217. // 分页查询
  1218. $articles = $query
  1219. ->select(
  1220. 'article.id',
  1221. 'article.title',
  1222. 'article.imgurl',
  1223. 'article.author',
  1224. 'article.updated_at',
  1225. 'article.introduce',
  1226. 'article.islink',
  1227. 'article.linkurl',
  1228. 'article.copyfrom',
  1229. 'article.catid',
  1230. 'article.department_arr_id',
  1231. 'article.city_arr_id',
  1232. )
  1233. ->orderBy("updated_at", "desc")
  1234. ->offset(($data['page'] - 1) * $data['pageSize'])
  1235. ->limit($data['pageSize'])
  1236. ->get()
  1237. ->map(function ($article) use ($data) {
  1238. $catid = $article->catid ?? 0;
  1239. $pinyin = '';
  1240. $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
  1241. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  1242. if ($category->pid != 0 && !empty($category->aLIas_pinyin)) {
  1243. $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
  1244. $pinyin = $childCategory->aLIas_pinyin ? $childCategory->aLIas_pinyin . '/' . $category->aLIas_pinyin : null;
  1245. }
  1246. $article->pinyin = $pinyin;
  1247. return $article;
  1248. });
  1249. if (empty($articles)) {
  1250. return Result::error("没有符合条件的资讯数据");
  1251. }
  1252. $data = [
  1253. 'rows' => $articles,
  1254. 'count' => $count,
  1255. ];
  1256. return Result::success($data);
  1257. }
  1258. /**
  1259. * 模块新闻加强版
  1260. * @param array $data
  1261. * @return array
  1262. */
  1263. public function getWebsiteCatidArticle(array $data): array
  1264. {
  1265. // return Result::success($data);
  1266. $where = [
  1267. // 'category.status' => 1,
  1268. 'website_category.category_id' => $data['catid'],
  1269. 'website_category.website_id' => $data['website_id'],
  1270. // 'article.status' => 1,
  1271. ];
  1272. // $category = WebsiteCategory::where($where);
  1273. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  1274. $child_catnum = $data['child_catnum'] ?? 1;
  1275. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  1276. $childCategoryIds = array_column($category['child'], 'category_id');
  1277. if (empty($childCategoryIds)) {
  1278. return Result::error("暂无子栏目", 0);
  1279. }
  1280. $imgArticles = [];
  1281. $textArticles = [];
  1282. // return Result::success($childCategoryIds);
  1283. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  1284. // 初始化子分类图片新闻和文字新闻数组
  1285. // 查询所有子级栏目的图文新闻
  1286. $imgArticles = Article::where('catid', $childCategoryIds[0])
  1287. ->where(function ($query) use ($data) {
  1288. $query->where(function ($subQuery) use ($data) {
  1289. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1290. })->orWhereNull("ignore_ids");
  1291. })
  1292. ->where('status', 1)
  1293. ->where('imgurl', '!=', '')
  1294. ->select('*')
  1295. ->orderBy('updated_at', 'desc')
  1296. ->limit($data['child_imgnum'])
  1297. ->get();
  1298. }
  1299. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  1300. // 查询所有子级栏目的文字新闻
  1301. $textArticles = Article::where('catid', $childCategoryIds[0])
  1302. ->where('status', 1)
  1303. ->where(function ($query) use ($data) {
  1304. $query->where(function ($subQuery) use ($data) {
  1305. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1306. })->orWhereNull("ignore_ids");
  1307. })
  1308. // ->where(function ($query) {
  1309. // $query->whereNull('imgurl')
  1310. // ->orWhere('imgurl', '');
  1311. // })
  1312. ->select('*')
  1313. ->orderBy('updated_at', 'desc')
  1314. ->limit($data['child_textnum'])
  1315. ->get();
  1316. }
  1317. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  1318. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  1319. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  1320. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  1321. return $child;
  1322. }, $category['child']);
  1323. }
  1324. // }
  1325. if (isset($data['img_num']) && !empty($data['img_num'])) {
  1326. $category['img'] = WebsiteCategory::where($where)
  1327. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1328. ->where('article.status', 1)
  1329. ->where('article.imgurl', '!=', '')
  1330. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1331. ->orderBy('article.updated_at', 'desc')
  1332. ->limit($data['img_num'])
  1333. ->get();
  1334. }
  1335. if (isset($data['text_num']) && !empty($data['text_num'])) {
  1336. $category['text'] = WebsiteCategory::where($where)
  1337. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1338. ->where('article.status', 1)
  1339. // ->where(function ($query) {
  1340. // $query->whereNull('article.imgurl')
  1341. // ->orWhere('article.imgurl', '');
  1342. // })
  1343. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1344. ->orderBy('article.updated_at', 'desc')
  1345. ->limit($data['text_num'])
  1346. ->get();
  1347. }
  1348. // $category = $category->get();
  1349. if (empty($category)) {
  1350. return Result::error("查询失败", 0);
  1351. }
  1352. return Result::success($category);
  1353. }
  1354. /**
  1355. * 模块新闻加强plus版
  1356. * @param array $data
  1357. * @return array
  1358. */
  1359. public function getWebsiteAllArticle(array $data): array
  1360. {
  1361. // 修正传入的字符串,将单引号替换为双引号
  1362. $input['id'] = $data['id'];
  1363. $input['website_id'] = $data['website_id'];
  1364. // 将 JSON 字符串转换为 PHP 数组
  1365. $data = json_decode($input['id'], true);
  1366. // 使用 array_map 处理每个元素
  1367. $result = array_map(function ($item) use ($input) {
  1368. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  1369. $website = [
  1370. 'website_id' => $input['website_id'],
  1371. ];
  1372. // 查询栏目名称
  1373. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  1374. if (empty($category)) {
  1375. $imgArticles = [];
  1376. $textArticles = [];
  1377. // return Result::error("暂无此栏目",0);
  1378. } else {
  1379. $parent_alias = $category->alias ?? '';
  1380. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  1381. // 查询图片新闻
  1382. $imgArticles = Article::where('catid', $parentCatId)
  1383. ->where('status', 1)
  1384. ->where(function ($query) use ($website) {
  1385. $query->where(function ($subQuery) use ($website) {
  1386. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1387. })->orWhereNull("ignore_ids");
  1388. })
  1389. ->where('imgurl', '!=', '')
  1390. ->select(
  1391. 'article.id',
  1392. 'article.title',
  1393. 'article.imgurl',
  1394. 'article.author',
  1395. 'article.updated_at',
  1396. 'article.introduce',
  1397. 'article.islink',
  1398. 'article.linkurl',
  1399. 'article.copyfrom',
  1400. DB::raw("'$parent_pinyin' as pinyin") // 添加 pinyin 字段
  1401. )
  1402. ->orderBy('updated_at', 'desc')
  1403. ->limit($parentImgNum)
  1404. ->get()->all();
  1405. // 查询文字新闻
  1406. $textArticles = Article::where('catid', $parentCatId)
  1407. ->where('status', 1)
  1408. ->where(function ($query) use ($website) {
  1409. $query->where(function ($subQuery) use ($website) {
  1410. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1411. })->orWhereNull("ignore_ids");
  1412. })
  1413. ->select(
  1414. 'article.id',
  1415. 'article.title',
  1416. 'article.author',
  1417. 'article.updated_at',
  1418. 'article.introduce',
  1419. 'article.islink',
  1420. 'article.linkurl',
  1421. 'article.copyfrom',
  1422. DB::raw("'$parent_pinyin' as pinyin")
  1423. )
  1424. ->orderBy('updated_at', 'desc')
  1425. ->limit($parentTextNum)
  1426. ->get()->all();
  1427. }
  1428. $resultItem = [
  1429. 'alias' => $parent_alias,
  1430. 'category_id' => $parentCatId,
  1431. 'pinyin' => $parent_pinyin,
  1432. 'imgnum' => $imgArticles,
  1433. 'textnum' => $textArticles,
  1434. ];
  1435. if (!empty($item['child']) && $item['child'] != "") {
  1436. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  1437. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  1438. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  1439. ->get()->all();
  1440. if ($childCategory) {
  1441. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  1442. // 查询子栏目名称
  1443. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  1444. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  1445. ->first();
  1446. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  1447. if (empty($childCategoryInfo)) {
  1448. $childImgArticles = [];
  1449. $childTextArticles = [];
  1450. } else {
  1451. // 查询子栏目图片新闻
  1452. $childImgArticles = Article::where('catid', $childCatId)
  1453. ->where('status', 1)
  1454. ->where(function ($query) use ($website) {
  1455. $query->where(function ($subQuery) use ($website) {
  1456. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1457. })->orWhereNull("ignore_ids");
  1458. })
  1459. ->select(
  1460. 'article.id',
  1461. 'article.title',
  1462. 'article.imgurl',
  1463. 'article.author',
  1464. 'article.updated_at',
  1465. 'article.introduce',
  1466. 'article.islink',
  1467. 'article.linkurl',
  1468. 'article.copyfrom',
  1469. DB::raw("'$child_pinyin' as pinyin")
  1470. )
  1471. ->where('imgurl', '!=', '')
  1472. ->orderBy('updated_at', 'desc')
  1473. ->limit($childImgNum)
  1474. ->get()->all();
  1475. // 查询子栏目文字新闻
  1476. $childTextArticles = Article::where('catid', $childCatId)
  1477. ->where('status', 1)
  1478. ->where(function ($query) use ($website) {
  1479. $query->where(function ($subQuery) use ($website) {
  1480. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1481. })->orWhereNull("ignore_ids");
  1482. })
  1483. ->select(
  1484. 'article.id',
  1485. 'article.title',
  1486. 'article.author',
  1487. 'article.updated_at',
  1488. 'article.introduce',
  1489. 'article.islink',
  1490. 'article.linkurl',
  1491. 'article.copyfrom',
  1492. DB::raw("'$child_pinyin' as pinyin")
  1493. )
  1494. ->orderBy('updated_at', 'desc')
  1495. ->limit($childTextNum)
  1496. ->get()->all();
  1497. }
  1498. $resultItem['child'] = [
  1499. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  1500. 'category_id' => $childCatId,
  1501. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  1502. 'all_childcat' => $childCategory,
  1503. 'imgnum' => $childImgArticles,
  1504. 'textnum' => $childTextArticles,
  1505. ];
  1506. // $resultItem['pinyin'] = $childCategoryInfo->aLIas_pinyin ?? '';
  1507. }
  1508. }
  1509. return $resultItem;
  1510. }, $data);
  1511. return Result::success($result);
  1512. // return Result::success($data);
  1513. }
  1514. /**
  1515. * 乡村网-获取特殊新闻模块
  1516. * @param array $data
  1517. * @return array
  1518. */
  1519. public function getWebsiteArticles(array $data): array
  1520. {
  1521. $input['id'] = $data['id'];
  1522. $input['website_id'] = $data['website_id'];
  1523. $data = json_decode($input['id'], true);
  1524. // 使用 array_map 处理每个元素
  1525. $result = array_map(function ($item) use ($input) {
  1526. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  1527. $website = [
  1528. 'website_id' => $input['website_id']
  1529. ];
  1530. // 查询栏目名称
  1531. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  1532. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  1533. if (empty($category)) {
  1534. $imgArticles = [];
  1535. $textArticles = [];
  1536. // return Result::error("暂无此栏目",0);
  1537. } else {
  1538. $parent_alias = $category->aLIas_pinyin ? $category->aLIas_pinyin . '/' : null;
  1539. // return Result::success($website);
  1540. // 查询图片新闻
  1541. // 合并查询条件
  1542. $baseQuery = Article::where(function ($query) use ($website) {
  1543. $query->where(function ($subQuery) use ($website) {
  1544. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1545. })->orWhereNull("ignore_ids");
  1546. })
  1547. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($parentCatId) . "')")
  1548. ->leftJoin('website_category', 'website_category.category_id', 'article.catid')
  1549. ->where('website_category.website_id', $website['website_id'])
  1550. ->where('article.status', 1);
  1551. // 查询文字新闻
  1552. $textArticles = clone $baseQuery;
  1553. $textArticles = $textArticles
  1554. ->select(
  1555. 'article.id',
  1556. 'article.title',
  1557. // 'article.imgurl',
  1558. 'article.author',
  1559. 'article.updated_at',
  1560. 'article.introduce',
  1561. 'article.islink',
  1562. 'article.linkurl',
  1563. 'article.copyfrom',
  1564. 'website_category.category_id',
  1565. 'website_category.alias',
  1566. 'website_category.aLIas_pinyin'
  1567. )
  1568. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1569. ->orderBy('article.updated_at', 'desc')
  1570. ->limit($parentTextNum)
  1571. ->get()
  1572. ->all();
  1573. // 查询图片新闻
  1574. $imgArticles = clone $baseQuery;
  1575. $imgArticles = $imgArticles
  1576. ->select(
  1577. 'article.id',
  1578. 'article.title',
  1579. 'article.imgurl',
  1580. 'article.author',
  1581. 'article.updated_at',
  1582. 'article.introduce',
  1583. 'article.islink',
  1584. 'article.linkurl',
  1585. 'article.copyfrom',
  1586. 'website_category.category_id',
  1587. 'website_category.alias',
  1588. 'website_category.aLIas_pinyin'
  1589. )
  1590. ->selectRaw("CONCAT(?, aLIas_pinyin ) as aLIas_pinyin", [$parent_alias])
  1591. ->orderBy('article.updated_at', 'desc')
  1592. ->where('imgurl', '!=', '')
  1593. ->limit($parentImgNum)
  1594. ->get()
  1595. ->all();
  1596. }
  1597. $resultItem = [
  1598. 'alias' => $category ? $category->alias : null,
  1599. 'category_id' => $parentCatId,
  1600. 'pinyin' => $pinyin ? $pinyin : null,
  1601. 'imgnum' => $imgArticles ?? [],
  1602. 'textnum' => $textArticles ?? [],
  1603. ];
  1604. return $resultItem;
  1605. }, $data);
  1606. return Result::success($result);
  1607. }
  1608. /**
  1609. *获取头条类新闻模块-合集
  1610. * @param array $data
  1611. * @return array
  1612. */
  1613. public function getWebsiteAllArticlett(array $data): array
  1614. {
  1615. $input['id'] = $data['id'];
  1616. $input['website_id'] = $data['website_id'];
  1617. $data = json_decode($input['id'], true);
  1618. // 使用 array_map 处理每个元素
  1619. $result = array_map(function ($item) use ($input) {
  1620. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  1621. $website = [
  1622. 'website_id' => $input['website_id']
  1623. ];
  1624. $category = WebsiteCategory::where('website_id', $input['website_id'])->pluck('category_id');
  1625. $category = array_values(array_unique($category->toArray()));
  1626. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  1627. $where = [
  1628. 'status' => 1,
  1629. ];
  1630. return $category;
  1631. }, $data); // 添加第二个参数 $data,确保 array_map 函数有两个参数
  1632. return Result::success($result);
  1633. }
  1634. /**
  1635. * 验证导航名称是否重复
  1636. * @return void
  1637. */
  1638. public function checkCategoryName(array $data): array
  1639. {
  1640. $result = Category::when($data, function ($query) use ($data) {
  1641. if (isset($data['name']) && $data['name']) {
  1642. $query->where("name", $data['name']);
  1643. }
  1644. if (isset($data['id']) && $data['id']) {
  1645. $query->where("id", "!=", $data['id']);
  1646. }
  1647. })->first();
  1648. if ($result) {
  1649. return Result::error("已存在");
  1650. } else {
  1651. return Result::success();
  1652. }
  1653. }
  1654. //20250226 产品列表
  1655. public function getGoodList(array $data): array
  1656. {
  1657. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  1658. unset($data['type_id']);
  1659. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  1660. $where = [];
  1661. if ($type_id != '10000') {
  1662. $where = [
  1663. 'good.user_id' => $user_id,
  1664. ];
  1665. }
  1666. //类型
  1667. if (isset($data['type_id']) && $data['type_id']) {
  1668. $where = [
  1669. 'type_id' => $data['type_id'],
  1670. ];
  1671. }
  1672. //名称
  1673. if (isset($data['name']) && $data['name']) {
  1674. $where = [
  1675. 'good.name' => $data['name'],
  1676. ];
  1677. }
  1678. $where1 = [];
  1679. //website_id
  1680. // if (isset($data['website_id']) && $data['website_id']) {
  1681. // $where1 = [
  1682. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  1683. // ];
  1684. // }
  1685. // website_name
  1686. if (isset($data['website_name']) && $data['website_name']) {
  1687. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  1688. }
  1689. // catid
  1690. if (isset($data['category_name']) && $data['category_name']) {
  1691. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  1692. }
  1693. // $result = Good::where($where)
  1694. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  1695. $result = Good::where($where)
  1696. ->when(!empty($where1), function ($query) use ($where1) {
  1697. return $query->where($where1);
  1698. })
  1699. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  1700. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  1701. ->leftJoin('category', 'good.catid', '=', 'category.id')
  1702. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  1703. ->orderBy("id", "desc")
  1704. ->limit($data['page_size'])
  1705. ->offset(($data['page'] - 1) * $data['page_size'])
  1706. ->get();
  1707. $count = Good::where($where)
  1708. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  1709. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  1710. ->leftJoin('category', 'good.catid', '=', 'category.id')
  1711. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  1712. ->orderBy("updated_at", "desc")->count();
  1713. $data = [
  1714. 'rows' => $result->toArray(),
  1715. 'count' => $count,
  1716. ];
  1717. if (empty($result)) {
  1718. return Result::error("此栏目暂无相关产品", 0);
  1719. }
  1720. return Result::success($data);
  1721. }
  1722. public function getGoodInfo(array $data): array
  1723. {
  1724. $result = Good::where('id', $data['id'])->first();
  1725. if (empty($result)) {
  1726. return Result::error("此产品不存在", 0);
  1727. }
  1728. return Result::success($result);
  1729. }
  1730. public function addGood(array $data): array
  1731. {
  1732. // unset($data['city_arr_id']);
  1733. // unset($data['cat_arr_id']);
  1734. $data['city_id'] = end($data['city_arr_id']);
  1735. $data['catid'] = end($data['cat_arr_id']);
  1736. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  1737. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  1738. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  1739. unset($data['imgUrl']);
  1740. $result = Good::insert($data);
  1741. if (empty($result)) {
  1742. return Result::error("添加失败", 0);
  1743. }
  1744. return Result::success($result);
  1745. }
  1746. public function updateGood(array $data): array
  1747. {
  1748. $data['city_id'] = end($data['city_arr_id']);
  1749. $data['catid'] = end($data['cat_arr_id']);
  1750. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  1751. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  1752. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  1753. //设置东八区
  1754. date_default_timezone_set('Asia/Shanghai');
  1755. $data['updated_at'] = date('Y-m-d H:i:s');
  1756. $result = Good::where('id', $data['id'])->update($data);
  1757. if (empty($result)) {
  1758. return Result::error("更新失败", 0);
  1759. }
  1760. return Result::success($result);
  1761. }
  1762. public function delGood(array $data): array
  1763. {
  1764. $result = Good::where('id', $data['id'])->delete();
  1765. if (empty($result)) {
  1766. return Result::error("删除失败", 0);
  1767. }
  1768. return Result::success($result);
  1769. }
  1770. //20250226 产品列表
  1771. //20250306 求职信息
  1772. public function getJobHuntingList(array $data): array
  1773. {
  1774. $where = [];
  1775. if (isset($data['username']) && !empty($data['username'])) {
  1776. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  1777. }
  1778. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  1779. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  1780. unset($data['type_id']);
  1781. if ($type_id != '10000') {
  1782. $where[] = ['job_hunting.user_id', '=', $user_id];
  1783. }
  1784. $result = JobHunting::where($where)
  1785. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  1786. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  1787. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  1788. ->orderBy("id", "desc")
  1789. ->limit($data['page_size'])
  1790. ->offset(($data['page'] - 1) * $data['page_size'])
  1791. ->get();
  1792. if (empty($result)) {
  1793. return Result::error("查询失败", 0);
  1794. }
  1795. $count = JobHunting::where($where)
  1796. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  1797. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  1798. ->count();
  1799. $data = [
  1800. 'rows' => $result->toArray(),
  1801. 'count' => $count,
  1802. ];
  1803. return Result::success($data);
  1804. }
  1805. public function addJobHunting(array $data): array
  1806. {
  1807. date_default_timezone_set('Asia/Shanghai');
  1808. unset($data['company_name']);
  1809. unset($data['job_industry']);
  1810. unset($data['job_name']);
  1811. unset($data['department']);
  1812. unset($data['job_timeList']);
  1813. unset($data['job_content']);
  1814. $data['created_at'] = date('Y-m-d H:i:s');
  1815. $data['updated_at'] = date('Y-m-d H:i:s');
  1816. var_dump($data, '-----------------test---------');
  1817. $result = JobHunting::create($data);
  1818. if (empty($result)) {
  1819. return Result::error("添加失败", 0);
  1820. }
  1821. return Result::success($result);
  1822. }
  1823. public function delJobHunting(array $data): array
  1824. {
  1825. $result = JobHunting::where('id', $data['id'])->delete();
  1826. if (empty($result)) {
  1827. return Result::error("删除失败", 0);
  1828. }
  1829. return Result::success($result);
  1830. }
  1831. public function updateJobHunting(array $data): array
  1832. {
  1833. //设置东八区
  1834. date_default_timezone_set('Asia/Shanghai');
  1835. unset($data['company_name']);
  1836. unset($data['job_industry']);
  1837. unset($data['job_name']);
  1838. unset($data['department']);
  1839. unset($data['job_timeList']);
  1840. unset($data['job_content']);
  1841. $data['created_at'] = date('Y-m-d H:i:s');
  1842. $data['updated_at'] = date('Y-m-d H:i:s');
  1843. $result = JobHunting::where('id', $data['id'])->update($data);
  1844. if (empty($result)) {
  1845. return Result::error("更新失败", 0);
  1846. }
  1847. return Result::success($result);
  1848. }
  1849. public function getJobHuntingInfo(array $data): array
  1850. {
  1851. $result = JobHunting::where('id', $data['id'])->first();
  1852. if (empty($result)) {
  1853. return Result::error("查询失败", 0);
  1854. }
  1855. return Result::success($result);
  1856. }
  1857. public function getJobHuntingData(array $data): array
  1858. {
  1859. $jobEnum = JobEnum::get();
  1860. $jobIndustry = JobIndustry::get();
  1861. $jobNature = JobNature::get();
  1862. $jobPosition = JobPosition::get();
  1863. $data = [
  1864. 'jobEnum' => $jobEnum,
  1865. 'jobIndustry' => $jobIndustry,
  1866. 'jobNature' => $jobNature,
  1867. 'jobPosition' => $jobPosition,
  1868. ];
  1869. return Result::success($data);
  1870. }
  1871. public function delJobHuntingInfo(array $data): array
  1872. {
  1873. $result = JobHunting::where('id', $data['id'])->delete();
  1874. return Result::success();
  1875. }
  1876. //20250324 通知,公告,消息
  1877. public function delNotice(array $data): array
  1878. {
  1879. return Result::success();
  1880. }
  1881. public function getNoticeInfo(array $data): array
  1882. {
  1883. $result = Notice::where('id', $data['id'])->first();
  1884. if (empty($result)) {
  1885. return Result::error("查询失败", 0);
  1886. }
  1887. return Result::success($result);
  1888. }
  1889. public function addNotice(array $data): array
  1890. {
  1891. date_default_timezone_set('Asia/Shanghai');
  1892. $data['created_at'] = date('Y-m-d H:i:s');
  1893. $data['updated_at'] = date('Y-m-d H:i:s');
  1894. $user_id = UserInfo::
  1895. //city_id不是null
  1896. whereNotNull('city_id')
  1897. ->whereNotNull('department_id')
  1898. ->where(function ($query) use ($data) {
  1899. $query->where(function ($subQuery) use ($data) {
  1900. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  1901. });
  1902. })
  1903. ->where(function ($query) use ($data) {
  1904. $query->where(function ($subQuery) use ($data) {
  1905. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  1906. });
  1907. })
  1908. ->pluck('user_id')->toArray();
  1909. $user_id = array_unique($user_id);
  1910. $chat_ids = $user_id;
  1911. $user_id = json_encode($user_id);
  1912. $data['re_user_ids'] = $user_id;
  1913. $result = Notice::insertGetId($data);
  1914. if ($result && $data['is_group'] == 1) {
  1915. //chat_group
  1916. $group_id = PublicData::uuid();
  1917. $groupData = [
  1918. 'id' => $group_id,
  1919. 'creator_id' => $data['user_id'],
  1920. 'group_name' => $data['group_name'] ?? '',
  1921. 'profile' => $data['profile'] ?? 0,
  1922. ];
  1923. $groupResult = ChatGroups::insertGetId($groupData);
  1924. var_dump($groupResult, '-----------------groupid-------');
  1925. $groupMemberData = [
  1926. 'id' => PublicData::uuid(),
  1927. 'user_id' => $data['user_id'],
  1928. 'group_id' => $group_id,
  1929. 'leader' => 2,
  1930. ];
  1931. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  1932. //$chat_ids 去除掉$data['user_id']
  1933. $chat_ids = array_diff($chat_ids, [$data['user_id']]);
  1934. //插入群成员表
  1935. $groupMemberDataUser = [];
  1936. foreach ($chat_ids as $key => $value) {
  1937. $groupMemberDataUser[] = [
  1938. 'id' => PublicData::uuid(),
  1939. 'user_id' => $value,
  1940. 'group_id' => $group_id,
  1941. 'leader' => 1,
  1942. ];
  1943. }
  1944. ChatGroupsMember::insert($groupMemberDataUser);
  1945. //更新result的 group_id
  1946. $data['group_id'] = $group_id;
  1947. Notice::where(['id' => $result])->update($data);
  1948. }
  1949. if (empty($result)) {
  1950. return Result::error("添加失败", 0);
  1951. }
  1952. return Result::success($result);
  1953. }
  1954. public function updateNotice(array $data): array
  1955. {
  1956. date_default_timezone_set('Asia/Shanghai');
  1957. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  1958. $user_id = UserInfo::
  1959. //city_id不是null
  1960. whereNotNull('city_id')
  1961. ->whereNotNull('department_id')
  1962. ->where(function ($query) use ($data) {
  1963. $query->where(function ($subQuery) use ($data) {
  1964. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  1965. });
  1966. })
  1967. ->where(function ($query) use ($data) {
  1968. $query->where(function ($subQuery) use ($data) {
  1969. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  1970. });
  1971. })
  1972. ->pluck('user_id')->toArray();
  1973. $user_id = array_unique($user_id);
  1974. $user_id = json_encode($user_id);
  1975. $data['re_user_ids'] = $user_id;
  1976. $data['updated_at'] = date('Y-m-d H:i:s');
  1977. $result = Notice::where('id', $data['id'])->update($data);
  1978. return Result::success($result);
  1979. }
  1980. public function getNoticeList(array $data): array
  1981. {
  1982. $where = [];
  1983. //title
  1984. if (isset($data['title']) && !empty($data['title'])) {
  1985. $where[] = ['title', 'like', '%' . $data['title'] . '%'];
  1986. }
  1987. //level
  1988. if (isset($data['level']) && !empty($data['level'])) {
  1989. $where[] = ['level', '=', $data['level']];
  1990. }
  1991. var_dump($data['type_id'], '-----------------test---------');
  1992. if ($data['type_id'] == 10000) {
  1993. $result = Notice::where('status', 1)
  1994. ->where($where)
  1995. ->orderBy('updated_at', 'desc')
  1996. ->limit($data['page_size'])
  1997. ->offset(($data['page'] - 1) * $data['page_size'])
  1998. ->get();
  1999. } else {
  2000. $result = Notice::where('status', 1)
  2001. ->where($where)
  2002. ->where('user_id', $data['user_id'])
  2003. ->orWhere(function ($query) use ($data) {
  2004. $query->where('re_user_ids', 'like', '%' . $data['user_id'] . '%');
  2005. })
  2006. ->orderBy('updated_at', 'desc')
  2007. ->limit($data['page_size'])
  2008. ->offset(($data['page'] - 1) * $data['page_size'])
  2009. ->get();
  2010. }
  2011. if (empty($result)) {
  2012. return Result::error("查询失败", 0);
  2013. }
  2014. $count = Notice::where('status', 1)->count();
  2015. $data = [
  2016. 'rows' => $result,
  2017. 'count' => $count,
  2018. ];
  2019. return Result::success($data);
  2020. }
  2021. public function getNoticeDetail(array $data): array
  2022. {
  2023. $result = Notice::where('id', $data['id'])->first();
  2024. if (empty($result)) {
  2025. return Result::error("查询失败", 0);
  2026. }
  2027. return Result::success($result);
  2028. }
  2029. public function deleteNotice(array $data): array
  2030. {
  2031. $notice = Notice::where('id', $data['id'])->first();
  2032. if (empty($notice)) {
  2033. return Result::error("删除失败", 0);
  2034. }
  2035. $chat_group_id = $notice->group_id;
  2036. if ($chat_group_id) {
  2037. //删除群聊
  2038. ChatGroups::where('id', $chat_group_id)->delete();
  2039. //删除群成员
  2040. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  2041. //删除群聊记录
  2042. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  2043. }
  2044. $result = Notice::where('id', $data['id'])->delete();
  2045. return Result::success($result);
  2046. }
  2047. public function getMSG(array $data): array
  2048. {
  2049. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  2050. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  2051. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  2052. $result = [];
  2053. if ($type_id == 1) {
  2054. //最近的5篇已审的文章
  2055. $apply_articale = Article::where('status', 1)
  2056. ->where('admin_user_id', $user_id)
  2057. ->orderBy('updated_at', 'desc')
  2058. ->limit(5)->get();
  2059. //获取5条单聊未读聊天消息
  2060. $chat = ChatRecords::where('is_read', 0)
  2061. ->where('user_id', $user_id)
  2062. ->where('talk_type', 1)
  2063. ->orderBy('created_at', 'desc')
  2064. ->limit(5)->get();
  2065. //获取5条未读群聊信息
  2066. $chat_group = ChatRecords::where('is_read', 0)
  2067. ->where('user_id', $user_id)
  2068. ->where('talk_type', 2)
  2069. ->orderBy('created_at', 'desc')
  2070. ->limit(5)->get();
  2071. $count = count($chat) + count($chat_group) + count($apply_articale);
  2072. $result = [
  2073. 'apply_articale' => $apply_articale,
  2074. 'chat' => $chat,
  2075. 'chat_group' => $chat_group,
  2076. 'count' => $count,
  2077. ];
  2078. } elseif ($type_id == 2) {
  2079. //最近的5篇已审的文章
  2080. $apply_articale = Article::where('status', 1)
  2081. ->where('admin_user_id', $user_id)
  2082. ->limit(5)->get();
  2083. //获取5条单聊未读聊天消息
  2084. $chat = ChatRecords::where('is_read', 0)
  2085. ->where('user_id', $user_id)
  2086. ->where('talk_type', 1)
  2087. ->orderBy('created_at', 'desc')
  2088. ->limit(5)->get();
  2089. //获取5条未读群聊信息
  2090. $chat_group = ChatRecords::where('is_read', 0)
  2091. ->where('user_id', $user_id)
  2092. ->where('talk_type', 2)
  2093. ->orderBy('created_at', 'desc')
  2094. ->limit(5)->get();
  2095. $count = count($chat) + count($chat_group) + count($apply_articale);
  2096. $result = [
  2097. 'apply_articale' => $apply_articale,
  2098. 'chat' => $chat,
  2099. 'chat_group' => $chat_group,
  2100. 'count' => $count,
  2101. ];
  2102. } elseif ($type_id == 3) {
  2103. //最近的5篇已审的文章
  2104. $apply_articale = Article::where('status', 1)
  2105. ->where('admin_user_id', $user_id)
  2106. ->limit(5)->get();
  2107. //获取5条单聊未读聊天消息
  2108. $chat = ChatRecords::where('is_read', 0)
  2109. ->where('user_id', $user_id)
  2110. ->where('talk_type', 1)
  2111. ->orderBy('created_at', 'desc')
  2112. ->limit(5)->get();
  2113. //获取5条未读群聊信息
  2114. $chat_group = ChatRecords::where('is_read', 0)
  2115. ->where('user_id', $user_id)
  2116. ->where('talk_type', 2)
  2117. ->orderBy('created_at', 'desc')
  2118. ->limit(5)->get();
  2119. $count = count($chat) + count($chat_group) + count($apply_articale);
  2120. $result = [
  2121. 'apply_articale' => $apply_articale,
  2122. 'chat' => $chat,
  2123. 'chat_group' => $chat_group,
  2124. 'count' => $count,
  2125. ];
  2126. } elseif ($type_id == 4) {
  2127. //最近的5篇已审的文章
  2128. $apply_articale = Article::where('status', 1)
  2129. ->where('admin_user_id', $user_id)
  2130. ->limit(5)->get();
  2131. $count = count($apply_articale);
  2132. $result = [
  2133. 'apply_articale' => $apply_articale,
  2134. 'count' => $count,
  2135. ];
  2136. } elseif ($type_id == 10000) {
  2137. //获取未审核的5篇文章
  2138. $apply_articale = Article::where('status', 0)
  2139. ->orderBy('updated_at', 'desc')
  2140. ->limit(5)->get();
  2141. //获取5条单聊未读聊天消息
  2142. $chat = ChatRecords::where('is_read', 0)
  2143. ->where('user_id', $user_id)
  2144. ->where('talk_type', 1)
  2145. ->orderBy('created_at', 'desc')
  2146. ->limit(5)->get();
  2147. //获取5条未读群聊信息
  2148. $chat_group = ChatRecords::where('is_read', 0)
  2149. ->where('user_id', $user_id)
  2150. ->where('talk_type', 2)
  2151. ->orderBy('created_at', 'desc')
  2152. ->limit(5)->get();
  2153. $count = count($chat) + count($chat_group) + count($apply_articale);
  2154. $result = [
  2155. 'apply_articale' => $apply_articale,
  2156. 'chat' => $chat,
  2157. 'chat_group' => $chat_group,
  2158. 'count' => $count,
  2159. ];
  2160. } elseif ($type_id == 20000) {
  2161. }
  2162. var_dump($type_id, '-----------------test---------');
  2163. return Result::success($result);
  2164. }
  2165. public function getComplaintList(array $data): array
  2166. {
  2167. $result = Notice::where('status', 1)->get();
  2168. return Result::success($result);
  2169. }
  2170. public function getComplaintInfo(array $data): array
  2171. {
  2172. $result = Notice::where('id', $data['id'])->first();
  2173. if (empty($result)) {
  2174. return Result::error("查询失败", 0);
  2175. }
  2176. return Result::success($result);
  2177. }
  2178. public function addComplaint(array $data): array
  2179. {
  2180. $result = Notice::create($data);
  2181. return Result::success($result);
  2182. }
  2183. public function updateComplaint(array $data): array
  2184. {
  2185. $result = Notice::where('id', $data['id'])->update($data);
  2186. return Result::success($result);
  2187. }
  2188. public function deleteComplaint(array $data): array
  2189. {
  2190. $result = Notice::where('id', $data['id'])->delete();
  2191. return Result::success($result);
  2192. }
  2193. public function getComplainInfo(array $data): array
  2194. {
  2195. $result = Notice::where('id', $data['id'])->first();
  2196. if (empty($result)) {
  2197. return Result::error("查询失败", 0);
  2198. }
  2199. return Result::success($result);
  2200. }
  2201. //20250324 通知,公告,消息
  2202. // 20250306 -------招聘--------fr
  2203. /*
  2204. * 招聘列表
  2205. * */
  2206. public function getJobRecruitingList(array $data): array
  2207. {
  2208. $where = [];
  2209. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2210. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  2211. }
  2212. $user = User::where('id', $data['user_id'])->first();
  2213. if (empty($user)) {
  2214. return Result::error("用户不存在", 0);
  2215. }
  2216. // 3:企业会员
  2217. if ($user['type_id'] == 3) {
  2218. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  2219. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  2220. }
  2221. // 如果 $where 为空,则不添加 where 条件
  2222. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  2223. return $query->where($where);
  2224. })
  2225. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  2226. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  2227. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  2228. ->orderBy("updated_at", "desc")
  2229. ->offset(($data['page'] - 1) * $data['page_size'])
  2230. ->limit($data['page_size'])
  2231. ->get()
  2232. ->all();
  2233. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  2234. return $query->where($where);
  2235. })
  2236. ->count();
  2237. if (empty($result)) {
  2238. return Result::error("暂无招聘信息", 0);
  2239. }
  2240. return Result::success($result);
  2241. }
  2242. /*
  2243. * 招聘信息添加
  2244. * */
  2245. public function addJobRecruiting(array $data): array
  2246. {
  2247. // return Result::success($data);
  2248. $user = User::where('user.id', $data['user_id'])
  2249. ->where('user.status',1)
  2250. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  2251. ->select(
  2252. 'user.type_id', 'user.mobile','user.email',
  2253. 'user_info.business_name',
  2254. 'user_info.company_hy_id',
  2255. 'user_info.company_nature',
  2256. 'user_info.company_size',
  2257. 'user_info.introduction',
  2258. 'user_info.real_name',
  2259. 'user_info.company_url',
  2260. 'user_info.address_arr_id',
  2261. 'user_info.address'
  2262. )
  2263. ->first();
  2264. if(empty($user) || $user['type_id'] != $data['user_type']){
  2265. return Result::error("用户不存在", 0);
  2266. }
  2267. $web = Website::where('id', $data['website_id'])->first();
  2268. if (empty($web)) {
  2269. return Result::error("网站不存在", 0);
  2270. }
  2271. // return Result::success($user);
  2272. $data['action_id'] = $data['user_id'];
  2273. $data['user_type'] = $user['type_id'];
  2274. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  2275. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  2276. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  2277. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  2278. // 公司地址 管理员必填
  2279. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  2280. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  2281. // 管理员-企业相关信息
  2282. $company = [
  2283. // 'user_id' => $data['user_id']?? null,
  2284. 'business_name' => $data['business_name'] ?? null,
  2285. 'company_hy_id' => $data['company_hy_id'] ?? null,
  2286. 'company_size' => $data['company_size'] ?? null,
  2287. 'company_nature' => $data['company_nature'] ?? null,
  2288. 'introduction' => $data['introduction'] ?? null,
  2289. 'real_name' => $data['real_name'] ?? null,
  2290. 'mobile' => $data['mobile'] ?? null,
  2291. 'company_url' => $data['company_url'] ?? null,
  2292. 'address_arr_id' => $data['address_arr_id'] ?? null,
  2293. 'address' => $data['address'] ?? null,
  2294. 'email' => $data['email'] ?? null,
  2295. ];
  2296. //去掉相关企业信息
  2297. $job = array_diff_key($data, array_flip(array_keys($company)));
  2298. Db::beginTransaction();
  2299. try {
  2300. // 先添加职位相关信息
  2301. $jobId = JobRecruiting::insertGetId($job);
  2302. if (empty($jobId)) {
  2303. Db::rollBack();
  2304. return Result::error("添加失败");
  2305. }
  2306. // 添加公司信息
  2307. $company['user_id'] = $data['user_id'] ?? null;
  2308. $company['job_id'] = $jobId;
  2309. $company['user_type'] = $user['type_id'] ?? null;
  2310. $company['website_id'] = $data['website_id'] ?? null;
  2311. if ($user['type_id'] == 10000) {
  2312. // 管理员添加企业信息
  2313. // return Result::success($company);
  2314. $companyId = JobCompany::insertGetId($company);
  2315. if (empty($companyId)) {
  2316. Db::rollBack();
  2317. return Result::error("添加失败");
  2318. }
  2319. } else {
  2320. // 企业会员添加企业信息
  2321. $company = [
  2322. 'user_id' => $data['user_id']?? null,
  2323. 'business_name' => $user['business_name']?? null,
  2324. 'company_hy_id' => $user['company_hy_id']?? null,
  2325. 'company_size' => $user['company_size']?? null,
  2326. 'company_nature' => $user['company_nature']?? null,
  2327. 'introduction' => $user['introduction']?? null,
  2328. 'real_name' => $user['real_name']?? null,
  2329. 'mobile' => $user['mobile']?? null,
  2330. 'company_url' => $user['company_url']?? null,
  2331. 'address_arr_id' => $user['address_arr_id']?? null,
  2332. 'address' => $user['address']?? null,
  2333. 'email' => $user['email']?? null,
  2334. 'website_id' => $data['website_id']?? null,
  2335. 'user_type' => $user['type_id']?? null,
  2336. 'job_id' => $jobId,
  2337. ];
  2338. $companyId = JobCompany::insertGetId($company);
  2339. if (empty($companyId)) {
  2340. Db::rollBack();
  2341. return Result::error("添加失败");
  2342. }
  2343. // return Result::success($company);
  2344. }
  2345. Db::commit();
  2346. } catch (\Exception $e) {
  2347. Db::rollBack();
  2348. return Result::error($e->getMessage(), 0);
  2349. }
  2350. $result = [
  2351. 'job_id' => $jobId,
  2352. 'company_id' => $companyId,
  2353. ];
  2354. if (empty($result)) {
  2355. return Result::error("添加失败", 0);
  2356. }
  2357. return Result::success($result);
  2358. }
  2359. /*
  2360. * 获取招聘信息详情
  2361. * */
  2362. public function getJobRecruitingInfo(array $data): array
  2363. {
  2364. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  2365. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  2366. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2367. ->select(
  2368. 'job_recruiting.*',
  2369. 'website.website_name as website_name',
  2370. 'job_company.business_name',
  2371. 'job_company.company_hy_id',
  2372. 'job_company.company_size',
  2373. 'job_company.company_nature',
  2374. 'job_company.introduction',
  2375. 'job_company.real_name',
  2376. 'job_company.mobile',
  2377. 'job_company.company_url',
  2378. 'job_company.address_arr_id',
  2379. 'job_company.address',
  2380. 'job_company.email'
  2381. )
  2382. ->first();
  2383. if (empty($result)) {
  2384. return Result::error("招聘信息不存在", 0);
  2385. }
  2386. // return Result::success($job);
  2387. return Result::success($result);
  2388. }
  2389. /*
  2390. * 修改招聘信息
  2391. * */
  2392. public function upJobRecruiting(array $data): array
  2393. {
  2394. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  2395. // return Result::success($job);
  2396. if (empty($job)) {
  2397. return Result::error("招聘信息不存在", 0);
  2398. }
  2399. $user = User::where('id', $data['user_id'])->first();
  2400. // return Result::success($user);
  2401. if (empty($user) || $user['type_id'] != $data['user_type']) {
  2402. return Result::error("用户不存在", 0);
  2403. }
  2404. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  2405. return Result::error("用户暂无权限修改此招聘信息!", 0);
  2406. }
  2407. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  2408. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  2409. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  2410. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  2411. // 公司地址 管理员必填
  2412. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  2413. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  2414. // 管理员-企业相关信息
  2415. $company = [
  2416. 'business_name' => $data['business_name'] ?? null,
  2417. 'company_hy_id' => $data['hy_id'] ?? null,
  2418. 'company_size' => $data['company_size'] ?? null,
  2419. 'company_nature' => $data['company_nature'] ?? null,
  2420. 'introduction' => $data['introduction'] ?? null,
  2421. 'real_name' => $data['real_name'] ?? null,
  2422. 'mobile' => $data['mobile'] ?? null,
  2423. 'company_url' => $data['company_url'] ?? null,
  2424. 'address_arr_id' => $data['address_arr_id'] ?? null,
  2425. 'address' => $data['address'] ?? null,
  2426. 'email' => $data['email'] ?? null,
  2427. ];
  2428. //去掉相关企业信息
  2429. $data = array_diff_key($data, array_flip(array_keys($company)));
  2430. $jobId = $data['id'];
  2431. $web = $data['website_id'];
  2432. $data['action_id'] = $data['user_id'];
  2433. unset($data['user_id']);
  2434. unset($data['user_type']);
  2435. unset($data['id']);
  2436. unset($data['website_id']);
  2437. // return Result::success($data);
  2438. Db::beginTransaction();
  2439. try {
  2440. // 管理员修改招聘信息
  2441. if ($user['type_id'] == 10000) {
  2442. $data['website_id'] = $web;
  2443. $company['website_id'] = $data['website_id'];
  2444. }
  2445. // Db::rollBack();
  2446. // return Result::success($company);
  2447. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  2448. if (empty($result['job'])) {
  2449. Db::rollBack();
  2450. return Result::error("修改招聘信息失败");
  2451. }
  2452. // 管理员修改企业相关信息
  2453. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  2454. if (empty($result['company'])) {
  2455. Db::rollBack();
  2456. return Result::error("修改企业相关信息失败");
  2457. }
  2458. Db::commit();
  2459. // return Result::success($result);
  2460. } catch (\Exception $e) {
  2461. Db::rollBack();
  2462. return Result::error($e->getMessage(), 0);
  2463. }
  2464. return Result::success($result);
  2465. }
  2466. /*
  2467. * 招聘信息删除
  2468. * */
  2469. public function delJobRecruiting(array $data): array
  2470. {
  2471. $user = User::where('id', $data['user_id'])->first();
  2472. if (empty($user)) {
  2473. return Result::error("用户不存在", 0);
  2474. }
  2475. $job = JobRecruiting::where('id', $data['id'])->first();
  2476. if (empty($job)) {
  2477. return Result::error("招聘信息不存在", 0);
  2478. }
  2479. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  2480. return Result::error("用户暂无权限修改此招聘信息!", 0);
  2481. }
  2482. Db::beginTransaction();
  2483. try {
  2484. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  2485. if (empty($result['job'])) {
  2486. Db::rollBack();
  2487. return Result::error("删除招聘信息失败");
  2488. }
  2489. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  2490. if (empty($result['company'])) {
  2491. Db::rollBack();
  2492. return Result::error("删除企业相关信息失败");
  2493. }
  2494. Db::commit();
  2495. } catch (\Exception $e) {
  2496. Db::rollBack();
  2497. return Result::error($e->getMessage(), 0);
  2498. }
  2499. return Result::success($result);
  2500. }
  2501. /*
  2502. * 获取公司信息
  2503. * */
  2504. public function getJobCompany(array $data): array
  2505. {
  2506. $user = User::where('user.id', $data['user_id'])
  2507. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  2508. ->select('user.user_name','user.mobile','user.email','user.type_id','user_info.*')
  2509. ->first();
  2510. // return Result::success($user);
  2511. if (empty($user)) {
  2512. return Result::error("用户不存在", 0);
  2513. }
  2514. if ($user['type_id'] == 3) {
  2515. $result = [
  2516. // 'id' => 0,
  2517. 'user_id' => $data['user_id'],
  2518. 'website_id' => $data['website_id'],
  2519. 'business_name' => $user['business_name'], // 企业名称
  2520. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  2521. 'company_nature' => $user['company_nature'], // 公司性质
  2522. 'company_size' => $user['company_size'], // 公司规模
  2523. 'introduction' => $user['introduction'], // 公司简介
  2524. 'real_name' => $user['real_name'], // 企业联系人
  2525. 'mobile' => $user['mobile'], // 企业联系电话
  2526. 'company_url' => $user['company_url'], // 企业网址
  2527. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  2528. 'address' => $user['address'], // 企业地址
  2529. 'email' => $user['email'], // 企业邮箱
  2530. ];
  2531. } else {
  2532. return Result::error("用户类型错误", 0);
  2533. }
  2534. if (empty($result)) {
  2535. return Result::error("公司信息不存在", 0);
  2536. }
  2537. return Result::success($result);
  2538. }
  2539. /*
  2540. * 修改公司信息
  2541. * */
  2542. public function upJobCompany(array $data): array
  2543. {
  2544. // return Result::success($data);
  2545. $user = User::where('user.id', $data['user_id'])
  2546. ->where('user.status',1)
  2547. ->select('user.user_name','user.type_id')
  2548. ->first();
  2549. if(empty($user)){
  2550. return Result::error("用户不存在", 0);
  2551. }
  2552. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  2553. $company = [
  2554. 'business_name' => $data['business_name'], // 企业名称
  2555. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  2556. 'company_nature' => $data['company_nature'], // 公司性质
  2557. 'company_size' => $data['company_size'], // 公司规模
  2558. 'introduction' => $data['introduction'], // 公司简介
  2559. // 'real_name' => $data['real_name'], // 企业联系人
  2560. 'company_url' => $data['company_url'], // 企业网址
  2561. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  2562. 'address' => $data['address'], // 企业详细地址
  2563. ];
  2564. if($user['type_id'] == 3){
  2565. Db::beginTransaction();
  2566. try {
  2567. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  2568. 'business_name' => $data['business_name'], // 企业名称
  2569. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  2570. 'company_nature' => $data['company_nature'], // 公司性质
  2571. 'company_size' => $data['company_size'], // 公司规模
  2572. 'introduction' => $data['introduction'], // 公司简介
  2573. // 'real_name' => $data['real_name'], // 企业联系人
  2574. 'company_url' => $data['company_url'], // 企业网址
  2575. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  2576. 'address' => $data['address'], // 企业详细地址
  2577. ]);
  2578. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  2579. Db::commit();
  2580. } catch (\Exception $e) {
  2581. Db::rollBack();
  2582. return Result::error($e->getMessage(), 0);
  2583. }
  2584. }else{
  2585. return Result::error("用户类型错误", 0);
  2586. }
  2587. if (empty($result)) {
  2588. return Result::error("修改失败", 0);
  2589. }
  2590. return Result::success($result);
  2591. }
  2592. /*
  2593. * 获取省-市
  2594. * */
  2595. public function getJobRecruitingArea(array $data): array
  2596. {
  2597. if (isset($data['province_id']) && $data['province_id'] != null) {
  2598. $result = District::where('pid', $data['pid'])->get()->all();
  2599. } else {
  2600. $result = District::where('level', 1)->get()->all();
  2601. }
  2602. if (empty($result)) {
  2603. return Result::error("暂无此省市", 0);
  2604. }
  2605. return Result::success($result);
  2606. }
  2607. /*
  2608. * 获取行业分类
  2609. * */
  2610. public function getIndustry(array $data): array
  2611. {
  2612. $result = JobIndustry::get()->all();
  2613. if (empty($result)) {
  2614. return Result::error("暂无行业分类", 0);
  2615. }
  2616. return Result::success($result);
  2617. }
  2618. /*
  2619. * 获取职位
  2620. * */
  2621. public function getPositionList(array $data): array
  2622. {
  2623. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  2624. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  2625. } else {
  2626. $result = JobPosition::where('zwpid', 0)->get()->all();
  2627. }
  2628. if (empty($result)) {
  2629. return Result::error("暂无此职位", 0);
  2630. }
  2631. return Result::success($result);
  2632. }
  2633. /*
  2634. * 获取工作性质-菜单
  2635. * */
  2636. public function getJobNature(array $data): array
  2637. {
  2638. $result = JobEnum::where('egroup', 'nature')->get()->all();
  2639. if (empty($result)) {
  2640. return Result::error("暂无工作性质", 0);
  2641. }
  2642. return Result::success($result);
  2643. }
  2644. /*
  2645. * 获取工作经验-菜单
  2646. * */
  2647. public function getExperience(array $data): array
  2648. {
  2649. $result = JobEnum::where('egroup', 'years')->get()->all();
  2650. if (empty($result)) {
  2651. return Result::error("暂无工作经验", 0);
  2652. }
  2653. return Result::success($result);
  2654. }
  2655. /*
  2656. * 获取学历-菜单
  2657. * */
  2658. public function getEducation(array $data): array
  2659. {
  2660. $result = JobEnum::where('egroup', 'education')->get()->all();
  2661. if (empty($result)) {
  2662. return Result::error("暂无学历", 0);
  2663. }
  2664. return Result::success($result);
  2665. }
  2666. /*
  2667. * 获取薪资-菜单
  2668. * */
  2669. public function getSalary(array $data): array
  2670. {
  2671. $result = JobEnum::where('egroup', 'income')->get()->all();
  2672. if (empty($result)) {
  2673. return Result::error("暂无薪资", 0);
  2674. }
  2675. return Result::success($result);
  2676. }
  2677. /*
  2678. * 获取语言-菜单
  2679. * */
  2680. public function getLanguage(array $data): array
  2681. {
  2682. $result = JobEnum::where('egroup', 'language')->get()->all();
  2683. if (empty($result)) {
  2684. return Result::error("暂无语言", 0);
  2685. }
  2686. return Result::success($result);
  2687. }
  2688. /*
  2689. * 获取掌握程度-菜单
  2690. * */
  2691. public function getLevel(array $data): array
  2692. {
  2693. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  2694. if (empty($result)) {
  2695. return Result::error("暂无工作性质", 0);
  2696. }
  2697. return Result::success($result);
  2698. }
  2699. // 公司信息
  2700. /*
  2701. * 获取公司性质-菜单
  2702. * */
  2703. public function getCompanyNature(array $data): array
  2704. {
  2705. $result = JobNature::get()->all();
  2706. if (empty($result)) {
  2707. return Result::error("暂无公司性质", 0);
  2708. }
  2709. return Result::success($result);
  2710. }
  2711. /*
  2712. * 获取公司规模-菜单
  2713. * */
  2714. public function getCompanySize(array $data): array
  2715. {
  2716. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  2717. if (empty($result)) {
  2718. return Result::error("暂无公司规模", 0);
  2719. }
  2720. return Result::success($result);
  2721. }
  2722. // 20250306 招聘
  2723. }