NewsService.php 238 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291
  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\District;
  9. use App\Model\Good;
  10. use App\Model\JobCompany;
  11. use App\Model\Website;
  12. use App\Model\JobRecruiting;
  13. use App\Model\JobIndustry;
  14. use App\Model\Book;
  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 App\Model\jobResume;
  25. use Hyperf\DbConnection\Db;
  26. use Hyperf\RpcServer\Annotation\RpcService;
  27. use App\Tools\Result;
  28. use Directory;
  29. use Ramsey\Uuid\Uuid;
  30. use Hyperf\Utils\Random;
  31. use Fukuball\Jieba\Jieba;
  32. use Fukuball\Jieba\Finalseg;
  33. use Hyperf\Utils\Collection;
  34. use function Hyperf\Support\retry;
  35. use App\Tools\PublicData;
  36. use App\Model\ChatGroups;
  37. use App\Model\ChatGroupsMember;
  38. use App\Model\ChatRecords;
  39. use App\Model\Complaint;
  40. use Hamcrest\Arrays\IsArray;
  41. use Hyperf\Codec\Json;
  42. use App\Tools\buildMenuTree;
  43. use App\Model\JobApply;
  44. use App\Model\JobHunting;
  45. use App\Model\JobRemuse;
  46. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  47. class NewsService implements NewsServiceInterface
  48. {
  49. /**
  50. * 获取导航池列表
  51. * @param array $data
  52. * @return array
  53. */
  54. public function getCategoryList(array $data): array
  55. {
  56. $search = $data['name'] ?? '';
  57. $page = (int)($data['page'] ?? 1);
  58. $perPage = (int)($data['pageSize'] ?? 10);
  59. // 1. 查出所有匹配的分类id
  60. if ($search) {
  61. $matchedIds = Category::where('name', 'like', "%{$search}%")->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  62. if (empty($matchedIds)) {
  63. return Result::success(['rows' => [], 'total' => 0]);
  64. }
  65. // 2. 递归查所有父级,直到一级分类
  66. $idsStr = implode(',', $matchedIds);
  67. $sql = "
  68. WITH RECURSIVE parents AS (
  69. SELECT * FROM category WHERE id IN ($idsStr)
  70. UNION ALL
  71. SELECT c.* FROM category c
  72. INNER JOIN parents p ON c.id = p.pid
  73. )
  74. SELECT * FROM parents
  75. ";
  76. $parents = Db::select($sql);
  77. $parentIds = [];
  78. foreach ($parents as $row) {
  79. if ($row->pid == 0) {
  80. $parentIds[] = $row->id;
  81. }
  82. }
  83. $parentIds = array_unique($parentIds);
  84. } else {
  85. // 没有搜索,一级分类就是根
  86. $parentIds = Category::where('pid', 0)->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  87. }
  88. // 3. 一级分类分页
  89. $total = count($parentIds);
  90. $parentIds = array_slice($parentIds, ($page - 1) * $perPage, $perPage);
  91. if (empty($parentIds)) {
  92. return Result::success(['rows' => [], 'total' => $total]);
  93. }
  94. // 4. 递归查所有子孙
  95. $idsStr = implode(',', $parentIds);
  96. $sql = "
  97. WITH RECURSIVE subcategories AS (
  98. SELECT * FROM category WHERE id IN ($idsStr)
  99. UNION ALL
  100. SELECT c.* FROM category c
  101. INNER JOIN subcategories s ON c.pid = s.id
  102. )
  103. SELECT * FROM subcategories ORDER BY updated_at DESC
  104. ";
  105. $allCategories = Db::select($sql);
  106. // 5. 组装树结构
  107. $categoryMap = [];
  108. foreach ($allCategories as $cat) {
  109. $cat = (array)$cat;
  110. $cat['children'] = [];
  111. $categoryMap[$cat['id']] = $cat;
  112. }
  113. foreach ($categoryMap as $id => &$cat) {
  114. if ($cat['pid'] && isset($categoryMap[$cat['pid']])) {
  115. $categoryMap[$cat['pid']]['children'][] = &$cat;
  116. }
  117. }
  118. unset($cat);
  119. $categoryTree = [];
  120. foreach ($parentIds as $id) {
  121. if (isset($categoryMap[$id])) {
  122. $categoryTree[] = $categoryMap[$id];
  123. }
  124. }
  125. return Result::success([
  126. 'rows' => $categoryTree,
  127. 'total' => $total,
  128. ]);
  129. }
  130. private function findMatchedCategories($search)
  131. {
  132. if ($search) {
  133. return Category::where('name', 'like', "%{$search}%")
  134. ->orderBy('updated_at', 'desc')
  135. ->get();
  136. }
  137. return Category::orderBy('updated_at', 'desc') // 按 updated_at 字段倒序排序
  138. ->get();
  139. }
  140. private function findAllParents($categories)
  141. {
  142. $allCategories = [];
  143. foreach ($categories as $category) {
  144. $parentId = $category->pid;
  145. while ($parentId > 0) {
  146. $parent = Category::find($parentId);
  147. if ($parent) {
  148. $allCategories[$parent->id] = $parent;
  149. $parentId = $parent->pid;
  150. } else {
  151. break;
  152. }
  153. }
  154. $allCategories[$category->id] = $category;
  155. }
  156. return array_values($allCategories);
  157. }
  158. private function buildCategoryTree($category, $allRequiredCategories)
  159. {
  160. $categoryData = $category->toArray();
  161. $children = [];
  162. foreach ($allRequiredCategories as $c) {
  163. if ($c->pid === $category->id) {
  164. $children[] = $this->buildCategoryTree($c, $allRequiredCategories);
  165. }
  166. }
  167. if (!empty($children)) {
  168. $categoryData['children'] = $children;
  169. }
  170. return $categoryData;
  171. }
  172. public function myCategoryList(array $data): array
  173. {
  174. $sszq = $data['sszq'] ?? '';
  175. unset($data['sszq']);
  176. //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
  177. $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
  178. $where[] = [
  179. 'pid',
  180. '=',
  181. $data['pid'],
  182. ];
  183. if (isset($data['name'])) {
  184. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  185. }
  186. var_dump($where);
  187. //根据分类id,从category表中取出分类信息
  188. $result = Category::where($where)
  189. ->whereIn('category.id', $catorytids)
  190. ->select('category.*', 'category.id as category_id')->get();
  191. if (empty($result)) {
  192. return Result::error("没有栏目数据");
  193. }
  194. return Result::success($result);
  195. }
  196. /**
  197. * @param array $data
  198. * @return array
  199. */
  200. public function categoryList(array $data): array
  201. {
  202. $where[] = [
  203. 'pid',
  204. '=',
  205. $data['pid']
  206. ];
  207. if (isset($data['name'])) {
  208. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  209. }
  210. var_dump($where);
  211. $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
  212. if (empty($result)) {
  213. return Result::error("没有栏目数据");
  214. }
  215. return Result::success($result);
  216. }
  217. /**
  218. * @param array $data
  219. * @return array
  220. */
  221. public function addCategory(array $data): array
  222. {
  223. if (isset($data['id'])) {
  224. unset($data['id']);
  225. }
  226. $id = Category::insertGetId($data);
  227. if (empty($id)) {
  228. return Result::error("添加失败");
  229. }
  230. return Result::success(['id' => $id]);
  231. }
  232. /**
  233. * @param array $data
  234. * @return array
  235. */
  236. public function delCategory(array $data): array
  237. {
  238. Db::beginTransaction();
  239. try {
  240. $categoryList = Category::where(['pid' => $data['id']])->get();
  241. if ($categoryList->toArray()) {
  242. Db::rollBack();
  243. return Result::error("分类下面有子分类不能删除");
  244. }
  245. $articleList = Article::where(['catid' => $data['id']])->get();
  246. if ($articleList->toArray()) {
  247. Db::rollBack();
  248. return Result::error("分类下面有资讯不能删除");
  249. }
  250. $result = Category::where($data)->delete();
  251. WebsiteCategory::where(['category_id' => $data['id']])->delete();
  252. if (!$result) {
  253. return Result::error("删除失败");
  254. }
  255. return Result::success($result);
  256. Db::commit();
  257. } catch (\Exception $e) {
  258. Db::rollBack();
  259. return Result::error("删除失败");
  260. }
  261. }
  262. /**
  263. * @param array $data
  264. * @return array
  265. */
  266. public function updateCategory(array $data): array
  267. {
  268. $where = [
  269. 'id' => $data['id'],
  270. ];
  271. $result = Category::where($where)->update($data);
  272. if ($result) {
  273. return Result::success($result);
  274. } else {
  275. return Result::error("更新失败");
  276. }
  277. }
  278. /**
  279. * 获取导航池信息
  280. * @param array $data
  281. * @return array
  282. */
  283. public function getCategoryInfo(array $data): array
  284. {
  285. $where = [
  286. 'id' => $data['id'],
  287. ];
  288. $result = Category::where($where)->first();
  289. if ($result) {
  290. return Result::success($result);
  291. } else {
  292. return Result::error("更新失败");
  293. }
  294. }
  295. /**
  296. * @param array $data
  297. * @return array
  298. */
  299. public function getArticleList(array $data): array
  300. {
  301. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  302. $type_id = $data['type_id'];
  303. unset($data['type_id']);
  304. $user_id = $data['user_id'];
  305. unset($data['user_id']);
  306. $where = [];
  307. $status1 = [];
  308. if (isset($data['id']) && $data['id']) {
  309. array_push($where, ['article.id', '=', $data['id']]);
  310. }
  311. if (isset($data['title']) && $data['title']) {
  312. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  313. }
  314. if (isset($data['category_name']) && $data['category_name']) {
  315. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  316. }
  317. if (isset($data['author']) && $data['author']) {
  318. array_push($where, ['article.author', '=', $data['author']]);
  319. }
  320. if (isset($data['islink']) && $data['islink'] !== "") {
  321. array_push($where, ['article.islink', '=', $data['islink']]);
  322. }
  323. if (isset($data['status']) && $data['status'] !== "") {
  324. array_push($where, ['article.status', '=', $data['status']]);
  325. }
  326. if (isset($data['status1'])) {
  327. $status1 = json_decode(($data['status1']));
  328. }
  329. //不是管理员展示个人数据;
  330. if ($type_id != 10000) {
  331. $where[] = ['article.admin_user_id', '=', $user_id];
  332. }
  333. $rep = Article::where($where)
  334. ->whereNotIn('article.status', [404])
  335. ->when($status1, function ($query) use ($status1) {
  336. if (isset($status1) && $status1) {
  337. $query->whereIn('article.status', $status1);
  338. }
  339. })
  340. ->leftJoin('category', 'article.catid', 'category.id')
  341. ->leftJoin('website_category', function ($join) {
  342. $join->on('article.web_site_id', '=', 'website_category.website_id')
  343. ->on('article.catid', '=', 'website_category.category_id');
  344. })
  345. ->select("article.*", "category.name as category_name", "website_category.alias")
  346. ->orderBy("article.updated_at", "desc")
  347. ->limit($data['pageSize'])
  348. ->offset(($data['page'] - 1) * $data['pageSize'])->get();
  349. $count = Article::where($where)->whereNotIn('article.status', [404])
  350. ->when($status1, function ($query) use ($status1) {
  351. if (isset($status1) && $status1) {
  352. $query->whereIn('article.status', $status1);
  353. }
  354. })
  355. ->leftJoin('category', 'article.catid', 'category.id')->count();
  356. $data = [
  357. 'rows' => $rep->toArray(),
  358. 'count' => $count,
  359. ];
  360. if (empty($rep)) {
  361. return Result::error("没有信息数据");
  362. }
  363. return Result::success($data);
  364. }
  365. /**
  366. * @param array $data
  367. * @return array
  368. */
  369. public function addArticle(array $data): array
  370. {
  371. var_dump($data, '----------12-----------1');
  372. unset($data['user_type']);
  373. unset($data['nav_add_pool_id']);
  374. // unset($data['commend_id']);
  375. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  376. Db::beginTransaction();
  377. try {
  378. //处理投票
  379. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  380. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  381. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  382. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  383. unset($data['is_survey']);
  384. unset($data['survey_name']);
  385. unset($data['suvey_array']);
  386. // unset($data['website_id']);
  387. // unset($data['web_site_id']);
  388. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  389. if ($data['hits'] == '') {
  390. $data['hits'] = 0;
  391. }
  392. if ($data['is_original'] == '') {
  393. $data['is_original'] = 0;
  394. }
  395. if ($data['status'] == '') {
  396. $data['status'] = 0;
  397. }
  398. $articleData = $data;
  399. unset($articleData['content']);
  400. //自动处理缩略图、关键字、描述
  401. if ($articleData['imgurl'] == '') {
  402. //如果没有图,设置level=0
  403. $levelArr = json_decode($articleData['level'], true);
  404. var_dump($levelArr, '----------levelArr-----------1');
  405. //content中提取图片第一个图,正则提取
  406. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  407. preg_match_all($reg, $data['content'], $matches);
  408. if (isset($matches[1][0])) {
  409. //截取varchar240
  410. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  411. //如果有图,设置level=3
  412. if (!in_array(3, $levelArr)) {
  413. $levelArr[] = 3;
  414. }
  415. $articleData['level'] = json_encode($levelArr);
  416. } else {
  417. if (!in_array(0, $levelArr)) {
  418. $levelArr[] = 0;
  419. }
  420. $articleData['level'] = json_encode($levelArr);
  421. }
  422. }
  423. var_dump($articleData['level'], '----------$articleData[level]----------1');
  424. if ($articleData['keyword'] == '') {
  425. //提取标题+内容中的关键词
  426. $articleData['keyword'] = $data['title'];
  427. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  428. Jieba::init(); // 初始化 jieba-php
  429. Finalseg::init();
  430. $segList = Jieba::cut($articleData['keyword']);
  431. $segList1 = array_slice($segList, 0, 8);
  432. $articleData['keyword'] = implode(',', $segList1);
  433. }
  434. if ($articleData['introduce'] == '') {
  435. //提取内容中的描述
  436. $articleData['introduce'] = substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
  437. }
  438. $id = Article::insertGetId($articleData);
  439. $articleDataContent = [
  440. 'article_id' => $id,
  441. 'content' => $data['content'],
  442. ];
  443. ArticleData::insertGetId($articleDataContent);
  444. //处理投票
  445. if ($is_survey == 1) {
  446. //生成年月日时分秒+8位随机数
  447. $uuid = date('YmdHis') . rand(10000000, 99999999);
  448. var_dump($suvey_array, 'suvey_array________');
  449. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  450. var_dump($suveys_array, '---------------------1');
  451. var_dump($suvey_array, '---------------------2');
  452. $suvey_data = [];
  453. foreach ($suveys_array as $key => $value) {
  454. if ($value == '') {
  455. continue;
  456. }
  457. if (is_array($value)) {
  458. $suvey_data[] = [
  459. 'sur_id' => $uuid,
  460. 'art_id' => $id,
  461. 'website_id' => $website_id ?? 2,
  462. 'survey_name' => $survey_name,
  463. 'choice_name' => $value[1],
  464. 'is_other' => 1,
  465. 'other_id' => 0,
  466. 'results' => 0,
  467. ];
  468. } else {
  469. $suvey_data[] = [
  470. 'sur_id' => $uuid,
  471. 'art_id' => $id,
  472. 'website_id' => $website_id ?? 2,
  473. 'survey_name' => $survey_name,
  474. 'choice_name' => $value,
  475. 'is_other' => 0,
  476. 'other_id' => 0,
  477. 'results' => 0,
  478. ];
  479. }
  480. if (empty($suvey_data)) {
  481. throw new \Exception("投票数据为空");
  482. }
  483. }
  484. $result = ArticleSurvey::insert($suvey_data);
  485. if (!$result) {
  486. throw new \Exception("投票失败,ArticleSurvey插入失败");
  487. }
  488. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  489. if (!$result) {
  490. throw new \Exception("投票失败,更新主表失败");
  491. }
  492. }
  493. Db::commit();
  494. return Result::success(['id' => $id]);
  495. } catch (\Throwable $ex) {
  496. Db::rollBack();
  497. var_dump($ex->getMessage());
  498. return Result::error("创建失败", 0);
  499. }
  500. }
  501. /**
  502. * @param array $data
  503. * @return array
  504. */
  505. public function delArticle(array $data): array
  506. {
  507. $result = Article::where($data)->delete();
  508. //survey投票删除
  509. articleSurvey::where(['art_id' => $data['id']])->delete();
  510. if (!$result) {
  511. return Result::error("删除失败");
  512. }
  513. return Result::success($result);
  514. }
  515. /**
  516. * @param array $data
  517. * @return array
  518. */
  519. public function updateArticle(array $data): array
  520. {
  521. var_dump($data, '----------12-----------1');
  522. Db::beginTransaction();
  523. unset($data['user_type']);
  524. // unset($data['web_site_id']);
  525. unset($data['nav_add_pool_id']);
  526. try {
  527. //处理投票
  528. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  529. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  530. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  531. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  532. unset($data['is_survey']);
  533. unset($data['survey_name']);
  534. unset($data['suvey_array']);
  535. unset($data['website_id']);
  536. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  537. if ($data['hits'] == '') {
  538. $data['hits'] = 0;
  539. }
  540. if ($data['is_original'] == '') {
  541. $data['is_original'] = 0;
  542. }
  543. if ($data['status'] == '') {
  544. $data['status'] = 0;
  545. }
  546. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  547. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  548. $articleData = $data;
  549. unset($articleData['content']);
  550. unset($articleData['status_name']);
  551. unset($articleData['name']);
  552. unset($articleData['content']);
  553. unset($articleData['pid_arr']);
  554. unset($articleData['pid']);
  555. //自动处理缩略图、关键字、描述
  556. if ($articleData['imgurl'] == '') {
  557. //如果没有图,设置level=0
  558. $levelArr = json_decode($articleData['level'], true);
  559. var_dump($levelArr, '----------levelArr-----------1');
  560. //content中提取图片第一个图,正则提取
  561. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  562. preg_match_all($reg, $data['content'], $matches);
  563. if (isset($matches[1][0])) {
  564. //截取varchar240
  565. // 截取到第一个<
  566. $articleData['imgurl'] = $matches[1][0];
  567. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  568. $pos = strpos($articleData['imgurl'], '"');
  569. if ($pos !== false) {
  570. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  571. }
  572. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  573. //如果有图,设置level=3
  574. if (!in_array(3, $levelArr)) {
  575. $levelArr[] = 3;
  576. }
  577. $articleData['level'] = json_encode($levelArr);
  578. } else {
  579. if (!in_array(0, $levelArr)) {
  580. $levelArr[] = 0;
  581. }
  582. $articleData['level'] = json_encode($levelArr);
  583. }
  584. }
  585. var_dump($articleData['level'], '----------$articleData[level]----------1');
  586. if ($articleData['keyword'] == '') {
  587. //提取标题+内容中的关键词
  588. $articleData['keyword'] = $data['title'];
  589. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  590. Jieba::init(); // 初始化 jieba-php
  591. Finalseg::init();
  592. $segList = Jieba::cut($articleData['keyword']);
  593. $segList1 = array_slice($segList, 0, 8);
  594. $articleData['keyword'] = implode(',', $segList1);
  595. }
  596. if ($articleData['introduce'] == '') {
  597. //提取内容中的描述
  598. $articleData['introduce'] = substr(preg_replace('/\s+/', '', strip_tags($data['content'])), 0, 100);
  599. // substr(str_replace(' ', '', strip_tags($data['content'])), 0, 100);
  600. }
  601. $id = Article::where(['id' => $data['id']])->update($articleData);
  602. $articleDataContent = [
  603. 'content' => $data['content'],
  604. ];
  605. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  606. //处理投票
  607. $id = $data['id'];
  608. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  609. var_dump($suvey_array, 'suvey_array________delete');
  610. //处理投票
  611. if ($is_survey == 1) {
  612. //生成年月日时分秒+8位随机数
  613. $uuid = date('YmdHis') . rand(10000000, 99999999);
  614. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  615. var_dump($suveys_array, '---------------------1');
  616. $suvey_data = [];
  617. if (is_array($suveys_array)) {
  618. foreach ($suveys_array as $key => $value) {
  619. if ($value == '') {
  620. continue;
  621. }
  622. if (is_array($value)) {
  623. $suvey_data[] = [
  624. 'sur_id' => $uuid,
  625. 'art_id' => $id,
  626. 'website_id' => $website_id ?? 2,
  627. 'survey_name' => $survey_name,
  628. 'choice_name' => $value[1],
  629. 'is_other' => 1,
  630. 'other_id' => 0,
  631. 'results' => 0,
  632. ];
  633. } else {
  634. $suvey_data[] = [
  635. 'sur_id' => $uuid,
  636. 'art_id' => $id,
  637. 'website_id' => $website_id ?? 2,
  638. 'survey_name' => $survey_name,
  639. 'choice_name' => $value,
  640. 'is_other' => 0,
  641. 'other_id' => 0,
  642. 'results' => 0,
  643. ];
  644. }
  645. if (empty($suvey_data)) {
  646. throw new \Exception("投票数据为空");
  647. }
  648. }
  649. }
  650. $result = ArticleSurvey::insert($suvey_data);
  651. if (!$result) {
  652. throw new \Exception("投票失败");
  653. }
  654. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  655. if (!$result) {
  656. throw new \Exception("投票失败");
  657. }
  658. } else {
  659. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  660. }
  661. Db::commit();
  662. return Result::success([]);
  663. } catch (\Throwable $ex) {
  664. Db::rollBack();
  665. var_dump($ex->getMessage());
  666. return Result::error("更新失败" . $ex->getMessage(), 0);
  667. }
  668. }
  669. /**
  670. * 更新资讯状态
  671. * @param array $data
  672. * @return array
  673. */
  674. public function upArticleStatus(array $data): array
  675. {
  676. $result = Article::where(['id' => $data['id']])->update($data);
  677. if ($result) {
  678. return Result::success();
  679. } else {
  680. return Result::error("更新状态失败", 0);
  681. }
  682. }
  683. /**
  684. * 获取新闻详情
  685. * @param array $data
  686. * @return array
  687. */
  688. public function getArticleInfo(array $data): array
  689. {
  690. $where = [
  691. 'article.id' => $data['id'],
  692. // 'article.status' => 1,
  693. ];
  694. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  695. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  696. $info = $result;
  697. // var_dump($info, 'info');
  698. $info['survey_array'] = $articleSurvey;
  699. if ($result) {
  700. return Result::success($info);
  701. } else {
  702. return Result::error("查询失败", 0);
  703. }
  704. }
  705. /**
  706. * 获取头条新闻
  707. * @param array $data
  708. * @return array
  709. */
  710. public function getWebsiteArticlett(array $data): array
  711. {
  712. // return Result::success($data['website_id']);
  713. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
  714. $category = array_values(array_unique($category->toArray()));
  715. $web['website_id'] = $data['website_id'];
  716. if ($category) {
  717. $where = [
  718. 'status' => 1,
  719. ];
  720. var_dump($data, 'data-----------------');
  721. // level=7 根据文章key来匹配文章
  722. if (isset($data['level']) && $data['level'] == 7) {
  723. // 根据文章id获取key
  724. // $data['id'] = 50142;
  725. if (isset($data['id']) && !empty($data['id'])) {
  726. $keyword = Article::where('id', $data['id'])->value('keyword');
  727. $keywordArray = explode(',', $keyword);
  728. $whereL7 = [];
  729. foreach ($keywordArray as $k => $v) {
  730. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  731. }
  732. // 原始查询
  733. $result['level7'] = Article::where($whereL7)
  734. ->when(!empty($data['imgnum']), function ($query) use ($data) {
  735. $query->where('article.imgurl', '!=', '')
  736. ->select('article.*')
  737. ->offset($data['placeid'])
  738. ->limit($data['imgnum']);
  739. })
  740. ->when(!empty($data['textnum']), function ($query) use ($data) {
  741. $query->select('article.*')
  742. ->offset($data['placeid'])
  743. ->limit($data['textnum']);
  744. })
  745. ->orderBy('updated_at', 'desc')
  746. ->get();
  747. $result['level7'] = $this->processArticle($result['level7'], $web);
  748. if (empty($result)) {
  749. return Result::success();
  750. }
  751. return Result::success($result);
  752. } else {
  753. return Result::error("参数错误level=7,id不能为空", 0);
  754. }
  755. }
  756. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  757. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  758. var_dump($where, 'where-----------------');
  759. // 初始化基础查询
  760. $query = Article::where($where)
  761. ->whereIn("catid", $category)
  762. ->where(function ($query) use ($data) {
  763. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  764. ->orWhereNull("ignore_ids");
  765. });
  766. // 处理 level 相关查询条件
  767. $query->when($data['level'] == 5, function ($query) {
  768. $query->inRandomOrder()
  769. ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  770. })->when($data['level'] == 4, function ($query) {
  771. $query->orderBy("article.updated_at", "desc");
  772. })->when(!empty($data['level']), function ($query) use ($data) {
  773. if ($data['level'] != 4 && $data['level'] != 5) {
  774. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  775. ->orderBy("article.updated_at", "desc");
  776. }
  777. });
  778. // 初始化结果数组
  779. $result = [];
  780. // $input = $data['website_id'];
  781. // 处理图片新闻查询
  782. if (!empty($data['imgnum'])) {
  783. // 原错误提示表明 cleanBindings 方法需要传入数组类型的参数,而实际传入了 null。
  784. // 这里克隆查询构建器,确保绑定参数为数组,避免该错误。
  785. $imgQuery = clone $query;
  786. if ($imgQuery->getBindings() === null) {
  787. $imgQuery->setBindings([]);
  788. }
  789. $result['img'] = $imgQuery->where('article.imgurl', '!=', '')
  790. ->select(
  791. 'article.id',
  792. 'article.title',
  793. 'article.imgurl',
  794. 'article.author',
  795. 'article.updated_at',
  796. 'article.introduce',
  797. 'article.islink',
  798. 'article.linkurl',
  799. 'article.copyfrom',
  800. 'article.cat_arr_id',
  801. 'article.catid'
  802. )
  803. ->offset($data['placeid'])
  804. ->limit($data['imgnum'])
  805. ->get();
  806. $result['img'] = $this->processArticles($result['img'], $web);
  807. }
  808. // 处理文字新闻查询
  809. if (!empty($data['textnum'])) {
  810. $textQuery = clone $query;
  811. $result['text'] = $textQuery
  812. ->select(
  813. 'article.id',
  814. 'article.title',
  815. 'article.imgurl',
  816. 'article.author',
  817. 'article.updated_at',
  818. 'article.introduce',
  819. 'article.islink',
  820. 'article.linkurl',
  821. 'article.copyfrom',
  822. 'article.cat_arr_id',
  823. 'article.catid'
  824. )
  825. ->offset($data['placeid'])
  826. ->limit($data['textnum'])
  827. ->get();
  828. $result['text'] = $this->processArticles($result['text'], $web);
  829. }
  830. if (empty($result) || count($result) == 0) {
  831. return Result::error("暂无头条新闻");
  832. }
  833. return Result::success($result);
  834. } else {
  835. return Result::error("本网站下暂无相关栏目", 0);
  836. }
  837. }
  838. /**
  839. * 获取模块新闻
  840. * @param array $data
  841. * @return array
  842. */
  843. public function getWebsiteModelArticles(array $data): array
  844. {
  845. $catid = $data['catid'];
  846. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  847. $category = $category->toArray();
  848. if (!empty($category)) {
  849. $where = [
  850. 'status' => 1,
  851. 'catid' => $catid,
  852. ];
  853. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  854. // 1:文字新闻;2:轮播图;3:图文;
  855. // 级别:0:未分类
  856. // 3:推荐图片
  857. if ($data['level'] == 1) {
  858. $data['level'] = 0;
  859. }
  860. $result = Article::where($where)
  861. ->where(function ($query) use ($data) {
  862. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  863. ->orWhereNull("level")
  864. ->orWhereRaw("level = '[]'");
  865. })
  866. ->where(function ($query) use ($data) {
  867. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  868. ->orWhereNull("ignore_ids");
  869. })
  870. ->orderBy("updated_at", "desc")
  871. ->offset($placeid)
  872. ->limit($data['pagesize'])
  873. ->get();
  874. if (empty($result)) {
  875. return Result::error("此栏目暂无相关新闻", 0);
  876. }
  877. } else {
  878. return Result::error("此网站暂无此栏目", 0);
  879. }
  880. return Result::success($result);
  881. }
  882. /**
  883. *获取新闻列表
  884. * @param array $data
  885. * @return array
  886. */
  887. public function getWebsiteArticleList(array $data): array
  888. {
  889. // return Result::success($data);
  890. $where[] = ['status', '=', 1];
  891. if (isset($data['catid']) && !empty($data['catid'])) {
  892. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  893. array_push($where, ['catid', '=', $data['catid']]);
  894. if (empty($category)) {
  895. return Result::error("此网站暂无此栏目", 0);
  896. }
  897. }
  898. // return Result::success($where);
  899. $rep = Article::where($where)
  900. ->where(function ($query) use ($data) {
  901. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  902. ->orWhereNull("ignore_ids");
  903. })
  904. ->select(
  905. 'article.id',
  906. 'article.title',
  907. 'article.imgurl',
  908. 'article.author',
  909. 'article.updated_at',
  910. 'article.introduce',
  911. 'article.islink',
  912. 'article.linkurl',
  913. 'article.copyfrom',
  914. 'article.cat_arr_id',
  915. 'article.catid'
  916. )
  917. ->orderBy("updated_at", "desc")
  918. ->offset(($data['page'] - 1) * $data['pageSize'])
  919. ->limit($data['pageSize'])
  920. ->get();
  921. $web['website_id'] = $data['website_id'];
  922. $rep = $this->processArticles($rep, $web);
  923. $count = Article::where($where)
  924. ->where(function ($query) use ($data) {
  925. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  926. ->orWhereNull("ignore_ids");
  927. })->count();
  928. $data = [
  929. 'rows' => $rep->toArray(),
  930. 'count' => $count,
  931. ];
  932. if (empty($rep)) {
  933. return Result::error("没有信息数据");
  934. }
  935. return Result::success($data);
  936. }
  937. /**
  938. * 前端-获取新闻详情
  939. * @param array $data
  940. * @return array
  941. */
  942. public function selectWebsiteArticleInfo(array $data): array
  943. {
  944. $where = [
  945. 'article.id' => $data['id'],
  946. 'article.status' => 1,
  947. ];
  948. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")
  949. ->where(function ($query) use ($data) {
  950. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  951. ->orWhereNull("ignore_ids");
  952. })
  953. ->first();
  954. if (empty($result)) {
  955. return Result::error("暂无此新闻!", 0);
  956. }
  957. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  958. ->select('website_category.*', 'website.website_name', 'website.suffix')
  959. ->where('website_category.website_id', $data['website_id'])
  960. ->where(['website_category.category_id' => $result['catid']])
  961. ->first();
  962. if (empty($category)) {
  963. return Result::error("查询失败", 0);
  964. }
  965. //手动推荐文章
  966. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  967. $commendArticle = Article::whereIn('id', $commend_ids)
  968. ->where('status', 1)
  969. ->select('id', 'title', 'catid', 'imgurl', 'hits', 'created_at')
  970. ->orderBy('updated_at', 'desc')
  971. ->limit(5)
  972. ->get();
  973. $result['category_id'] = $category['category_id'];
  974. $result['cat_name'] = $category['alias'];
  975. $result['website_name'] = $category['website_name'] ?? "";
  976. $result['suffix'] = $category['suffix'] ?? "";
  977. $result['commendArticle'] = $commendArticle;
  978. return Result::success($result);
  979. }
  980. /**
  981. * 前端-获取网站调查问卷
  982. * @param array $data
  983. * @return array
  984. */
  985. public function getWebsiteSurvey(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. }
  993. if (isset($data['art_id']) && !empty($data['art_id'])) {
  994. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  995. if (empty($article)) {
  996. return Result::error("暂无此文章", 0);
  997. }
  998. // return Result::error($data,0);
  999. $where['art_id'] = $data['art_id'];
  1000. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1001. } else {
  1002. $survey = Article::where(function ($query) {
  1003. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1004. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1005. })
  1006. ->where('status', 1)
  1007. ->where('is_survey', 1)
  1008. ->select('survey_id')
  1009. ->orderBy('updated_at', 'desc')
  1010. ->first();
  1011. if (empty($survey)) {
  1012. return Result::error("暂无调查问卷", 0);
  1013. }
  1014. $where['sur_id'] = $survey['survey_id'];
  1015. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1016. }
  1017. // return Result::success($where);
  1018. $result = ArticleSurvey::where($where)
  1019. ->where(function ($query) {
  1020. $query->where('is_other', 0)
  1021. ->orWhere(function ($subQuery) {
  1022. $subQuery->where('is_other', 1)
  1023. ->where('other_id', 0);
  1024. });
  1025. })
  1026. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1027. ->select('article_survey.*', 'article.survey_type')
  1028. ->get()->all();
  1029. if (empty($result)) {
  1030. return Result::error("此文章暂无调查问卷", 0);
  1031. }
  1032. return Result::success($result);
  1033. }
  1034. /**
  1035. * 前端-添加网站调查问卷选项
  1036. * @param array $data
  1037. * @return array
  1038. */
  1039. public function addWebsiteSurveyOption(array $data): array
  1040. {
  1041. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1042. $website = Website::where('id', $data['website_id'])->first();
  1043. if (empty($website)) {
  1044. return Result::error("暂无此网站", 0);
  1045. }
  1046. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1047. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1048. if (empty($survey)) {
  1049. return Result::error("此调查问卷不可添加选项", 0);
  1050. }
  1051. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1052. $choice = [
  1053. 'art_id' => $survey['art_id'],
  1054. 'website_id' => $data['website_id'],
  1055. 'survey_name' => $survey['survey_name'],
  1056. 'choice_name' => $data['choice_name'],
  1057. 'sur_id' => $survey['sur_id'],
  1058. 'is_other' => 1,
  1059. 'other_id' => $survey['id'],
  1060. ];
  1061. $result = ArticleSurvey::insertGetId($choice);
  1062. if (empty($result)) {
  1063. return Result::error("添加失败", 0);
  1064. }
  1065. return Result::success($result);
  1066. }
  1067. }
  1068. return Result::error("添加失败", 0);
  1069. }
  1070. return Result::error("添加失败", 0);
  1071. }
  1072. /**
  1073. * 前端-调查问卷投票
  1074. * @param array $data
  1075. * @return array
  1076. */
  1077. public function addWebsiteSurveyVote(array $data): array
  1078. {
  1079. // return Result::success($data);
  1080. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1081. $website = Website::where('id', $data['website_id'])->first();
  1082. if (empty($website)) {
  1083. return Result::error("暂无此网站", 0);
  1084. }
  1085. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1086. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1087. // return Result::success($survey);
  1088. if (empty($is_survey)) {
  1089. return Result::error("此调查问卷不存在", 0);
  1090. }
  1091. // return Result::success($survey);
  1092. // 调查问卷类型
  1093. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1094. //多选 若是json型则转化成数组类型
  1095. if (strpos($data['choice_id'], '[') === 0) {
  1096. $data['choice_id'] = json_decode($data['choice_id'], true);
  1097. } else {
  1098. // 单选 也转换成数组
  1099. $data['choice_id'] = [$data['choice_id']];
  1100. }
  1101. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1102. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1103. // ->where('website_id',$data['website_id'])
  1104. ->where('is_other', 1)
  1105. ->where('other_id', 0)
  1106. ->first();
  1107. if (!empty($other)) {
  1108. return Result::error("请选择已有的选项!", 0);
  1109. }
  1110. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1111. // ->where('website_id',$data['website_id'])
  1112. ->where('is_other', 1)
  1113. ->where('other_id', '!=', 0)
  1114. ->first();
  1115. // return Result::success($choice['other']);
  1116. $choice_id = $data['choice_id'];
  1117. if (!empty($choice['other'])) {
  1118. // array_push($data['choice_id'],$choice['other']['other_id']);
  1119. if (!empty($choice_id)) {
  1120. $key = array_search($choice['other']['id'], $choice_id);
  1121. if ($key !== false) {
  1122. unset($choice_id[$key]);
  1123. $choice_id = array_values($choice_id);
  1124. }
  1125. array_push($choice_id, $choice['other']['other_id']);
  1126. } else {
  1127. $choice_id[0] = $choice['other']['other_id'];
  1128. }
  1129. array_push($data['choice_id'], $choice['other']['other_id']);
  1130. }
  1131. // return Result::success($data);
  1132. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1133. // ->where('website_id',$data['website_id'])
  1134. ->increment('results', 1);
  1135. if (empty($choice)) {
  1136. return Result::error("请选择已有的选项!", 0);
  1137. }
  1138. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1139. // ->where('website_id',$data['website_id'])
  1140. ->where('other_id', 0)
  1141. ->get();
  1142. $survey['choice'] = $choice_id;
  1143. return Result::success($survey);
  1144. }
  1145. return Result::error("参数必填!");
  1146. }
  1147. return Result::error("此调查问卷不存在", 0);
  1148. }
  1149. return Result::error("参数必填!");
  1150. }
  1151. /**
  1152. * 后端-获取网站调查问卷列表
  1153. * @param array $data
  1154. * @return array
  1155. */
  1156. public function getSurveyList(array $data): array
  1157. {
  1158. $where = [];
  1159. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1160. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1161. }
  1162. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  1163. array_push($where, ['survey_type', '=', $data['survey_type']]);
  1164. }
  1165. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  1166. array_push($where, ['is_survey', '=', $data['is_survey']]);
  1167. }
  1168. // return Result::success($where);
  1169. if (!empty($where)) {
  1170. $query = Article::where($where)->where(function ($q) {
  1171. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1172. });
  1173. } else {
  1174. $query = Article::where(function ($q) {
  1175. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1176. });
  1177. }
  1178. $count = $query->count();
  1179. $survey = $query->orderByDesc('id')
  1180. ->limit($data['pageSize'])
  1181. ->offset(($data['page'] - 1) * $data['pageSize'])
  1182. ->get();
  1183. if (empty($survey->toArray())) {
  1184. return Result::error("暂无调查问卷!", 0);
  1185. }
  1186. $result = [
  1187. 'rows' => $survey,
  1188. 'count' => $count,
  1189. ];
  1190. return Result::success($result);
  1191. }
  1192. /**
  1193. * 后端-获取网站调查问卷详情
  1194. * @param array $data
  1195. * @return array
  1196. */
  1197. public function getSurveyInfo(array $data): array
  1198. {
  1199. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1200. $where = ['sur_id' => $data['sur_id']];
  1201. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1202. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1203. ->select('article_survey.*', 'article.survey_type')
  1204. ->get()->all();
  1205. if (empty($choose)) {
  1206. return Result::error("此调查问卷不存在", 0);
  1207. }
  1208. $resultsArray = array_column($choose, 'results');
  1209. $total = array_sum($resultsArray);
  1210. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1211. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1212. // $total = 0;
  1213. if (!empty($other)) {
  1214. $total = $total + $other['results'];
  1215. $other['choice_name'] = '(其他)';
  1216. if (!empty($others)) {
  1217. $other['hasChildren'] = true;
  1218. // array_push($other,['hasChildren','=',true]);
  1219. $other['children'] = $others;
  1220. $other_choices = [$other->toArray()];
  1221. $mer_choice = array_merge($choose, $other_choices);
  1222. $value_choice = array_values($mer_choice);
  1223. } else {
  1224. // return Result::error('1111');
  1225. $other_choices = [$other->toArray()];
  1226. $other_choices = array_merge($choose, $other_choices);
  1227. $value_choice = array_values($other_choices);
  1228. // return Result::success($result);
  1229. }
  1230. } else {
  1231. $value_choice = $choose;
  1232. }
  1233. $result = [
  1234. 'choose' => $value_choice,
  1235. 'total' => $total,
  1236. ];
  1237. }
  1238. return Result::success($result);
  1239. }
  1240. /**
  1241. * 前端-搜索新闻列表
  1242. * @param array $data
  1243. * @return array
  1244. */
  1245. public function selectWebsiteArticle(array $data): array
  1246. {
  1247. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
  1248. $query = Article::where('status', 1)
  1249. ->whereIn('catid', $category)
  1250. ->where(function ($query) use ($data) {
  1251. $query->where(function ($subQuery) use ($data) {
  1252. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1253. })->orWhereNull("ignore_ids");
  1254. });
  1255. // return Result::success($all_articles);
  1256. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1257. $query->whereRaw("JSON_CONTAINS(city_arr_id, '" . intval($data['cityid']) . "')");
  1258. }
  1259. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1260. $query->whereRaw("JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "')");
  1261. }
  1262. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1263. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  1264. }
  1265. // 计算总数
  1266. $count = $query->count();
  1267. // 分页查询
  1268. $articles = $query
  1269. ->select(
  1270. 'article.id',
  1271. 'article.title',
  1272. 'article.imgurl',
  1273. 'article.author',
  1274. 'article.updated_at',
  1275. 'article.introduce',
  1276. 'article.islink',
  1277. 'article.linkurl',
  1278. 'article.copyfrom',
  1279. 'article.cat_arr_id',
  1280. 'article.catid',
  1281. 'article.department_arr_id',
  1282. 'article.city_arr_id',
  1283. )
  1284. ->orderBy("updated_at", "desc")
  1285. ->offset(($data['page'] - 1) * $data['pageSize'])
  1286. ->limit($data['pageSize'])
  1287. ->get();
  1288. $web['website_id'] = $data['website_id'];
  1289. $articles = $this->processArticles($articles, $web);
  1290. if (empty($articles)) {
  1291. return Result::error("没有符合条件的资讯数据");
  1292. }
  1293. $result = [
  1294. 'rows' => $articles,
  1295. 'count' => $count,
  1296. ];
  1297. return Result::success($result);
  1298. }
  1299. /**
  1300. * 模块新闻加强版
  1301. * @param array $data
  1302. * @return array
  1303. */
  1304. public function getWebsiteCatidArticle(array $data): array
  1305. {
  1306. $where = [
  1307. 'website_category.category_id' => $data['catid'],
  1308. 'website_category.website_id' => $data['website_id'],
  1309. ];
  1310. // $category = WebsiteCategory::where($where);
  1311. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  1312. $child_catnum = $data['child_catnum'] ?? 1;
  1313. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  1314. $childCategoryIds = array_column($category['child'], 'category_id');
  1315. if (empty($childCategoryIds)) {
  1316. return Result::error("暂无子栏目", 0);
  1317. }
  1318. $imgArticles = [];
  1319. $textArticles = [];
  1320. // return Result::success($childCategoryIds);
  1321. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  1322. // 初始化子分类图片新闻和文字新闻数组
  1323. // 查询所有子级栏目的图文新闻
  1324. $imgArticles = Article::where('catid', $childCategoryIds[0])
  1325. ->where(function ($query) use ($data) {
  1326. $query->where(function ($subQuery) use ($data) {
  1327. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1328. })->orWhereNull("ignore_ids");
  1329. })
  1330. ->where('status', 1)
  1331. ->where('imgurl', '!=', '')
  1332. ->select('*')
  1333. ->orderBy('updated_at', 'desc')
  1334. ->limit($data['child_imgnum'])
  1335. ->get();
  1336. }
  1337. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  1338. // 查询所有子级栏目的文字新闻
  1339. $textArticles = Article::where('catid', $childCategoryIds[0])
  1340. ->where('status', 1)
  1341. ->where(function ($query) use ($data) {
  1342. $query->where(function ($subQuery) use ($data) {
  1343. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1344. })->orWhereNull("ignore_ids");
  1345. })
  1346. ->select('*')
  1347. ->orderBy('updated_at', 'desc')
  1348. ->limit($data['child_textnum'])
  1349. ->get();
  1350. }
  1351. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  1352. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  1353. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  1354. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  1355. return $child;
  1356. }, $category['child']);
  1357. }
  1358. // }
  1359. if (isset($data['img_num']) && !empty($data['img_num'])) {
  1360. $category['img'] = WebsiteCategory::where($where)
  1361. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1362. ->where('article.status', 1)
  1363. ->where('article.imgurl', '!=', '')
  1364. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1365. ->orderBy('article.updated_at', 'desc')
  1366. ->limit($data['img_num'])
  1367. ->get();
  1368. }
  1369. if (isset($data['text_num']) && !empty($data['text_num'])) {
  1370. $category['text'] = WebsiteCategory::where($where)
  1371. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1372. ->where('article.status', 1)
  1373. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1374. ->orderBy('article.updated_at', 'desc')
  1375. ->limit($data['text_num'])
  1376. ->get();
  1377. }
  1378. // $category = $category->get();
  1379. if (empty($category)) {
  1380. return Result::error("查询失败", 0);
  1381. }
  1382. return Result::success($category);
  1383. }
  1384. /**
  1385. * 优化后的获取网站所有文章接口
  1386. *
  1387. * @param array $data 请求数据
  1388. * @return array 处理结果
  1389. */
  1390. public function getWebsiteAllArticle(array $data): array
  1391. {
  1392. $array = '[{"alias":null,"category_id":null,"pinyin":null,"imgnum":[],"textnum":[],"child":{"alias":null,"category_id":null,"pinyin":null,"all_childcat":[],"imgnum":[],"textnum":[]}},{"alias":"三农服务","category_id":27,"pinyin":"sannongfuwu","imgnum":[],"textnum":[{"id":52408,"title":"张家镇政协工作站:助力农耕 护航粮食安全","author":"佚名","updated_at":"2025-05-13 14:25:38","cat_arr_id":"[27,305]","introduce":"  初夏时节,张家镇湖洋新村水田边,一场助农活动火热开展。张家镇政","islink":0,"linkurl":"","copyfrom":"广西壮族自治区农业农村厅","catid":305,"category_name":"策划服务","pinyin":"sannongfuwu\/cehuafuwu"},{"id":52390,"title":"科技赋能助力石碑坪镇玉米产业发展","author":"佚名","updated_at":"2025-05-13 13:38:16","cat_arr_id":"[27,305]","introduce":"  石碑坪镇玉米栽培面积约5700亩,年产量3750吨,主栽品种为中糯二号,","islink":0,"linkurl":"","copyfrom":"广西壮族自治区农业农村厅","catid":305,"category_name":"策划服务","pinyin":"sannongfuwu\/cehuafuwu"},{"id":52383,"title":"柳城饲料厂建设项目正式开工","author":"佚名","updated_at":"2025-05-13 13:25:09","cat_arr_id":"[27,305]","introduce":"  4月29日,盛塘牧业公司年产50万吨饲料厂建设项目开工仪式在柳城县马","islink":0,"linkurl":"","copyfrom":"广西壮族自治区农业农村厅","catid":305,"category_name":"策划服务","pinyin":"sannongfuwu\/cehuafuwu"},{"id":51670,"title":"全州县抓好早稻病虫害防治 科技护航稳产增收","author":"佚名","updated_at":"2025-05-06 16:39:12","cat_arr_id":"[27,308]","introduce":"  4月25日,全州县植保站发布第六期《植物病虫情报》,为全县早稻精准","islink":0,"linkurl":"","copyfrom":"广西壮族自治区农业农村厅","catid":308,"category_name":"信息服务","pinyin":"sannongfuwu\/xinxifuwu"}],"child":{"alias":"三农服务","category_id":27,"pinyin":"sannongfuwu","all_childcat":[{"alias":"政策法规","category_id":1,"aLIas_pinyin":"zhengcefagui","pid":0,"cat_arr_id":"[1]","pinyin":"zhengcefagui"},{"alias":"三农之窗","category_id":2,"aLIas_pinyin":"sannongzhichuang","pid":0,"cat_arr_id":"[2]","pinyin":"sannongzhichuang"},{"alias":"区域经济","category_id":5,"aLIas_pinyin":"quyujingji","pid":0,"cat_arr_id":"[5]","pinyin":"quyujingji"},{"alias":"新农村","category_id":11,"aLIas_pinyin":"xinnongcun","pid":0,"cat_arr_id":"[11]","pinyin":"xinnongcun"},{"alias":"三农投资","category_id":12,"aLIas_pinyin":"sannongtouzi","pid":0,"cat_arr_id":"[12]","pinyin":"sannongtouzi"},{"alias":"农贸资讯","category_id":13,"aLIas_pinyin":"nongmaozixun","pid":0,"cat_arr_id":"[13]","pinyin":"nongmaozixun"},{"alias":"三农科教","category_id":14,"aLIas_pinyin":"sannongkejiao","pid":0,"cat_arr_id":"[14]","pinyin":"sannongkejiao"},{"alias":"文化生活","category_id":15,"aLIas_pinyin":"wenhuashenghuo","pid":0,"cat_arr_id":"[15]","pinyin":"wenhuashenghuo"},{"alias":"三农探索","category_id":16,"aLIas_pinyin":"sannongtansuo","pid":0,"cat_arr_id":"[16]","pinyin":"sannongtansuo"},{"alias":"三农人物","category_id":18,"aLIas_pinyin":"sannongrenwu","pid":0,"cat_arr_id":"[18]","pinyin":"sannongrenwu"},{"alias":"三农专题","category_id":19,"aLIas_pinyin":"sannongzhuantiwailian","pid":0,"cat_arr_id":"[19]","pinyin":"sannongzhuantiwailian"},{"alias":"招工招聘","category_id":20,"aLIas_pinyin":"zhaogongzhaopin","pid":0,"cat_arr_id":"[20]","pinyin":"zhaogongzhaopin"},{"alias":"农资购销","category_id":21,"aLIas_pinyin":"nongzigouxiao","pid":0,"cat_arr_id":"[21]","pinyin":"nongzigouxiao"},{"alias":"书刊信息","category_id":24,"aLIas_pinyin":"shukanxinxi","pid":0,"cat_arr_id":"[24]","pinyin":"shukanxinxi"},{"alias":"农网导航","category_id":25,"aLIas_pinyin":"nongwangdaohangwailian","pid":0,"cat_arr_id":"[25]","pinyin":"nongwangdaohangwailian"},{"alias":"打假维权","category_id":26,"aLIas_pinyin":"dajiaweiquan","pid":0,"cat_arr_id":"[26]","pinyin":"dajiaweiquan"},{"alias":"三农服务","category_id":27,"aLIas_pinyin":"sannongfuwu","pid":0,"cat_arr_id":"[27]","pinyin":"sannongfuwu"},{"alias":"三农调查","category_id":28,"aLIas_pinyin":"sannongdiaocha","pid":0,"cat_arr_id":"[28]","pinyin":"sannongdiaocha"},{"alias":"三农论坛","category_id":29,"aLIas_pinyin":"sannongluntan","pid":0,"cat_arr_id":"[29]","pinyin":"sannongluntan"},{"alias":"三农内参","category_id":30,"aLIas_pinyin":"sannongneicanwailian","pid":0,"cat_arr_id":"[30]","pinyin":"sannongneicanwailian"},{"alias":"贴身宝贝","category_id":138,"aLIas_pinyin":"tieshenbaobeiwailian","pid":0,"cat_arr_id":"[138]","pinyin":"tieshenbaobeiwailian"},{"alias":"写作大全","category_id":150,"aLIas_pinyin":"xiezuodaquan","pid":0,"cat_arr_id":"[150]","pinyin":"xiezuodaquan"},{"alias":"农产购销","category_id":153,"aLIas_pinyin":"nongchangouxiao","pid":0,"cat_arr_id":"[153]","pinyin":"nongchangouxiao"},{"alias":"农民工","category_id":317,"aLIas_pinyin":"nongmingong","pid":0,"cat_arr_id":"[317]","pinyin":"nongmingong"},{"alias":"致富信息","category_id":689,"aLIas_pinyin":"zhifuxinxiwailian","pid":0,"cat_arr_id":"[689]","pinyin":"zhifuxinxiwailian"}],"imgnum":[{"id":52408,"title":"张家镇政协工作站:助力农耕 护航粮食安全","imgurl":"http:\/\/img.bjzxtw.org.cn\/master\/image\/jpeg\/20250513\/1747117528273105.jpg","author":"佚名","updated_at":"2025-05-13 14:25:38","introduce":"  初夏时节,张家镇湖洋新村水田边,一场助农活动火热开展。张家镇政","islink":0,"linkurl":"","catid":305,"cat_arr_id":"[27,305]","copyfrom":"广西壮族自治区农业农村厅","pinyin":"sannongfuwu\/cehuafuwu"}],"textnum":[{"id":52408,"title":"张家镇政协工作站:助力农耕 护航粮食安全","author":"佚名","updated_at":"2025-05-13 14:25:38","introduce":"  初夏时节,张家镇湖洋新村水田边,一场助农活动火热开展。张家镇政","islink":0,"linkurl":"","catid":305,"cat_arr_id":"[27,305]","copyfrom":"广西壮族自治区农业农村厅","pinyin":"sannongfuwu\/cehuafuwu"}]}},{"alias":null,"category_id":null,"pinyin":null,"imgnum":[],"textnum":[],"child":[]},{"alias":null,"category_id":null,"pinyin":null,"imgnum":[],"textnum":[],"child":{"alias":null,"category_id":null,"pinyin":null,"all_childcat":[],"imgnum":[],"textnum":[]}},{"alias":null,"category_id":null,"pinyin":null,"imgnum":[],"textnum":[],"child":[]},{"alias":null,"category_id":null,"pinyin":null,"imgnum":[],"textnum":[],"child":[]},{"alias":null,"category_id":null,"pinyin":null,"imgnum":[],"textnum":[],"child":[]},{"alias":"三农投资","category_id":12,"pinyin":"sannongtouzi","imgnum":[{"id":53335,"title":"恭城瑶族自治县农业农村局开展2025年防灾减灾日宣传活动","imgurl":"http:\/\/img.bjzxtw.org.cn\/master\/image\/jpeg\/20250521\/1747789831236997.jpg","author":"佚名","updated_at":"2025-05-21 10:20:56","introduce":"  5月12日是全国防灾减灾日,防灾减灾宣传是提高公众防灾意识的有效措","islink":0,"linkurl":"","copyfrom":"广西壮族自治区农业农村厅 ","cat_arr_id":"[12,227]","catid":227,"category_name":"公益活动","pinyin":"sannongtouzi\/gongyihuodong"},{"id":53185,"title":"省农能中心联合部沼科所专家赴西昌开展零碳村镇宣传培训","imgurl":"http:\/\/img.bjzxtw.org.cn\/master\/image\/jpeg\/20250520\/1747708053332262.jpg","author":"佚名","updated_at":"2025-05-20 10:27:43","introduce":"  5月13日,省农村能源发展中心联合农业农村部成都沼气科学研究所相关","islink":0,"linkurl":"","copyfrom":"四川省农业农村厅","cat_arr_id":"[12,223]","catid":223,"category_name":"国家拨款","pinyin":"sannongtouzi\/guojiabokuan"},{"id":53181,"title":"省园艺总站驻村工作队员助力灾后重建","imgurl":"http:\/\/img.bjzxtw.org.cn\/master\/image\/jpeg\/20250520\/174770762522241.jpg","author":"佚名","updated_at":"2025-05-20 10:20:35","introduce":"  5月9日傍晚,昭觉县四开镇阿波洛村遭受特大冰雹灾害,全村7647亩农作","islink":0,"linkurl":"","copyfrom":"四川省农业农村厅","cat_arr_id":"[12,227]","catid":227,"category_name":"公益活动","pinyin":"sannongtouzi\/gongyihuodong"}],"textnum":[{"id":53400,"title":"荔浦:一把团扇背后的匠心与诚信","author":"佚名","updated_at":"2025-05-21 14:31:16","cat_arr_id":"[12,227]","introduce":"  5月12日,记者来到荔浦市马岭镇的一座院落,看到一条条竹丝在女工们","islink":0,"linkurl":"","copyfrom":"广西壮族自治区农业农村厅","catid":227,"category_name":"公益活动","pinyin":"sannongtouzi\/gongyihuodong"},{"id":53335,"title":"恭城瑶族自治县农业农村局开展2025年防灾减灾日宣传活动","author":"佚名","updated_at":"2025-05-21 10:20:56","cat_arr_id":"[12,227]","introduce":"  5月12日是全国防灾减灾日,防灾减灾宣传是提高公众防灾意识的有效措","islink":0,"linkurl":"","copyfrom":"广西壮族自治区农业农村厅 ","catid":227,"category_name":"公益活动","pinyin":"sannongtouzi\/gongyihuodong"},{"id":53185,"title":"省农能中心联合部沼科所专家赴西昌开展零碳村镇宣传培训","author":"佚名","updated_at":"2025-05-20 10:27:43","cat_arr_id":"[12,223]","introduce":"  5月13日,省农村能源发展中心联合农业农村部成都沼气科学研究所相关","islink":0,"linkurl":"","copyfrom":"四川省农业农村厅","catid":223,"category_name":"国家拨款","pinyin":"sannongtouzi\/guojiabokuan"},{"id":53181,"title":"省园艺总站驻村工作队员助力灾后重建","author":"佚名","updated_at":"2025-05-20 10:20:35","cat_arr_id":"[12,227]","introduce":"  5月9日傍晚,昭觉县四开镇阿波洛村遭受特大冰雹灾害,全村7647亩农作","islink":0,"linkurl":"","copyfrom":"四川省农业农村厅","catid":227,"category_name":"公益活动","pinyin":"sannongtouzi\/gongyihuodong"},{"id":53157,"title":"全省培树帮扶项目资产规范管理先行县(指导县)启动暨培训会在成都召开","author":"佚名","updated_at":"2025-05-20 08:36:05","cat_arr_id":"[12,227]","introduce":"  4月24日,全省培树帮扶项目资产规范管理先行县(指导县)启动暨培训会","islink":0,"linkurl":"","copyfrom":"四川省农业农村厅","catid":227,"category_name":"公益活动","pinyin":"sannongtouzi\/gongyihuodong"},{"id":53153,"title":"四川省举办第25个世界兽医日公益宣传活动","author":"佚名","updated_at":"2025-05-20 08:29:45","cat_arr_id":"[12,227]","introduce":"  4月26日是第25个世界兽医日。今年世界兽医日的主题:&ldquo;动物健康需","islink":0,"linkurl":"","copyfrom":"四川省农业农村厅","catid":227,"category_name":"公益活动","pinyin":"sannongtouzi\/gongyihuodong"},{"id":53063,"title":"渝北:大盛镇人居环境整治刷新乡村“颜值”","author":"佚名","updated_at":"2025-05-19 14:13:25","cat_arr_id":"[12,226]","introduce":"  近日,一场&ldquo;净家园美环境&rdquo;村庄焕新行动在渝北区大盛镇全域","islink":0,"linkurl":"","copyfrom":"重庆市农业农村委员会","catid":226,"category_name":"地方引资","pinyin":"sannongtouzi\/difangyinzi"},{"id":52867,"title":"省水产校毕业生喜获高职单招考试全员上线佳绩","author":"佚名","updated_at":"2025-05-16 11:02:23","cat_arr_id":"[12,227]","introduce":"  在2025年四川省高职单招考试中,省水产校再创佳绩,普通三年制应届毕","islink":0,"linkurl":"","copyfrom":"四川省农业农村厅","catid":227,"category_name":"公益活动","pinyin":"sannongtouzi\/gongyihuodong"},{"id":52765,"title":"4万尾!三亚国企首次实现金鲳鱼苗出口马来西亚","author":"佚名","updated_at":"2025-05-15 16:20:05","cat_arr_id":"[12,229]","introduce":"  5月14日13时30分,三亚环农集团旗下三亚农投海洋产业有限公司在陵水合","islink":0,"linkurl":"","copyfrom":"海南省农业农村厅","catid":229,"category_name":"外商投资","pinyin":"sannongtouzi\/waishangtouzi"},{"id":52687,"title":"海南新一批热带水果出口新加坡朝鲜","author":"佚名","updated_at":"2025-05-15 10:36:12","cat_arr_id":"[12,228]","introduce":"  伴随着海南水果进入销售旺季,越来越多的海南企业在做好国内销售的","islink":0,"linkurl":"","copyfrom":"海南省农业农村厅","catid":228,"category_name":"风险投资","pinyin":"sannongtouzi\/fengxiantouzi"}],"child":{"alias":"三农投资","category_id":12,"pinyin":"sannongtouzi","all_childcat":[{"alias":"政策法规","category_id":1,"aLIas_pinyin":"zhengcefagui","pid":0,"cat_arr_id":"[1]","pinyin":"zhengcefagui"},{"alias":"三农之窗","category_id":2,"aLIas_pinyin":"sannongzhichuang","pid":0,"cat_arr_id":"[2]","pinyin":"sannongzhichuang"},{"alias":"区域经济","category_id":5,"aLIas_pinyin":"quyujingji","pid":0,"cat_arr_id":"[5]","pinyin":"quyujingji"},{"alias":"新农村","category_id":11,"aLIas_pinyin":"xinnongcun","pid":0,"cat_arr_id":"[11]","pinyin":"xinnongcun"},{"alias":"三农投资","category_id":12,"aLIas_pinyin":"sannongtouzi","pid":0,"cat_arr_id":"[12]","pinyin":"sannongtouzi"},{"alias":"农贸资讯","category_id":13,"aLIas_pinyin":"nongmaozixun","pid":0,"cat_arr_id":"[13]","pinyin":"nongmaozixun"},{"alias":"三农科教","category_id":14,"aLIas_pinyin":"sannongkejiao","pid":0,"cat_arr_id":"[14]","pinyin":"sannongkejiao"},{"alias":"文化生活","category_id":15,"aLIas_pinyin":"wenhuashenghuo","pid":0,"cat_arr_id":"[15]","pinyin":"wenhuashenghuo"},{"alias":"三农探索","category_id":16,"aLIas_pinyin":"sannongtansuo","pid":0,"cat_arr_id":"[16]","pinyin":"sannongtansuo"},{"alias":"三农人物","category_id":18,"aLIas_pinyin":"sannongrenwu","pid":0,"cat_arr_id":"[18]","pinyin":"sannongrenwu"},{"alias":"三农专题","category_id":19,"aLIas_pinyin":"sannongzhuantiwailian","pid":0,"cat_arr_id":"[19]","pinyin":"sannongzhuantiwailian"},{"alias":"招工招聘","category_id":20,"aLIas_pinyin":"zhaogongzhaopin","pid":0,"cat_arr_id":"[20]","pinyin":"zhaogongzhaopin"},{"alias":"农资购销","category_id":21,"aLIas_pinyin":"nongzigouxiao","pid":0,"cat_arr_id":"[21]","pinyin":"nongzigouxiao"},{"alias":"书刊信息","category_id":24,"aLIas_pinyin":"shukanxinxi","pid":0,"cat_arr_id":"[24]","pinyin":"shukanxinxi"},{"alias":"农网导航","category_id":25,"aLIas_pinyin":"nongwangdaohangwailian","pid":0,"cat_arr_id":"[25]","pinyin":"nongwangdaohangwailian"},{"alias":"打假维权","category_id":26,"aLIas_pinyin":"dajiaweiquan","pid":0,"cat_arr_id":"[26]","pinyin":"dajiaweiquan"},{"alias":"三农服务","category_id":27,"aLIas_pinyin":"sannongfuwu","pid":0,"cat_arr_id":"[27]","pinyin":"sannongfuwu"},{"alias":"三农调查","category_id":28,"aLIas_pinyin":"sannongdiaocha","pid":0,"cat_arr_id":"[28]","pinyin":"sannongdiaocha"},{"alias":"三农论坛","category_id":29,"aLIas_pinyin":"sannongluntan","pid":0,"cat_arr_id":"[29]","pinyin":"sannongluntan"},{"alias":"三农内参","category_id":30,"aLIas_pinyin":"sannongneicanwailian","pid":0,"cat_arr_id":"[30]","pinyin":"sannongneicanwailian"},{"alias":"贴身宝贝","category_id":138,"aLIas_pinyin":"tieshenbaobeiwailian","pid":0,"cat_arr_id":"[138]","pinyin":"tieshenbaobeiwailian"},{"alias":"写作大全","category_id":150,"aLIas_pinyin":"xiezuodaquan","pid":0,"cat_arr_id":"[150]","pinyin":"xiezuodaquan"},{"alias":"农产购销","category_id":153,"aLIas_pinyin":"nongchangouxiao","pid":0,"cat_arr_id":"[153]","pinyin":"nongchangouxiao"},{"alias":"农民工","category_id":317,"aLIas_pinyin":"nongmingong","pid":0,"cat_arr_id":"[317]","pinyin":"nongmingong"},{"alias":"致富信息","category_id":689,"aLIas_pinyin":"zhifuxinxiwailian","pid":0,"cat_arr_id":"[689]","pinyin":"zhifuxinxiwailian"}],"imgnum":[{"id":53335,"title":"恭城瑶族自治县农业农村局开展2025年防灾减灾日宣传活动","imgurl":"http:\/\/img.bjzxtw.org.cn\/master\/image\/jpeg\/20250521\/1747789831236997.jpg","author":"佚名","updated_at":"2025-05-21 10:20:56","introduce":"  5月12日是全国防灾减灾日,防灾减灾宣传是提高公众防灾意识的有效措","islink":0,"linkurl":"","catid":227,"cat_arr_id":"[12,227]","copyfrom":"广西壮族自治区农业农村厅 ","pinyin":"sannongtouzi\/gongyihuodong"}],"textnum":[{"id":53400,"title":"荔浦:一把团扇背后的匠心与诚信","author":"佚名","updated_at":"2025-05-21 14:31:16","introduce":"  5月12日,记者来到荔浦市马岭镇的一座院落,看到一条条竹丝在女工们","islink":0,"linkurl":"","catid":227,"cat_arr_id":"[12,227]","copyfrom":"广西壮族自治区农业农村厅","pinyin":"sannongtouzi\/gongyihuodong"}]}},{"alias":null,"category_id":null,"pinyin":null,"imgnum":[],"textnum":[],"child":[]},{"alias":null,"category_id":null,"pinyin":null,"imgnum":[],"textnum":[],"child":[]},{"alias":null,"category_id":null,"pinyin":null,"imgnum":[],"textnum":[],"child":[]}]';
  1393. $b = json_decode($array);
  1394. return Result::success($b);
  1395. try {
  1396. // 解析输入数据
  1397. $input = [
  1398. 'id' => $data['id'] ?? '',
  1399. 'website_id' => $data['website_id'] ?? 0
  1400. ];
  1401. // 验证必要参数
  1402. if (empty($input['website_id'])) {
  1403. return Result::error("缺少网站ID参数", 0);
  1404. }
  1405. // 将 JSON 字符串转换为 PHP 数组
  1406. $items = json_decode($input['id'], true);
  1407. if (json_last_error() !== JSON_ERROR_NONE || !is_array($items)) {
  1408. return Result::error("无效的JSON格式", 0);
  1409. }
  1410. // 提取所有需要查询的分类ID
  1411. $parentCatIds = [];
  1412. $childCatIds = [];
  1413. foreach ($items as $item) {
  1414. if (isset($item['parent']) && $item['parent'] && $item['parent'] !== 'undefined') {
  1415. $parts = explode(',', $item['parent']);
  1416. if (count($parts) === 3) {
  1417. $parentCatIds[] = $parts[0];
  1418. }
  1419. }
  1420. if (isset($item['child']) && $item['child'] && $item['child'] !== 'undefined') {
  1421. $parts = explode(',', $item['child']);
  1422. if (count($parts) === 3) {
  1423. $childCatIds[] = $parts[0];
  1424. }
  1425. }
  1426. }
  1427. // 去重分类ID
  1428. $parentCatIds = array_unique($parentCatIds);
  1429. $childCatIds = array_unique($childCatIds);
  1430. // 批量查询分类信息
  1431. $websiteCondition = ['website_id' => $input['website_id']];
  1432. $categories = $this->getCategoriesByIds(array_merge($parentCatIds, $childCatIds), $websiteCondition);
  1433. // 处理每个项目
  1434. $result = [];
  1435. foreach ($items as $item) {
  1436. $resultItem = [
  1437. 'alias' => null,
  1438. 'category_id' => null,
  1439. 'pinyin' => null,
  1440. 'imgnum' => [],
  1441. 'textnum' => [],
  1442. 'child' => []
  1443. ];
  1444. // 处理父级栏目
  1445. if (isset($item['parent']) && $item['parent'] && $item['parent'] !== 'undefined') {
  1446. $parts = explode(',', $item['parent']);
  1447. if (count($parts) !== 3) {
  1448. return Result::error("父级栏目:缺少必需参数错误", 0);
  1449. }
  1450. list($parentCatId, $parentImgNum, $parentTextNum) = $parts;
  1451. // 从已查询的分类中获取信息
  1452. $category = $categories[$parentCatId] ?? null;
  1453. if ($category) {
  1454. $resultItem['alias'] = $category->alias;
  1455. $resultItem['category_id'] = $category->category_id;
  1456. $resultItem['pinyin'] = $category->alias_pinyin;
  1457. // 查询图片新闻
  1458. if ($parentImgNum > 0) {
  1459. $resultItem['imgnum'] = $this->getArticles(
  1460. $parentCatId,
  1461. $input['website_id'],
  1462. (int) $parentImgNum,
  1463. true
  1464. );
  1465. }
  1466. // 查询文字新闻
  1467. if ($parentTextNum > 0) {
  1468. $resultItem['textnum'] = $this->getArticles(
  1469. $parentCatId,
  1470. $input['website_id'],
  1471. (int) $parentTextNum,
  1472. false
  1473. );
  1474. }
  1475. }
  1476. }
  1477. // 处理子级栏目
  1478. if (isset($item['child']) && $item['child'] && $item['child'] !== 'undefined') {
  1479. $parts = explode(',', $item['child']);
  1480. if (count($parts) !== 3) {
  1481. return Result::error("子级栏目:缺少必需参数错误", 0);
  1482. }
  1483. list($childCatId, $childImgNum, $childTextNum) = $parts;
  1484. // 从已查询的分类中获取信息
  1485. $childCategory = $categories[$childCatId] ?? null;
  1486. if ($childCategory) {
  1487. $childData = [
  1488. 'alias' => $childCategory->alias,
  1489. 'category_id' => $childCategory->category_id,
  1490. 'pinyin' => $childCategory->alias_pinyin,
  1491. 'all_childcat' => [],
  1492. 'imgnum' => [],
  1493. 'textnum' => []
  1494. ];
  1495. // 查询此层级的所有子栏目
  1496. $childData['all_childcat'] = $this->getChildCategories(
  1497. $childCategory->pid,
  1498. $input['website_id']
  1499. );
  1500. // 查询子栏目图片新闻
  1501. if ($childImgNum > 0) {
  1502. $childData['imgnum'] = $this->getArticles(
  1503. $childCatId,
  1504. $input['website_id'],
  1505. (int) $childImgNum,
  1506. true
  1507. );
  1508. }
  1509. // 查询子栏目文字新闻
  1510. if ($childTextNum > 0) {
  1511. $childData['textnum'] = $this->getArticles(
  1512. $childCatId,
  1513. $input['website_id'],
  1514. (int) $childTextNum,
  1515. false
  1516. );
  1517. }
  1518. $resultItem['child'] = $childData;
  1519. }
  1520. }
  1521. $result[] = $resultItem;
  1522. }
  1523. return Result::success($result);
  1524. } catch (\Exception $e) {
  1525. return Result::error("处理请求时出错: " . $e->getMessage(), 0);
  1526. }
  1527. }
  1528. /**
  1529. * 批量获取分类信息
  1530. *
  1531. * @Cacheable(prefix="categories", value="#{ids}_{website['website_id']}", ttl=3600)
  1532. */
  1533. protected function getCategoriesByIds(array $ids, array $website): array
  1534. {
  1535. if (empty($ids)) {
  1536. return [];
  1537. }
  1538. $categories = WebsiteCategory::whereIn('category_id', $ids)
  1539. ->where($website)
  1540. ->get(['alias', 'category_id', 'alias_pinyin', 'type', 'pid', 'category_arr_id']);
  1541. $result = [];
  1542. foreach ($categories as $category) {
  1543. $result[$category->category_id] = $category;
  1544. }
  1545. return $result;
  1546. }
  1547. /**
  1548. * 获取文章列表
  1549. *
  1550. * @Cacheable(prefix="articles", value="#{catId}_{websiteId}_{limit}_{isImage}", ttl=300)
  1551. */
  1552. protected function getArticles(int $catId, int $websiteId, int $limit, bool $isImage = false): array
  1553. {
  1554. $query = Article::where('article.status', 1)
  1555. ->where(function($query) use ($catId) {
  1556. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$catId\"')")
  1557. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$catId')");
  1558. })
  1559. ->where(function ($query) use ($websiteId) {
  1560. $query->where(function ($subQuery) use ($websiteId) {
  1561. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '$websiteId') = 0")
  1562. ->orWhereNull("ignore_ids");
  1563. });
  1564. })
  1565. ->leftJoin('website_category', function($join) use ($websiteId) {
  1566. $join->on('article.catid', '=', 'website_category.category_id')
  1567. ->where('website_category.website_id', '=', $websiteId);
  1568. })
  1569. ->select(
  1570. 'article.id', 'article.title', 'article.imgurl', 'article.author', 'article.updated_at',
  1571. 'article.introduce', 'article.islink', 'article.linkurl', 'article.copyfrom', 'article.cat_arr_id',
  1572. 'article.catid', 'website_category.alias as category_name',
  1573. )
  1574. ->orderBy('updated_at', 'desc')
  1575. ->limit($limit);
  1576. if ($isImage) {
  1577. $query->where('imgurl', '!=', '');
  1578. }
  1579. $articles = $query->get();
  1580. // 处理文章路由
  1581. if (!empty($articles)) {
  1582. $articles = $this->processArticles($articles, ['website_id' => $websiteId]);
  1583. }
  1584. return $articles->toArray();
  1585. }
  1586. /**
  1587. * 获取子分类
  1588. *
  1589. * @Cacheable(prefix="child_categories", value="#{pid}_{websiteId}", ttl=3600)
  1590. */
  1591. protected function getChildCategories(int $pid, int $websiteId): array
  1592. {
  1593. $categories = WebsiteCategory::where('website_id', $websiteId)
  1594. ->where("pid", $pid)
  1595. ->get(['alias', 'category_id', 'alias_pinyin', 'pid', 'category_arr_id']);
  1596. // 处理分类路由
  1597. if (!empty($categories)) {
  1598. $categories = $this->processArticles($categories, ['website_id' => $websiteId]);
  1599. }
  1600. return $categories->toArray();
  1601. }
  1602. /**
  1603. * 乡村网-获取特殊新闻模块
  1604. * @param array $data
  1605. * @return array
  1606. */
  1607. public function getWebsiteArticles(array $data): array
  1608. {
  1609. $input['id'] = $data['id'];
  1610. $input['website_id'] = $data['website_id'];
  1611. $data = json_decode($input['id'], true);
  1612. // 使用 array_map 处理每个元素
  1613. $result = array_map(function ($item) use ($input) {
  1614. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  1615. $website = [
  1616. 'website_id' => $input['website_id']
  1617. ];
  1618. // 查询栏目名称
  1619. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  1620. $pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  1621. if (empty($category)) {
  1622. $imgArticles = [];
  1623. $textArticles = [];
  1624. // return Result::error("暂无此栏目",0);
  1625. } else {
  1626. $child_category = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  1627. $parent_alias = $category->aLIas_pinyin ? $category->aLIas_pinyin . '/' : null;
  1628. // return Result::success($website);
  1629. // 查询图片新闻
  1630. // 合并查询条件
  1631. $baseQuery = Article::where(function ($query) use ($website) {
  1632. $query->where(function ($subQuery) use ($website) {
  1633. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0");
  1634. })->orWhereNull("ignore_ids");
  1635. })
  1636. ->where('article.status', 1)
  1637. ->leftJoin('website_category', 'website_category.category_id', 'article.catid')
  1638. ->where('website_category.website_id', $website['website_id']);
  1639. // 查询文字新闻
  1640. $textArticles = clone $baseQuery;
  1641. $textArticles = $textArticles->whereIn('catid', $child_category)
  1642. ->select(
  1643. 'article.id',
  1644. 'article.title',
  1645. // 'article.imgurl',
  1646. 'article.author',
  1647. 'article.updated_at',
  1648. 'article.introduce',
  1649. 'article.islink',
  1650. 'article.linkurl',
  1651. 'article.copyfrom',
  1652. 'website_category.category_id',
  1653. 'website_category.alias',
  1654. 'website_category.aLIas_pinyin'
  1655. )
  1656. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1657. ->orderBy('article.updated_at', 'desc')
  1658. ->limit($parentTextNum)
  1659. ->get()
  1660. ->all();
  1661. if (empty($textArticles)) {
  1662. $textArticles = clone $baseQuery;
  1663. $textArticles = $textArticles->where('catid', $parentCatId)
  1664. ->select(
  1665. 'article.id',
  1666. 'article.title',
  1667. // 'article.imgurl',
  1668. 'article.author',
  1669. 'article.updated_at',
  1670. 'article.introduce',
  1671. 'article.islink',
  1672. 'article.linkurl',
  1673. 'article.copyfrom',
  1674. 'website_category.category_id',
  1675. 'website_category.alias',
  1676. 'website_category.aLIas_pinyin'
  1677. )
  1678. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1679. ->orderBy('article.updated_at', 'desc')
  1680. ->limit($parentTextNum)
  1681. ->get()
  1682. ->all();
  1683. }
  1684. // 查询图片新闻
  1685. $imgArticles = clone $baseQuery;
  1686. $imgArticles = $imgArticles->where('imgurl', '!=', '')->whereIn('catid', $child_category)
  1687. ->select(
  1688. 'article.id',
  1689. 'article.title',
  1690. 'article.imgurl',
  1691. 'article.author',
  1692. 'article.updated_at',
  1693. 'article.introduce',
  1694. 'article.islink',
  1695. 'article.linkurl',
  1696. 'article.copyfrom',
  1697. 'website_category.category_id',
  1698. 'website_category.alias',
  1699. 'website_category.aLIas_pinyin'
  1700. )
  1701. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1702. ->orderBy('article.updated_at', 'desc')
  1703. ->limit($parentImgNum)
  1704. ->get()
  1705. ->all();
  1706. if (empty($imgArticles)) {
  1707. $imgArticles = clone $baseQuery;
  1708. $imgArticles = $imgArticles->where('imgurl', '!=', '')->where('catid', $parentCatId)
  1709. ->select(
  1710. 'article.id',
  1711. 'article.title',
  1712. 'article.imgurl',
  1713. 'article.author',
  1714. 'article.updated_at',
  1715. 'article.introduce',
  1716. 'article.islink',
  1717. 'article.linkurl',
  1718. 'article.copyfrom',
  1719. 'website_category.category_id',
  1720. 'website_category.alias',
  1721. 'website_category.aLIas_pinyin'
  1722. )
  1723. ->selectRaw("CONCAT(?, aLIas_pinyin) as aLIas_pinyin", [$parent_alias])
  1724. ->orderBy('article.updated_at', 'desc')
  1725. ->limit($parentImgNum)
  1726. ->get()
  1727. ->all();
  1728. }
  1729. }
  1730. $resultItem = [
  1731. 'alias' => $category ? $category->alias : null,
  1732. 'category_id' => $parentCatId,
  1733. 'pinyin' => $pinyin ? $pinyin : null,
  1734. 'imgnum' => $imgArticles ?? [],
  1735. 'textnum' => $textArticles ?? [],
  1736. ];
  1737. return $resultItem;
  1738. }, $data);
  1739. return Result::success($result);
  1740. }
  1741. // 封装处理商品的路由问题
  1742. function processGoods($goods, $data)
  1743. {
  1744. return $goods->map(function ($good) use ($data) {
  1745. $catid = $good->catid ?? 0;
  1746. // $pinyin = '';
  1747. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  1748. if (!empty($category->pid) && $category->pid != 0) {
  1749. $level = json_decode($category->category_arr_id);
  1750. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  1751. ->whereIn('category_id', $level)
  1752. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  1753. ->get(['aLIas_pinyin'])
  1754. ->pluck('aLIas_pinyin')
  1755. ->implode('/');
  1756. } else {
  1757. $pinyin = $category->aLIas_pinyin ?? '';
  1758. }
  1759. if (isset($good->city_id) && !empty($good->city_id)) {
  1760. $city = District::where('id', $good->city_id)->first(['name']);
  1761. $good->city_name = $city->name ?? '';
  1762. }
  1763. // 解析imgurl JSON并取第一条数据
  1764. $imgUrls = json_decode($good->imgurl, true);
  1765. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  1766. $good->pinyin = $pinyin;
  1767. return $good;
  1768. });
  1769. }
  1770. /**
  1771. * 获取商城首页-根据栏目id
  1772. * @param array $data
  1773. * @return array
  1774. * */
  1775. function getWebsiteCatidshop(array $data): array
  1776. {
  1777. $input['catid'] = $data['catid'];
  1778. $input['website_id'] = $data['website_id'];
  1779. $data = json_decode($input['catid'] ?? '', true) ?? [];
  1780. $result = array_map(function ($item) use ($input) {
  1781. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  1782. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  1783. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  1784. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  1785. if (empty($category) || $category->type != 2) {
  1786. return Result::error("暂无此栏目", 0);
  1787. } else {
  1788. $website['website_id'] = $input['website_id'];
  1789. $goods = Good::where('good.status', 2)
  1790. ->where('good.website_id', $website['website_id'])
  1791. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  1792. ->select(
  1793. 'good.id',
  1794. 'good.name',
  1795. 'good.imgurl',
  1796. 'good.description',
  1797. 'good.updated_at',
  1798. 'good.catid',
  1799. 'good.type_id',
  1800. 'good.price',
  1801. 'good.com',
  1802. 'good.level',
  1803. 'good.unit'
  1804. )
  1805. ->orderBy('updated_at', 'desc')
  1806. ->offset($goodStart)
  1807. ->limit($goodNum);
  1808. $all_goods = $goods->get();
  1809. $all_goods = $this->processGoods($all_goods, $website);
  1810. }
  1811. return $all_goods ?? [];
  1812. }
  1813. }, $data);
  1814. return Result::success($result);
  1815. }
  1816. /**
  1817. * 获取商品模块
  1818. * @param array $data
  1819. * @return array
  1820. * */
  1821. public function getWebsiteshop(array $data): array
  1822. {
  1823. $input['id'] = $data['id'];
  1824. $input['website_id'] = $data['website_id'];
  1825. $catid = $data['catid'];
  1826. $data = json_decode($input['id'] ?? '', true) ?? [];
  1827. $result['goods'] = array_map(function ($item) use ($input) {
  1828. // 检查parent元素是否存在且不是undefined
  1829. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  1830. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  1831. $website = $input['website_id'];
  1832. $query = Good::where('good.status', 2)
  1833. ->where('good.website_id', $website);
  1834. switch ($Levelid) {
  1835. case 1:
  1836. case 2:
  1837. case 3:
  1838. $goods = $query->where(function ($q) use ($Levelid) {
  1839. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  1840. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  1841. });
  1842. break;
  1843. case 4:
  1844. $goods = $query;
  1845. break;
  1846. case 5:
  1847. $goods = $query->where('type_id', 1);
  1848. break;
  1849. case 6:
  1850. $goods = $query->where('type_id', 2);
  1851. break;
  1852. default:
  1853. return [];
  1854. }
  1855. $all_goods = $goods
  1856. ->select(
  1857. 'good.id',
  1858. 'good.name',
  1859. 'good.imgurl',
  1860. 'good.description',
  1861. 'good.updated_at',
  1862. 'good.catid',
  1863. 'good.type_id',
  1864. 'good.price',
  1865. 'good.level',
  1866. 'good.website_id'
  1867. )
  1868. ->orderBy('updated_at', 'desc')
  1869. ->offset($goodStart)
  1870. ->limit($goodNum)
  1871. ->get();
  1872. $web['website_id'] = $website;
  1873. $all_goods = $this->processGoods($all_goods, $web);
  1874. }
  1875. return $all_goods;
  1876. }, $data);
  1877. $website = $input['website_id'];
  1878. $result['article'] = Article::where(function ($query) use ($website) {
  1879. $query->where(function ($subQuery) use ($website) {
  1880. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  1881. })->orWhereNull("ignore_ids");
  1882. })
  1883. ->where('catid', $catid)
  1884. ->where('article.status', 1)
  1885. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  1886. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  1887. ->orderBy('article.updated_at', 'desc')
  1888. ->first();
  1889. return Result::success($result);
  1890. }
  1891. /**
  1892. * 获取商品分类
  1893. * @param array $data
  1894. * @return array
  1895. * */
  1896. public function getWebsiteshopCat(array $data): array
  1897. {
  1898. $website = $data['website_id'];
  1899. $category = WebsiteCategory::where('website_id', $website)
  1900. ->whereRaw("JSON_CONTAINS(category_arr_id, '". intval($data['id']). "') = 1")
  1901. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"". intval($data['id']). "\"') = 1")
  1902. ->select('category_id', 'alias','aLIas_pinyin','pid','category_arr_id' ,'sort')
  1903. ->orderBy('sort')
  1904. ->get();
  1905. $cat = $category->map(function ($item) use ($website) {
  1906. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  1907. $pid = $item->pid?? 0;
  1908. if(!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0){
  1909. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  1910. ->where('website_id', $website)
  1911. ->orderByRaw('FIELD(category_id, '. implode(',', $cat_arr_id). ')')
  1912. ->get(['aLIas_pinyin'])
  1913. ->pluck('aLIas_pinyin')
  1914. ->implode('/');
  1915. }else{
  1916. $pinyin = $item->aLIas_pinyin ?? '';
  1917. }
  1918. $item->pinyin = $pinyin;
  1919. });
  1920. if(empty($category)){
  1921. return Result::error("栏目查询失败", 0);
  1922. }
  1923. $cat_tree = Result::buildMenuTree($category);
  1924. $web['website_id'] = $website;
  1925. $goods = Good::where('website_id', $website)
  1926. ->where('status', 2)
  1927. ->select('good.id as good_id', 'name','imgurl','description','updated_at','catid','type_id','website_id')
  1928. ->latest('updated_at')
  1929. ->offset(($data['page']-1)*$data['pageSize'])
  1930. ->limit($data['pageSize'])
  1931. ->get();
  1932. if(!empty($goods)){
  1933. if($goods->count() > 1 && !empty($goods)){
  1934. $goods = $this->processGoods($goods, $web);
  1935. }
  1936. } else {
  1937. $goods = [];
  1938. }
  1939. $result = [
  1940. 'category' => $cat_tree,
  1941. 'goods' => $goods,
  1942. ];
  1943. // $resul['goods'] = $goods;
  1944. if (empty($result)) {
  1945. return Result::error("查询失败", 0);
  1946. }
  1947. return Result::success($result);
  1948. }
  1949. /*
  1950. * 获取商品列表
  1951. * @param array $data
  1952. * @return array
  1953. * */
  1954. public function getWebsiteshopList(array $data): array
  1955. {
  1956. // return Result::success($data);
  1957. $where = [
  1958. 'status' => 2,
  1959. 'website_id' => $data['website_id'],
  1960. ];
  1961. if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  1962. return Result::error("查询失败", 0);
  1963. }
  1964. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  1965. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  1966. $data['catid'] = $category->category_id ?? 0;
  1967. }
  1968. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1969. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  1970. }
  1971. if (isset($data['type_id']) && !empty($data['type_id'])) {
  1972. array_push($where, ['type_id', $data['type_id']]);
  1973. }
  1974. $query = Good::where($where)
  1975. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  1976. $query->where(function ($q) use ($data) {
  1977. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  1978. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  1979. });
  1980. })
  1981. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  1982. $query->where(function ($q) use ($data) {
  1983. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  1984. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  1985. });
  1986. })
  1987. ->select(
  1988. 'good.id',
  1989. 'good.name',
  1990. 'good.imgurl',
  1991. 'good.description',
  1992. 'good.updated_at',
  1993. 'good.com',
  1994. 'good.catid',
  1995. 'good.type_id',
  1996. 'good.website_id',
  1997. 'good.cat_arr_id',
  1998. 'good.created_at',
  1999. 'good.city_id'
  2000. )
  2001. ->latest('updated_at');
  2002. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  2003. // 获取 type_id 为 1 的数据
  2004. $result['type1'] = $this->processGoods(
  2005. $query->clone()
  2006. ->where('type_id', 1)
  2007. ->offset(($data['page'] - 1) * $data['pageSize'])
  2008. ->limit($data['pageSize'])
  2009. ->get(),
  2010. $data
  2011. );
  2012. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2013. // 获取 type_id 为 2 的数据
  2014. $result['type2'] = $this->processGoods(
  2015. $query->clone()
  2016. ->where('type_id', 2)
  2017. ->offset(($data['page'] - 1) * $data['pageSize'])
  2018. ->limit($data['pageSize'])
  2019. ->get(),
  2020. $data
  2021. );
  2022. if (empty($result)) {
  2023. return Result::error("查询失败", 0);
  2024. }
  2025. return Result::success($result);
  2026. }
  2027. /**
  2028. * 获取商品详情
  2029. * @param array $data
  2030. * @return array
  2031. * */
  2032. public function getWebsiteshopInfo(array $data): array
  2033. {
  2034. $where = [
  2035. 'good.status' => 2,
  2036. 'good.website_id' => $data['website_id'],
  2037. 'good.id' => $data['id'],
  2038. ];
  2039. $goods = Good::where($where)
  2040. ->where('good.id', $data['id'])
  2041. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2042. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2043. ->first();
  2044. if (empty($goods)) {
  2045. return Result::error("查询失败", 0);
  2046. }
  2047. $goods->imgurl = json_decode($goods->imgurl, true);
  2048. return Result::success($goods);
  2049. }
  2050. /**
  2051. * 封装处理文章的路由问题
  2052. * */
  2053. function processArticles($articles, $data)
  2054. {
  2055. // 检查 $articles 是否为数组或可迭代对象
  2056. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  2057. return $articles->map(function ($article) use ($data) {
  2058. if(isset($article->cat_arr_id) &&!empty($article->cat_arr_id)){
  2059. $catid = $article->cat_arr_id?? '';
  2060. }
  2061. if(isset($article->category_arr_id) &&!empty($article->category_arr_id)){
  2062. $catid = $article->category_arr_id?? '';
  2063. }
  2064. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  2065. $level = json_decode($catid, true);
  2066. if (!is_array($level)) {
  2067. return $article;
  2068. } else {
  2069. $level = array_map('intval', $level);
  2070. }
  2071. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2072. ->where($data)
  2073. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2074. ->pluck('aLIas_pinyin')
  2075. ->implode('/');
  2076. $article->pinyin = $pinyin ?? '';
  2077. return $article;
  2078. });
  2079. } else {
  2080. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2081. $catid = $articles->cat_arr_id ?? '';
  2082. $level = json_decode($catid, true);
  2083. if (!is_array($level)) {
  2084. return $articles;
  2085. } else {
  2086. $level = array_map('intval', $level);
  2087. }
  2088. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2089. ->where($data)
  2090. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2091. ->pluck('aLIas_pinyin')
  2092. ->implode('/');
  2093. $articles->pinyin = $pinyin ?? '';
  2094. return $articles;
  2095. }
  2096. }
  2097. // 封装处理由问题
  2098. function processJob($job, $data)
  2099. {
  2100. return $job->map(function ($job) use ($data) {
  2101. $category = $job->cat_arr_id ?? '';
  2102. $cityid = $job->city_arr_id ?? '';
  2103. $city = json_decode($cityid, true);
  2104. $pinyin = '';
  2105. $level = json_decode($category, true);
  2106. // 路由
  2107. if (!empty($level) && is_array($level)) {
  2108. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2109. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2110. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2111. ->get(['aLIas_pinyin'])
  2112. ->pluck('aLIas_pinyin')
  2113. ->implode('/');
  2114. if (empty($pinyin)) {
  2115. $pinyin = $pinyin->aLIas_pinyin ?? '';
  2116. }
  2117. $job->pinyin = $pinyin;
  2118. }
  2119. // 取职位-城市 市??省
  2120. if (!empty($city) && is_array($city)) {
  2121. if (isset($city[1]) && !empty($city[1])) {
  2122. $city = District::where('id', $city[1])->first(['name']);
  2123. $job->city_name = $city->name ?? '';
  2124. } else if (isset($city[0]) && !empty($city[0])) {
  2125. $city = District::where('id', $city[0])->first(['name']);
  2126. $job->city_name = $city->name ?? '';
  2127. } else {
  2128. $job->city_name = '全国';
  2129. }
  2130. }
  2131. // 获取简历最后一级地区
  2132. if (isset($job->city_id) && !empty($job->city_id)) {
  2133. $city = District::where('id', $job->city_id)->first(['name']);
  2134. $job->hunt_cityname = $city->name ?? '';
  2135. }
  2136. // 组合详细地址
  2137. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  2138. $address_id = json_decode($job->address_arr_id, true) ?? [];
  2139. if (is_array($address_id) && !empty($address_id)) {
  2140. $address = District::whereIn('id', $address_id)
  2141. ->orderBy('level', 'asc')
  2142. ->get(['name'])
  2143. ->pluck('name')
  2144. ->implode('');
  2145. // $job->address_name = $address ?? '';
  2146. $job->address_name = ($address ?? '') . ($job->address ?? '');
  2147. }
  2148. }
  2149. // 取行业
  2150. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  2151. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  2152. if (!empty($job->industry)) {
  2153. $query->where('hyid', $job->industry);
  2154. } else if (!empty($job->hy_id)) {
  2155. $query->where('hyid', $job->hy_id);
  2156. } else if (!empty($job->company_hy_id)) {
  2157. $query->where('hyid', $job->company_hy_id);
  2158. } else {
  2159. $query->where('hyid', $job->job_industry);
  2160. }
  2161. })->first(['hyname']);
  2162. $job->hy_name = $hy_name->hyname ?? '';
  2163. }
  2164. // 取职位类别
  2165. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  2166. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  2167. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  2168. $job->zw_name = $zw_name->zwname ?? '';
  2169. }
  2170. // 取具体职位
  2171. if ((isset($job->jtzw_id) && !empty($job->jtzw_id)) || (isset($job->job_name_get) && !empty($job->job_name_get)) || (isset($job->job_name) && !empty($job->job_name))) {
  2172. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  2173. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  2174. $job->jtzw_name = $jtzw_name->zwname ?? '';
  2175. }
  2176. // 取工作经验
  2177. if (isset($job->experience) && !empty($job->experience)) {
  2178. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  2179. $job->experience_name = $experience->ename ?? '';
  2180. }
  2181. // 取学历
  2182. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  2183. $education = $job->educational ?? $job->school_education;
  2184. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  2185. $job->education_name = $education->ename ?? '';
  2186. }
  2187. // 语言
  2188. if (isset($job->language) && !empty($job->language)) {
  2189. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  2190. $job->language_name = $language->ename ?? '';
  2191. }
  2192. // 薪资
  2193. if (isset($job->salary) && !empty($job->salary)) {
  2194. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  2195. $job->salary_name = $salary->ename ?? '';
  2196. }
  2197. // 职位性质
  2198. if (isset($job->nature_id) && !empty($job->nature_id)) {
  2199. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  2200. $job->job_nature_name = $job_nature->ename ?? '';
  2201. }
  2202. // 公司规模
  2203. if (isset($job->company_size) && !empty($job->company_size)) {
  2204. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  2205. $job->company_size_name = $company_size->ename ?? '';
  2206. }
  2207. // 公司性质
  2208. if (isset($job->company_nature) && !empty($job->company_nature)) {
  2209. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  2210. $job->company_nature_name = $company_nature->nature_name ?? '';
  2211. }
  2212. // $job->pinyin = $pinyin;
  2213. return $job;
  2214. });
  2215. }
  2216. /**
  2217. * 获取书籍模块
  2218. * @param array $data
  2219. * @return array
  2220. * */
  2221. public function getWebsiteBook(array $data): array
  2222. {
  2223. $input['id'] = $data['id'];
  2224. $input['website_id'] = $data['website_id'];
  2225. // 将 JSON 字符串转换为 PHP 数组
  2226. $data = json_decode($input['id'], true);
  2227. // 使用 array_map 处理每个元素
  2228. $result = array_map(function ($item) use ($input) {
  2229. // 检查parent元素是否存在且不是undefined
  2230. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  2231. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2232. $website = [
  2233. 'website_id' => $input['website_id'],
  2234. ];
  2235. // 查询栏目名称
  2236. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2237. if (empty($category)) {
  2238. $parent_alias = '';
  2239. $parent_pinyin = null;
  2240. $imgBooks = [];
  2241. $textBooks = [];
  2242. } else {
  2243. $parent_alias = $category->alias ?? '';
  2244. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  2245. // 查找子分类ID数组
  2246. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  2247. array_push($childCategoryIds, $parentCatId);
  2248. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  2249. if ($parentImgNum != 0) {
  2250. // 查询图片新闻
  2251. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  2252. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2253. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2254. })
  2255. ->where('book.status', 2)
  2256. ->where('book.img_url', '!=', '')
  2257. ->leftJoin('website_category', function ($join) use ($website) {
  2258. $join->on('book.cat_id', '=', 'website_category.category_id')
  2259. ->where('website_category.website_id', '=', $website['website_id']);
  2260. })
  2261. ->select(
  2262. 'book.id',
  2263. 'book.title',
  2264. 'book.img_url',
  2265. 'book.price',
  2266. 'book.market_price',
  2267. 'book.description',
  2268. 'book.cat_id',
  2269. 'book.description',
  2270. 'book.updated_at',
  2271. 'website_category.alias as category_name',
  2272. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2273. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2274. )
  2275. ->orderBy('updated_at', 'desc')
  2276. ->limit($parentImgNum)
  2277. ->get()->all();
  2278. // 查询文字新闻
  2279. }
  2280. if ($parentTextNum != 0) {
  2281. $textBooks = [];
  2282. $textBooks = Book::where(function ($query) use ($parentCatId) {
  2283. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2284. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2285. })
  2286. ->where('book.status', 2)
  2287. ->leftJoin('website_category', function ($join) use ($website) {
  2288. $join->on('book.cat_id', '=', 'website_category.category_id')
  2289. ->where('website_category.website_id', '=', $website['website_id']);
  2290. })
  2291. ->select(
  2292. 'book.id',
  2293. 'book.title',
  2294. 'book.img_url',
  2295. 'book.price',
  2296. 'book.market_price',
  2297. 'book.description',
  2298. 'book.cat_id',
  2299. 'book.description',
  2300. 'book.updated_at',
  2301. 'website_category.alias as category_name',
  2302. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2303. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2304. )
  2305. ->orderBy('updated_at', 'desc')
  2306. ->limit($parentTextNum)
  2307. ->get()->all();
  2308. }
  2309. }
  2310. }
  2311. $resultItem = [
  2312. 'alias' => $parent_alias ?? '',
  2313. 'category_id' => $parentCatId ?? 0,
  2314. 'pinyin' => $parent_pinyin ?? null,
  2315. 'imgnum' => $imgBooks ?? [],
  2316. 'textnum' => $textBooks ?? [],
  2317. ];
  2318. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  2319. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  2320. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  2321. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2322. ->get()->all();
  2323. if (!empty($childCategory)) {
  2324. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  2325. // 查询子栏目名称
  2326. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  2327. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2328. ->first();
  2329. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  2330. $childImgArticles = [];
  2331. $childTextArticles = [];
  2332. $resultItem['child'] = [];
  2333. } else {
  2334. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  2335. // 查询子栏目图片新闻
  2336. $childImgArticles = Book::where('cat_id', $childCatId)
  2337. ->where('status', 2)
  2338. ->where('img_url', '!=', '')
  2339. ->leftJoin('website_category', function ($join) use ($website) {
  2340. $join->on('book.cat_id', '=', 'website_category.category_id')
  2341. ->where('website_category.website_id', '=', $website['website_id']);
  2342. })
  2343. ->select(
  2344. 'book.id',
  2345. 'book.title',
  2346. 'book.img_url',
  2347. 'book.price',
  2348. 'book.market_price',
  2349. 'book.description',
  2350. 'book.cat_id',
  2351. 'book.description',
  2352. 'book.updated_at',
  2353. DB::raw("'$child_pinyin' as pinyin")
  2354. )
  2355. ->orderBy('updated_at', 'desc')
  2356. ->limit($childImgNum)
  2357. ->get()->all();
  2358. // 查询子栏目文字新闻
  2359. $childTextArticles = Book::where('cat_id', $childCatId)
  2360. ->where('status', 2)
  2361. ->leftJoin('website_category', function ($join) use ($website) {
  2362. $join->on('book.cat_id', '=', 'website_category.category_id')
  2363. ->where('website_category.website_id', '=', $website['website_id']);
  2364. })
  2365. ->select(
  2366. 'book.id',
  2367. 'book.title',
  2368. 'book.img_url',
  2369. 'book.price',
  2370. 'book.market_price',
  2371. 'book.description',
  2372. 'book.cat_id',
  2373. 'book.description',
  2374. 'book.updated_at',
  2375. DB::raw("'$child_pinyin' as pinyin")
  2376. )
  2377. ->orderBy('updated_at', 'desc')
  2378. ->limit($childTextNum)
  2379. ->get()->all();
  2380. $resultItem['child'] = [
  2381. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  2382. 'category_id' => $childCatId,
  2383. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  2384. 'all_childcat' => $childCategory,
  2385. 'imgnum' => $childImgArticles,
  2386. 'textnum' => $childTextArticles,
  2387. ];
  2388. }
  2389. }
  2390. } else {
  2391. $resultItem['child'] = [];
  2392. }
  2393. return $resultItem;
  2394. }, $data);
  2395. return Result::success($result);
  2396. }
  2397. /**
  2398. * 获取书刊列表
  2399. * @param array $data
  2400. * @return array
  2401. * */
  2402. public function getWebsiteBookList(array $data): array
  2403. {
  2404. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2405. if (empty($web)) {
  2406. return Result::error("查询失败", 0);
  2407. }
  2408. $catid = $data['id'];
  2409. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  2410. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  2411. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  2412. $category_pinyin = $category ? $category->aLias_pinyin : '';
  2413. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  2414. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  2415. ->where('pid', $category['pid'])
  2416. ->select(
  2417. 'category_id',
  2418. 'alias',
  2419. 'aLIas_pinyin',
  2420. 'pid',
  2421. 'sort',
  2422. 'is_url',
  2423. 'web_url',
  2424. 'seo_title',
  2425. 'seo_keywords',
  2426. 'seo_description',
  2427. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  2428. )
  2429. ->orderBy('sort')
  2430. ->get()->all();
  2431. if (empty($category)) {
  2432. return Result::error("查询失败", 0);
  2433. }
  2434. $query = Book::where('book.status', 2)
  2435. ->where('book.website_id', $data['website_id'])
  2436. ->where('book.cat_id', $catid)
  2437. ->select(
  2438. 'book.id',
  2439. 'book.title',
  2440. 'book.img_url',
  2441. 'book.description',
  2442. 'book.updated_at',
  2443. 'book.cat_id',
  2444. DB::raw("'$pinyin' as pinyin")
  2445. )
  2446. ->orderBy('book.updated_at', 'desc');
  2447. $count = $query->count();
  2448. $query = clone $query;
  2449. $Book = $query
  2450. ->limit($data['pageSize'])
  2451. ->offset(($data['page'] - 1) * $data['pageSize'])
  2452. ->get()->all();
  2453. $result = [
  2454. 'category' => $categorys,
  2455. 'books' => $Book,
  2456. 'count' => $count,
  2457. ];
  2458. // if(empty($result)){
  2459. // return Result::error("查询失败", 0);
  2460. // }
  2461. return Result::success($result);
  2462. }
  2463. /**
  2464. * 获取书刊详情
  2465. * @param array $data
  2466. * @return array
  2467. * */
  2468. public function getWebsiteBookInfo(array $data): array
  2469. {
  2470. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2471. if (empty($web)) {
  2472. return Result::error("查询失败", 0);
  2473. }
  2474. $book = Book::where('status', 2)
  2475. ->where('website_id', $data['website_id'])
  2476. ->where('id', $data['id'])
  2477. ->select(
  2478. 'book.*',
  2479. )
  2480. ->orderBy('updated_at', 'desc')
  2481. ->first();
  2482. if (empty($book)) {
  2483. return Result::error("查询失败", 0);
  2484. }
  2485. // 先查询当前分类的 pid
  2486. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  2487. ->where('category_id', $book['cat_id'])
  2488. ->first(['pid', 'category_id']);
  2489. $query = WebsiteCategory::where('website_id', $data['website_id']);
  2490. if (!empty($carpid)) {
  2491. if ($carpid->pid != 0) {
  2492. $pid = $carpid['pid'];
  2493. // $parent_pinyin = '';
  2494. } else {
  2495. $pid = $carpid['category_id'];
  2496. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  2497. }
  2498. }
  2499. $categorys = $query->where('pid', $pid)
  2500. ->select(
  2501. 'category_id',
  2502. 'alias',
  2503. 'aLIas_pinyin',
  2504. 'pid',
  2505. 'sort',
  2506. 'is_url',
  2507. 'web_url',
  2508. 'category_arr_id as cat_arr_id',
  2509. )
  2510. ->orderBy('sort')
  2511. ->get();
  2512. $category = $this->processArticle($categorys, $data);
  2513. $result = [
  2514. 'category' => $category,
  2515. 'books' => $book,
  2516. ];
  2517. return Result::success($result);
  2518. }
  2519. /**
  2520. * 尝试
  2521. * @param array $data
  2522. * @return array
  2523. * */
  2524. public function test(array $data): array
  2525. {
  2526. $input['id'] = $data['id'];
  2527. $input['website_id'] = $data['website_id'];
  2528. // 将 JSON 字符串转换为 PHP 数组
  2529. $data = json_decode($input['id'], true);
  2530. $result = [];
  2531. $article = $data;
  2532. $result = array_map(function ($item) use ($input) {
  2533. $website = [
  2534. 'website_id' => $input['website_id'],
  2535. ];
  2536. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2537. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2538. $parent = [
  2539. 0 => $category['category_id'] ?? [],
  2540. 1 => $parentImgNum ?? [],
  2541. 2 => $parentTextNum ?? [],
  2542. ];
  2543. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  2544. $child = [];
  2545. $resultItem = [
  2546. // 'alias' => $parent_alias ?? '',
  2547. 'category_id' => $parentCatId ?? 0,
  2548. 'pinyin' => $parentImgNum ?? null,
  2549. 'imgnum' => $parentTextNum ?? [],
  2550. // 'textnum' => $textArticles ?? [],
  2551. ];
  2552. return $parent;
  2553. }, $data);
  2554. return Result::success($result);
  2555. // });
  2556. }
  2557. /**
  2558. * 封装处理文章的路由问题
  2559. * */
  2560. function processArticle($article, $data)
  2561. {
  2562. return $article->map(function ($article) use ($data) {
  2563. $catid = $article->cat_arr_id ?? '';
  2564. $level = json_decode($catid, true);
  2565. $pinyin = '';
  2566. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2567. if (!empty($level) && is_array($level)) {
  2568. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2569. ->where('website_id', $data['website_id'])
  2570. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2571. ->get(['aLIas_pinyin'])
  2572. ->pluck('aLIas_pinyin')
  2573. ->implode('/');
  2574. } else {
  2575. $pinyin = '';
  2576. }
  2577. $article->pinyin = $pinyin;
  2578. return $article;
  2579. });
  2580. }
  2581. /**
  2582. * c端-获取招工招聘下拉选框
  2583. * @param array $data
  2584. * @return array
  2585. * */
  2586. public function getWebsiteJobSelect(array $data): array
  2587. {
  2588. $web = Website::where('id', $data['website_id'])->first();
  2589. if (empty($web)) {
  2590. return Result::error("该网站不存在", 0);
  2591. }
  2592. $hy = JobIndustry::get()->all();
  2593. $zw = JobPosition::where('zwpid', 0)->get()->all();
  2594. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  2595. $result = [
  2596. 'hy' => $hy,
  2597. 'zw' => $zw,
  2598. 'jtzw' => $jtzw,
  2599. ];
  2600. if (empty($result)) {
  2601. return Result::error("查询失败", 0);
  2602. }
  2603. return Result::success($result);
  2604. }
  2605. /**
  2606. * c端-获取招工招聘
  2607. * @param array $data
  2608. * @return array
  2609. * */
  2610. public function getWebsiteJob(array $data): array
  2611. {
  2612. $web = Website::where('id', $data['website_id'])->first();
  2613. if (empty($web)) {
  2614. return Result::error("该网站不存在", 0);
  2615. }
  2616. $job_hunting = JobHunting::where('job_hunting.status', 2)
  2617. ->where('job_hunting.website_id', $data['website_id'])
  2618. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2619. $query->where(function ($q) use ($data) {
  2620. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2621. });
  2622. })
  2623. ->select(
  2624. 'job_hunting.id',
  2625. 'job_hunting.cat_arr_id',
  2626. 'job_hunting.job_name_get',
  2627. 'job_hunting.industry',
  2628. 'job_hunting.name',
  2629. 'job_hunting.sexy',
  2630. 'job_hunting.origin',
  2631. 'job_hunting.city_arr_id',
  2632. 'job_hunting.experience',
  2633. 'job_hunting.updated_at',
  2634. 'job_hunting.salary'
  2635. )
  2636. ->orderBy('updated_at', 'desc')
  2637. ->limit($data['job1_num'])
  2638. ->get();
  2639. $web['website_id'] = $data['website_id'];
  2640. if (empty($job_hunting)) {
  2641. $job_huntings = "未查询到相关简历信息";
  2642. } else {
  2643. $job_huntings = $this->processJob($job_hunting, $web);
  2644. }
  2645. // 0:待审核 1:已通过 2:已拒绝
  2646. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  2647. ->where('job_recruiting.website_id', $data['website_id'])
  2648. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2649. $query->where(function ($q) use ($data) {
  2650. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2651. });
  2652. })
  2653. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2654. ->select(
  2655. 'job_recruiting.id',
  2656. 'job_recruiting.cat_arr_id',
  2657. 'job_recruiting.title',
  2658. 'job_recruiting.jtzw_id',
  2659. 'job_recruiting.hy_id',
  2660. 'job_recruiting.city_arr_id',
  2661. 'job_recruiting.due_data',
  2662. 'job_recruiting.updated_at',
  2663. 'job_recruiting.experience',
  2664. 'job_recruiting.educational',
  2665. 'job_recruiting.salary',
  2666. 'job_recruiting.zw_id',
  2667. 'job_company.business_name'
  2668. )
  2669. ->orderBy('updated_at', 'desc')
  2670. ->limit($data['job2_num'])
  2671. ->get();
  2672. if (empty($job_recruiting->toArray())) {
  2673. $job_recruitings = "未查询到相关职位信息";
  2674. } else {
  2675. $job_recruitings = $this->processJob($job_recruiting, $web);
  2676. }
  2677. $result = [
  2678. 'job_hunting' => $job_huntings,
  2679. 'job_recuiting' => $job_recruitings,
  2680. ];
  2681. return Result::success($result);
  2682. }
  2683. /**
  2684. * c端-获取招工招聘列表
  2685. * @param array $data
  2686. * @return array
  2687. * */
  2688. public function getWebsiteJobList(array $data): array
  2689. {
  2690. $recruit_where = [];
  2691. $hunt_where = [];
  2692. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2693. if (empty($web)) {
  2694. return Result::error("此网站不存在", 0);
  2695. }
  2696. $website_id['website_id'] = $data['website_id'];
  2697. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  2698. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  2699. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  2700. }
  2701. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  2702. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  2703. }
  2704. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  2705. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  2706. }
  2707. $query = JobRecruiting::where('job_recruiting.status', 1)
  2708. ->where('job_recruiting.website_id', $data['website_id'])
  2709. ->where($recruit_where)
  2710. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2711. $query->where(function ($q) use ($data) {
  2712. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2713. });
  2714. })
  2715. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2716. $query->where(function ($q) use ($data) {
  2717. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  2718. });
  2719. })
  2720. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2721. ->select(
  2722. 'job_recruiting.id',
  2723. 'job_recruiting.hy_id',
  2724. 'job_recruiting.title',
  2725. 'job_recruiting.zw_id',
  2726. 'job_recruiting.educational',
  2727. 'job_recruiting.jtzw_id',
  2728. 'job_recruiting.city_arr_id',
  2729. 'job_recruiting.due_data',
  2730. 'job_recruiting.experience',
  2731. 'job_recruiting.cat_arr_id',
  2732. 'job_recruiting.updated_at',
  2733. 'job_company.business_name'
  2734. )
  2735. ->orderBy('updated_at', 'desc');
  2736. $recruit_count = $query->count();
  2737. $query = clone $query;
  2738. $JobRecruiting = $query
  2739. ->offset(($data['page'] - 1) * $data['pageSize'])
  2740. ->limit($data['pageSize'])
  2741. ->get();
  2742. if (empty($JobRecruiting)) {
  2743. $JobRecruiting = "暂无相关职位信息";
  2744. } else {
  2745. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  2746. }
  2747. }
  2748. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  2749. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  2750. array_push($hunt_where, ['job', $data['zw_id']]);
  2751. }
  2752. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  2753. array_push($hunt_where, ['job_name_get', $data['jtzw_id']]);
  2754. }
  2755. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  2756. array_push($hunt_where, ['industry', $data['hy_id']]);
  2757. }
  2758. $query = JobHunting::where('status', 2)
  2759. ->where('job_hunting.website_id', $data['website_id'])
  2760. ->where($hunt_where)
  2761. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2762. $query->where(function ($q) use ($data) {
  2763. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2764. });
  2765. })
  2766. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  2767. $query->where(function ($q) use ($data) {
  2768. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  2769. });
  2770. })
  2771. ->select('id', 'sexy', 'experience', 'origin', 'industry', 'name', 'job', 'job_name_get', 'city_arr_id', 'cat_arr_id', 'created_at', 'updated_at')
  2772. ->orderBy('updated_at', 'desc');
  2773. $hunt_count = $query->count();
  2774. $query = clone $query;
  2775. $JobHunting = $query
  2776. ->offset(($data['page'] - 1) * $data['pageSize'])
  2777. ->limit($data['pageSize'])
  2778. ->get();
  2779. if (empty($JobHunting)) {
  2780. $JobRecruiting = "暂无相关简历信息";
  2781. } else {
  2782. $JobHunting = $this->processJob($JobHunting, $website_id);
  2783. }
  2784. }
  2785. $result = [
  2786. 'JobRecruiting' => $JobRecruiting ?? [],
  2787. 'recruit_count' => $recruit_count ?? 0,
  2788. 'JobHunting' => $JobHunting ?? [],
  2789. 'hunt_count' => $hunt_count ?? 0,
  2790. ];
  2791. return Result::success($result);
  2792. }
  2793. /**
  2794. * c端-获取招工招聘详情
  2795. * @param array $data
  2796. * @return array
  2797. * */
  2798. public function getWebsiteJobInfo(array $data): array
  2799. {
  2800. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2801. if (empty($web)) {
  2802. return Result::error("该网站不存在", 0);
  2803. }
  2804. $webid = [
  2805. 'website_id' => $data['website_id'],
  2806. ];
  2807. // 职位相关信息
  2808. if ($data['type'] == 1) {
  2809. $query = JobRecruiting::where('status', 1)
  2810. ->where('website_id', $data['website_id'])
  2811. ->select('*');
  2812. $job = $query->where('job_recruiting.id', $data['id'])->get();
  2813. $company = JobCompany::where('job_id', $data['id'])->select('id', 'business_name', 'company_hy_id', 'company_size', 'company_nature', 'address_arr_id', 'address', 'job_company.email')->get();
  2814. if (!empty($company)) {
  2815. $result['company'] = $this->processJob($company, $webid);
  2816. }
  2817. $other_job = JobRecruiting::where('status', 1)
  2818. ->where('website_id', $data['website_id'])
  2819. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  2820. ->where('id', '!=', $data['id'])
  2821. ->where('user_id', '=', $job[0]['user_id'])
  2822. ->limit($data['pageSize'])
  2823. ->get();
  2824. if (!empty($other_job)) {
  2825. $result['other_job'] = $this->processJob($other_job, $webid);
  2826. }
  2827. } else {
  2828. // 简历相关信息
  2829. $job = JobHunting::where('job_hunting.status', 2)
  2830. ->where('job_hunting.website_id', $data['website_id'])
  2831. ->where('job_hunting.id', $data['id'])
  2832. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  2833. ->select('job_hunting.*', 'user_name')
  2834. ->get();
  2835. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  2836. if (!empty($resume->toArray())) {
  2837. $result['resume'] = 1;
  2838. } else {
  2839. $result['resume'] = 0;
  2840. }
  2841. }
  2842. if (empty($job->toArray())) {
  2843. return Result::error("id参数错误", 0);
  2844. }
  2845. if (!empty($job[0]['job_experience'])) {
  2846. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  2847. if (!empty($job_experience)) {
  2848. // $hy = [];
  2849. foreach ($job_experience as $key => $value) {
  2850. // $id = $value['id'];
  2851. $hy[$key] = $value['job_industry'];
  2852. $zw_id[$key] = $value['job_typename'];
  2853. $jtzw_id[$key] = $value['job_name'];
  2854. }
  2855. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  2856. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  2857. // 先将关联表转换为索引数组,提高查找效率
  2858. $hyLookup = [];
  2859. foreach ($hy_table as $item) {
  2860. $hyLookup[$item['hyid']] = $item['hyname'];
  2861. }
  2862. $zwLookup = [];
  2863. foreach ($zw_table as $item) {
  2864. $zwLookup[$item['zwid']] = $item['zwname'];
  2865. }
  2866. foreach ($job_experience as $key => &$value) {
  2867. // 处理行业名称
  2868. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  2869. $value['hy_name'] = $hyLookup[$hy[$key]];
  2870. }
  2871. // 处理职位名称
  2872. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  2873. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  2874. }
  2875. // 处理具体职位名称
  2876. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  2877. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  2878. }
  2879. }
  2880. // 释放引用,防止意外修改后续代码
  2881. unset($value);
  2882. }
  2883. $result['job_experience'] = $job_experience ?? [];
  2884. }
  2885. if (!empty($job[0]['education_experience'])) {
  2886. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  2887. if (!empty($education_experience)) {
  2888. foreach ($education_experience as $key => $value) {
  2889. // $id = $value['id'];
  2890. $education[$key] = $value['school_education'];
  2891. }
  2892. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  2893. // // 先将关联表转换为索引数组,提高查找效率
  2894. $educationLookup = [];
  2895. foreach ($education_table as $item) {
  2896. $educationLookup[$item['evalue']] = $item['ename'];
  2897. }
  2898. foreach ($education_experience as $key => &$value) {
  2899. // 处理学历名称
  2900. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  2901. $value['education_name'] = $educationLookup[$education[$key]];
  2902. }
  2903. }
  2904. }
  2905. $result['education_experience'] = $job_experience ?? [];
  2906. }
  2907. $result['job'] = $this->processJob($job, $webid);
  2908. // // 返现对应的栏目
  2909. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  2910. $category = WebsiteCategory::where('website_id', $data['website_id'])
  2911. ->whereIn('category_id', $catid)
  2912. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  2913. ->orderBy('pid')->get()->all();
  2914. if (!empty($category)) {
  2915. $result['category'] = $category;
  2916. }
  2917. $result['job'] = $job;
  2918. $result['job_experience'] = $job_experience ?? [];
  2919. $result['education_experience'] = $education_experience ?? [];
  2920. if (empty($result)) {
  2921. return Result::error("参数错误", 0);
  2922. }
  2923. return Result::success($result);
  2924. }
  2925. /**
  2926. * c端-申请职位
  2927. * @param array $data
  2928. * @return array
  2929. * */
  2930. public function getWebsiteJobApply(array $data): array
  2931. {
  2932. // 首先验证网站是否存在
  2933. // return Result::success($data);
  2934. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2935. if (empty($web)) {
  2936. return Result::error("该网站不存在", 0);
  2937. }
  2938. // 验证用户是否存在且为个人会员/管理员
  2939. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  2940. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  2941. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  2942. return Result::error("用户不存在", 0);
  2943. }
  2944. // 去除重复元素和空元素,并保持原始顺序
  2945. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  2946. return !empty($value);
  2947. }));
  2948. // 验证职位是否存在 1:审核通过
  2949. $recruiting = JobRecruiting::where('status', 1)
  2950. ->where('website_id', $data['website_id'])
  2951. ->whereIn('id', $data['recruit_id'])
  2952. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  2953. if (empty($recruiting)) {
  2954. return Result::error("该职位不存在", 0);
  2955. }
  2956. // 简历是否存在
  2957. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  2958. if (empty($hunt_id)) {
  2959. return Result::error("该简历不存在", 0);
  2960. }
  2961. $data['hunt_id'] = $hunt_id['hunt_id'];
  2962. // // 验证是否已投递过该职位
  2963. $apply = JobApply::where('user_id', $data['user_id'])
  2964. ->where('hunt_id', $data['hunt_id'])
  2965. ->where('website_id', $data['website_id'])
  2966. ->whereIn('recruit_id', $data['recruit_id'])
  2967. ->get(['recruit_id']);
  2968. if (!empty($apply->toArray())) {
  2969. return Result::error("您已投递过该职位!");
  2970. }
  2971. $insertData = array_map(function ($recruiting) use ($data) {
  2972. return [
  2973. 'user_id' => $data['user_id'],
  2974. 'hunt_id' => $data['hunt_id'],
  2975. 'website_id' => $data['website_id'],
  2976. 'recruit_id' => $recruiting['recruit_id'],
  2977. 'receiver_id' => $recruiting['receiver_id'],
  2978. 'status' => 1,
  2979. ];
  2980. }, $recruiting);
  2981. // 批量插入数据
  2982. $result = JobApply::insert($insertData);
  2983. if (empty($result)) {
  2984. return Result::error("投递失败", 0);
  2985. }
  2986. return Result::success($result);
  2987. }
  2988. /**
  2989. * 招工招聘-沟通简历
  2990. * @param array $data
  2991. * @return array
  2992. * */
  2993. public function getWebsiteJobResume(array $data): array
  2994. {
  2995. // 首先验证网站是否存在
  2996. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2997. if (empty($web)) {
  2998. return Result::error("该网站不存在", 0);
  2999. }
  3000. // return Result::success($data);
  3001. // 验证用户是否存在且为企业会员/管理员
  3002. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3003. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3004. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3005. return Result::error("用户不存在", 0);
  3006. }
  3007. // 去除重复元素和空元素,并保持原始顺序
  3008. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  3009. return !empty($value);
  3010. }));
  3011. // 验证简历是否存在
  3012. $hunting = JobHunting::where('status', 2)
  3013. ->where('website_id', $data['website_id'])
  3014. ->whereIn('id', $data['hunt_id'])
  3015. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  3016. if (empty($hunting)) {
  3017. return Result::error("该简历不存在", 0);
  3018. }
  3019. // 验证是否已沟通过该简历
  3020. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3021. ->where('recruit_id', $data['recruit_id'])
  3022. ->where('website_id', $data['website_id'])
  3023. ->whereIn('hunt_id', $data['hunt_id'])
  3024. ->get(['hunt_id']);
  3025. if (!empty($remuse->toArray())) {
  3026. return Result::error("您已沟通过该简历!");
  3027. }
  3028. // 准备要插入的数据数组
  3029. $insertData = array_map(function ($hunting) use ($data) {
  3030. return [
  3031. 'user_id' => $data['user_id'],
  3032. 'recruit_id' => $data['recruit_id'],
  3033. 'website_id' => $data['website_id'],
  3034. 'hunt_id' => $hunting['hunt_id'],
  3035. 'receiver_id' => $hunting['receiver_id'],
  3036. 'status' => 1,
  3037. ];
  3038. }, $hunting);
  3039. // 批量插入数据
  3040. $result = JobRemuse::insert($insertData);
  3041. if (empty($result)) {
  3042. return Result::error("沟通失败", 0);
  3043. }
  3044. return Result::success($result);
  3045. }
  3046. /**
  3047. * 招工招聘 -我的职位(企业会员)
  3048. * @param array $data
  3049. * @return array
  3050. */
  3051. public function getWebsiteJobRecruiting(array $data): array
  3052. {
  3053. $web = Website::where('id', $data['website_id'])->first('id');
  3054. if (empty($web)) {
  3055. return Result::error("该网站不存在", 0);
  3056. }
  3057. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3058. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3059. return Result::error("用户暂无权限!", 0);
  3060. }
  3061. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3062. $result = JobRecruiting::where('website_id', $data['website_id'])
  3063. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  3064. $query->where('user_id', $user['id']);
  3065. })
  3066. ->where('status', 1)
  3067. ->select('id', 'title', 'website_id', 'user_id', 'updated_at')
  3068. ->orderBy('updated_at', 'desc')
  3069. ->limit($data['pageSize'])
  3070. ->get();
  3071. if (empty($result)) {
  3072. return Result::error("暂无相关职位信息", 0);
  3073. }
  3074. return Result::success($result);
  3075. }
  3076. /**
  3077. * c端 - 验证路由
  3078. * @param array $data
  3079. * @return array
  3080. */
  3081. public function checkWebsiteRoute(array $data): array
  3082. {
  3083. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3084. if (empty($web)) {
  3085. return Result::error("该网站不存在", 0);
  3086. }
  3087. // 验证栏目路由
  3088. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  3089. ->where('aLIas_pinyin', $data['last_route'])
  3090. ->first();
  3091. if (empty($last_category)) {
  3092. return Result::error("该栏目不存在", 0);
  3093. }
  3094. if (isset($data['id']) && !empty($data['id'])) {
  3095. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  3096. switch ($last_category['type']) {
  3097. case 1:
  3098. // 文章
  3099. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  3100. $article = Article::where('status', 1)
  3101. ->where('id', $data['id'])
  3102. ->where(function ($query) use ($data) {
  3103. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  3104. ->orWhereNull("ignore_ids");
  3105. })
  3106. ->first(['cat_arr_id']);
  3107. if (empty($article)) {
  3108. return Result::error("该文章不存在", 0);
  3109. }
  3110. // return Result::success($article);
  3111. break;
  3112. case 2:
  3113. // 商品
  3114. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3115. $article = Good::where('website_id', $data['website_id'])
  3116. ->where('status', 2)
  3117. ->where('id', $data['id'])
  3118. ->first(['cat_arr_id']);
  3119. if (empty($article)) {
  3120. return Result::error("该商品不存在", 0);
  3121. }
  3122. break;
  3123. case 3:
  3124. // 书刊信息
  3125. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3126. $article = Book::where('website_id', $data['website_id'])
  3127. ->where('status', 2)
  3128. ->where('id', $data['id'])
  3129. ->first(['id', 'cat_arr_id']);
  3130. if (empty($article)) {
  3131. return Result::error("该书刊不存在", 0);
  3132. }
  3133. break;
  3134. case 4:
  3135. // 招聘
  3136. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核;(只有企业会员需要审核)',
  3137. $article = JobRecruiting::where('website_id', $data['website_id'])
  3138. ->where('status', 1)
  3139. ->where('id', $data['id'])
  3140. ->first(['cat_arr_id']);
  3141. if (empty($article)) {
  3142. return Result::error("该招聘不存在", 0);
  3143. }
  3144. break;
  3145. case 5:
  3146. // 求职
  3147. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3148. $article = JobHunting::where('website_id', $data['website_id'])
  3149. ->where('status', 2)
  3150. ->where('id', $data['id'])
  3151. ->first(['cat_arr_id']);
  3152. if (empty($article)) {
  3153. return Result::error("该求职不存在", 0);
  3154. }
  3155. break;
  3156. case 6:
  3157. // 招工招聘
  3158. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3159. $article = JobRecruiting::where('website_id', $data['website_id'])
  3160. ->where('status', 1)
  3161. ->where('id', $data['id'])
  3162. ->first(['cat_arr_id']);
  3163. if (empty($article)) {
  3164. $article = JobHunting::where('website_id', $data['website_id'])
  3165. ->where('status', 2)
  3166. ->where('id', $data['id'])
  3167. ->first(['cat_arr_id']);
  3168. }
  3169. if (empty($article)) {
  3170. return Result::error("该招工招聘不存在", 0);
  3171. }
  3172. break;
  3173. default:
  3174. return Result::error("该数据不存在", 0);
  3175. break;
  3176. }
  3177. $catid = json_decode($article['cat_arr_id'], true);
  3178. if (empty($catid)) {
  3179. return Result::error("该数据不存在", 0);
  3180. }
  3181. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3182. ->orderByRaw('FIELD(category_id, ' . implode(',', $catid) . ')')
  3183. ->whereIn('category_id', $catid)
  3184. ->pluck('aLIas_pinyin')
  3185. ->implode('/');
  3186. }
  3187. if ($last_category['pid'] != 0) {
  3188. $cat_arr = json_decode($last_category['category_arr_id'], true);
  3189. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3190. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr) . ')')
  3191. ->whereIn('category_id', $cat_arr)
  3192. ->pluck('aLIas_pinyin')
  3193. ->implode('/');
  3194. } else {
  3195. $pinyin = $last_category['aLIas_pinyin'];
  3196. }
  3197. if (empty($pinyin) || $pinyin != $data['all_route']) {
  3198. return Result::error('非法路径!');
  3199. } else {
  3200. return Result::success($pinyin);
  3201. }
  3202. }
  3203. /**
  3204. * 验证导航名称是否重复
  3205. * @return void
  3206. */
  3207. public function checkCategoryName(array $data): array
  3208. {
  3209. $result = Category::when($data, function ($query) use ($data) {
  3210. if (isset($data['name']) && $data['name']) {
  3211. $query->where("name", $data['name']);
  3212. }
  3213. if (isset($data['id']) && $data['id']) {
  3214. $query->where("id", "!=", $data['id']);
  3215. }
  3216. })->first();
  3217. if ($result) {
  3218. return Result::error("已存在");
  3219. } else {
  3220. return Result::success();
  3221. }
  3222. }
  3223. //20250226 产品列表
  3224. public function getGoodList(array $data): array
  3225. {
  3226. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3227. unset($data['type_id']);
  3228. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3229. $where = [];
  3230. if ($type_id != '10000') {
  3231. $where = [
  3232. 'good.user_id' => $user_id,
  3233. ];
  3234. }
  3235. //类型
  3236. if (isset($data['type_id']) && $data['type_id']) {
  3237. $where = [
  3238. 'type_id' => $data['type_id'],
  3239. ];
  3240. }
  3241. //名称
  3242. if (isset($data['name']) && $data['name']) {
  3243. $where = [
  3244. 'good.name' => $data['name'],
  3245. ];
  3246. }
  3247. //status
  3248. if (isset($data['status']) && $data['status'] != '') {
  3249. $where = [
  3250. 'good.status' => $data['status'],
  3251. ];
  3252. }
  3253. //status1
  3254. // if (isset($data['status1']) && $data['status1'] == 1) {
  3255. // $status1 = 1;
  3256. // }
  3257. $where1 = [];
  3258. //website_id
  3259. // if (isset($data['website_id']) && $data['website_id']) {
  3260. // $where1 = [
  3261. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  3262. // ];
  3263. // }
  3264. // website_name
  3265. if (isset($data['website_name']) && $data['website_name']) {
  3266. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  3267. }
  3268. // catid
  3269. if (isset($data['category_name']) && $data['category_name']) {
  3270. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  3271. }
  3272. // $result = Good::where($where)
  3273. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  3274. $result = Good::where($where)
  3275. ->when(!empty($where1), function ($query) use ($where1) {
  3276. return $query->where($where1);
  3277. })
  3278. //status 1待审核2已审核3已拒绝
  3279. ->when(isset($data['status1']), function ($query) {
  3280. return $query->whereIn('good.status', [1, 3]);
  3281. })
  3282. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3283. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3284. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3285. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3286. ->orderBy("updated_at", "desc")
  3287. ->limit($data['page_size'])
  3288. ->offset(($data['page'] - 1) * $data['page_size'])
  3289. ->get();
  3290. $count = Good::where($where)
  3291. ->when(!empty($where1), function ($query) use ($where1) {
  3292. return $query->where($where1);
  3293. })
  3294. //status 1待审核2已审核3已拒绝
  3295. ->when(isset($data['status1']), function ($query) {
  3296. return $query->whereIn('good.status', [1, 3]);
  3297. })
  3298. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3299. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3300. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3301. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3302. ->orderBy("updated_at", "desc")->count();
  3303. $data = [
  3304. 'rows' => $result->toArray(),
  3305. 'count' => $count,
  3306. ];
  3307. if (empty($result)) {
  3308. return Result::error("此栏目暂无相关产品", 0);
  3309. }
  3310. return Result::success($data);
  3311. }
  3312. public function getGoodInfo(array $data): array
  3313. {
  3314. $result = Good::where('id', $data['id'])->first();
  3315. if (empty($result)) {
  3316. return Result::error("此产品不存在", 0);
  3317. }
  3318. return Result::success($result);
  3319. }
  3320. public function addGood(array $data): array
  3321. {
  3322. // unset($data['city_arr_id']);
  3323. // unset($data['cat_arr_id']);
  3324. $data['city_id'] = end($data['city_arr_id']);
  3325. $data['catid'] = end($data['cat_arr_id']);
  3326. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3327. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3328. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3329. unset($data['imgUrl']);
  3330. if (isset($data['price']) && $data['price'] == '') {
  3331. $data['price'] = 0;
  3332. }
  3333. $result = Good::insert($data);
  3334. if (empty($result)) {
  3335. return Result::error("添加失败", 0);
  3336. }
  3337. return Result::success($result);
  3338. }
  3339. public function updateGood(array $data): array
  3340. {
  3341. $data['city_id'] = end($data['city_arr_id']);
  3342. $data['catid'] = end($data['cat_arr_id']);
  3343. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3344. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3345. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3346. //设置东八区
  3347. date_default_timezone_set('Asia/Shanghai');
  3348. $data['updated_at'] = date('Y-m-d H:i:s');
  3349. if (isset($data['price']) && $data['price'] == '') {
  3350. $data['price'] = 0;
  3351. }
  3352. $result = Good::where('id', $data['id'])->update($data);
  3353. if (empty($result)) {
  3354. return Result::error("更新失败", 0);
  3355. }
  3356. return Result::success($result);
  3357. }
  3358. public function delGood(array $data): array
  3359. {
  3360. $result = Good::where('id', $data['id'])->delete();
  3361. if (empty($result)) {
  3362. return Result::error("删除失败", 0);
  3363. }
  3364. return Result::success($result);
  3365. }
  3366. //20250226 产品列表
  3367. //20250306 求职信息
  3368. public function getJobHuntingList(array $data): array
  3369. {
  3370. $where = [];
  3371. if (isset($data['username']) && !empty($data['username'])) {
  3372. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3373. }
  3374. //status 1待审核2已审核3已拒绝
  3375. if (isset($data['status']) && $data['status'] != '') {
  3376. $where = [
  3377. 'job_hunting.status' => $data['status'],
  3378. ];
  3379. }
  3380. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3381. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3382. unset($data['type_id']);
  3383. if ($type_id != '10000') {
  3384. $where[] = ['job_hunting.user_id', '=', $user_id];
  3385. }
  3386. $result = JobHunting::where($where)
  3387. ->when(!empty($data['status1']), function ($query) use ($data) {
  3388. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3389. })
  3390. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3391. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3392. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  3393. ->orderBy("updated_at", "desc")
  3394. ->limit($data['page_size'])
  3395. ->offset(($data['page'] - 1) * $data['page_size'])
  3396. ->get();
  3397. if (empty($result)) {
  3398. return Result::error("查询失败", 0);
  3399. }
  3400. $count = JobHunting::where($where)
  3401. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3402. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3403. ->count();
  3404. $data = [
  3405. 'rows' => $result->toArray(),
  3406. 'count' => $count,
  3407. ];
  3408. return Result::success($data);
  3409. }
  3410. public function getJobHuntingApply(array $data): array
  3411. {
  3412. var_dump($data, '-----------------test--------1-');
  3413. $where = [];
  3414. if (isset($data['username']) && !empty($data['username'])) {
  3415. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3416. }
  3417. if (isset($data['salary']) && !empty($data['salary'])) {
  3418. $where[] = [
  3419. 'job_hunting.salary',
  3420. '=',
  3421. $data['salary'],
  3422. ];
  3423. }
  3424. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3425. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3426. unset($data['type_id']);
  3427. if ($type_id != '10000') {
  3428. $where[] = ['job_apply.user_id', '=', $user_id];
  3429. }
  3430. var_dump($where, '-----------------test---------');
  3431. $result = jobApply::where($where)
  3432. // ->when(!empty($data['status1']), function ($query) use ($data) {
  3433. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3434. // })
  3435. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  3436. ->where('job_enum.egroup', '=', 'income')
  3437. ->where('job_hunting.status', 2) //已审核
  3438. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3439. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3440. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3441. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3442. //职位----是申请职位
  3443. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3444. ->select('job_apply.*', 'job_position.zwname as job_name', 'job_hunting.salary as salary', 'district.name as cityname', 'job_enum.ename as salary_name', 'user.nickname as nickname', 'user.user_name as username', 'job_hunting.updated_at as updated_at')
  3445. ->orderBy("job_hunting.updated_at", "desc")
  3446. ->limit($data['page_size'])
  3447. ->offset(($data['page'] - 1) * $data['page_size'])
  3448. ->get();
  3449. if (empty($result)) {
  3450. return Result::error("查询失败", 0);
  3451. }
  3452. $count = jobApply::where($where)
  3453. ->where('job_enum.egroup', '=', 'income')
  3454. ->where('job_hunting.status', 2) //已审核
  3455. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3456. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3457. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3458. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3459. //职位----是申请职位
  3460. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3461. ->select('job_apply.*', 'job_position.zwname as job_name', 'job_hunting.salary as salary', 'district.name as cityname', 'job_enum.ename as salary_name', 'user.nickname as nickname', 'user.user_name as username', 'job_hunting.updated_at as updated_at')
  3462. ->count();
  3463. $data = [
  3464. 'rows' => $result->toArray(),
  3465. 'count' => $count,
  3466. ];
  3467. return Result::success($data);
  3468. }
  3469. public function addJobHunting(array $data): array
  3470. {
  3471. date_default_timezone_set('Asia/Shanghai');
  3472. unset($data['company_name']);
  3473. unset($data['job_industry']);
  3474. unset($data['job_name']);
  3475. unset($data['department']);
  3476. unset($data['job_timeList']);
  3477. unset($data['job_content']);
  3478. $data['created_at'] = date('Y-m-d H:i:s');
  3479. $data['updated_at'] = date('Y-m-d H:i:s');
  3480. var_dump($data, '-----------------test---------');
  3481. $result = JobHunting::create($data);
  3482. if (empty($result)) {
  3483. return Result::error("添加失败", 0);
  3484. }
  3485. return Result::success($result);
  3486. }
  3487. public function delJobHunting(array $data): array
  3488. {
  3489. $result = JobHunting::where('id', $data['id'])->delete();
  3490. if (empty($result)) {
  3491. return Result::error("删除失败", 0);
  3492. }
  3493. return Result::success($result);
  3494. }
  3495. public function updateJobHunting(array $data): array
  3496. {
  3497. //设置东八区
  3498. date_default_timezone_set('Asia/Shanghai');
  3499. unset($data['company_name']);
  3500. unset($data['job_industry']);
  3501. unset($data['job_name']);
  3502. unset($data['department']);
  3503. unset($data['job_timeList']);
  3504. unset($data['job_content']);
  3505. unset($data['job_typename']); //不知道这是啥,
  3506. $data['created_at'] = date('Y-m-d H:i:s');
  3507. $data['updated_at'] = date('Y-m-d H:i:s');
  3508. $result = JobHunting::where('id', $data['id'])->update($data);
  3509. if (empty($result)) {
  3510. return Result::error("更新失败", 0);
  3511. }
  3512. return Result::success($result);
  3513. }
  3514. public function getJobHuntingInfo(array $data): array
  3515. {
  3516. $result = JobHunting::where('id', $data['id'])->first();
  3517. if (empty($result)) {
  3518. return Result::error("查询失败", 0);
  3519. }
  3520. return Result::success($result);
  3521. }
  3522. public function getJobHuntingData(array $data): array
  3523. {
  3524. $jobEnum = JobEnum::get();
  3525. $jobIndustry = JobIndustry::get();
  3526. $jobNature = JobNature::get();
  3527. $jobPosition = JobPosition::get();
  3528. $data = [
  3529. 'jobEnum' => $jobEnum,
  3530. 'jobIndustry' => $jobIndustry,
  3531. 'jobNature' => $jobNature,
  3532. 'jobPosition' => $jobPosition,
  3533. ];
  3534. return Result::success($data);
  3535. }
  3536. public function delJobHuntingInfo(array $data): array
  3537. {
  3538. $result = JobHunting::where('id', $data['id'])->delete();
  3539. return Result::success();
  3540. }
  3541. //20250324 通知,公告,消息
  3542. public function delNotice(array $data): array
  3543. {
  3544. $result = Notice::where('id', $data['id'])->delete();
  3545. if ($result) {
  3546. return Result::success();
  3547. } else {
  3548. return Result::error("删除失败", 0);
  3549. }
  3550. }
  3551. public function getNoticeInfo(array $data): array
  3552. {
  3553. $result = Notice::where('id', $data['id'])->first();
  3554. if (empty($result)) {
  3555. return Result::error("查询失败", 0);
  3556. }
  3557. return Result::success($result);
  3558. }
  3559. public function addNotice(array $data): array
  3560. {
  3561. date_default_timezone_set('Asia/Shanghai');
  3562. $data['created_at'] = date('Y-m-d H:i:s');
  3563. $data['updated_at'] = date('Y-m-d H:i:s');
  3564. $user_id = UserInfo::
  3565. //city_id不是null
  3566. whereNotNull('city_id')
  3567. ->whereNotNull('department_id')
  3568. ->where(function ($query) use ($data) {
  3569. $query->where(function ($subQuery) use ($data) {
  3570. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3571. });
  3572. })
  3573. ->where(function ($query) use ($data) {
  3574. $query->where(function ($subQuery) use ($data) {
  3575. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  3576. });
  3577. })
  3578. ->pluck('user_id')->toArray();
  3579. $user_id = array_unique($user_id);
  3580. $chat_ids = $user_id;
  3581. $user_id = json_encode($user_id);
  3582. $data['re_user_ids'] = $user_id;
  3583. $result = Notice::insertGetId($data);
  3584. if ($result && $data['is_group'] == 1) {
  3585. //chat_group
  3586. $group_id = PublicData::uuid();
  3587. $groupData = [
  3588. 'id' => $group_id,
  3589. 'creator_id' => $data['user_id'],
  3590. 'group_name' => $data['group_name'] ?? '',
  3591. 'profile' => $data['profile'] ?? 0,
  3592. ];
  3593. var_dump($groupData, '-----------------groupData-------');
  3594. $groupResult = ChatGroups::insertGetId($groupData);
  3595. var_dump($groupResult, '-----------------groupid-------');
  3596. $groupMemberData = [
  3597. 'id' => PublicData::uuid(),
  3598. 'user_id' => $data['user_id'],
  3599. 'group_id' => $group_id,
  3600. 'leader' => 2,
  3601. ];
  3602. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  3603. //$chat_ids 去除掉$data['user_id']
  3604. $chat_ids = array_diff($chat_ids, [$data['user_id']]);
  3605. //插入群成员表
  3606. $groupMemberDataUser = [];
  3607. $chatData = [];
  3608. foreach ($chat_ids as $key => $value) {
  3609. $groupMemberDataUser[] = [
  3610. 'id' => PublicData::uuid(),
  3611. 'user_id' => $value,
  3612. 'group_id' => $group_id,
  3613. 'leader' => 1,
  3614. ];
  3615. $chatData[] = [
  3616. 'user_id' => $value,
  3617. 'msg_type' => 1,
  3618. 'receiver_id' => $group_id,
  3619. 'content' => '通过通知创建群聊',
  3620. 'group_receiver_id' => $data['user_id'],
  3621. 'action' => 'recieved',
  3622. 'created_at' => date('Y-m-d H:i:s'),
  3623. ];
  3624. }
  3625. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  3626. ChatGroupsMember::insert($groupMemberDataUser);
  3627. //插入一条管理员聊天记录
  3628. $chatData[] = [
  3629. 'user_id' => $data['user_id'],
  3630. 'msg_type' => 1,
  3631. 'receiver_id' => $group_id,
  3632. 'content' => '通过通知创建群聊',
  3633. 'group_receiver_id' => $data['user_id'],
  3634. 'action' => 'said',
  3635. 'created_at' => date('Y-m-d H:i:s'),
  3636. ];
  3637. var_dump($chatData, '-----------------chatData-------');
  3638. $chatResult = ChatRecords::insert($chatData);
  3639. //更新result的 group_id
  3640. $data['group_id'] = $group_id;
  3641. Notice::where(['id' => $result])->update($data);
  3642. }
  3643. if (empty($result)) {
  3644. return Result::error("添加失败", 0);
  3645. }
  3646. return Result::success($result);
  3647. }
  3648. public function updateNotice(array $data): array
  3649. {
  3650. date_default_timezone_set('Asia/Shanghai');
  3651. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  3652. $user_id = UserInfo::
  3653. //city_id不是null
  3654. whereNotNull('city_id')
  3655. ->whereNotNull('department_id')
  3656. ->where(function ($query) use ($data) {
  3657. $query->where(function ($subQuery) use ($data) {
  3658. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3659. });
  3660. })
  3661. ->where(function ($query) use ($data) {
  3662. $query->where(function ($subQuery) use ($data) {
  3663. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  3664. });
  3665. })
  3666. ->pluck('user_id')->toArray();
  3667. $user_id = array_unique($user_id);
  3668. $user_id = json_encode($user_id);
  3669. $data['re_user_ids'] = $user_id;
  3670. $data['updated_at'] = date('Y-m-d H:i:s');
  3671. $result = Notice::where('id', $data['id'])->update($data);
  3672. return Result::success($result);
  3673. }
  3674. public function getNoticeList(array $data): array
  3675. {
  3676. $where = [];
  3677. //title
  3678. if (isset($data['title']) && !empty($data['title'])) {
  3679. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  3680. }
  3681. //level
  3682. if (isset($data['level']) && !empty($data['level'])) {
  3683. $where[] = ['notice.level', '=', $data['level']];
  3684. }
  3685. //status
  3686. if (isset($data['status']) && !empty($data['status'])) {
  3687. $where[] = ['notice.status', '=', $data['status']];
  3688. }
  3689. var_dump($data, '-----------------test---------');
  3690. if ($data['type_id'] == 10000) {
  3691. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  3692. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  3693. })
  3694. ->where($where)
  3695. ->orderBy('updated_at', 'desc')
  3696. ->limit($data['page_size'])
  3697. ->offset(($data['page'] - 1) * $data['page_size'])
  3698. ->get();
  3699. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  3700. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  3701. })
  3702. ->where($where)
  3703. ->orderBy('updated_at', 'desc')
  3704. ->count();
  3705. } else {
  3706. $result = Notice::where($where)
  3707. // ->where('user_id', $data['user_id'])
  3708. ->Where(function ($query) use ($data) {
  3709. $query->Where(function ($q) use ($data) {
  3710. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  3711. ->orWhere('notice.user_id', $data['user_id']);
  3712. });
  3713. })
  3714. ->orderBy('updated_at', 'desc')
  3715. ->limit($data['page_size'])
  3716. ->offset(($data['page'] - 1) * $data['page_size'])
  3717. ->get();
  3718. $total = Notice::where($where)
  3719. // ->where('user_id', $data['user_id'])
  3720. ->Where(function ($query) use ($data) {
  3721. $query->Where(function ($q) use ($data) {
  3722. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  3723. ->orWhere('notice.user_id', $data['user_id']);
  3724. });
  3725. })
  3726. ->count();
  3727. }
  3728. if (empty($result)) {
  3729. return Result::error("查询失败", 0);
  3730. }
  3731. $data = [
  3732. 'rows' => $result,
  3733. 'count' => $total,
  3734. ];
  3735. return Result::success($data);
  3736. }
  3737. public function getNoticeDetail(array $data): array
  3738. {
  3739. $result = Notice::where('id', $data['id'])->first();
  3740. if (empty($result)) {
  3741. return Result::error("查询失败", 0);
  3742. }
  3743. return Result::success($result);
  3744. }
  3745. public function deleteNotice(array $data): array
  3746. {
  3747. $notice = Notice::where('id', $data['id'])->first();
  3748. if (empty($notice)) {
  3749. return Result::error("删除失败", 0);
  3750. }
  3751. $chat_group_id = $notice->group_id;
  3752. if ($chat_group_id) {
  3753. //删除群聊
  3754. ChatGroups::where('id', $chat_group_id)->delete();
  3755. //删除群成员
  3756. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  3757. //删除群聊记录
  3758. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  3759. }
  3760. $result = Notice::where('id', $data['id'])->delete();
  3761. return Result::success($result);
  3762. }
  3763. public function getMSG(array $data): array
  3764. {
  3765. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  3766. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3767. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  3768. $result = [];
  3769. if ($type_id == 1) {
  3770. //最近的5篇已审的文章
  3771. $apply_articale = Article::where('status', 1)
  3772. ->where('admin_user_id', $user_id)
  3773. ->orderBy('updated_at', 'desc')
  3774. ->limit(5)->get();
  3775. //获取5条单聊未读聊天消息
  3776. $chat = ChatRecords::where('is_read', 0)
  3777. ->where('user_id', $user_id)
  3778. ->where('talk_type', 1)
  3779. ->orderBy('created_at', 'desc')
  3780. ->limit(5)->get();
  3781. //获取5条未读群聊信息
  3782. $chat_group = ChatRecords::where('is_read', 0)
  3783. ->where('user_id', $user_id)
  3784. ->where('talk_type', 2)
  3785. ->orderBy('created_at', 'desc')
  3786. ->limit(5)->get();
  3787. //获取5条用户的已审核商品
  3788. $good = Good::where('status', 2)
  3789. ->where('user_id', $user_id)
  3790. ->orderBy('updated_at', 'desc')
  3791. ->limit(5)->get();
  3792. //获取5条用户待审核的公告
  3793. $notice = Notice::where('status', 2)
  3794. ->where('user_id', $user_id)
  3795. ->orderBy('updated_at', 'desc')
  3796. ->limit(5)->get();
  3797. //获取5条用户的待审核投诉
  3798. $complaint = Complaint::where('status', 2)
  3799. ->where('user_id', $user_id)
  3800. ->orderBy('updated_at', 'desc')
  3801. ->limit(5)->get();
  3802. //获取5条用户的book
  3803. $book = Book::where('status', 2)
  3804. ->where('user_id', $user_id)
  3805. ->orderBy('updated_at', 'desc')
  3806. ->limit(5)->get();
  3807. //获取5条用户的求职
  3808. //获取5条用户的求职 1
  3809. $job_hunting = JobHunting::where('job_hunting.status', 1)
  3810. ->where('job_hunting.user_id', $user_id)
  3811. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3812. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  3813. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  3814. ->orderBy('updated_at', 'desc')
  3815. ->limit(5)->get();
  3816. //获取5条用户的求职 2
  3817. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3818. ->where('job_recruiting.user_id', $user_id)
  3819. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  3820. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  3821. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  3822. ->orderBy('updated_at', 'desc')
  3823. ->limit(5)->get();
  3824. //人才库 1
  3825. $job_apply = JobApply::where('job_apply.status', 1)
  3826. ->where('job_apply.receiver_id', $user_id)
  3827. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  3828. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  3829. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  3830. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  3831. ->select('job_recruiting', 'job_recruiting.', '', '')
  3832. ->select('job_apply.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name', 'job_company.business_name as business_name', 'job_recruiting.title as job_name')
  3833. ->orderBy('updated_at', 'desc')
  3834. ->limit(5)->get();
  3835. // 职场机会 2
  3836. $job_resume = JobResume::where('job_resume.status', 1)
  3837. ->where('job_resume.receiver_id', $user_id)
  3838. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  3839. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  3840. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  3841. ->select('job_resume.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name', 'job_company.business_name as business_name')
  3842. ->orderBy('updated_at', 'desc')
  3843. ->limit(5)->get();
  3844. $count = count($chat) + count($chat_group) + count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting) + count($job_apply) + count($job_resume);
  3845. $result = [
  3846. 'apply_articale' => $apply_articale,
  3847. 'chat' => $chat,
  3848. 'chat_group' => $chat_group,
  3849. 'good' => $good,
  3850. 'notice' => $notice,
  3851. 'complaint' => $complaint,
  3852. 'book' => $book,
  3853. 'job_hunting' => $job_hunting,
  3854. 'job_recruiting' => $job_recruiting,
  3855. 'job_apply' => $job_apply,
  3856. 'job_resume' => $job_resume,
  3857. 'count' => $count,
  3858. ];
  3859. } elseif ($type_id == 2) {
  3860. //最近的5篇已审的文章
  3861. $apply_articale = Article::where('status', 1)
  3862. ->where('admin_user_id', $user_id)
  3863. ->limit(5)->get();
  3864. //获取5条单聊未读聊天消息
  3865. $chat = ChatRecords::where('is_read', 0)
  3866. ->where('user_id', $user_id)
  3867. ->where('talk_type', 1)
  3868. ->orderBy('created_at', 'desc')
  3869. ->limit(5)->get();
  3870. //获取5条未读群聊信息
  3871. $chat_group = ChatRecords::where('is_read', 0)
  3872. ->where('user_id', $user_id)
  3873. ->where('talk_type', 2)
  3874. ->orderBy('created_at', 'desc')
  3875. ->limit(5)->get();
  3876. //获取5条用户的已审核商品
  3877. $good = Good::where('status', 2)
  3878. ->where('user_id', $user_id)
  3879. ->orderBy('updated_at', 'desc')
  3880. ->limit(5)->get();
  3881. $count = count($chat) + count($chat_group) + count($apply_articale) + count($good);
  3882. $result = [
  3883. 'apply_articale' => $apply_articale,
  3884. 'chat' => $chat,
  3885. 'chat_group' => $chat_group,
  3886. 'good' => $good,
  3887. 'count' => $count,
  3888. ];
  3889. } elseif ($type_id == 3) {
  3890. //最近的5篇已审的文章
  3891. $apply_articale = Article::where('status', 1)
  3892. ->where('admin_user_id', $user_id)
  3893. ->limit(5)->get();
  3894. //获取5条单聊未读聊天消息
  3895. $chat = ChatRecords::where('is_read', 0)
  3896. ->where('user_id', $user_id)
  3897. ->where('talk_type', 1)
  3898. ->orderBy('created_at', 'desc')
  3899. ->limit(5)->get();
  3900. //获取5条未读群聊信息
  3901. $chat_group = ChatRecords::where('is_read', 0)
  3902. ->where('user_id', $user_id)
  3903. ->where('talk_type', 2)
  3904. ->orderBy('created_at', 'desc')
  3905. ->limit(5)->get();
  3906. //获取5条用户的已审核商品
  3907. $good = Good::where('status', 2)
  3908. ->where('user_id', $user_id)
  3909. ->orderBy('updated_at', 'desc')
  3910. ->limit(5)->get();
  3911. $count = count($chat) + count($chat_group) + count($apply_articale) + count($good);
  3912. $result = [
  3913. 'apply_articale' => $apply_articale,
  3914. 'chat' => $chat,
  3915. 'chat_group' => $chat_group,
  3916. 'good' => $good,
  3917. 'count' => $count,
  3918. ];
  3919. } elseif ($type_id == 4) {
  3920. //最近的5篇已审的文章
  3921. $apply_articale = Article::where('status', 1)
  3922. ->where('admin_user_id', $user_id)
  3923. ->limit(5)->get();
  3924. //获取5条用户的已审核商品
  3925. $good = Good::where('status', 2)
  3926. ->where('user_id', $user_id)
  3927. ->orderBy('updated_at', 'desc')
  3928. ->limit(5)->get();
  3929. $count = count($apply_articale) + count($good);
  3930. $result = [
  3931. 'apply_articale' => $apply_articale,
  3932. 'chat' => '',
  3933. 'chat_group' => '',
  3934. 'good' => $good,
  3935. 'count' => $count,
  3936. ];
  3937. } elseif ($type_id == 10000) {
  3938. //获取未审核的5篇文章
  3939. $apply_articale = Article::where('status', 0)
  3940. ->orderBy('updated_at', 'desc')
  3941. ->limit(5)->get();
  3942. //获取5条单聊未读聊天消息
  3943. $chat = ChatRecords::where('is_read', 0)
  3944. ->where('user_id', $user_id)
  3945. ->where('talk_type', 1)
  3946. ->orderBy('created_at', 'desc')
  3947. ->limit(5)->get();
  3948. //获取5条未读群聊信息
  3949. $chat_group = ChatRecords::where('is_read', 0)
  3950. ->where('user_id', $user_id)
  3951. ->where('talk_type', 2)
  3952. ->orderBy('created_at', 'desc')
  3953. ->limit(5)->get();
  3954. //获取5条用户的已审核商品
  3955. $good = Good::where('status', 1)
  3956. // ->where('user_id', $user_id)
  3957. ->orderBy('updated_at', 'desc')
  3958. ->limit(5)->get();
  3959. //获取5条用户待审核的公告
  3960. $notice = Notice::where('status', 1)
  3961. ->orderBy('updated_at', 'desc')
  3962. ->limit(5)->get();
  3963. //获取5条用户的待审核投诉
  3964. $complaint = Complaint::where('status', 1)
  3965. ->orderBy('updated_at', 'desc')
  3966. ->limit(5)->get();
  3967. //获取5条用户的book
  3968. $book = Book::where('status', 1)
  3969. ->orderBy('updated_at', 'desc')
  3970. ->limit(5)->get();
  3971. //获取5条用户的求职 1
  3972. $job_hunting = JobHunting::where('job_hunting.status', 1)
  3973. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3974. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  3975. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  3976. ->orderBy('updated_at', 'desc')
  3977. ->limit(5)->get();
  3978. //获取5条用户的求职 2
  3979. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3980. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  3981. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  3982. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  3983. ->orderBy('updated_at', 'desc')
  3984. ->limit(5)->get();
  3985. //人才库 1
  3986. $job_apply = JobApply::where('job_apply.status', 1)
  3987. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  3988. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  3989. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  3990. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  3991. ->select('job_apply.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name', 'job_company.business_name as business_name', 'job_recruiting.title as job_name')
  3992. ->orderBy('updated_at', 'desc')
  3993. ->limit(5)->get();
  3994. // 职场机会 2
  3995. $job_resume = JobResume::where('job_resume.status', 1)
  3996. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  3997. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  3998. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  3999. ->select('job_resume.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name', 'job_company.business_name as business_name')
  4000. ->orderBy('updated_at', 'desc')
  4001. ->limit(5)->get();
  4002. $count = count($chat) + count($chat_group) + count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting) + count($job_apply) + count($job_resume);
  4003. $result = [
  4004. 'apply_articale' => $apply_articale,
  4005. 'chat' => $chat,
  4006. 'chat_group' => $chat_group,
  4007. 'good' => $good,
  4008. 'notice' => $notice,
  4009. 'complaint' => $complaint,
  4010. 'book' => $book,
  4011. 'job_hunting' => $job_hunting,
  4012. 'job_recruiting' => $job_recruiting,
  4013. 'job_apply' => $job_apply,
  4014. 'job_resume' => $job_resume,
  4015. 'count' => $count,
  4016. ];
  4017. } elseif ($type_id == 20000) {
  4018. }
  4019. var_dump($type_id, '-----------------test---------');
  4020. return Result::success($result);
  4021. }
  4022. public function getComplaintList(array $data): array
  4023. {
  4024. var_dump($data, '00000001000000000000');
  4025. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4026. unset($data['type_id']);
  4027. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4028. $where = [];
  4029. if ($type_id != 10000 && empty($data['deal_user'])) {
  4030. $where['complaint.user_id'] = $user_id;
  4031. }
  4032. if (!empty($data['title'])) {
  4033. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4034. }
  4035. if (!empty($data['department_id'])) {
  4036. $where['complaint.department_id'] = $data['department_id'];
  4037. }
  4038. if (!empty($data['deal'])) {
  4039. $where['complaint.deal'] = $data['deal'];
  4040. }
  4041. if (!empty($data['status'])) {
  4042. $where['complaint.status'] = $data['status'];
  4043. }
  4044. var_dump(!empty($data['deal_user']), '----------1');
  4045. $result = Complaint::where($where)
  4046. ->when(!empty($data['status1']), function ($query) use ($data) {
  4047. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4048. })
  4049. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4050. //json re_user_ids data[user_id]是不是在里面
  4051. $query->Where(function ($q) use ($data) {
  4052. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4053. ->where('complaint.status', 2);
  4054. });
  4055. })
  4056. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4057. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4058. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4059. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4060. ->orderBy('updated_at', 'desc')
  4061. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4062. //sql输出
  4063. if (empty($result)) {
  4064. return Result::error("暂无投诉信息", 0);
  4065. }
  4066. // 取出数据
  4067. $rows = $result->items();
  4068. $count = $result->total();
  4069. $responseData = [
  4070. 'rows' => $rows,
  4071. 'count' => $count,
  4072. ];
  4073. return Result::success($responseData);
  4074. }
  4075. public function getComplaintInfo(array $data): array
  4076. {
  4077. $result = Complaint::where('id', $data['id'])->first();
  4078. if (empty($result)) {
  4079. return Result::error("查询失败", 0);
  4080. }
  4081. return Result::success($result);
  4082. }
  4083. public function addComplaint(array $data): array
  4084. {
  4085. date_default_timezone_set('Asia/Shanghai');
  4086. $data['created_at'] = date('Y-m-d H:i:s');
  4087. $data['updated_at'] = date('Y-m-d H:i:s');
  4088. $result = Complaint::create($data);
  4089. return Result::success($result);
  4090. }
  4091. public function updateComplaint(array $data): array
  4092. {
  4093. date_default_timezone_set('Asia/Shanghai');
  4094. $data['updated_at'] = date('Y-m-d H:i:s');
  4095. $user_id = $data['user_id'] ?? 0;
  4096. $type_id = $data['type_id'] ?? 0;
  4097. unset($data['user_id']);
  4098. unset($data['type_id']);
  4099. $result = Complaint::where('id', $data['id'])->update($data);
  4100. return Result::success($result);
  4101. }
  4102. public function deleteComplaint(array $data): array
  4103. {
  4104. $result = Complaint::where('id', $data['id'])->delete();
  4105. return Result::success($result);
  4106. }
  4107. public function getComplainInfo(array $data): array
  4108. {
  4109. $result = Complaint::where('id', $data['id'])->first();
  4110. if (empty($result)) {
  4111. return Result::error("查询失败", 0);
  4112. }
  4113. return Result::success($result);
  4114. }
  4115. public function updateComplaintStatus(array $data): array
  4116. {
  4117. date_default_timezone_set('Asia/Shanghai');
  4118. $data['updated_at'] = date('Y-m-d H:i:s');
  4119. $user_id = $data['user_id'] ?? 0;
  4120. $type_id = $data['type_id'] ?? 0;
  4121. unset($data['user_id']);
  4122. unset($data['type_id']);
  4123. //处理, 写入处理人
  4124. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  4125. $data['real_deal_user'] = $user_id;
  4126. }
  4127. //如果是deal 23,则判断是不是处理人
  4128. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  4129. $complaintInof = Complaint::where('id', $data['id'])
  4130. ->where('real_deal_user', $user_id)
  4131. ->first();
  4132. if (empty($complaintInof)) {
  4133. return Result::error("处理人错误", 0);
  4134. }
  4135. }
  4136. $result = complaint::where('id', $data['id'])->update($data);
  4137. return Result::success($result);
  4138. }
  4139. public function updateGoodStatus(array $data): array
  4140. {
  4141. $user_id = $data['user_id'] ?? 0;
  4142. $type_id = $data['type_id'] ?? 0;
  4143. unset($data['user_id']);
  4144. unset($data['type_id']);
  4145. $result = Good::where('id', $data['id'])->update($data);
  4146. return Result::success($result);
  4147. }
  4148. public function updateJobHuntingStatus(array $data): array
  4149. {
  4150. $user_id = $data['user_id'] ?? 0;
  4151. $type_id = $data['type_id'] ?? 0;
  4152. unset($data['user_id']);
  4153. unset($data['type_id']);
  4154. $result = JobHunting::where('id', $data['id'])->update($data);
  4155. return Result::success($result);
  4156. }
  4157. public function updateNoticeStatus(array $data): array
  4158. {
  4159. $user_id = $data['user_id'] ?? 0;
  4160. $type_id = $data['type_id'] ?? 0;
  4161. unset($data['user_id']);
  4162. unset($data['type_id']);
  4163. $result = Notice::where('id', $data['id'])->update($data);
  4164. return Result::success($result);
  4165. }
  4166. public function getDUser(array $data): array
  4167. {
  4168. if (!empty($data['ids'])) {
  4169. $user = User::whereIn('id', $data['ids'])->getall();
  4170. if (empty($user)) {
  4171. return Result::error('无数据', 0);
  4172. }
  4173. return Result::success($user);
  4174. }
  4175. $where = [];
  4176. if (!empty($data['department_id'])) {
  4177. $where['department_id'] = $data['department_id'];
  4178. }
  4179. if (!empty($data['city_id'])) {
  4180. $where['city_id'] = $data['city_id'];
  4181. }
  4182. $result = User::where('type_id', 2)
  4183. ->where('status', 1)
  4184. ->where($where)
  4185. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  4186. ->get();
  4187. if (empty($result)) {
  4188. return Result::error("查询失败", 0);
  4189. }
  4190. return Result::success($result);
  4191. }
  4192. //20250324 通知,公告,消息
  4193. // 20250306 -------招聘--------fr
  4194. /*
  4195. * 招聘列表
  4196. * */
  4197. public function getJobRecruitingList(array $data): array
  4198. {
  4199. $where = [];
  4200. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  4201. if ($data['checkout'] == 0) {
  4202. $job_status = [0, 2];
  4203. } else {
  4204. $job_status = [1];
  4205. }
  4206. if (isset($data['keyword']) && !empty($data['keyword'])) {
  4207. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  4208. }
  4209. $user = User::where('id', $data['user_id'])->first();
  4210. if (empty($user)) {
  4211. return Result::error("用户不存在", 0);
  4212. }
  4213. // 3:企业会员
  4214. if ($user['type_id'] == 3) {
  4215. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  4216. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  4217. }
  4218. // 如果 $where 为空,则不添加 where 条件
  4219. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4220. return $query->where($where);
  4221. })
  4222. ->whereIn('job_recruiting.status', $job_status)
  4223. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4224. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  4225. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  4226. ->orderBy("updated_at", "desc")
  4227. ->offset(($data['page'] - 1) * $data['page_size'])
  4228. ->limit($data['page_size'])
  4229. ->get()
  4230. ->all();
  4231. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4232. return $query->where($where);
  4233. })
  4234. ->whereIn('job_recruiting.status', $job_status)
  4235. ->count();
  4236. if (empty($result)) {
  4237. return Result::error("暂无招聘信息", 0);
  4238. }
  4239. return Result::success($result);
  4240. }
  4241. /*
  4242. * 招聘信息添加
  4243. * */
  4244. public function addJobRecruiting(array $data): array
  4245. {
  4246. // return Result::success($data);
  4247. $user = User::where('user.id', $data['user_id'])
  4248. ->where('user.status', 1)
  4249. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  4250. ->select(
  4251. 'user.type_id',
  4252. 'user.mobile',
  4253. 'user.email',
  4254. 'user_info.business_name',
  4255. 'user_info.company_hy_id',
  4256. 'user_info.company_nature',
  4257. 'user_info.company_size',
  4258. 'user_info.introduction',
  4259. 'user_info.real_name',
  4260. 'user_info.company_url',
  4261. 'user_info.address_arr_id',
  4262. 'user_info.address'
  4263. )
  4264. ->first();
  4265. if (empty($user) || $user['type_id'] != $data['user_type']) {
  4266. return Result::error("用户不存在", 0);
  4267. }
  4268. $web = Website::where('id', $data['website_id'])->first();
  4269. if (empty($web)) {
  4270. return Result::error("网站不存在", 0);
  4271. }
  4272. // return Result::success($user);
  4273. $data['action_id'] = $data['user_id'];
  4274. $data['user_type'] = $user['type_id'];
  4275. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  4276. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  4277. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  4278. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  4279. // 公司地址 管理员必填
  4280. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  4281. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4282. // 管理员-企业相关信息
  4283. $company = [
  4284. // 'user_id' => $data['user_id']?? null,
  4285. 'business_name' => $data['business_name'] ?? null,
  4286. 'company_hy_id' => $data['company_hy_id'] ?? null,
  4287. 'company_size' => $data['company_size'] ?? null,
  4288. 'company_nature' => $data['company_nature'] ?? null,
  4289. 'introduction' => $data['introduction'] ?? null,
  4290. 'real_name' => $data['real_name'] ?? null,
  4291. 'mobile' => $data['mobile'] ?? null,
  4292. 'company_url' => $data['company_url'] ?? null,
  4293. 'address_arr_id' => $data['address_arr_id'] ?? null,
  4294. 'address' => $data['address'] ?? null,
  4295. 'email' => $data['email'] ?? null,
  4296. ];
  4297. //去掉相关企业信息
  4298. $job = array_diff_key($data, array_flip(array_keys($company)));
  4299. Db::beginTransaction();
  4300. try {
  4301. // 先添加职位相关信息
  4302. if ($user['type_id'] == 10000) {
  4303. $job['status'] = 1;
  4304. }
  4305. $jobId = JobRecruiting::insertGetId($job);
  4306. if (empty($jobId)) {
  4307. Db::rollBack();
  4308. return Result::error("添加失败");
  4309. }
  4310. // 添加公司信息
  4311. $company['user_id'] = $data['user_id'] ?? null;
  4312. $company['job_id'] = $jobId;
  4313. $company['user_type'] = $user['type_id'] ?? null;
  4314. $company['website_id'] = $data['website_id'] ?? null;
  4315. if ($user['type_id'] == 10000) {
  4316. // 管理员添加企业信息
  4317. // return Result::success($company);
  4318. $companyId = JobCompany::insertGetId($company);
  4319. if (empty($companyId)) {
  4320. Db::rollBack();
  4321. return Result::error("添加失败");
  4322. }
  4323. } else {
  4324. // 企业会员添加企业信息
  4325. $company = [
  4326. 'user_id' => $data['user_id'] ?? null,
  4327. 'business_name' => $user['business_name'] ?? null,
  4328. 'company_hy_id' => $user['company_hy_id'] ?? null,
  4329. 'company_size' => $user['company_size'] ?? null,
  4330. 'company_nature' => $user['company_nature'] ?? null,
  4331. 'introduction' => $user['introduction'] ?? null,
  4332. 'real_name' => $user['real_name'] ?? null,
  4333. 'mobile' => $user['mobile'] ?? null,
  4334. 'company_url' => $user['company_url'] ?? null,
  4335. 'address_arr_id' => $user['address_arr_id'] ?? null,
  4336. 'address' => $user['address'] ?? null,
  4337. 'email' => $user['email'] ?? null,
  4338. 'website_id' => $data['website_id'] ?? null,
  4339. 'user_type' => $user['type_id'] ?? null,
  4340. 'job_id' => $jobId,
  4341. ];
  4342. $companyId = JobCompany::insertGetId($company);
  4343. if (empty($companyId)) {
  4344. Db::rollBack();
  4345. return Result::error("添加失败");
  4346. }
  4347. // return Result::success($company);
  4348. }
  4349. Db::commit();
  4350. } catch (\Exception $e) {
  4351. Db::rollBack();
  4352. return Result::error($e->getMessage(), 0);
  4353. }
  4354. $result = [
  4355. 'job_id' => $jobId,
  4356. 'company_id' => $companyId,
  4357. ];
  4358. if (empty($result)) {
  4359. return Result::error("添加失败", 0);
  4360. }
  4361. return Result::success($result);
  4362. }
  4363. /*
  4364. * 获取招聘信息详情
  4365. * */
  4366. public function getJobRecruitingInfo(array $data): array
  4367. {
  4368. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  4369. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4370. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4371. ->select(
  4372. 'job_recruiting.*',
  4373. 'website.website_name as website_name',
  4374. 'job_company.business_name',
  4375. 'job_company.company_hy_id',
  4376. 'job_company.company_size',
  4377. 'job_company.company_nature',
  4378. 'job_company.introduction',
  4379. 'job_company.real_name',
  4380. 'job_company.mobile',
  4381. 'job_company.company_url',
  4382. 'job_company.address_arr_id',
  4383. 'job_company.address',
  4384. 'job_company.email'
  4385. )
  4386. ->first();
  4387. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  4388. if (!empty($cityId)) {
  4389. if (isset($cityId[1]) && $cityId[1] != null) {
  4390. $city = District::where('id', $cityId[1])->first(['name']);
  4391. } else {
  4392. $city = District::where('id', $cityId[0])->first(['name']);
  4393. }
  4394. $result['city'] = $city['name'] ?? '';
  4395. }
  4396. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  4397. if (is_array($addressId) && !empty($addressId)) {
  4398. $address = District::whereIn('id', $addressId)
  4399. ->orderBy('level', 'asc')
  4400. ->get(['name'])
  4401. ->pluck('name')
  4402. ->implode('');
  4403. // $job->address_name = $address ?? '';
  4404. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  4405. }
  4406. if (empty($result)) {
  4407. return Result::error("招聘信息不存在", 0);
  4408. }
  4409. // return Result::success($job);
  4410. return Result::success($result);
  4411. }
  4412. /*
  4413. * 修改招聘信息
  4414. * */
  4415. public function upJobRecruiting(array $data): array
  4416. {
  4417. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  4418. // return Result::success($job);
  4419. if (empty($job)) {
  4420. return Result::error("招聘信息不存在", 0);
  4421. }
  4422. $user = User::where('id', $data['user_id'])->first();
  4423. // return Result::success($user);
  4424. if (empty($user) || $user['type_id'] != $data['user_type']) {
  4425. return Result::error("用户不存在", 0);
  4426. }
  4427. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  4428. return Result::error("用户暂无权限修改此招聘信息!", 0);
  4429. }
  4430. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  4431. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  4432. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  4433. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  4434. // 公司地址 管理员必填
  4435. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  4436. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4437. // 管理员-企业相关信息
  4438. $company = [
  4439. 'business_name' => $data['business_name'] ?? null,
  4440. 'company_hy_id' => $data['hy_id'] ?? null,
  4441. 'company_size' => $data['company_size'] ?? null,
  4442. 'company_nature' => $data['company_nature'] ?? null,
  4443. 'introduction' => $data['introduction'] ?? null,
  4444. 'real_name' => $data['real_name'] ?? null,
  4445. 'mobile' => $data['mobile'] ?? null,
  4446. 'company_url' => $data['company_url'] ?? null,
  4447. 'address_arr_id' => $data['address_arr_id'] ?? null,
  4448. 'address' => $data['address'] ?? null,
  4449. 'email' => $data['email'] ?? null,
  4450. ];
  4451. //去掉相关企业信息
  4452. $data = array_diff_key($data, array_flip(array_keys($company)));
  4453. $jobId = $data['id'];
  4454. $web = $data['website_id'];
  4455. $data['action_id'] = $data['user_id'];
  4456. unset($data['user_id']);
  4457. unset($data['user_type']);
  4458. unset($data['id']);
  4459. unset($data['website_id']);
  4460. // return Result::success($data);
  4461. Db::beginTransaction();
  4462. try {
  4463. // 管理员修改招聘信息
  4464. if ($user['type_id'] == 10000) {
  4465. $data['website_id'] = $web;
  4466. $company['website_id'] = $data['website_id'];
  4467. $data['status'] = 1;
  4468. } else {
  4469. $data['status'] = 0;
  4470. }
  4471. // Db::rollBack();
  4472. // return Result::success($company);
  4473. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  4474. if (empty($result['job'])) {
  4475. Db::rollBack();
  4476. return Result::error("修改招聘信息失败");
  4477. }
  4478. // 管理员修改企业相关信息
  4479. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  4480. if (empty($result['company'])) {
  4481. Db::rollBack();
  4482. return Result::error("修改企业相关信息失败");
  4483. }
  4484. Db::commit();
  4485. // return Result::success($result);
  4486. } catch (\Exception $e) {
  4487. Db::rollBack();
  4488. return Result::error($e->getMessage(), 0);
  4489. }
  4490. return Result::success($result);
  4491. }
  4492. /*
  4493. * 招聘信息删除
  4494. * */
  4495. public function delJobRecruiting(array $data): array
  4496. {
  4497. $user = User::where('id', $data['user_id'])->first();
  4498. if (empty($user)) {
  4499. return Result::error("用户不存在", 0);
  4500. }
  4501. $job = JobRecruiting::where('id', $data['id'])->first();
  4502. if (empty($job)) {
  4503. return Result::error("招聘信息不存在", 0);
  4504. }
  4505. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  4506. return Result::error("用户暂无权限修改此招聘信息!", 0);
  4507. }
  4508. Db::beginTransaction();
  4509. try {
  4510. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  4511. if (empty($result['job'])) {
  4512. Db::rollBack();
  4513. return Result::error("删除招聘信息失败");
  4514. }
  4515. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  4516. if (empty($result['company'])) {
  4517. Db::rollBack();
  4518. return Result::error("删除企业相关信息失败");
  4519. }
  4520. Db::commit();
  4521. } catch (\Exception $e) {
  4522. Db::rollBack();
  4523. return Result::error($e->getMessage(), 0);
  4524. }
  4525. return Result::success($result);
  4526. }
  4527. /*
  4528. * 获取公司信息
  4529. * */
  4530. public function getJobCompany(array $data): array
  4531. {
  4532. $user = User::where('user.id', $data['user_id'])
  4533. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  4534. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  4535. ->first();
  4536. // return Result::success($user);
  4537. if (empty($user)) {
  4538. return Result::error("用户不存在", 0);
  4539. }
  4540. if ($user['type_id'] == 3) {
  4541. $result = [
  4542. // 'id' => 0,
  4543. 'user_id' => $data['user_id'],
  4544. 'website_id' => $data['website_id'],
  4545. 'business_name' => $user['business_name'], // 企业名称
  4546. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  4547. 'company_nature' => $user['company_nature'], // 公司性质
  4548. 'company_size' => $user['company_size'], // 公司规模
  4549. 'introduction' => $user['introduction'], // 公司简介
  4550. 'real_name' => $user['real_name'], // 企业联系人
  4551. 'mobile' => $user['mobile'], // 企业联系电话
  4552. 'company_url' => $user['company_url'], // 企业网址
  4553. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  4554. 'address' => $user['address'], // 企业地址
  4555. 'email' => $user['email'], // 企业邮箱
  4556. ];
  4557. } else {
  4558. return Result::error("用户类型错误", 0);
  4559. }
  4560. if (empty($result)) {
  4561. return Result::error("公司信息不存在", 0);
  4562. }
  4563. return Result::success($result);
  4564. }
  4565. /*
  4566. * 修改公司信息
  4567. * */
  4568. public function upJobCompany(array $data): array
  4569. {
  4570. // return Result::success($data);
  4571. $user = User::where('user.id', $data['user_id'])
  4572. ->where('user.status', 1)
  4573. ->select('user.user_name', 'user.type_id')
  4574. ->first();
  4575. if (empty($user)) {
  4576. return Result::error("用户不存在", 0);
  4577. }
  4578. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4579. $company = [
  4580. 'business_name' => $data['business_name'], // 企业名称
  4581. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  4582. 'company_nature' => $data['company_nature'], // 公司性质
  4583. 'company_size' => $data['company_size'], // 公司规模
  4584. 'introduction' => $data['introduction'], // 公司简介
  4585. // 'real_name' => $data['real_name'], // 企业联系人
  4586. 'company_url' => $data['company_url'], // 企业网址
  4587. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  4588. 'address' => $data['address'], // 企业详细地址
  4589. ];
  4590. if ($user['type_id'] == 3) {
  4591. Db::beginTransaction();
  4592. try {
  4593. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  4594. 'business_name' => $data['business_name'], // 企业名称
  4595. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  4596. 'company_nature' => $data['company_nature'], // 公司性质
  4597. 'company_size' => $data['company_size'], // 公司规模
  4598. 'introduction' => $data['introduction'], // 公司简介
  4599. // 'real_name' => $data['real_name'], // 企业联系人
  4600. 'company_url' => $data['company_url'], // 企业网址
  4601. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  4602. 'address' => $data['address'], // 企业详细地址
  4603. ]);
  4604. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  4605. Db::commit();
  4606. } catch (\Exception $e) {
  4607. Db::rollBack();
  4608. return Result::error($e->getMessage(), 0);
  4609. }
  4610. } else {
  4611. return Result::error("用户类型错误", 0);
  4612. }
  4613. if (empty($result)) {
  4614. return Result::error("修改失败", 0);
  4615. }
  4616. return Result::success($result);
  4617. }
  4618. /*
  4619. * 获取省-市
  4620. * */
  4621. public function getJobRecruitingArea(array $data): array
  4622. {
  4623. if (isset($data['pid']) && $data['pid'] != null) {
  4624. $result = District::where('pid', $data['pid'])->get()->all();
  4625. } else {
  4626. $result = District::where('level', 1)->get()->all();
  4627. }
  4628. if (empty($result)) {
  4629. return Result::error("暂无此省市", 0);
  4630. }
  4631. return Result::success($result);
  4632. }
  4633. /*
  4634. * 获取行业分类
  4635. * */
  4636. public function getIndustry(array $data): array
  4637. {
  4638. $result = JobIndustry::get()->all();
  4639. if (empty($result)) {
  4640. return Result::error("暂无行业分类", 0);
  4641. }
  4642. return Result::success($result);
  4643. }
  4644. /*
  4645. * 获取职位
  4646. * */
  4647. public function getPositionList(array $data): array
  4648. {
  4649. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  4650. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  4651. } else {
  4652. $result = JobPosition::where('zwpid', 0)->get()->all();
  4653. }
  4654. if (empty($result)) {
  4655. return Result::error("暂无此职位", 0);
  4656. }
  4657. return Result::success($result);
  4658. }
  4659. /*
  4660. * 获取工作性质-菜单
  4661. * */
  4662. public function getJobNature(array $data): array
  4663. {
  4664. $result = JobEnum::where('egroup', 'nature')->get()->all();
  4665. if (empty($result)) {
  4666. return Result::error("暂无工作性质", 0);
  4667. }
  4668. return Result::success($result);
  4669. }
  4670. /*
  4671. * 获取工作经验-菜单
  4672. * */
  4673. public function getExperience(array $data): array
  4674. {
  4675. $result = JobEnum::where('egroup', 'years')->get()->all();
  4676. if (empty($result)) {
  4677. return Result::error("暂无工作经验", 0);
  4678. }
  4679. return Result::success($result);
  4680. }
  4681. /*
  4682. * 获取学历-菜单
  4683. * */
  4684. public function getEducation(array $data): array
  4685. {
  4686. $result = JobEnum::where('egroup', 'education')->get()->all();
  4687. if (empty($result)) {
  4688. return Result::error("暂无学历", 0);
  4689. }
  4690. return Result::success($result);
  4691. }
  4692. /*
  4693. * 获取薪资-菜单
  4694. * */
  4695. public function getSalary(array $data): array
  4696. {
  4697. $result = JobEnum::where('egroup', 'income')->get()->all();
  4698. if (empty($result)) {
  4699. return Result::error("暂无薪资", 0);
  4700. }
  4701. return Result::success($result);
  4702. }
  4703. /*
  4704. * 获取语言-菜单
  4705. * */
  4706. public function getLanguage(array $data): array
  4707. {
  4708. $result = JobEnum::where('egroup', 'language')->get()->all();
  4709. if (empty($result)) {
  4710. return Result::error("暂无语言", 0);
  4711. }
  4712. return Result::success($result);
  4713. }
  4714. /*
  4715. * 获取掌握程度-菜单
  4716. * */
  4717. public function getLevel(array $data): array
  4718. {
  4719. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  4720. if (empty($result)) {
  4721. return Result::error("暂无工作性质", 0);
  4722. }
  4723. return Result::success($result);
  4724. }
  4725. // 公司信息
  4726. /*
  4727. * 获取公司性质-菜单
  4728. * */
  4729. public function getCompanyNature(array $data): array
  4730. {
  4731. $result = JobNature::get()->all();
  4732. if (empty($result)) {
  4733. return Result::error("暂无公司性质", 0);
  4734. }
  4735. return Result::success($result);
  4736. }
  4737. /*
  4738. * 获取公司规模-菜单
  4739. * */
  4740. public function getCompanySize(array $data): array
  4741. {
  4742. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  4743. if (empty($result)) {
  4744. return Result::error("暂无公司规模", 0);
  4745. }
  4746. return Result::success($result);
  4747. }
  4748. /*
  4749. * 招聘信息审核
  4750. * */
  4751. public function checkJobRecruiting(array $data): array
  4752. {
  4753. $user = User::where('id', $data['user_id'])->first();
  4754. if (empty($user)) {
  4755. return Result::error("用户不存在", 0);
  4756. }
  4757. $job = JobRecruiting::where('id', $data['id'])->first();
  4758. if (empty($job)) {
  4759. return Result::error("招聘信息不存在", 0);
  4760. }
  4761. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  4762. if ($user['type_id'] != 10000) {
  4763. return Result::error("用户暂无权限审核此招聘信息!", 0);
  4764. }
  4765. // 驳回原因
  4766. if ($data['status'] == 2) {
  4767. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  4768. }
  4769. $data['action_id'] = $data['user_id'];
  4770. unset($data['user_id']);
  4771. $result = JobRecruiting::where('id', $data['id'])->update($data);
  4772. if (empty($result)) {
  4773. return Result::error("审核失败", 0);
  4774. }
  4775. return Result::success($result);
  4776. }
  4777. public function myApplyList(array $data): array
  4778. {
  4779. $user = User::where('id', $data['user_id'])->first();
  4780. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  4781. return Result::error("用户不存在", 0);
  4782. }
  4783. // 1:个人会员 职场机会
  4784. if ($user['type_id'] == 1) {
  4785. $where['user_id'] = $user['id'];
  4786. }
  4787. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  4788. $query->where('recruit_id', $user['id']);
  4789. })
  4790. ->pluck('recruit_id');
  4791. $where = [];
  4792. if (isset($data['salary']) && $data['salary'] != null) {
  4793. $where['job_recruiting.salary'] = $data['salary'];
  4794. }
  4795. if (isset($data['experience']) && $data['experience'] != null) {
  4796. $where['job_recruiting.experience'] = $data['experience'];
  4797. }
  4798. if (isset($data['business_name']) && $data['business_name'] != null) {
  4799. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  4800. }
  4801. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  4802. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4803. ->where($where);
  4804. // ->count();
  4805. $count = $query->count();
  4806. $query = clone $query;
  4807. $job = $query
  4808. ->leftJoin('job_enum as income_enum', function ($join) {
  4809. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  4810. ->where('income_enum.egroup', 'income');
  4811. })
  4812. ->leftJoin('job_enum as years_enum', function ($join) {
  4813. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  4814. ->where('years_enum.egroup', 'years');
  4815. })
  4816. // ->where($where)
  4817. ->orderBy('job_recruiting.updated_at', 'desc')
  4818. ->select(
  4819. 'job_recruiting.id',
  4820. 'job_recruiting.title',
  4821. 'job_company.business_name',
  4822. 'income_enum.evalue as salary_evalue',
  4823. 'income_enum.ename as salary_ename',
  4824. 'years_enum.evalue as experience_evalue',
  4825. 'years_enum.ename as experience_ename',
  4826. 'job_recruiting.updated_at'
  4827. )
  4828. ->offset(($data['page'] - 1) * $data['pageSize'])
  4829. ->limit($data['pageSize'])
  4830. ->get()
  4831. ->all();
  4832. if (empty($job)) {
  4833. return Result::error("暂无招聘信息", 0);
  4834. }
  4835. $result = [
  4836. 'row' => $job,
  4837. 'count' => $count,
  4838. ];
  4839. return Result::success($result);
  4840. }
  4841. /*
  4842. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  4843. * */
  4844. public function getRecruitingList(array $data): array
  4845. {
  4846. $user = User::where('id', $data['user_id'])->first();
  4847. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  4848. return Result::error("用户不存在", 0);
  4849. }
  4850. // 1:个人会员 职场机会
  4851. if ($user['type_id'] == 1) {
  4852. $where['user_id'] = $user['id'];
  4853. }
  4854. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  4855. $query->where('recruit_id', $user['id']);
  4856. })
  4857. ->pluck('recruit_id');
  4858. $where = [];
  4859. if (isset($data['salary']) && $data['salary'] != null) {
  4860. $where['job_recruiting.salary'] = $data['salary'];
  4861. }
  4862. if (isset($data['experience']) && $data['experience'] != null) {
  4863. $where['job_recruiting.experience'] = $data['experience'];
  4864. }
  4865. if (isset($data['business_name']) && $data['business_name'] != null) {
  4866. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  4867. }
  4868. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  4869. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4870. ->where($where);
  4871. // ->count();
  4872. $count = $query->count();
  4873. $query = clone $query;
  4874. $job = $query
  4875. ->leftJoin('job_enum as income_enum', function ($join) {
  4876. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  4877. ->where('income_enum.egroup', 'income');
  4878. })
  4879. ->leftJoin('job_enum as years_enum', function ($join) {
  4880. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  4881. ->where('years_enum.egroup', 'years');
  4882. })
  4883. // ->where($where)
  4884. ->orderBy('job_recruiting.updated_at', 'desc')
  4885. ->select(
  4886. 'job_recruiting.id',
  4887. 'job_recruiting.title',
  4888. 'job_company.business_name',
  4889. 'income_enum.evalue as salary_evalue',
  4890. 'income_enum.ename as salary_ename',
  4891. 'years_enum.evalue as experience_evalue',
  4892. 'years_enum.ename as experience_ename',
  4893. 'job_recruiting.updated_at'
  4894. )
  4895. ->offset(($data['page'] - 1) * $data['pageSize'])
  4896. ->limit($data['pageSize'])
  4897. ->get()
  4898. ->all();
  4899. if (empty($job)) {
  4900. return Result::error("暂无招聘信息", 0);
  4901. }
  4902. $result = [
  4903. 'row' => $job,
  4904. 'count' => $count,
  4905. ];
  4906. return Result::success($result);
  4907. }
  4908. /*
  4909. * 获取企业会员-招聘信息列表
  4910. * */
  4911. public function getRecruitingInfo(array $data): array
  4912. {
  4913. $user = User::where('id', $data['user_id'])->first();
  4914. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  4915. return Result::error("用户不存在", 0);
  4916. }
  4917. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  4918. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4919. ->select(
  4920. 'job_recruiting.*',
  4921. 'job_company.business_name',
  4922. 'job_company.company_hy_id',
  4923. 'job_company.company_size',
  4924. 'job_company.company_nature',
  4925. 'job_company.introduction',
  4926. 'job_company.real_name',
  4927. 'job_company.mobile',
  4928. 'job_company.company_url',
  4929. 'job_company.address_arr_id',
  4930. 'job_company.address',
  4931. 'job_company.email'
  4932. )
  4933. ->get();
  4934. if (empty($recruiting)) {
  4935. return Result::error("暂无招聘信息", 0);
  4936. }
  4937. return Result::success($recruiting);
  4938. }
  4939. /*
  4940. * 获取企业会员-我的沟通
  4941. * */
  4942. public function getJobResumeList(array $data): array
  4943. {
  4944. $user = User::where('id', $data['user_id'])->first();
  4945. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  4946. return Result::error("用户不存在", 0);
  4947. }
  4948. $where = [];
  4949. if (isset($data['salary']) && $data['salary'] != null) {
  4950. $where['job_hunting.salary'] = $data['salary'];
  4951. }
  4952. if (isset($data['user_name']) && $data['user_name'] != null) {
  4953. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  4954. }
  4955. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  4956. $query->where('job_resume.user_id', $user['id']);
  4957. })
  4958. ->when(!empty($where), function ($query) use ($where) {
  4959. $query->where($where);
  4960. })
  4961. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  4962. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  4963. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  4964. ->select('job_resume.hunt_id', 'job_resume.recruit_id', 'job_hunting.id', 'job_hunting.salary', 'job_hunting.city_id', 'job_hunting.updated_at', 'job_recruiting.jtzw_id', 'user.user_name');
  4965. $count = $job->count();
  4966. if ($count == 0) {
  4967. return Result::error("暂无沟通记录", 0);
  4968. }
  4969. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  4970. ->offset(($data['page'] - 1) * $data['pageSize'])
  4971. ->limit($data['pageSize'])
  4972. ->get();
  4973. if (empty($jobs)) {
  4974. return Result::error("暂无沟通记录", 0);
  4975. }
  4976. $result['row'] = $this->processJob($jobs, '');
  4977. $result['count'] = $count;
  4978. return Result::success($result);
  4979. }
  4980. // 20250306 招聘
  4981. //20250422 书刊音像
  4982. public function addBook(array $data): array
  4983. {
  4984. // $user_id = $data['user_id'] ?? 0;
  4985. $type_id = $data['type_id'] ?? 0;
  4986. // $website_id = $data['website_id'] ?? 0;
  4987. // unset($data['user_id']);
  4988. unset($data['type_id']);
  4989. // unset($data['website_id']);
  4990. //处理数组
  4991. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  4992. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  4993. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  4994. if ($data['img_url'] == '') {
  4995. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4996. preg_match_all($reg, $data['detail'], $matches);
  4997. if (isset($matches[1][0])) {
  4998. //截取varchar240
  4999. $data['img_url'] = substr($matches[1][0], 0, 240);
  5000. }
  5001. }
  5002. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  5003. //提取标题+内容中的关键词
  5004. $data['keyword'] = $data['title'];
  5005. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5006. Jieba::init(); // 初始化 jieba-php
  5007. Finalseg::init();
  5008. $segList = Jieba::cut($data['keyword']);
  5009. $segList1 = array_slice($segList, 0, 8);
  5010. $data['keyword'] = implode(',', $segList1);
  5011. }
  5012. if ($data['description'] == '') {
  5013. //提取内容中的描述
  5014. $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  5015. }
  5016. var_dump($data, '--');
  5017. $result = Book::insertGetId($data);
  5018. if (empty($result)) {
  5019. return Result::error("添加失败", 0);
  5020. }
  5021. return Result::success($result);
  5022. }
  5023. public function getBookList(array $data): array
  5024. {
  5025. $where = [];
  5026. if (!empty($data["title"])) {
  5027. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  5028. }
  5029. if (!empty($data['website_name'])) {
  5030. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  5031. }
  5032. if (!empty($data['status'])) {
  5033. $where[] = ['book.status', '=', $data['status']];
  5034. }
  5035. $user_id = $data['user_id'];
  5036. $type_id = $data['type_id'];
  5037. // $type_id = 4;
  5038. var_dump($type_id, '------1--------');
  5039. if ($type_id != 10000) {
  5040. $where[] = ['book.user_id', '=', $user_id];
  5041. }
  5042. var_dump(!empty($data['status1']), '=-===1');
  5043. $result = Book::where($where)
  5044. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  5045. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  5046. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  5047. ->when(isset($data['status1']), function ($query) use ($data) {
  5048. $query->whereIn('book.status', [1, 3]);
  5049. })
  5050. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  5051. ->orderBy("updated_at", "desc")
  5052. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  5053. if (empty($result)) {
  5054. return Result::error("暂无数据", 0);
  5055. }
  5056. // 取出数据
  5057. $rows = $result->items();
  5058. $count = $result->total();
  5059. $responseData = [
  5060. 'rows' => $rows,
  5061. 'count' => $count,
  5062. ];
  5063. return Result::success($responseData);
  5064. }
  5065. public function deleteBook(array $data): array
  5066. {
  5067. $result = Book::where('id', $data['id'])->delete();
  5068. if (empty($result)) {
  5069. return Result::error("删除失败", 0);
  5070. }
  5071. return Result::success($result);
  5072. }
  5073. public function updateBook(array $data): array
  5074. {
  5075. // $user_id = $data['user_id'] ?? 0;
  5076. $type_id = $data['type_id'] ?? 0;
  5077. // $website_id = $data['website_id'] ?? 0;
  5078. unset($data['user_id']);
  5079. unset($data['type_id']);
  5080. // unset($data['website_id']);
  5081. //处理数组
  5082. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  5083. if ($data['img_url'] == '') {
  5084. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5085. preg_match_all($reg, $data['detail'], $matches);
  5086. if (isset($matches[1][0])) {
  5087. //截取varchar240
  5088. $data['img_url'] = substr($matches[1][0], 0, 240);
  5089. }
  5090. }
  5091. if ($data['keyword'] == '') {
  5092. //提取标题+内容中的关键词
  5093. $data['keyword'] = $data['title'];
  5094. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5095. Jieba::init(); // 初始化 jieba-php
  5096. Finalseg::init();
  5097. $segList = Jieba::cut($data['keyword']);
  5098. $segList1 = array_slice($segList, 0, 8);
  5099. $data['keyword'] = implode(',', $segList1);
  5100. }
  5101. if ($data['description'] == '') {
  5102. //提取内容中的描述
  5103. $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  5104. }
  5105. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  5106. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  5107. $result = Book::where("id", $data["id"])->update($data);
  5108. if (empty($result)) {
  5109. return Result::error("更新失败", 0);
  5110. }
  5111. return Result::success($result);
  5112. }
  5113. public function getBookInfo(array $data): array
  5114. {
  5115. $result = Book::where("id", $data["id"])->first();
  5116. if (empty($result)) {
  5117. return Result::error("获取失败", 0);
  5118. }
  5119. return Result::success($result);
  5120. }
  5121. public function updateBookStatus(array $data): array
  5122. {
  5123. //审核
  5124. unset($data['user_id']);
  5125. $result = Book::where("id", $data["id"])->update($data);
  5126. if (empty($result)) {
  5127. return Result::error("更新失败", 0);
  5128. }
  5129. return Result::success($result);
  5130. }
  5131. //20250422 书刊音像
  5132. }