NewsService.php 253 KB

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