NewsService.php 240 KB

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