NewsService.php 234 KB

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