NewsService.php 256 KB

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