NewsService.php 115 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798
  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. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
  655. $category = array_values(array_unique($category->toArray()));
  656. $result = [];
  657. if ($category) {
  658. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  659. $where = [
  660. 'status' => 1,
  661. ];
  662. var_dump($data, 'data-----------------');
  663. // level=7 根据文章key来匹配文章
  664. if (isset($data['level']) && $data['level'] == 7) {
  665. // 根据文章id获取key
  666. // $data['id'] = 50142;
  667. if (isset($data['id']) && !empty($data['id'])) {
  668. $keyword = Article::where('id', $data['id'])->value('keyword');
  669. $keywordArray = explode(',', $keyword);
  670. $whereL7 = [];
  671. foreach ($keywordArray as $k => $v) {
  672. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  673. }
  674. // 原始查询
  675. $result = Article::where($whereL7)
  676. ->offset($placeid)
  677. ->limit($data['pageSize'])
  678. ->orderBy('updated_at', 'desc')
  679. ->get()
  680. ->map(function ($article) use ($data) {
  681. $catid = $article->catid;
  682. $pinyin = '';
  683. $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
  684. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  685. if ($category->pid != 0 && !empty($category->aLIas_pinyin)) {
  686. $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
  687. $pinyin = $childCategory->aLIas_pinyin ? $childCategory->aLIas_pinyin . '/' . $category->aLIas_pinyin : null;
  688. }
  689. $article->pinyin = $pinyin;
  690. return $article;
  691. });
  692. if (empty($result)) {
  693. return Result::success([]);
  694. }
  695. return Result::success($result);
  696. } else {
  697. return Result::error("参数错误level=7,id不能为空", 0);
  698. }
  699. }
  700. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  701. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  702. var_dump($where, 'where-----------------');
  703. $result = Article::where($where)
  704. ->whereIn("catid", $category)
  705. // ->leftJoin('website_category', 'article.catid', 'website_category.category_id')
  706. // ->where('website_category.website_id', $data['website_id'])
  707. ->where(function ($query) use ($data) {
  708. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  709. ->orWhereNull("ignore_ids");
  710. })
  711. //$data['level'] == 4 || $data['level'] == 5 查询随机
  712. ->when($data['level'] == 5, function ($query) {
  713. $query->inRandomOrder()
  714. //updated_at最近三十天;
  715. ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  716. })
  717. ->when($data['level'] == 4, function ($query) {
  718. $query->orderBy("article.updated_at", "desc");
  719. })
  720. ->when(!empty($data['level']), function ($query) use ($data) {
  721. if ($data['level'] != 4 && $data['level'] != 5) {
  722. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  723. ->orderBy("article.updated_at", "desc");
  724. }
  725. })
  726. ->select('article.*')
  727. ->offset($placeid)
  728. ->limit($data['pageSize'])
  729. ->get()
  730. ->map(function ($article) use ($data) {
  731. $catid = $article->catid;
  732. $pinyin = '';
  733. // $category = WebsiteCategory::whereIn('category_id', $catArrId)->where('website_category.website_id', $data['website_id'])->get()->all();
  734. // if ($catArrId) {
  735. // foreach ($catArrId as $categoryId) {
  736. $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
  737. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  738. if ($category->pid != 0 && !empty($category->aLIas_pinyin)) {
  739. $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
  740. $pinyin = $childCategory->aLIas_pinyin ? $childCategory->aLIas_pinyin . '/' . $category->aLIas_pinyin : null;
  741. }
  742. // }
  743. // }
  744. $article->pinyin = $pinyin;
  745. return $article;
  746. });
  747. if (empty($result)) {
  748. return Result::error("暂无头条新闻", 0);
  749. }
  750. return Result::success($result);
  751. } else {
  752. return Result::error("本网站下暂无相关栏目", 0);
  753. }
  754. }
  755. /**
  756. * 获取模块新闻
  757. * @param array $data
  758. * @return array
  759. */
  760. public function getWebsiteModelArticles(array $data): array
  761. {
  762. $catid = $data['catid'];
  763. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  764. $category = $category->toArray();
  765. if (!empty($category)) {
  766. $where = [
  767. 'status' => 1,
  768. 'catid' => $catid,
  769. ];
  770. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  771. // 1:文字新闻;2:轮播图;3:图文;
  772. // 级别:0:未分类
  773. // 3:推荐图片
  774. if ($data['level'] == 1) {
  775. $data['level'] = 0;
  776. }
  777. $result = Article::where($where)
  778. ->where(function ($query) use ($data) {
  779. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  780. ->orWhereNull("level")
  781. ->orWhereRaw("level = '[]'");
  782. })
  783. ->where(function ($query) use ($data) {
  784. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  785. ->orWhereNull("ignore_ids");
  786. })
  787. ->orderBy("updated_at", "desc")
  788. ->offset($placeid)
  789. ->limit($data['pagesize'])
  790. ->get();
  791. if (empty($result)) {
  792. return Result::error("此栏目暂无相关新闻", 0);
  793. }
  794. } else {
  795. return Result::error("此网站暂无此栏目", 0);
  796. }
  797. return Result::success($result);
  798. }
  799. /**
  800. *获取新闻列表
  801. * @param array $data
  802. * @return array
  803. */
  804. public function getWebsiteArticleList(array $data): array
  805. {
  806. // return Result::success($data);
  807. $where[] = ['status', '=', 1];
  808. if (isset($data['catid']) && !empty($data['catid'])) {
  809. if (is_array($data['catid'])) {
  810. $category = WebsiteCategory::where('website_id', $data['website_id'])->whereIn('category_id', $data['catid'])->pluck('category_id');
  811. array_push($where, ['catid', 'in', $data['catid']]);
  812. } else {
  813. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  814. array_push($where, ['catid', '=', $data['catid']]);
  815. }
  816. if (empty($category)) {
  817. return Result::error("此网站暂无此栏目", 0);
  818. }
  819. }
  820. // return Result::success($where);
  821. $rep = Article::where(function ($query) use ($where) {
  822. foreach ($where as $condition) {
  823. if ($condition[1] === 'in') {
  824. $query->whereIn($condition[0], $condition[2]);
  825. } else {
  826. $query->where($condition[0], $condition[1], $condition[2]);
  827. }
  828. }
  829. })
  830. ->where(function ($query) use ($data) {
  831. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  832. ->orWhereNull("ignore_ids");
  833. })
  834. ->select(
  835. 'article.id',
  836. 'article.title',
  837. 'article.imgurl',
  838. 'article.author',
  839. 'article.updated_at',
  840. 'article.introduce',
  841. 'article.islink',
  842. 'article.linkurl',
  843. 'article.copyfrom',
  844. 'article.catid'
  845. )
  846. ->orderBy("updated_at", "desc")
  847. ->limit($data['pageSize'])
  848. ->offset(($data['page'] - 1) * $data['pageSize'])
  849. ->get()
  850. ->map(function ($article) use ($data) {
  851. $catid = $article->catid ?? 0;
  852. $pinyin = '';
  853. $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
  854. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  855. if ($category->pid != 0 && !empty($category->aLIas_pinyin)) {
  856. $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
  857. $pinyin = $childCategory->aLIas_pinyin ? $childCategory->aLIas_pinyin . '/' . $category->aLIas_pinyin : null;
  858. }
  859. $article->pinyin = $pinyin;
  860. return $article;
  861. });
  862. $count = Article::where(function ($query) use ($where) {
  863. foreach ($where as $condition) {
  864. if ($condition[1] === 'in') {
  865. $query->whereIn($condition[0], $condition[2]);
  866. } else {
  867. $query->where($condition[0], $condition[1], $condition[2]);
  868. }
  869. }
  870. })->count();
  871. $data = [
  872. 'rows' => $rep->toArray(),
  873. 'count' => $count,
  874. ];
  875. if (empty($rep)) {
  876. return Result::error("没有信息数据");
  877. }
  878. return Result::success($data);
  879. }
  880. /**
  881. * 前端-获取新闻详情
  882. * @param array $data
  883. * @return array
  884. */
  885. public function selectWebsiteArticleInfo(array $data): array
  886. {
  887. $where = [
  888. 'article.id' => $data['id'],
  889. 'article.status' => 1,
  890. ];
  891. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")
  892. ->where(function ($query) use ($data) {
  893. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  894. ->orWhereNull("ignore_ids");
  895. })
  896. ->first();
  897. if (empty($result)) {
  898. return Result::error("暂无此新闻!", 0);
  899. }
  900. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  901. ->select('website_category.*', 'website.website_name', 'website.suffix')
  902. ->where('website_category.website_id', $data['website_id'])
  903. ->where(['website_category.category_id' => $result['catid']])
  904. ->first();
  905. if (empty($category)) {
  906. return Result::error("查询失败", 0);
  907. }
  908. //手动推荐文章
  909. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  910. $commendArticle = Article::whereIn('id', $commend_ids)
  911. ->where('status', 1)
  912. ->select('id', 'title', 'catid', 'imgurl', 'hits', 'created_at')
  913. ->orderBy('updated_at', 'desc')
  914. ->limit(5)
  915. ->get();
  916. $result['category_id'] = $category['category_id'];
  917. $result['cat_name'] = $category['alias'];
  918. $result['website_name'] = $category['website_name'] ?? "";
  919. $result['suffix'] = $category['suffix'] ?? "";
  920. $result['commendArticle'] = $commendArticle;
  921. return Result::success($result);
  922. }
  923. /**
  924. * 前端-获取网站调查问卷
  925. * @param array $data
  926. * @return array
  927. */
  928. public function getWebsiteSurvey(array $data): array
  929. {
  930. if (isset($data['website_id']) && !empty($data['website_id'])) {
  931. $website = Website::where('id', $data['website_id'])->first();
  932. if (empty($website)) {
  933. return Result::error("暂无此网站", 0);
  934. }
  935. }
  936. if (isset($data['art_id']) && !empty($data['art_id'])) {
  937. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  938. if (empty($article)) {
  939. return Result::error("暂无此文章", 0);
  940. }
  941. // return Result::error($data,0);
  942. $where['art_id'] = $data['art_id'];
  943. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  944. } else {
  945. $survey = Article::where(function ($query) {
  946. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  947. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  948. })
  949. ->where('status', 1)
  950. ->where('is_survey', 1)
  951. ->select('survey_id')
  952. ->orderBy('updated_at', 'desc')
  953. ->first();
  954. if (empty($survey)) {
  955. return Result::error("暂无调查问卷", 0);
  956. }
  957. $where['sur_id'] = $survey['survey_id'];
  958. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  959. }
  960. // return Result::success($where);
  961. $result = ArticleSurvey::where($where)
  962. ->where(function ($query) {
  963. $query->where('is_other', 0)
  964. ->orWhere(function ($subQuery) {
  965. $subQuery->where('is_other', 1)
  966. ->where('other_id', 0);
  967. });
  968. })
  969. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  970. ->select('article_survey.*', 'article.survey_type')
  971. ->get()->all();
  972. if (empty($result)) {
  973. return Result::error("此文章暂无调查问卷", 0);
  974. }
  975. return Result::success($result);
  976. }
  977. /**
  978. * 前端-添加网站调查问卷选项
  979. * @param array $data
  980. * @return array
  981. */
  982. public function addWebsiteSurveyOption(array $data): array
  983. {
  984. if (isset($data['website_id']) && !empty($data['website_id'])) {
  985. $website = Website::where('id', $data['website_id'])->first();
  986. if (empty($website)) {
  987. return Result::error("暂无此网站", 0);
  988. }
  989. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  990. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('website_id', $data['website_id'])->where('is_other', 1)->where('other_id', 0)->first();
  991. if (empty($survey)) {
  992. return Result::error("此调查问卷不可添加选项", 0);
  993. }
  994. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  995. $choice = [
  996. 'art_id' => $survey['art_id'],
  997. 'website_id' => $data['website_id'],
  998. 'survey_name' => $survey['survey_name'],
  999. 'choice_name' => $data['choice_name'],
  1000. 'sur_id' => $survey['sur_id'],
  1001. 'is_other' => 1,
  1002. 'other_id' => $survey['id'],
  1003. ];
  1004. $result = ArticleSurvey::insertGetId($choice);
  1005. if (empty($result)) {
  1006. return Result::error("添加失败", 0);
  1007. }
  1008. return Result::success($result);
  1009. }
  1010. }
  1011. return Result::error("添加失败", 0);
  1012. }
  1013. return Result::error("添加失败", 0);
  1014. }
  1015. /**
  1016. * 前端-调查问卷投票
  1017. * @param array $data
  1018. * @return array
  1019. */
  1020. public function addWebsiteSurveyVote(array $data): array
  1021. {
  1022. // return Result::success($data);
  1023. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1024. $website = Website::where('id', $data['website_id'])->first();
  1025. if (empty($website)) {
  1026. return Result::error("暂无此网站", 0);
  1027. }
  1028. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1029. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1030. // return Result::success($survey);
  1031. if (empty($is_survey)) {
  1032. return Result::error("此调查问卷不存在", 0);
  1033. }
  1034. // return Result::success($survey);
  1035. // 调查问卷类型
  1036. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1037. //多选 若是json型则转化成数组类型
  1038. if (strpos($data['choice_id'], '[') === 0) {
  1039. $data['choice_id'] = json_decode($data['choice_id'], true);
  1040. } else {
  1041. // 单选 也转换成数组
  1042. $data['choice_id'] = [$data['choice_id']];
  1043. }
  1044. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1045. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1046. ->where('website_id', $data['website_id'])
  1047. ->where('is_other', 1)
  1048. ->where('other_id', 0)
  1049. ->first();
  1050. if (!empty($other)) {
  1051. return Result::error("请选择已有的选项!", 0);
  1052. }
  1053. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1054. ->where('website_id', $data['website_id'])
  1055. ->where('is_other', 1)
  1056. ->where('other_id', '!=', 0)
  1057. ->first();
  1058. // return Result::success($choice['other']);
  1059. $choice_id = $data['choice_id'];
  1060. if (!empty($choice['other'])) {
  1061. // array_push($data['choice_id'],$choice['other']['other_id']);
  1062. if (!empty($choice_id)) {
  1063. $key = array_search($choice['other']['id'], $choice_id);
  1064. if ($key !== false) {
  1065. unset($choice_id[$key]);
  1066. $choice_id = array_values($choice_id);
  1067. }
  1068. array_push($choice_id, $choice['other']['other_id']);
  1069. } else {
  1070. $choice_id[0] = $choice['other']['other_id'];
  1071. }
  1072. array_push($data['choice_id'], $choice['other']['other_id']);
  1073. }
  1074. // return Result::success($data);
  1075. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1076. ->where('website_id', $data['website_id'])
  1077. ->increment('results', 1);
  1078. if (empty($choice)) {
  1079. return Result::error("请选择已有的选项!", 0);
  1080. }
  1081. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1082. ->where('website_id', $data['website_id'])
  1083. ->where('other_id', 0)
  1084. ->get();
  1085. $survey['choice'] = $choice_id;
  1086. return Result::success($survey);
  1087. }
  1088. return Result::error("参数必填!");
  1089. }
  1090. return Result::error("此调查问卷不存在", 0);
  1091. }
  1092. return Result::error("参数必填!");
  1093. }
  1094. /**
  1095. * 后端-获取网站调查问卷列表
  1096. * @param array $data
  1097. * @return array
  1098. */
  1099. public function getSurveyList(array $data): array
  1100. {
  1101. $where = [];
  1102. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1103. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1104. }
  1105. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  1106. array_push($where, ['survey_type', '=', $data['survey_type']]);
  1107. }
  1108. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  1109. array_push($where, ['is_survey', '=', $data['is_survey']]);
  1110. }
  1111. // return Result::success($where);
  1112. if (!empty($where)) {
  1113. $query = Article::where($where)->where(function ($q) {
  1114. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1115. });
  1116. } else {
  1117. $query = Article::where(function ($q) {
  1118. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1119. });
  1120. }
  1121. $count = $query->count();
  1122. $survey = $query->orderByDesc('id')
  1123. ->limit($data['pageSize'])
  1124. ->offset(($data['page'] - 1) * $data['pageSize'])
  1125. ->get();
  1126. if (empty($survey->toArray())) {
  1127. return Result::error("暂无调查问卷!", 0);
  1128. }
  1129. $result = [
  1130. 'rows' => $survey,
  1131. 'count' => $count,
  1132. ];
  1133. return Result::success($result);
  1134. }
  1135. /**
  1136. * 后端-获取网站调查问卷详情
  1137. * @param array $data
  1138. * @return array
  1139. */
  1140. public function getSurveyInfo(array $data): array
  1141. {
  1142. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1143. $where = ['sur_id' => $data['sur_id']];
  1144. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1145. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1146. ->select('article_survey.*', 'article.survey_type')
  1147. ->get()->all();
  1148. if (empty($choose)) {
  1149. return Result::error("此调查问卷不存在", 0);
  1150. }
  1151. $resultsArray = array_column($choose, 'results');
  1152. $total = array_sum($resultsArray);
  1153. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1154. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1155. // $total = 0;
  1156. if (!empty($other)) {
  1157. $total = $total + $other['results'];
  1158. $other['choice_name'] = '(其他)';
  1159. if (!empty($others)) {
  1160. $other['hasChildren'] = true;
  1161. // array_push($other,['hasChildren','=',true]);
  1162. $other['children'] = $others;
  1163. $other_choices = [$other->toArray()];
  1164. $mer_choice = array_merge($choose, $other_choices);
  1165. $value_choice = array_values($mer_choice);
  1166. } else {
  1167. // return Result::error('1111');
  1168. $other_choices = [$other->toArray()];
  1169. $other_choices = array_merge($choose, $other_choices);
  1170. $value_choice = array_values($other_choices);
  1171. // return Result::success($result);
  1172. }
  1173. } else {
  1174. $value_choice = $choose;
  1175. }
  1176. $result = [
  1177. 'choose' => $value_choice,
  1178. 'total' => $total,
  1179. ];
  1180. }
  1181. return Result::success($result);
  1182. }
  1183. /**
  1184. * 前端-搜索新闻列表
  1185. * @param array $data
  1186. * @return array
  1187. */
  1188. public function selectWebsiteArticle(array $data): array
  1189. {
  1190. $where = [];
  1191. // 初始化查询构造器
  1192. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
  1193. $query = Article::where('status', 1)
  1194. ->whereIn('catid', $category)
  1195. ->where(function ($query) use ($data) {
  1196. $query->where(function ($subQuery) use ($data) {
  1197. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1198. })->orWhereNull("ignore_ids");
  1199. });
  1200. // return Result::success($all_articles);
  1201. // 检查是否存在 cityid 参数
  1202. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1203. $query->whereRaw("JSON_CONTAINS(city_arr_id, '" . intval($data['cityid']) . "')");
  1204. }
  1205. // 检查是否存在 department_id 参数
  1206. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1207. $query->whereRaw("JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "')");
  1208. }
  1209. // 检查是否存在 keyword 参数
  1210. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1211. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  1212. }
  1213. // 计算总数
  1214. $count = $query->count();
  1215. // 分页查询
  1216. $articles = $query
  1217. ->select(
  1218. 'article.id',
  1219. 'article.title',
  1220. 'article.imgurl',
  1221. 'article.author',
  1222. 'article.updated_at',
  1223. 'article.introduce',
  1224. 'article.islink',
  1225. 'article.linkurl',
  1226. 'article.copyfrom',
  1227. 'article.catid',
  1228. 'article.department_arr_id',
  1229. 'article.city_arr_id',
  1230. )
  1231. ->orderBy("updated_at", "desc")
  1232. ->offset(($data['page'] - 1) * $data['pageSize'])
  1233. ->limit($data['pageSize'])
  1234. ->get()
  1235. ->map(function ($article) use ($data) {
  1236. $catid = $article->catid ?? 0;
  1237. $pinyin = '';
  1238. $category = WebsiteCategory::where('category_id', $catid)->where('website_category.website_id', $data['website_id'])->first();
  1239. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  1240. if ($category->pid != 0 && !empty($category->aLIas_pinyin)) {
  1241. $childCategory = WebsiteCategory::where('category_id', $category->pid)->where('website_category.website_id', $data['website_id'])->first();
  1242. $pinyin = $childCategory->aLIas_pinyin ? $childCategory->aLIas_pinyin . '/' . $category->aLIas_pinyin : null;
  1243. }
  1244. $article->pinyin = $pinyin;
  1245. return $article;
  1246. });
  1247. if (empty($articles)) {
  1248. return Result::error("没有符合条件的资讯数据");
  1249. }
  1250. $data = [
  1251. 'rows' => $articles,
  1252. 'count' => $count,
  1253. ];
  1254. return Result::success($data);
  1255. }
  1256. /**
  1257. * 模块新闻加强版
  1258. * @param array $data
  1259. * @return array
  1260. */
  1261. public function getWebsiteCatidArticle(array $data): array
  1262. {
  1263. // return Result::success($data);
  1264. $where = [
  1265. // 'category.status' => 1,
  1266. 'website_category.category_id' => $data['catid'],
  1267. 'website_category.website_id' => $data['website_id'],
  1268. // 'article.status' => 1,
  1269. ];
  1270. // $category = WebsiteCategory::where($where);
  1271. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  1272. $child_catnum = $data['child_catnum'] ?? 1;
  1273. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  1274. $childCategoryIds = array_column($category['child'], 'category_id');
  1275. if (empty($childCategoryIds)) {
  1276. return Result::error("暂无子栏目", 0);
  1277. }
  1278. $imgArticles = [];
  1279. $textArticles = [];
  1280. // return Result::success($childCategoryIds);
  1281. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  1282. // 初始化子分类图片新闻和文字新闻数组
  1283. // 查询所有子级栏目的图文新闻
  1284. $imgArticles = Article::where('catid', $childCategoryIds[0])
  1285. ->where(function ($query) use ($data) {
  1286. $query->where(function ($subQuery) use ($data) {
  1287. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1288. })->orWhereNull("ignore_ids");
  1289. })
  1290. ->where('status', 1)
  1291. ->where('imgurl', '!=', '')
  1292. ->select('*')
  1293. ->orderBy('updated_at', 'desc')
  1294. ->limit($data['child_imgnum'])
  1295. ->get();
  1296. }
  1297. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  1298. // 查询所有子级栏目的文字新闻
  1299. $textArticles = Article::where('catid', $childCategoryIds[0])
  1300. ->where('status', 1)
  1301. ->where(function ($query) use ($data) {
  1302. $query->where(function ($subQuery) use ($data) {
  1303. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1304. })->orWhereNull("ignore_ids");
  1305. })
  1306. // ->where(function ($query) {
  1307. // $query->whereNull('imgurl')
  1308. // ->orWhere('imgurl', '');
  1309. // })
  1310. ->select('*')
  1311. ->orderBy('updated_at', 'desc')
  1312. ->limit($data['child_textnum'])
  1313. ->get();
  1314. }
  1315. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  1316. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  1317. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  1318. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  1319. return $child;
  1320. }, $category['child']);
  1321. }
  1322. // }
  1323. if (isset($data['img_num']) && !empty($data['img_num'])) {
  1324. $category['img'] = WebsiteCategory::where($where)
  1325. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1326. ->where('article.status', 1)
  1327. ->where('article.imgurl', '!=', '')
  1328. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1329. ->orderBy('article.updated_at', 'desc')
  1330. ->limit($data['img_num'])
  1331. ->get();
  1332. }
  1333. if (isset($data['text_num']) && !empty($data['text_num'])) {
  1334. $category['text'] = WebsiteCategory::where($where)
  1335. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1336. ->where('article.status', 1)
  1337. // ->where(function ($query) {
  1338. // $query->whereNull('article.imgurl')
  1339. // ->orWhere('article.imgurl', '');
  1340. // })
  1341. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1342. ->orderBy('article.updated_at', 'desc')
  1343. ->limit($data['text_num'])
  1344. ->get();
  1345. }
  1346. // $category = $category->get();
  1347. if (empty($category)) {
  1348. return Result::error("查询失败", 0);
  1349. }
  1350. return Result::success($category);
  1351. }
  1352. /**
  1353. * 模块新闻加强plus版
  1354. * @param array $data
  1355. * @return array
  1356. */
  1357. public function getWebsiteAllArticle(array $data): array
  1358. {
  1359. // 修正传入的字符串,将单引号替换为双引号
  1360. $input['id'] = $data['id'];
  1361. $input['website_id'] = $data['website_id'];
  1362. // 将 JSON 字符串转换为 PHP 数组
  1363. $data = json_decode($input['id'], true);
  1364. // 使用 array_map 处理每个元素
  1365. $result = array_map(function ($item) use ($input) {
  1366. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  1367. $website = [
  1368. 'website_id' => $input['website_id'],
  1369. ];
  1370. // 查询栏目名称
  1371. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  1372. if (empty($category)) {
  1373. $imgArticles = [];
  1374. $textArticles = [];
  1375. // return Result::error("暂无此栏目",0);
  1376. } else {
  1377. $parent_alias = $category->alias ?? '';
  1378. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  1379. // 查询图片新闻
  1380. $imgArticles = Article::where('catid', $parentCatId)
  1381. ->where('status', 1)
  1382. ->where(function ($query) use ($website) {
  1383. $query->where(function ($subQuery) use ($website) {
  1384. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1385. })->orWhereNull("ignore_ids");
  1386. })
  1387. ->where('imgurl', '!=', '')
  1388. ->select(
  1389. 'article.id',
  1390. 'article.title',
  1391. 'article.imgurl',
  1392. 'article.author',
  1393. 'article.updated_at',
  1394. 'article.introduce',
  1395. 'article.islink',
  1396. 'article.linkurl',
  1397. 'article.copyfrom',
  1398. DB::raw("'$parent_pinyin' as pinyin") // 添加 pinyin 字段
  1399. )
  1400. ->orderBy('updated_at', 'desc')
  1401. ->limit($parentImgNum)
  1402. ->get()->all();
  1403. // 查询文字新闻
  1404. $textArticles = Article::where('catid', $parentCatId)
  1405. ->where('status', 1)
  1406. ->where(function ($query) use ($website) {
  1407. $query->where(function ($subQuery) use ($website) {
  1408. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1409. })->orWhereNull("ignore_ids");
  1410. })
  1411. ->select(
  1412. 'article.id',
  1413. 'article.title',
  1414. 'article.author',
  1415. 'article.updated_at',
  1416. 'article.introduce',
  1417. 'article.islink',
  1418. 'article.linkurl',
  1419. 'article.copyfrom',
  1420. DB::raw("'$parent_pinyin' as pinyin")
  1421. )
  1422. ->orderBy('updated_at', 'desc')
  1423. ->limit($parentTextNum)
  1424. ->get()->all();
  1425. }
  1426. $resultItem = [
  1427. 'alias' => $parent_alias,
  1428. 'category_id' => $parentCatId,
  1429. 'pinyin' => $parent_pinyin,
  1430. 'imgnum' => $imgArticles,
  1431. 'textnum' => $textArticles,
  1432. ];
  1433. if (!empty($item['child']) && $item['child'] != "") {
  1434. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  1435. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  1436. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  1437. ->get()->all();
  1438. if ($childCategory) {
  1439. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  1440. // 查询子栏目名称
  1441. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  1442. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  1443. ->first();
  1444. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  1445. if (empty($childCategoryInfo)) {
  1446. $childImgArticles = [];
  1447. $childTextArticles = [];
  1448. } else {
  1449. // 查询子栏目图片新闻
  1450. $childImgArticles = Article::where('catid', $childCatId)
  1451. ->where('status', 1)
  1452. ->where(function ($query) use ($website) {
  1453. $query->where(function ($subQuery) use ($website) {
  1454. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1455. })->orWhereNull("ignore_ids");
  1456. })
  1457. ->select(
  1458. 'article.id',
  1459. 'article.title',
  1460. 'article.imgurl',
  1461. 'article.author',
  1462. 'article.updated_at',
  1463. 'article.introduce',
  1464. 'article.islink',
  1465. 'article.linkurl',
  1466. 'article.copyfrom',
  1467. DB::raw("'$child_pinyin' as pinyin")
  1468. )
  1469. ->where('imgurl', '!=', '')
  1470. ->orderBy('updated_at', 'desc')
  1471. ->limit($childImgNum)
  1472. ->get()->all();
  1473. // 查询子栏目文字新闻
  1474. $childTextArticles = Article::where('catid', $childCatId)
  1475. ->where('status', 1)
  1476. ->where(function ($query) use ($website) {
  1477. $query->where(function ($subQuery) use ($website) {
  1478. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1479. })->orWhereNull("ignore_ids");
  1480. })
  1481. ->select(
  1482. 'article.id',
  1483. 'article.title',
  1484. 'article.author',
  1485. 'article.updated_at',
  1486. 'article.introduce',
  1487. 'article.islink',
  1488. 'article.linkurl',
  1489. 'article.copyfrom',
  1490. DB::raw("'$child_pinyin' as pinyin")
  1491. )
  1492. ->orderBy('updated_at', 'desc')
  1493. ->limit($childTextNum)
  1494. ->get()->all();
  1495. }
  1496. $resultItem['child'] = [
  1497. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  1498. 'category_id' => $childCatId,
  1499. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  1500. 'all_childcat' => $childCategory,
  1501. 'imgnum' => $childImgArticles,
  1502. 'textnum' => $childTextArticles,
  1503. ];
  1504. // $resultItem['pinyin'] = $childCategoryInfo->aLIas_pinyin ?? '';
  1505. }
  1506. }
  1507. return $resultItem;
  1508. }, $data);
  1509. return Result::success($result);
  1510. // return Result::success($data);
  1511. }
  1512. /**
  1513. * 乡村网-获取特殊新闻模块
  1514. * @param array $data
  1515. * @return array
  1516. */
  1517. public function getWebsiteArticles(array $data): array
  1518. {
  1519. $input['id'] = $data['id'];
  1520. $input['website_id'] = $data['website_id'];
  1521. $data = json_decode($input['id'], true);
  1522. // 使用 array_map 处理每个元素
  1523. $result = array_map(function ($item) use ($input) {
  1524. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  1525. $website = [
  1526. 'website_id' => $input['website_id']
  1527. ];
  1528. // 查询栏目名称
  1529. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  1530. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  1531. if (empty($category)) {
  1532. $imgArticles = [];
  1533. $textArticles = [];
  1534. // return Result::error("暂无此栏目",0);
  1535. } else {
  1536. $parent_alias = $category->aLIas_pinyin ? $category->aLIas_pinyin . '/' : null;
  1537. // return Result::success($website);
  1538. // 查询图片新闻
  1539. // 合并查询条件
  1540. $baseQuery = Article::where(function ($query) use ($website) {
  1541. $query->where(function ($subQuery) use ($website) {
  1542. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1543. })->orWhereNull("ignore_ids");
  1544. })
  1545. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($parentCatId) . "')")
  1546. ->leftJoin('website_category', 'website_category.category_id', 'article.catid')
  1547. ->where('website_category.website_id', $website['website_id'])
  1548. ->where('article.status', 1);
  1549. // 查询文字新闻
  1550. $textArticles = clone $baseQuery;
  1551. $textArticles = $textArticles
  1552. ->select(
  1553. 'article.id',
  1554. 'article.title',
  1555. // 'article.imgurl',
  1556. 'article.author',
  1557. 'article.updated_at',
  1558. 'article.introduce',
  1559. 'article.islink',
  1560. 'article.linkurl',
  1561. 'article.copyfrom',
  1562. 'website_category.category_id',
  1563. 'website_category.alias',
  1564. 'website_category.aLIas_pinyin'
  1565. )
  1566. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1567. ->orderBy('article.updated_at', 'desc')
  1568. ->limit($parentTextNum)
  1569. ->get()
  1570. ->all();
  1571. // 查询图片新闻
  1572. $imgArticles = clone $baseQuery;
  1573. $imgArticles = $imgArticles
  1574. ->select(
  1575. 'article.id',
  1576. 'article.title',
  1577. 'article.imgurl',
  1578. 'article.author',
  1579. 'article.updated_at',
  1580. 'article.introduce',
  1581. 'article.islink',
  1582. 'article.linkurl',
  1583. 'article.copyfrom',
  1584. 'website_category.category_id',
  1585. 'website_category.alias',
  1586. 'website_category.aLIas_pinyin'
  1587. )
  1588. ->selectRaw("CONCAT(?, aLIas_pinyin ) as aLIas_pinyin", [$parent_alias])
  1589. ->orderBy('article.updated_at', 'desc')
  1590. ->where('imgurl', '!=', '')
  1591. ->limit($parentImgNum)
  1592. ->get()
  1593. ->all();
  1594. }
  1595. $resultItem = [
  1596. 'alias' => $category ? $category->alias : null,
  1597. 'category_id' => $parentCatId,
  1598. 'pinyin' => $pinyin ? $pinyin : null,
  1599. 'imgnum' => $imgArticles ?? [],
  1600. 'textnum' => $textArticles ?? [],
  1601. ];
  1602. return $resultItem;
  1603. }, $data);
  1604. return Result::success($result);
  1605. }
  1606. /**
  1607. *获取头条类新闻模块-合集
  1608. * @param array $data
  1609. * @return array
  1610. */
  1611. public function getWebsiteAllArticlett(array $data): array
  1612. {
  1613. $input['id'] = $data['id'];
  1614. $input['website_id'] = $data['website_id'];
  1615. $data = json_decode($input['id'], true);
  1616. // 使用 array_map 处理每个元素
  1617. $result = array_map(function ($item) use ($input) {
  1618. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  1619. $website = [
  1620. 'website_id' => $input['website_id']
  1621. ];
  1622. $category = WebsiteCategory::where('website_id', $input['website_id'])->pluck('category_id');
  1623. $category = array_values(array_unique($category->toArray()));
  1624. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  1625. $where = [
  1626. 'status' => 1,
  1627. ];
  1628. return $category;
  1629. }, $data); // 添加第二个参数 $data,确保 array_map 函数有两个参数
  1630. return Result::success($result);
  1631. }
  1632. /**
  1633. * 验证导航名称是否重复
  1634. * @return void
  1635. */
  1636. public function checkCategoryName(array $data): array
  1637. {
  1638. $result = Category::when($data, function ($query) use ($data) {
  1639. if (isset($data['name']) && $data['name']) {
  1640. $query->where("name", $data['name']);
  1641. }
  1642. if (isset($data['id']) && $data['id']) {
  1643. $query->where("id", "!=", $data['id']);
  1644. }
  1645. })->first();
  1646. if ($result) {
  1647. return Result::error("已存在");
  1648. } else {
  1649. return Result::success();
  1650. }
  1651. }
  1652. //20250226 产品列表
  1653. public function getGoodList(array $data): array
  1654. {
  1655. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  1656. unset($data['type_id']);
  1657. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  1658. $where = [];
  1659. if ($type_id != '10000') {
  1660. $where = [
  1661. 'good.user_id' => $user_id,
  1662. ];
  1663. }
  1664. //类型
  1665. if (isset($data['type_id']) && $data['type_id']) {
  1666. $where = [
  1667. 'type_id' => $data['type_id'],
  1668. ];
  1669. }
  1670. //名称
  1671. if (isset($data['name']) && $data['name']) {
  1672. $where = [
  1673. 'good.name' => $data['name'],
  1674. ];
  1675. }
  1676. $where1 = [];
  1677. //website_id
  1678. // if (isset($data['website_id']) && $data['website_id']) {
  1679. // $where1 = [
  1680. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  1681. // ];
  1682. // }
  1683. // website_name
  1684. if (isset($data['website_name']) && $data['website_name']) {
  1685. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  1686. }
  1687. // catid
  1688. if (isset($data['category_name']) && $data['category_name']) {
  1689. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  1690. }
  1691. // $result = Good::where($where)
  1692. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  1693. $result = Good::where($where)
  1694. ->when(!empty($where1), function ($query) use ($where1) {
  1695. return $query->where($where1);
  1696. })
  1697. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  1698. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  1699. ->leftJoin('category', 'good.catid', '=', 'category.id')
  1700. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  1701. ->orderBy("id", "desc")
  1702. ->limit($data['page_size'])
  1703. ->offset(($data['page'] - 1) * $data['page_size'])
  1704. ->get();
  1705. $count = Good::where($where)
  1706. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  1707. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  1708. ->leftJoin('category', 'good.catid', '=', 'category.id')
  1709. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  1710. ->orderBy("updated_at", "desc")->count();
  1711. $data = [
  1712. 'rows' => $result->toArray(),
  1713. 'count' => $count,
  1714. ];
  1715. if (empty($result)) {
  1716. return Result::error("此栏目暂无相关产品", 0);
  1717. }
  1718. return Result::success($data);
  1719. }
  1720. public function getGoodInfo(array $data): array
  1721. {
  1722. $result = Good::where('id', $data['id'])->first();
  1723. if (empty($result)) {
  1724. return Result::error("此产品不存在", 0);
  1725. }
  1726. return Result::success($result);
  1727. }
  1728. public function addGood(array $data): array
  1729. {
  1730. // unset($data['city_arr_id']);
  1731. // unset($data['cat_arr_id']);
  1732. $data['city_id'] = end($data['city_arr_id']);
  1733. $data['catid'] = end($data['cat_arr_id']);
  1734. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  1735. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  1736. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  1737. unset($data['imgUrl']);
  1738. $result = Good::insert($data);
  1739. if (empty($result)) {
  1740. return Result::error("添加失败", 0);
  1741. }
  1742. return Result::success($result);
  1743. }
  1744. public function updateGood(array $data): array
  1745. {
  1746. $data['city_id'] = end($data['city_arr_id']);
  1747. $data['catid'] = end($data['cat_arr_id']);
  1748. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  1749. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  1750. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  1751. //设置东八区
  1752. date_default_timezone_set('Asia/Shanghai');
  1753. $data['updated_at'] = date('Y-m-d H:i:s');
  1754. $result = Good::where('id', $data['id'])->update($data);
  1755. if (empty($result)) {
  1756. return Result::error("更新失败", 0);
  1757. }
  1758. return Result::success($result);
  1759. }
  1760. public function delGood(array $data): array
  1761. {
  1762. $result = Good::where('id', $data['id'])->delete();
  1763. if (empty($result)) {
  1764. return Result::error("删除失败", 0);
  1765. }
  1766. return Result::success($result);
  1767. }
  1768. //20250226 产品列表
  1769. //20250306 求职信息
  1770. public function getJobHuntingList(array $data): array
  1771. {
  1772. $where = [];
  1773. if (isset($data['username']) && !empty($data['username'])) {
  1774. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  1775. }
  1776. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  1777. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  1778. unset($data['type_id']);
  1779. if ($type_id != '10000') {
  1780. $where[] = ['job_hunting.user_id', '=', $user_id];
  1781. }
  1782. $result = JobHunting::where($where)
  1783. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  1784. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  1785. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  1786. ->orderBy("id", "desc")
  1787. ->limit($data['page_size'])
  1788. ->offset(($data['page'] - 1) * $data['page_size'])
  1789. ->get();
  1790. if (empty($result)) {
  1791. return Result::error("查询失败", 0);
  1792. }
  1793. $count = JobHunting::where($where)
  1794. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  1795. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  1796. ->count();
  1797. $data = [
  1798. 'rows' => $result->toArray(),
  1799. 'count' => $count,
  1800. ];
  1801. return Result::success($data);
  1802. }
  1803. public function addJobHunting(array $data): array
  1804. {
  1805. date_default_timezone_set('Asia/Shanghai');
  1806. unset($data['company_name']);
  1807. unset($data['job_industry']);
  1808. unset($data['job_name']);
  1809. unset($data['department']);
  1810. unset($data['job_timeList']);
  1811. unset($data['job_content']);
  1812. $data['created_at'] = date('Y-m-d H:i:s');
  1813. $data['updated_at'] = date('Y-m-d H:i:s');
  1814. var_dump($data, '-----------------test---------');
  1815. $result = JobHunting::create($data);
  1816. if (empty($result)) {
  1817. return Result::error("添加失败", 0);
  1818. }
  1819. return Result::success($result);
  1820. }
  1821. public function delJobHunting(array $data): array
  1822. {
  1823. $result = JobHunting::where('id', $data['id'])->delete();
  1824. if (empty($result)) {
  1825. return Result::error("删除失败", 0);
  1826. }
  1827. return Result::success($result);
  1828. }
  1829. public function updateJobHunting(array $data): array
  1830. {
  1831. //设置东八区
  1832. date_default_timezone_set('Asia/Shanghai');
  1833. unset($data['company_name']);
  1834. unset($data['job_industry']);
  1835. unset($data['job_name']);
  1836. unset($data['department']);
  1837. unset($data['job_timeList']);
  1838. unset($data['job_content']);
  1839. $data['created_at'] = date('Y-m-d H:i:s');
  1840. $data['updated_at'] = date('Y-m-d H:i:s');
  1841. $result = JobHunting::where('id', $data['id'])->update($data);
  1842. if (empty($result)) {
  1843. return Result::error("更新失败", 0);
  1844. }
  1845. return Result::success($result);
  1846. }
  1847. public function getJobHuntingInfo(array $data): array
  1848. {
  1849. $result = JobHunting::where('id', $data['id'])->first();
  1850. if (empty($result)) {
  1851. return Result::error("查询失败", 0);
  1852. }
  1853. return Result::success($result);
  1854. }
  1855. public function getJobHuntingData(array $data): array
  1856. {
  1857. $jobEnum = JobEnum::get();
  1858. $jobIndustry = JobIndustry::get();
  1859. $jobNature = JobNature::get();
  1860. $jobPosition = JobPosition::get();
  1861. $data = [
  1862. 'jobEnum' => $jobEnum,
  1863. 'jobIndustry' => $jobIndustry,
  1864. 'jobNature' => $jobNature,
  1865. 'jobPosition' => $jobPosition,
  1866. ];
  1867. return Result::success($data);
  1868. }
  1869. public function delJobHuntingInfo(array $data): array
  1870. {
  1871. $result = JobHunting::where('id', $data['id'])->delete();
  1872. return Result::success();
  1873. }
  1874. //20250324 通知,公告,消息
  1875. public function delNotice(array $data): array
  1876. {
  1877. return Result::success();
  1878. }
  1879. public function getNoticeInfo(array $data): array
  1880. {
  1881. $result = Notice::where('id', $data['id'])->first();
  1882. if (empty($result)) {
  1883. return Result::error("查询失败", 0);
  1884. }
  1885. return Result::success($result);
  1886. }
  1887. public function addNotice(array $data): array
  1888. {
  1889. date_default_timezone_set('Asia/Shanghai');
  1890. $data['created_at'] = date('Y-m-d H:i:s');
  1891. $data['updated_at'] = date('Y-m-d H:i:s');
  1892. $user_id = UserInfo::
  1893. //city_id不是null
  1894. whereNotNull('city_id')
  1895. ->whereNotNull('department_id')
  1896. ->where(function ($query) use ($data) {
  1897. $query->where(function ($subQuery) use ($data) {
  1898. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  1899. });
  1900. })
  1901. ->where(function ($query) use ($data) {
  1902. $query->where(function ($subQuery) use ($data) {
  1903. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  1904. });
  1905. })
  1906. ->pluck('user_id')->toArray();
  1907. $user_id = array_unique($user_id);
  1908. $chat_ids = $user_id;
  1909. $user_id = json_encode($user_id);
  1910. $data['re_user_ids'] = $user_id;
  1911. $result = Notice::insertGetId($data);
  1912. if ($result && $data['is_group'] == 1) {
  1913. //chat_group
  1914. $group_id = PublicData::uuid();
  1915. $groupData = [
  1916. 'id' => $group_id,
  1917. 'creator_id' => $data['user_id'],
  1918. 'group_name' => $data['group_name'] ?? '',
  1919. 'profile' => $data['profile'] ?? 0,
  1920. ];
  1921. $groupResult = ChatGroups::insertGetId($groupData);
  1922. var_dump($groupResult, '-----------------groupid-------');
  1923. $groupMemberData = [
  1924. 'id' => PublicData::uuid(),
  1925. 'user_id' => $data['user_id'],
  1926. 'group_id' => $group_id,
  1927. 'leader' => 2,
  1928. ];
  1929. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  1930. //$chat_ids 去除掉$data['user_id']
  1931. $chat_ids = array_diff($chat_ids, [$data['user_id']]);
  1932. //插入群成员表
  1933. $groupMemberDataUser = [];
  1934. foreach ($chat_ids as $key => $value) {
  1935. $groupMemberDataUser[] = [
  1936. 'id' => PublicData::uuid(),
  1937. 'user_id' => $value,
  1938. 'group_id' => $group_id,
  1939. 'leader' => 1,
  1940. ];
  1941. }
  1942. ChatGroupsMember::insert($groupMemberDataUser);
  1943. //更新result的 group_id
  1944. $data['group_id'] = $group_id;
  1945. Notice::where(['id' => $result])->update($data);
  1946. }
  1947. if (empty($result)) {
  1948. return Result::error("添加失败", 0);
  1949. }
  1950. return Result::success($result);
  1951. }
  1952. public function updateNotice(array $data): array
  1953. {
  1954. date_default_timezone_set('Asia/Shanghai');
  1955. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  1956. $user_id = UserInfo::
  1957. //city_id不是null
  1958. whereNotNull('city_id')
  1959. ->whereNotNull('department_id')
  1960. ->where(function ($query) use ($data) {
  1961. $query->where(function ($subQuery) use ($data) {
  1962. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  1963. });
  1964. })
  1965. ->where(function ($query) use ($data) {
  1966. $query->where(function ($subQuery) use ($data) {
  1967. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  1968. });
  1969. })
  1970. ->pluck('user_id')->toArray();
  1971. $user_id = array_unique($user_id);
  1972. $user_id = json_encode($user_id);
  1973. $data['re_user_ids'] = $user_id;
  1974. $data['updated_at'] = date('Y-m-d H:i:s');
  1975. $result = Notice::where('id', $data['id'])->update($data);
  1976. return Result::success($result);
  1977. }
  1978. public function getNoticeList(array $data): array
  1979. {
  1980. $where = [];
  1981. //title
  1982. if (isset($data['title']) && !empty($data['title'])) {
  1983. $where[] = ['title', 'like', '%' . $data['title'] . '%'];
  1984. }
  1985. //level
  1986. if (isset($data['level']) && !empty($data['level'])) {
  1987. $where[] = ['level', '=', $data['level']];
  1988. }
  1989. var_dump($data['type_id'], '-----------------test---------');
  1990. if ($data['type_id'] == 10000) {
  1991. $result = Notice::where('status', 1)
  1992. ->where($where)
  1993. ->orderBy('updated_at', 'desc')
  1994. ->limit($data['page_size'])
  1995. ->offset(($data['page'] - 1) * $data['page_size'])
  1996. ->get();
  1997. } else {
  1998. $result = Notice::where('status', 1)
  1999. ->where($where)
  2000. ->where('user_id', $data['user_id'])
  2001. ->orWhere(function ($query) use ($data) {
  2002. $query->where('re_user_ids', 'like', '%' . $data['user_id'] . '%');
  2003. })
  2004. ->orderBy('updated_at', 'desc')
  2005. ->limit($data['page_size'])
  2006. ->offset(($data['page'] - 1) * $data['page_size'])
  2007. ->get();
  2008. }
  2009. if (empty($result)) {
  2010. return Result::error("查询失败", 0);
  2011. }
  2012. $count = Notice::where('status', 1)->count();
  2013. $data = [
  2014. 'rows' => $result,
  2015. 'count' => $count,
  2016. ];
  2017. return Result::success($data);
  2018. }
  2019. public function getNoticeDetail(array $data): array
  2020. {
  2021. $result = Notice::where('id', $data['id'])->first();
  2022. if (empty($result)) {
  2023. return Result::error("查询失败", 0);
  2024. }
  2025. return Result::success($result);
  2026. }
  2027. public function deleteNotice(array $data): array
  2028. {
  2029. $notice = Notice::where('id', $data['id'])->first();
  2030. if (empty($notice)) {
  2031. return Result::error("删除失败", 0);
  2032. }
  2033. $chat_group_id = $notice->group_id;
  2034. if ($chat_group_id) {
  2035. //删除群聊
  2036. ChatGroups::where('id', $chat_group_id)->delete();
  2037. //删除群成员
  2038. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  2039. //删除群聊记录
  2040. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  2041. }
  2042. $result = Notice::where('id', $data['id'])->delete();
  2043. return Result::success($result);
  2044. }
  2045. public function getMSG(array $data): array
  2046. {
  2047. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  2048. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  2049. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  2050. $result = [];
  2051. if ($type_id == 1) {
  2052. //最近的5篇已审的文章
  2053. $apply_articale = Article::where('status', 1)
  2054. ->where('admin_user_id', $user_id)
  2055. ->orderBy('updated_at', 'desc')
  2056. ->limit(5)->get();
  2057. //获取5条单聊未读聊天消息
  2058. $chat = ChatRecords::where('is_read', 0)
  2059. ->where('user_id', $user_id)
  2060. ->where('talk_type', 1)
  2061. ->orderBy('created_at', 'desc')
  2062. ->limit(5)->get();
  2063. //获取5条未读群聊信息
  2064. $chat_group = ChatRecords::where('is_read', 0)
  2065. ->where('user_id', $user_id)
  2066. ->where('talk_type', 2)
  2067. ->orderBy('created_at', 'desc')
  2068. ->limit(5)->get();
  2069. $count = count($chat) + count($chat_group) + count($apply_articale);
  2070. $result = [
  2071. 'apply_articale' => $apply_articale,
  2072. 'chat' => $chat,
  2073. 'chat_group' => $chat_group,
  2074. 'count' => $count,
  2075. ];
  2076. } elseif ($type_id == 2) {
  2077. //最近的5篇已审的文章
  2078. $apply_articale = Article::where('status', 1)
  2079. ->where('admin_user_id', $user_id)
  2080. ->limit(5)->get();
  2081. //获取5条单聊未读聊天消息
  2082. $chat = ChatRecords::where('is_read', 0)
  2083. ->where('user_id', $user_id)
  2084. ->where('talk_type', 1)
  2085. ->orderBy('created_at', 'desc')
  2086. ->limit(5)->get();
  2087. //获取5条未读群聊信息
  2088. $chat_group = ChatRecords::where('is_read', 0)
  2089. ->where('user_id', $user_id)
  2090. ->where('talk_type', 2)
  2091. ->orderBy('created_at', 'desc')
  2092. ->limit(5)->get();
  2093. $count = count($chat) + count($chat_group) + count($apply_articale);
  2094. $result = [
  2095. 'apply_articale' => $apply_articale,
  2096. 'chat' => $chat,
  2097. 'chat_group' => $chat_group,
  2098. 'count' => $count,
  2099. ];
  2100. } elseif ($type_id == 3) {
  2101. //最近的5篇已审的文章
  2102. $apply_articale = Article::where('status', 1)
  2103. ->where('admin_user_id', $user_id)
  2104. ->limit(5)->get();
  2105. //获取5条单聊未读聊天消息
  2106. $chat = ChatRecords::where('is_read', 0)
  2107. ->where('user_id', $user_id)
  2108. ->where('talk_type', 1)
  2109. ->orderBy('created_at', 'desc')
  2110. ->limit(5)->get();
  2111. //获取5条未读群聊信息
  2112. $chat_group = ChatRecords::where('is_read', 0)
  2113. ->where('user_id', $user_id)
  2114. ->where('talk_type', 2)
  2115. ->orderBy('created_at', 'desc')
  2116. ->limit(5)->get();
  2117. $count = count($chat) + count($chat_group) + count($apply_articale);
  2118. $result = [
  2119. 'apply_articale' => $apply_articale,
  2120. 'chat' => $chat,
  2121. 'chat_group' => $chat_group,
  2122. 'count' => $count,
  2123. ];
  2124. } elseif ($type_id == 4) {
  2125. //最近的5篇已审的文章
  2126. $apply_articale = Article::where('status', 1)
  2127. ->where('admin_user_id', $user_id)
  2128. ->limit(5)->get();
  2129. $count = count($apply_articale);
  2130. $result = [
  2131. 'apply_articale' => $apply_articale,
  2132. 'count' => $count,
  2133. ];
  2134. } elseif ($type_id == 10000) {
  2135. //获取未审核的5篇文章
  2136. $apply_articale = Article::where('status', 0)
  2137. ->orderBy('updated_at', 'desc')
  2138. ->limit(5)->get();
  2139. //获取5条单聊未读聊天消息
  2140. $chat = ChatRecords::where('is_read', 0)
  2141. ->where('user_id', $user_id)
  2142. ->where('talk_type', 1)
  2143. ->orderBy('created_at', 'desc')
  2144. ->limit(5)->get();
  2145. //获取5条未读群聊信息
  2146. $chat_group = ChatRecords::where('is_read', 0)
  2147. ->where('user_id', $user_id)
  2148. ->where('talk_type', 2)
  2149. ->orderBy('created_at', 'desc')
  2150. ->limit(5)->get();
  2151. $count = count($chat) + count($chat_group) + count($apply_articale);
  2152. $result = [
  2153. 'apply_articale' => $apply_articale,
  2154. 'chat' => $chat,
  2155. 'chat_group' => $chat_group,
  2156. 'count' => $count,
  2157. ];
  2158. } elseif ($type_id == 20000) {
  2159. }
  2160. var_dump($type_id, '-----------------test---------');
  2161. return Result::success($result);
  2162. }
  2163. public function getComplaintList(array $data): array
  2164. {
  2165. $result = Notice::where('status', 1)->get();
  2166. return Result::success($result);
  2167. }
  2168. public function getComplaintInfo(array $data): array
  2169. {
  2170. $result = Notice::where('id', $data['id'])->first();
  2171. if (empty($result)) {
  2172. return Result::error("查询失败", 0);
  2173. }
  2174. return Result::success($result);
  2175. }
  2176. public function addComplaint(array $data): array
  2177. {
  2178. $result = Notice::create($data);
  2179. return Result::success($result);
  2180. }
  2181. public function updateComplaint(array $data): array
  2182. {
  2183. $result = Notice::where('id', $data['id'])->update($data);
  2184. return Result::success($result);
  2185. }
  2186. public function deleteComplaint(array $data): array
  2187. {
  2188. $result = Notice::where('id', $data['id'])->delete();
  2189. return Result::success($result);
  2190. }
  2191. public function getComplainInfo(array $data): array
  2192. {
  2193. $result = Notice::where('id', $data['id'])->first();
  2194. if (empty($result)) {
  2195. return Result::error("查询失败", 0);
  2196. }
  2197. return Result::success($result);
  2198. }
  2199. //20250324 通知,公告,消息
  2200. // 20250306 -------招聘--------fr
  2201. /*
  2202. * 招聘列表
  2203. * */
  2204. public function getJobRecruitingList(array $data): array
  2205. {
  2206. $where = [];
  2207. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2208. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  2209. }
  2210. $user = User::where('id', $data['user_id'])->first();
  2211. if (empty($user)) {
  2212. return Result::error("用户不存在", 0);
  2213. }
  2214. // 3:企业会员
  2215. if ($user['type_id'] == 3) {
  2216. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  2217. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  2218. }
  2219. // 如果 $where 为空,则不添加 where 条件
  2220. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  2221. return $query->where($where);
  2222. })
  2223. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  2224. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  2225. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  2226. ->orderBy("updated_at", "desc")
  2227. ->offset(($data['page'] - 1) * $data['page_size'])
  2228. ->limit($data['page_size'])
  2229. ->get()
  2230. ->all();
  2231. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  2232. return $query->where($where);
  2233. })
  2234. ->count();
  2235. if (empty($result)) {
  2236. return Result::error("暂无招聘信息", 0);
  2237. }
  2238. return Result::success($result);
  2239. }
  2240. /*
  2241. * 招聘信息添加
  2242. * */
  2243. public function addJobRecruiting(array $data): array
  2244. {
  2245. // return Result::success($data);
  2246. $user = User::where('user.id', $data['user_id'])
  2247. ->where('user.status', 1)
  2248. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  2249. ->select(
  2250. 'user.type_id',
  2251. 'user.mobile',
  2252. 'user.email',
  2253. 'user_info.business_name',
  2254. 'user_info.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['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. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  2548. ->select('user.user_name', 'user.type_id', 'user_info.*')
  2549. ->first();
  2550. if (empty($user)) {
  2551. return Result::error("用户不存在", 0);
  2552. }
  2553. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  2554. $company = [
  2555. 'business_name' => $data['business_name'], // 企业名称
  2556. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  2557. 'company_nature' => $data['company_nature'], // 公司性质
  2558. 'company_size' => $data['company_size'], // 公司规模
  2559. 'introduction' => $data['introduction'], // 公司简介
  2560. 'real_name' => $data['real_name'], // 企业联系人
  2561. 'company_url' => $data['company_url'], // 企业网址
  2562. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  2563. 'address' => $data['address'], // 企业详细地址
  2564. ];
  2565. if ($user['type_id'] == 3) {
  2566. $result['user'] = User::where('user.id', $data['user_id'])->update([
  2567. 'mobile' => $data['mobile'], // 企业联系电话
  2568. 'email' => $data['email'], // 企业邮箱
  2569. ]);
  2570. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  2571. 'business_name' => $data['business_name'], // 企业名称
  2572. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  2573. 'company_nature' => $data['company_nature'], // 公司性质
  2574. 'company_size' => $data['company_size'], // 公司规模
  2575. 'introduction' => $data['introduction'], // 公司简介
  2576. 'real_name' => $data['real_name'], // 企业联系人
  2577. 'company_url' => $data['company_url'], // 企业网址
  2578. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  2579. 'address' => $data['address'], // 企业详细地址
  2580. ]);
  2581. $result = JobCompany::where('user_id', $data['user_id'])->update($company);
  2582. } else {
  2583. return Result::error("用户类型错误", 0);
  2584. }
  2585. if (empty($result)) {
  2586. return Result::error("修改失败", 0);
  2587. }
  2588. return Result::success($result);
  2589. }
  2590. /*
  2591. * 获取省-市
  2592. * */
  2593. public function getJobRecruitingArea(array $data): array
  2594. {
  2595. if (isset($data['province_id']) && $data['province_id'] != null) {
  2596. $result = District::where('pid', $data['pid'])->get()->all();
  2597. } else {
  2598. $result = District::where('level', 1)->get()->all();
  2599. }
  2600. if (empty($result)) {
  2601. return Result::error("暂无此省市", 0);
  2602. }
  2603. return Result::success($result);
  2604. }
  2605. /*
  2606. * 获取行业分类
  2607. * */
  2608. public function getIndustry(array $data): array
  2609. {
  2610. $result = JobIndustry::get()->all();
  2611. if (empty($result)) {
  2612. return Result::error("暂无行业分类", 0);
  2613. }
  2614. return Result::success($result);
  2615. }
  2616. /*
  2617. * 获取职位
  2618. * */
  2619. public function getPositionList(array $data): array
  2620. {
  2621. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  2622. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  2623. } else {
  2624. $result = JobPosition::where('zwpid', 0)->get()->all();
  2625. }
  2626. if (empty($result)) {
  2627. return Result::error("暂无此职位", 0);
  2628. }
  2629. return Result::success($result);
  2630. }
  2631. /*
  2632. * 获取工作性质-菜单
  2633. * */
  2634. public function getJobNature(array $data): array
  2635. {
  2636. $result = JobEnum::where('egroup', 'nature')->get()->all();
  2637. if (empty($result)) {
  2638. return Result::error("暂无工作性质", 0);
  2639. }
  2640. return Result::success($result);
  2641. }
  2642. /*
  2643. * 获取工作经验-菜单
  2644. * */
  2645. public function getExperience(array $data): array
  2646. {
  2647. $result = JobEnum::where('egroup', 'years')->get()->all();
  2648. if (empty($result)) {
  2649. return Result::error("暂无工作经验", 0);
  2650. }
  2651. return Result::success($result);
  2652. }
  2653. /*
  2654. * 获取学历-菜单
  2655. * */
  2656. public function getEducation(array $data): array
  2657. {
  2658. $result = JobEnum::where('egroup', 'education')->get()->all();
  2659. if (empty($result)) {
  2660. return Result::error("暂无学历", 0);
  2661. }
  2662. return Result::success($result);
  2663. }
  2664. /*
  2665. * 获取薪资-菜单
  2666. * */
  2667. public function getSalary(array $data): array
  2668. {
  2669. $result = JobEnum::where('egroup', 'income')->get()->all();
  2670. if (empty($result)) {
  2671. return Result::error("暂无薪资", 0);
  2672. }
  2673. return Result::success($result);
  2674. }
  2675. /*
  2676. * 获取语言-菜单
  2677. * */
  2678. public function getLanguage(array $data): array
  2679. {
  2680. $result = JobEnum::where('egroup', 'language')->get()->all();
  2681. if (empty($result)) {
  2682. return Result::error("暂无语言", 0);
  2683. }
  2684. return Result::success($result);
  2685. }
  2686. /*
  2687. * 获取掌握程度-菜单
  2688. * */
  2689. public function getLevel(array $data): array
  2690. {
  2691. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  2692. if (empty($result)) {
  2693. return Result::error("暂无工作性质", 0);
  2694. }
  2695. return Result::success($result);
  2696. }
  2697. // 公司信息
  2698. /*
  2699. * 获取公司性质-菜单
  2700. * */
  2701. public function getCompanyNature(array $data): array
  2702. {
  2703. $result = JobNature::get()->all();
  2704. if (empty($result)) {
  2705. return Result::error("暂无公司性质", 0);
  2706. }
  2707. return Result::success($result);
  2708. }
  2709. /*
  2710. * 获取公司规模-菜单
  2711. * */
  2712. public function getCompanySize(array $data): array
  2713. {
  2714. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  2715. if (empty($result)) {
  2716. return Result::error("暂无公司规模", 0);
  2717. }
  2718. return Result::success($result);
  2719. }
  2720. // 20250306 招聘
  2721. }