NewsService.php 118 KB

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