NewsService.php 229 KB

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