NewsService.php 370 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138
  1. <?php
  2. namespace App\JsonRpc;
  3. use App\Model\Article;
  4. use App\Model\ArticleData;
  5. use App\Model\Category;
  6. use App\Model\HistoryToday;
  7. use App\Model\WebsiteCategory;
  8. use App\Model\ArticleSurvey;
  9. use App\Model\District;
  10. use App\Model\Good;
  11. use App\Model\JobCompany;
  12. use App\Model\Website;
  13. use App\Model\JobRecruiting;
  14. use App\Model\JobIndustry;
  15. use App\Model\Book;
  16. use App\Model\JobPosition;
  17. use App\Model\Notice;
  18. use App\Model\JobNature;
  19. use App\Model\JobEnum;
  20. use App\Model\User;
  21. use App\Model\UserRole;
  22. use App\Model\News;
  23. use App\Model\UserInfo;
  24. use App\Model\WebsiteGroup;;
  25. use App\Model\JobResume;
  26. use Hyperf\DbConnection\Db;
  27. use Hyperf\RpcServer\Annotation\RpcService;
  28. use App\Tools\Result;
  29. use Directory;
  30. use Ramsey\Uuid\Uuid;
  31. use Hyperf\Utils\Random;
  32. use Fukuball\Jieba\Jieba;
  33. use Fukuball\Jieba\Finalseg;
  34. use Hyperf\Utils\Collection;
  35. use function Hyperf\Support\retry;
  36. use App\Tools\PublicData;
  37. use App\Model\ChatGroups;
  38. use App\Model\ChatGroupsMember;
  39. use App\Model\ChatRecords;
  40. use App\Model\Complaint;
  41. use Hamcrest\Arrays\IsArray;
  42. use Hyperf\Codec\Json;
  43. use App\Tools\buildMenuTree;
  44. use App\Model\JobApply;
  45. use App\Model\JobHunting;
  46. use App\Model\JobRemuse;
  47. use Hyperf\Redis\Redis;
  48. use Hyperf\Di\Annotation\Inject;
  49. use App\Model\Festival;
  50. use App\Model\Character;
  51. use App\Model\Couplet;
  52. use App\Model\Riddle;
  53. use App\Model\Idiom;
  54. use App\Model\WhiteRouter;
  55. use Illuminate\Support\Facades\Cache;
  56. use App\Model\Company;
  57. use Hyperf\Paginator\Paginator;
  58. use App\Model\Project;
  59. use Hyperf\Context\Context;
  60. use Hyperf\Context\ApplicationContext as ContextApplicationContext;
  61. use Hyperf\Amqp\Producer;
  62. use App\Amqp\Producer\MqProducer;
  63. use App\Model\Web;
  64. use App\Model\GroupMemberImp;
  65. use App\Model\GroupImp;
  66. use App\Model\GroupTalkImp;
  67. use App\Model\GroupTalkMessagerImp;
  68. use App\Model\ArticleIgnore;
  69. use App\Model\Message;
  70. use App\Model\ResearchTopic;
  71. use App\Model\RetopicUser;
  72. use App\Model\WebCateinfo;
  73. use App\Model\SinglePage;
  74. use App\Model\WebsiteColumn;
  75. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  76. class NewsService implements NewsServiceInterface
  77. {
  78. #[Inject]
  79. protected Redis $redis;
  80. /**
  81. * 获取导航池列表
  82. * @param array $data
  83. * @return array
  84. */
  85. public function getCategoryList(array $data): array
  86. {
  87. $search = $data['name'] ?? '';
  88. $page = (int)($data['page'] ?? 1);
  89. $perPage = (int)($data['pageSize'] ?? 10);
  90. // 1. 查出所有匹配的分类id
  91. if ($search) {
  92. $matchedIds = Category::where('name', 'like', "%{$search}%")->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  93. if (empty($matchedIds)) {
  94. return Result::success(['rows' => [], 'total' => 0]);
  95. }
  96. // 2. 递归查所有父级,直到一级分类
  97. $idsStr = implode(',', $matchedIds);
  98. $sql = "
  99. WITH RECURSIVE parents AS (
  100. SELECT * FROM category WHERE id IN ($idsStr)
  101. UNION ALL
  102. SELECT c.* FROM category c
  103. INNER JOIN parents p ON c.id = p.pid
  104. )
  105. SELECT * FROM parents
  106. ";
  107. $parents = Db::select($sql);
  108. $parentIds = [];
  109. foreach ($parents as $row) {
  110. if ($row->pid == 0) {
  111. $parentIds[] = $row->id;
  112. }
  113. }
  114. $parentIds = array_unique($parentIds);
  115. } else {
  116. // 没有搜索,一级分类就是根
  117. $parentIds = Category::where('pid', 0)->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  118. }
  119. // 3. 一级分类分页
  120. $total = count($parentIds);
  121. $parentIds = array_slice($parentIds, ($page - 1) * $perPage, $perPage);
  122. if (empty($parentIds)) {
  123. return Result::success(['rows' => [], 'total' => $total]);
  124. }
  125. // 4. 递归查所有子孙
  126. $idsStr = implode(',', $parentIds);
  127. $sql = "
  128. WITH RECURSIVE subcategories AS (
  129. SELECT * FROM category WHERE id IN ($idsStr)
  130. UNION ALL
  131. SELECT c.* FROM category c
  132. INNER JOIN subcategories s ON c.pid = s.id
  133. )
  134. SELECT * FROM subcategories ORDER BY updated_at DESC
  135. ";
  136. $allCategories = Db::select($sql);
  137. // 5. 组装树结构
  138. $categoryMap = [];
  139. foreach ($allCategories as $cat) {
  140. $cat = (array)$cat;
  141. $cat['children'] = [];
  142. $categoryMap[$cat['id']] = $cat;
  143. }
  144. foreach ($categoryMap as $id => &$cat) {
  145. if ($cat['pid'] && isset($categoryMap[$cat['pid']])) {
  146. $categoryMap[$cat['pid']]['children'][] = &$cat;
  147. }
  148. }
  149. unset($cat);
  150. $categoryTree = [];
  151. foreach ($parentIds as $id) {
  152. if (isset($categoryMap[$id])) {
  153. $categoryTree[] = $categoryMap[$id];
  154. }
  155. }
  156. return Result::success([
  157. 'rows' => $categoryTree,
  158. 'total' => $total,
  159. ]);
  160. }
  161. private function findMatchedCategories($search)
  162. {
  163. if ($search) {
  164. return Category::where('name', 'like', "%{$search}%")
  165. ->orderBy('updated_at', 'desc')
  166. ->get();
  167. }
  168. return Category::orderBy('updated_at', 'desc') // 按 updated_at 字段倒序排序
  169. ->get();
  170. }
  171. private function findAllParents($categories)
  172. {
  173. $allCategories = [];
  174. foreach ($categories as $category) {
  175. $parentId = $category->pid;
  176. while ($parentId > 0) {
  177. $parent = Category::find($parentId);
  178. if ($parent) {
  179. $allCategories[$parent->id] = $parent;
  180. $parentId = $parent->pid;
  181. } else {
  182. break;
  183. }
  184. }
  185. $allCategories[$category->id] = $category;
  186. }
  187. return array_values($allCategories);
  188. }
  189. private function buildCategoryTree($category, $allRequiredCategories)
  190. {
  191. $categoryData = $category->toArray();
  192. $children = [];
  193. foreach ($allRequiredCategories as $c) {
  194. if ($c->pid === $category->id) {
  195. $children[] = $this->buildCategoryTree($c, $allRequiredCategories);
  196. }
  197. }
  198. if (!empty($children)) {
  199. $categoryData['children'] = $children;
  200. }
  201. return $categoryData;
  202. }
  203. public function myCategoryList(array $data): array
  204. {
  205. $sszq = $data['sszq'] ?? '';
  206. unset($data['sszq']);
  207. //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
  208. $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
  209. $where[] = [
  210. 'pid',
  211. '=',
  212. $data['pid'],
  213. ];
  214. if (isset($data['name'])) {
  215. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  216. }
  217. var_dump($where);
  218. //根据分类id,从category表中取出分类信息
  219. $result = Category::where($where)
  220. ->whereIn('category.id', $catorytids)
  221. ->select('category.*', 'category.id as category_id')->get();
  222. if (empty($result)) {
  223. return Result::error("没有栏目数据");
  224. }
  225. return Result::success($result);
  226. }
  227. /**
  228. * @param array $data
  229. * @return array
  230. */
  231. public function categoryList(array $data): array
  232. {
  233. $where[] = [
  234. 'pid',
  235. '=',
  236. $data['pid']
  237. ];
  238. if (isset($data['name'])) {
  239. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  240. }
  241. var_dump($where);
  242. $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
  243. if (empty($result)) {
  244. return Result::error("没有栏目数据");
  245. }
  246. return Result::success($result);
  247. }
  248. /**
  249. * @param array $data
  250. * @return array
  251. */
  252. public function addCategory(array $data): array
  253. {
  254. if (isset($data['id'])) {
  255. unset($data['id']);
  256. }
  257. $id = Category::insertGetId($data);
  258. if (empty($id)) {
  259. return Result::error("添加失败");
  260. }
  261. return Result::success(['id' => $id]);
  262. }
  263. /**
  264. * @param array $data
  265. * @return array
  266. */
  267. public function delCategory(array $data): array
  268. {
  269. Db::beginTransaction();
  270. try {
  271. $categoryList = Category::where(['pid' => $data['id']])->get();
  272. if ($categoryList->toArray()) {
  273. Db::rollBack();
  274. return Result::error("分类下面有子分类不能删除");
  275. }
  276. $articleList = Article::where(['catid' => $data['id']])->get();
  277. if ($articleList->toArray()) {
  278. Db::rollBack();
  279. return Result::error("分类下面有资讯不能删除");
  280. }
  281. $result = Category::where($data)->delete();
  282. WebsiteCategory::where(['category_id' => $data['id']])->delete();
  283. if (!$result) {
  284. Db::rollBack();
  285. return Result::error("删除失败");
  286. }
  287. Db::commit();
  288. return Result::success($result);
  289. } catch (\Exception $e) {
  290. Db::rollBack();
  291. return Result::error("删除失败" . $e->getMessage());
  292. }
  293. }
  294. /**
  295. * @param array $data
  296. * @return array
  297. */
  298. public function updateCategory(array $data): array
  299. {
  300. $where = [
  301. 'id' => $data['id'],
  302. ];
  303. $result = Category::where($where)->update($data);
  304. if ($result) {
  305. return Result::success($result);
  306. } else {
  307. return Result::error("更新失败");
  308. }
  309. }
  310. /**
  311. * 获取导航池信息
  312. * @param array $data
  313. * @return array
  314. */
  315. public function getCategoryInfo(array $data): array
  316. {
  317. $where = [
  318. 'id' => $data['id'],
  319. ];
  320. $result = Category::where($where)->first();
  321. if ($result) {
  322. return Result::success($result);
  323. } else {
  324. return Result::error("更新失败");
  325. }
  326. }
  327. public function getArticleCommend(array $data): array
  328. {
  329. $user = User::where('id',$data['user_id'])->first();
  330. if(empty($user)){
  331. return Result::error('用户不存在!');
  332. }
  333. $ids = [];
  334. if(empty($data['website_id']) && $user['type_id'] == 10000){
  335. $ids = [];
  336. }else{
  337. $where = [
  338. 'website_id' => $data['website_id'] ?? $data['web_id'],
  339. ];
  340. $ids = WebsiteCategory::where($where)->pluck('category_id')->toArray();
  341. // var_dump($ids);
  342. if (empty($ids)) {
  343. return Result::error("没有推荐数据");
  344. }
  345. }
  346. $whereArticle = [];
  347. if (isset($data['id']) && !empty($data['id'])) {
  348. $whereArticle['id'] = $data['id'];
  349. }
  350. //title like
  351. if (isset($data['title']) && !empty($data['id'])) {
  352. array_push($whereArticle, ['title', 'like', "%{$data['title']}%"]);
  353. }
  354. // 若存在过滤用的分类 id 数组,则加入 whereIn 条件,否则直接跳过
  355. $article = Article::when(!empty($ids) && is_array($ids), function ($query) use ($ids) {
  356. $query->whereIn('catid', $ids);
  357. })
  358. ->where('status', 1)
  359. ->when(!empty($whereArticle) , function ($query) use ($whereArticle){
  360. $query->where($whereArticle);
  361. })
  362. ->orderBy('updated_at', 'desc')
  363. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  364. if ($article) {
  365. $data = [
  366. 'rows' => $article->items(),
  367. 'count' => $article->total(),
  368. ];
  369. return Result::success($data);
  370. } else {
  371. return Result::error("获取失败失败");
  372. }
  373. }
  374. /**
  375. * @param array $data
  376. * @return array
  377. */
  378. public function getArticleList(array $data): array
  379. {
  380. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  381. $type_id = $data['type_id'];
  382. unset($data['type_id']);
  383. $user_id = $data['user_id'];
  384. unset($data['user_id']);
  385. $where = [];
  386. $status1 = [];
  387. if (isset($data['id']) && $data['id']) {
  388. array_push($where, ['article.id', '=', $data['id']]);
  389. }
  390. if (isset($data['title']) && $data['title']) {
  391. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  392. }
  393. if (isset($data['category_name']) && $data['category_name']) {
  394. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  395. }
  396. if (isset($data['catid']) && $data['catid']) {
  397. array_push($where, ['article.catid', '=', $data['catid']]);
  398. }
  399. if (isset($data['author']) && $data['author']) {
  400. array_push($where, ['article.author', '=', $data['author']]);
  401. }
  402. if (isset($data['islink']) && $data['islink'] !== "") {
  403. array_push($where, ['article.islink', '=', $data['islink']]);
  404. }
  405. if (isset($data['status']) && $data['status'] !== "") {
  406. array_push($where, ['article.status', '=', $data['status']]);
  407. }
  408. if (isset($data['status1'])) {
  409. $status1 = json_decode(($data['status1']));
  410. }
  411. //不是管理员展示个人数据;
  412. if ($type_id != 10000) {
  413. $where[] = ['article.admin_user_id', '=', $user_id];
  414. }
  415. $startTime = microtime(true);
  416. $rep = Article::query()
  417. // 预加载相关关联
  418. ->with([
  419. 'category' => function ($query) {
  420. $query->select('id', 'name');
  421. },
  422. 'websiteCategory' => function ($query) {
  423. $query->select('website_id', 'category_id', 'alias');
  424. },'user' => function ($query) {
  425. $query->select('id', 'nickname');
  426. }
  427. ])
  428. // 构建where条件
  429. ->when(isset($data['id']) && $data['id'], function ($query) use ($data) {
  430. $query->where('article.id', '=', $data['id']);
  431. })
  432. ->when(isset($data['title']) && $data['title'], function ($query) use ($data) {
  433. $query->where('article.title', 'like', '%' . $data['title'] . '%');
  434. })
  435. ->when(isset($data['category_name']) && $data['category_name'], function ($query) use ($data) {
  436. // 使用子查询替代左连接进行模糊搜索
  437. $query->whereHas('category', function ($subQuery) use ($data) {
  438. $subQuery->where('name', 'like', '%' . $data['category_name'] . '%');
  439. });
  440. })
  441. ->when(isset($data['catid']) && $data['catid'], function ($query) use ($data) {
  442. $query->where('article.catid', '=', $data['catid']);
  443. })
  444. ->when(isset($data['author']) && $data['author'], function ($query) use ($data) {
  445. $query->where('article.author', '=', $data['author']);
  446. })
  447. ->when(isset($data['islink']) && $data['islink'] !== "", function ($query) use ($data) {
  448. $query->where('article.islink', '=', $data['islink']);
  449. })
  450. ->when(isset($data['status']) && $data['status'] !== "", function ($query) use ($data) {
  451. $query->where('article.status', '=', $data['status']);
  452. })
  453. ->when(isset($data['status1']) && $data['status1'], function ($query) use ($data) {
  454. // 安全地处理JSON字符串
  455. $status1 = is_array($data['status1']) ? $data['status1'] : json_decode($data['status1'], true) ?? [];
  456. if (!empty($status1)) {
  457. $query->whereIn('article.status', $status1);
  458. }
  459. })
  460. ->select('article.*')
  461. // 非管理员限制
  462. ->when($type_id != 10000, function ($query) use ($user_id) {
  463. // 非管理员只能看自己的文章,同时把 article_ignore 的 c_show_time 一起查出来
  464. $query->where('article.admin_user_id', $user_id)
  465. ->leftJoin('article_ignore', function ($join) {
  466. // 关联条件:article.id = article_ignore.article_id 且 article.web_site_id = article_ignore.website_id
  467. $join->on('article_ignore.article_id', '=', 'article.id')
  468. ->whereColumn('article_ignore.website_id', 'article.web_site_id');
  469. })
  470. ->addSelect('article_ignore.article_id','article_ignore.c_show_time'); // 用 addSelect 追加字段,避免覆盖原有 select
  471. })
  472. // 基础条件
  473. ->whereNotIn('article.status', [404])
  474. // 排序和分页
  475. ->orderBy('article.updated_at', 'desc')
  476. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  477. // 获取结果并格式化
  478. $data = [
  479. 'rows' => $rep->items(),
  480. 'count' => $rep->total(),
  481. ];
  482. // 执行查询
  483. $endTime = microtime(true);
  484. $executionTime = ($endTime - $startTime) * 1000;
  485. echo "查询执行时间: {$executionTime}ms\n";
  486. return Result::success($data);
  487. }
  488. /**
  489. * @param array $data
  490. * @return array
  491. */
  492. public function addArticle(array $data): array
  493. {
  494. var_dump($data, '----------12-----------1');
  495. // ------c_show_time********add***1****
  496. $is_collect = $data['is_collect'] ?? 0;
  497. $user_type = $data['user_type'];
  498. unset($data['is_collect']);
  499. unset($data['user_type']);
  500. // ------c_show_time********add***1****
  501. unset($data['nav_add_pool_id']);
  502. // unset($data['commend_id']);
  503. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  504. Db::beginTransaction();
  505. try {
  506. //处理投票
  507. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  508. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  509. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  510. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  511. unset($data['is_survey']);
  512. unset($data['survey_name']);
  513. unset($data['suvey_array']);
  514. // unset($data['website_id']);
  515. // unset($data['web_site_id']);
  516. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  517. if ($data['hits'] == '') {
  518. $data['hits'] = 0;
  519. }
  520. if ($data['is_original'] == '') {
  521. $data['is_original'] = 0;
  522. }
  523. if ($data['status'] == '') {
  524. $data['status'] = 0;
  525. }
  526. $articleData = $data;
  527. unset($articleData['content']);
  528. //自动处理缩略图、关键字、描述
  529. if ($articleData['imgurl'] == '') {
  530. //如果没有图,设置level=0
  531. $levelArr = json_decode($articleData['level'], true);
  532. var_dump($levelArr, '----------levelArr-----------1');
  533. //content中提取图片第一个图,正则提取
  534. // -------采集器相关优化-----
  535. // 优化正则表达式,仅匹配 src 属性值,避免匹配到多余内容
  536. if ($is_collect == 1) {
  537. $reg = '/<img.*?src=[\'"]?((?!.*\.gif)[^\'" >]+)[\'"]?.*?>/i';
  538. } else {
  539. $reg = '/<img.*?src=[\'"]?([^\'" >]+)[\'"]?.*?>/i';
  540. }
  541. // -------采集器相关优化-----
  542. preg_match_all($reg, $data['content'], $matches);
  543. if (isset($matches[1][0])) {
  544. //截取varchar240
  545. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  546. //如果有图,设置level=3
  547. if (!in_array(3, $levelArr)) {
  548. $levelArr[] = 3;
  549. }
  550. $articleData['level'] = json_encode($levelArr);
  551. } else {
  552. if (!in_array(0, $levelArr)) {
  553. $levelArr[] = 0;
  554. }
  555. $articleData['level'] = json_encode($levelArr);
  556. }
  557. }
  558. var_dump($articleData['level'], '----------$articleData[level]----------1');
  559. if ($articleData['keyword'] == '') {
  560. //提取标题+内容中的关键词
  561. $articleData['keyword'] = $data['title'];
  562. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  563. Jieba::init(); // 初始化 jieba-php
  564. Finalseg::init();
  565. $segList = Jieba::cut($articleData['keyword']);
  566. $segList1 = array_slice($segList, 0, 8);
  567. $articleData['keyword'] = implode(',', $segList1);
  568. }
  569. if ($articleData['introduce'] == '') {
  570. //提取内容中的描述
  571. $content = $data['content'];
  572. // 去除 <style> 和 <script> 标签及其内容
  573. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  574. // 去除所有 HTML 标签
  575. $content = strip_tags($content);
  576. // 去除 HTML 实体
  577. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  578. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  579. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  580. // 去除多余空白
  581. $content = preg_replace('/\s+/u', '', $content);
  582. // 截取 100 个字符
  583. $articleData['introduce'] = mb_substr($content, 0, 100);
  584. }
  585. if ($articleData['status'] == 0) {
  586. $this->sendMessage([
  587. 'talk_type' => 100,
  588. 'title' => $articleData['title'],
  589. 'content' => '提交了审核',
  590. 'messageType' => 2,
  591. ]);
  592. }
  593. if(!empty($data['fujian'])){
  594. $articleData['fujian'] = $data['fujian'];
  595. }
  596. $id = Article::insertGetId($articleData);
  597. if (!$id) {
  598. throw new \Exception('文章插入失败');
  599. }
  600. $articleDataContent = [
  601. 'article_id' => $id,
  602. 'content' => $data['content'],
  603. ];
  604. // 采集器中的文章内容,在添加时,去掉div标签
  605. if ($is_collect == 1) {
  606. // 采集来的文章,content中可能包含div标签,需要先移除
  607. $pattern = '/<\/?div\b(?:[^"\'>]|"[^"]*"|\'[^\']*\')*>/is';
  608. $article_data = preg_replace($pattern, '', $data['content']);
  609. $$articleDataContent['content'] = $article_data;
  610. }
  611. $contentInsertId = ArticleData::insertGetId($articleDataContent);
  612. if (!$contentInsertId) {
  613. throw new \Exception('文章内容插入失败');
  614. }
  615. // ------c_show_time********add***2****
  616. // 直接使用当前系统时间,不再强制添加8小时
  617. $now = date('Y-m-d H:i:s');
  618. if ($user_type == 10000 || $is_collect == 1) {
  619. // 管理员添加文章时,核心站c端显示时间就是创建时间;非核心站c端显示时间就是此创建时间往后推二十分钟;
  620. // 非管理员添加文章时,不做操作只有在审核通过时获取c端显示时间
  621. if (!isset($data['catid'])) {
  622. throw new \Exception('缺少必要字段:catid');
  623. }
  624. $column_arr = WebsiteColumn::where('column_name','官网')->pluck('id')->toArray();
  625. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  626. $web = WebsiteCategory::where('category_id', $data['catid'])
  627. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  628. ->select(
  629. 'website_id',
  630. DB::raw('
  631. CASE
  632. WHEN website.id IS NULL THEN 2
  633. WHEN website.website_column_id IN ('.implode(',', $column_arr).') THEN 1
  634. ELSE 0
  635. END as is_core
  636. ')
  637. )
  638. ->get();
  639. // $id = 225; -----测试开启
  640. // 采集来的文章,错开时间在两小时之内发布
  641. if ($user_type == 10000 && $is_collect == 1) {
  642. $web_num = $web->where('is_core', '!=', 2)->count();
  643. $waiting_interval = 10;
  644. if ($web_num > 12) {
  645. // 若网站数量大于12个,则每个网站间隔时间取均值
  646. // 防止除数为 0,虽然这里 $web_num 是 count 结果不会为 0,但做健壮性检查
  647. $waiting_interval = 120 / max(1, $web_num);
  648. }
  649. $time = 0;
  650. } else {
  651. // 非核心站与核心站----显示时间-----间隔
  652. $time = 20;
  653. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  654. $waiting_interval = 5;
  655. }
  656. // 将 Hyperf\Database\Model\Collection 转换为数组
  657. $webArray = $web->toArray();
  658. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $id, $waiting_interval, $is_collect) {
  659. // 检查 $item 对象是否有 is_core 属性
  660. if (!isset($item['is_core'])) {
  661. throw new \Exception('$item 对象缺少 is_core 属性');
  662. }
  663. // 当 is_core 为 2 时,则表示此网站不存在
  664. if ($item['is_core'] == 2) {
  665. return null;
  666. }
  667. if ($is_collect == 1) {
  668. // 采集来的文章,错开时间在两小时之内发布
  669. // $time = 0;
  670. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  671. $time += $waiting_interval;
  672. } else if ($item['is_core'] == 1) {
  673. // 当 is_core 为 1 时,则表示此网站是核心站
  674. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  675. } else {
  676. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  677. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  678. if ($item['is_core'] == 0) {
  679. $time += $waiting_interval;
  680. }
  681. }
  682. return [
  683. 'article_id' => $id,
  684. 'website_id' => $item['website_id'],
  685. 'c_show_time' => $c_show_time,
  686. // 'is_core' => $item['is_core'],
  687. // 'time' => $time
  688. ];
  689. }, array_keys($webArray), $webArray)));
  690. // Db::commit();
  691. // return Result::success($article_ignore);
  692. if (!empty($article_ignore)) {
  693. $article_ignores = ArticleIgnore::insert($article_ignore);
  694. if (!$article_ignores) {
  695. throw new \Exception('c端展示时间插入失败');
  696. }
  697. }
  698. }
  699. // ------c_show_time********add***2****
  700. //处理投票
  701. if ($is_survey == 1) {
  702. //生成年月日时分秒+8位随机数
  703. $uuid = date('YmdHis') . rand(10000000, 99999999);
  704. var_dump($suvey_array, 'suvey_array________');
  705. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  706. var_dump($suveys_array, '---------------------1');
  707. var_dump($suvey_array, '---------------------2');
  708. $suvey_data = [];
  709. foreach ($suveys_array as $key => $value) {
  710. if ($value == '') {
  711. continue;
  712. }
  713. if (is_array($value)) {
  714. $suvey_data[] = [
  715. 'sur_id' => $uuid,
  716. 'art_id' => $id,
  717. 'website_id' => $website_id ?? 2,
  718. 'survey_name' => $survey_name,
  719. 'choice_name' => $value[1],
  720. 'is_other' => 1,
  721. 'other_id' => 0,
  722. 'results' => 0,
  723. ];
  724. } else {
  725. $suvey_data[] = [
  726. 'sur_id' => $uuid,
  727. 'art_id' => $id,
  728. 'website_id' => $website_id ?? 2,
  729. 'survey_name' => $survey_name,
  730. 'choice_name' => $value,
  731. 'is_other' => 0,
  732. 'other_id' => 0,
  733. 'results' => 0,
  734. ];
  735. }
  736. if (empty($suvey_data)) {
  737. throw new \Exception("投票数据为空");
  738. }
  739. }
  740. $result = ArticleSurvey::insert($suvey_data);
  741. if (!$result) {
  742. throw new \Exception("投票失败,ArticleSurvey插入失败");
  743. }
  744. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  745. if (!$result) {
  746. throw new \Exception("投票失败,更新主表失败");
  747. }
  748. }
  749. Db::commit();
  750. return Result::success(['id' => $id]);
  751. } catch (\Throwable $ex) {
  752. Db::rollBack();
  753. var_dump($ex->getMessage());
  754. return Result::error("创建失败", 0);
  755. }
  756. }
  757. /**
  758. * @param array $data
  759. * @return array
  760. */
  761. public function delArticle(array $data): array
  762. {
  763. // ------c_show_time********del*******
  764. Db::beginTransaction();
  765. try {
  766. $article = Article::where(['id' => $data['id']])->delete();
  767. // 若文章删除失败,抛出异常,后续 SQL 语句不会执行
  768. if (!$article) {
  769. throw new \Exception("删除失败,文章删除失败");
  770. }
  771. //survey投票删除
  772. ArticleSurvey::where(['art_id' => $data['id']])->delete(); // 修正类名大小写
  773. $articleIgnore = ArticleIgnore::where(['article_id' => $data['id']])->delete();
  774. $article_data = ArticleData::where(['article_id' => $data['id']])->delete();
  775. // 若文章详情删除失败,抛出异常
  776. if (!$article_data) {
  777. throw new \Exception("删除失败,文章详情删除失败");
  778. }
  779. Db::commit(); // 所有操作成功,提交事务
  780. } catch (\Throwable $ex) {
  781. Db::rollBack();
  782. var_dump($ex->getMessage());
  783. return Result::error("删除失败: " . $ex->getMessage(), 0);
  784. }
  785. // ------c_show_time********del*******
  786. if (!$article) {
  787. return Result::error("删除失败");
  788. }
  789. return Result::success($article);
  790. }
  791. /**
  792. * @param array $data
  793. * @return array
  794. */
  795. public function updateArticle(array $data): array
  796. {
  797. var_dump($data, '----------12-----------1');
  798. Db::beginTransaction();
  799. // ------c_show_time********up*******
  800. $user_type = isset($data['user_type']) ? $data['user_type'] : 0;
  801. // 无论是否改变了c端显示时间或者栏目,都需要将未屏蔽的网站显示时间删除记录
  802. // 若是存在交集,则进行修改,若无,则合并(此表中的记录应该包含被屏蔽网站及涉及所有网站的展示时间)
  803. $web = WebsiteCategory::where('category_id', $data['catid'])
  804. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  805. ->select(
  806. 'website_id',
  807. Db::raw('CASE WHEN website.id IS NULL THEN 2 WHEN JSON_CONTAINS(website.`website_column_arr_id`, \'3\') THEN 1 ELSE 0 END as is_core')
  808. )
  809. ->get();
  810. // 根据错误信息,问题在于 $web 可能是一个包含对象的集合,不能直接用于 whereNotIn 方法
  811. // 先从 $web 集合中提取 website_id 字段的值,再进行删除操作
  812. $websiteIds = $web->pluck('website_id')->toArray();
  813. $del_article_ignore = ArticleIgnore::where('article_id', $data['id'])->whereNotIn('website_id', $websiteIds)->delete();
  814. if ($user_type == 0) {
  815. throw new \Exception("用户类型不能为空");
  816. }
  817. if ($user_type == 10000) {
  818. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  819. $web = WebsiteCategory::where('category_id', $data['catid'])
  820. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  821. ->select(
  822. 'website_id',
  823. Db::raw('CASE WHEN website.id IS NULL THEN 2 WHEN JSON_CONTAINS(website.`website_column_arr_id`, \'3\') THEN 1 ELSE 0 END as is_core')
  824. )
  825. ->get();
  826. // 非核心站与核心站----显示时间-----间隔
  827. $time = 20;
  828. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  829. $waiting_interval = 5;
  830. $webArray = $web->toArray();
  831. if (empty($webArray)) {
  832. throw new \Exception('网站分类不存在');
  833. }
  834. // 直接使用当前系统时间,不再强制添加8小时
  835. $now = date('Y-m-d H:i:s');
  836. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  837. // 检查 $item 对象是否有 is_core 属性
  838. if (!isset($item['is_core'])) {
  839. throw new \Exception('$item 对象缺少 is_core 属性');
  840. }
  841. // 当 is_core 为 2 时,则表示此网站不存在
  842. if ($item['is_core'] == 2) {
  843. return null;
  844. } else if ($item['is_core'] == 1) {
  845. // 当 is_core 为 1 时,则表示此网站是核心站
  846. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  847. } else {
  848. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  849. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  850. if ($item['is_core'] == 0) {
  851. $time += $waiting_interval;
  852. }
  853. }
  854. return [
  855. 'article_id' => $data['id'],
  856. 'website_id' => $item['website_id'],
  857. 'c_show_time' => $c_show_time,
  858. ];
  859. }, array_keys($webArray), $webArray)));
  860. if (!empty($article_ignore)) {
  861. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  862. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  863. $article_ignores = ArticleIgnore::upsert(
  864. $article_ignore,
  865. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  866. ['c_show_time'] // 需要更新的字段
  867. );
  868. if (!$article_ignores) {
  869. throw new \Exception('c端展示时间插入失败');
  870. }
  871. }
  872. // Db::commit();
  873. // return Result::success($article_ignore);
  874. }
  875. // ------c_show_time********up*******
  876. unset($data['user_type']);
  877. // unset($data['web_site_id']);
  878. unset($data['nav_add_pool_id']);
  879. try {
  880. //处理投票
  881. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  882. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  883. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  884. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  885. unset($data['is_survey']);
  886. unset($data['survey_name']);
  887. unset($data['suvey_array']);
  888. unset($data['website_id']);
  889. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  890. if ($data['hits'] == '') {
  891. $data['hits'] = 0;
  892. }
  893. if ($data['is_original'] == '') {
  894. $data['is_original'] = 0;
  895. }
  896. if ($data['status'] == '') {
  897. $data['status'] = 0;
  898. }
  899. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  900. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  901. $articleData = $data;
  902. unset($articleData['content']);
  903. unset($articleData['status_name']);
  904. unset($articleData['name']);
  905. unset($articleData['content']);
  906. unset($articleData['pid_arr']);
  907. unset($articleData['pid']);
  908. //自动处理缩略图、关键字、描述
  909. if ($articleData['imgurl'] == '') {
  910. //如果没有图,设置level=0
  911. $levelArr = json_decode($articleData['level'], true);
  912. var_dump($levelArr, '----------levelArr-----------1');
  913. //content中提取图片第一个图,正则提取
  914. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  915. preg_match_all($reg, $data['content'], $matches);
  916. if (isset($matches[1][0])) {
  917. //截取varchar240
  918. // 截取到第一个<
  919. $articleData['imgurl'] = $matches[1][0];
  920. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  921. $pos = strpos($articleData['imgurl'], '"');
  922. if ($pos !== false) {
  923. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  924. }
  925. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  926. //如果有图,设置level=3
  927. if (!in_array(3, $levelArr)) {
  928. $levelArr[] = 3;
  929. }
  930. $articleData['level'] = json_encode($levelArr);
  931. } else {
  932. if (!in_array(0, $levelArr)) {
  933. $levelArr[] = 0;
  934. }
  935. $articleData['level'] = json_encode($levelArr);
  936. }
  937. }
  938. var_dump($articleData['level'], '----------$articleData[level]----------1');
  939. if ($articleData['keyword'] == '') {
  940. //提取标题+内容中的关键词
  941. $articleData['keyword'] = $data['title'];
  942. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  943. Jieba::init(); // 初始化 jieba-php
  944. Finalseg::init();
  945. $segList = Jieba::cut($articleData['keyword']);
  946. $segList1 = array_slice($segList, 0, 8);
  947. $articleData['keyword'] = implode(',', $segList1);
  948. }
  949. if ($articleData['introduce'] == '') {
  950. //提取内容中的描述
  951. $content = $data['content'];
  952. // 去除 <style> 和 <script> 标签及其内容
  953. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  954. // 去除所有 HTML 标签
  955. $content = strip_tags($content);
  956. // 去除 HTML 实体
  957. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  958. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  959. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  960. // 去除多余空白
  961. $content = preg_replace('/\s+/u', '', $content);
  962. // 截取 100 个字符
  963. $articleData['introduce'] = mb_substr($content, 0, 100);
  964. }
  965. if ($articleData['status'] == 0) {
  966. $this->sendMessage([
  967. 'talk_type' => 100,
  968. 'title' => $articleData['title'],
  969. 'content' => '提交了审核',
  970. 'messageType' => 2,
  971. ]);
  972. }
  973. if(!empty($data['fujian'])){
  974. $articleData['fujian'] = $data['fujian'];
  975. }
  976. $id = Article::where(['id' => $data['id']])->update($articleData);
  977. // $articleDataContent = [
  978. // 'content' => $data['content'],
  979. // ];
  980. // 采集来的文章,content中可能包含div标签,需要先移除
  981. $pattern = '/<\/?div\b(?:[^"\'>]|"[^"]*"|\'[^\']*\')*>/is';
  982. $article_data = preg_replace($pattern, '', $data['content']);
  983. $articleDataContent['content'] = $article_data;
  984. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  985. //处理投票
  986. $id = $data['id'];
  987. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  988. var_dump($suvey_array, 'suvey_array________delete');
  989. //处理投票
  990. if ($is_survey == 1) {
  991. //生成年月日时分秒+8位随机数
  992. $uuid = date('YmdHis') . rand(10000000, 99999999);
  993. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  994. var_dump($suveys_array, '---------------------1');
  995. $suvey_data = [];
  996. if (is_array($suveys_array)) {
  997. foreach ($suveys_array as $key => $value) {
  998. if ($value == '') {
  999. continue;
  1000. }
  1001. if (is_array($value)) {
  1002. $suvey_data[] = [
  1003. 'sur_id' => $uuid,
  1004. 'art_id' => $id,
  1005. 'website_id' => $website_id ?? 2,
  1006. 'survey_name' => $survey_name,
  1007. 'choice_name' => $value[1],
  1008. 'is_other' => 1,
  1009. 'other_id' => 0,
  1010. 'results' => 0,
  1011. ];
  1012. } else {
  1013. $suvey_data[] = [
  1014. 'sur_id' => $uuid,
  1015. 'art_id' => $id,
  1016. 'website_id' => $website_id ?? 2,
  1017. 'survey_name' => $survey_name,
  1018. 'choice_name' => $value,
  1019. 'is_other' => 0,
  1020. 'other_id' => 0,
  1021. 'results' => 0,
  1022. ];
  1023. }
  1024. if (empty($suvey_data)) {
  1025. throw new \Exception("投票数据为空");
  1026. }
  1027. }
  1028. }
  1029. $result = ArticleSurvey::insert($suvey_data);
  1030. if (!$result) {
  1031. throw new \Exception("投票失败");
  1032. }
  1033. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  1034. if (!$result) {
  1035. throw new \Exception("投票失败");
  1036. }
  1037. } else {
  1038. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  1039. }
  1040. Db::commit();
  1041. return Result::success([]);
  1042. } catch (\Throwable $ex) {
  1043. Db::rollBack();
  1044. var_dump($ex->getMessage());
  1045. return Result::error("更新失败" . $ex->getMessage(), 0);
  1046. }
  1047. }
  1048. /**
  1049. * 更新资讯状态
  1050. * @param array $data
  1051. * @return array
  1052. */
  1053. public function upArticleStatus(array $data): array
  1054. {
  1055. $articleData = Article::where(['id' => $data['id']])->first();
  1056. //发送10次
  1057. // for ($i = 0; $i < 10; $i++) {
  1058. // $this->sendMessage([
  1059. // 'talk_type' => 100,
  1060. // 'title' => $i . $articleData['title'],
  1061. // 'content' => '审核通过',
  1062. // 'messageType' => 2,
  1063. // 'user_id' => $articleData['admin_user_id'],
  1064. // ]);
  1065. // }
  1066. // var_dump($data['status'], 'status');
  1067. // return Result::success();
  1068. if ($data['status'] == 1) {
  1069. $this->sendMessage([
  1070. 'talk_type' => 101,
  1071. 'title' => $articleData['title'],
  1072. 'content' => '审核通过',
  1073. 'messageType' => 2,
  1074. 'user_id' => $articleData['admin_user_id'],
  1075. ]);
  1076. }
  1077. if ($data['status'] == 2) {
  1078. $this->sendMessage([
  1079. 'talk_type' => 101,
  1080. 'title' => $articleData['title'],
  1081. 'content' => '审核拒绝',
  1082. 'messageType' => 2,
  1083. 'user_id' => $articleData['admin_user_id'],
  1084. ]);
  1085. }
  1086. if ($data['status'] == 0) {
  1087. $this->sendMessage([
  1088. 'talk_type' => 100,
  1089. 'title' => $articleData['title'],
  1090. 'content' => '提交了审核',
  1091. 'messageType' => 2,
  1092. ]);
  1093. }
  1094. $result = Article::where(['id' => $data['id']])->update($data);
  1095. // ------c_show_time********up_status*******
  1096. // 若是审核通过 则更新c_show_time
  1097. if ($data['status'] == 1) {
  1098. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  1099. $column_arr = WebsiteColumn::where('column_name','官网')->pluck('id')->toArray();
  1100. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  1101. $web = WebsiteCategory::where('category_id', $data['catid'])
  1102. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  1103. ->select(
  1104. 'website_id',
  1105. DB::raw('
  1106. CASE
  1107. WHEN website.id IS NULL THEN 2
  1108. WHEN website.website_column_id IN ('.implode(',', $column_arr).') THEN 1
  1109. ELSE 0
  1110. END as is_core
  1111. ')
  1112. )
  1113. ->get();
  1114. // 非核心站与核心站----显示时间-----间隔
  1115. $time = 20;
  1116. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  1117. $waiting_interval = 5;
  1118. $webArray = $web->toArray();
  1119. if (empty($webArray)) {
  1120. throw new \Exception('网站分类不存在');
  1121. }
  1122. // 直接使用当前系统时间,不再强制添加8小时
  1123. $now = date('Y-m-d H:i:s');
  1124. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  1125. if (isset($data['ignore_ids'])) {
  1126. $ignore_website_ids = is_array($data['ignore_ids']) ? $data['ignore_ids'] : json_decode($data['ignore_ids'], true);
  1127. if (in_array($item['website_id'], $ignore_website_ids)) {
  1128. $is_ignore = 1;
  1129. } else {
  1130. $is_ignore = 0;
  1131. }
  1132. return [
  1133. 'article_id' => $data['id'],
  1134. 'website_id' => $item['website_id'],
  1135. 'is_ignore' => $is_ignore,
  1136. ];
  1137. } else {
  1138. // 检查 $item 对象是否有 is_core 属性
  1139. if (!isset($item['is_core'])) {
  1140. throw new \Exception('$item 对象缺少 is_core 属性');
  1141. }
  1142. // 当 is_core 为 2 时,则表示此网站不存在
  1143. if ($item['is_core'] == 2) {
  1144. return null;
  1145. } else if ($item['is_core'] == 1) {
  1146. // 当 is_core 为 1 时,则表示此网站是核心站
  1147. $c_show_time = $now;
  1148. } else {
  1149. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  1150. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  1151. if ($item['is_core'] == 0) {
  1152. $time += $waiting_interval;
  1153. }
  1154. }
  1155. return [
  1156. 'article_id' => $data['id'],
  1157. 'website_id' => $item['website_id'],
  1158. 'c_show_time' => $c_show_time,
  1159. ];
  1160. }
  1161. }, array_keys($webArray), $webArray)));
  1162. if (!empty($article_ignore) && !isset($data['ignore_ids'])) {
  1163. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  1164. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  1165. $websiteIds = $web->pluck('website_id')->toArray();
  1166. $del_article_ignore = ArticleIgnore::where('article_id', $data['id'])->whereNotIn('website_id', $websiteIds)->delete();
  1167. $article_ignores = ArticleIgnore::upsert(
  1168. $article_ignore,
  1169. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  1170. ['c_show_time'] // 需要更新的字段
  1171. );
  1172. if (!$article_ignores) {
  1173. throw new \Exception('c端展示时间插入失败');
  1174. }
  1175. }
  1176. if (!empty($data['ignore_ids'])) {
  1177. // return Result::success($article_ignore);
  1178. // 从数据库中删除 article_id 为 $data['id'] 且 website_id 在 $website_ids 中的记录
  1179. if (!empty($article_ignore)) {
  1180. $article_ignores = ArticleIgnore::upsert(
  1181. $article_ignore,
  1182. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  1183. ['is_ignore'] // 需要更新的字段
  1184. );
  1185. // if(!$article_ignores){
  1186. // throw new \Exception('屏蔽网站更新失败');
  1187. // }
  1188. }
  1189. }
  1190. }
  1191. // ------c_show_time********up_status*******
  1192. if ($result) {
  1193. return Result::success();
  1194. } else {
  1195. return Result::error("更新状态失败", 0);
  1196. }
  1197. }
  1198. /**
  1199. * 获取新闻详情
  1200. * @param array $data
  1201. * @return array
  1202. */
  1203. public function getArticleInfo(array $data): array
  1204. {
  1205. $where = [
  1206. 'article.id' => $data['id'],
  1207. // 'article.status' => 1,
  1208. ];
  1209. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  1210. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  1211. $info = $result;
  1212. // var_dump($info, 'info');
  1213. $info['survey_array'] = $articleSurvey;
  1214. if ($result) {
  1215. return Result::success($info);
  1216. } else {
  1217. return Result::error("查询失败", 0);
  1218. }
  1219. }
  1220. /**
  1221. * 获取头条新闻
  1222. * @param array $data
  1223. * @return array
  1224. */
  1225. public function getWebsiteArticlett(array $data): array
  1226. {
  1227. $website_id = $data['website_id'];
  1228. $website = Website::where('id', $data['website_id'])->first();
  1229. if (empty($website)) {
  1230. return Result::error("网站不存在", 0);
  1231. }
  1232. $categorys = $this->processArticlePro($website_id);
  1233. $catiall = $categorys['catiall'];
  1234. $categoryIds = $categorys['categoryIds'];
  1235. $where = [
  1236. 'status' => 1
  1237. ];
  1238. // $website_column = $website['column'];
  1239. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1240. $website_column = json_decode($website['website_column_arr_id'], true);
  1241. }
  1242. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1243. // return Result::success($diff_pid_categoryIds);
  1244. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1245. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1246. }
  1247. // $website_id = $data['website_id'];
  1248. $month = date("Y-m-d H:i:s", strtotime("-30 day"));
  1249. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  1250. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  1251. switch ($data['level']) {
  1252. case 1:
  1253. case 2:
  1254. case 3:
  1255. case 6: //1.头条资讯;2.轮播图;3.推荐图;6.今日热点
  1256. $query = Article::where($where)
  1257. ->where('level', 'like', '%' . $data['level'] . '%')
  1258. ->orderBy('updated_at', 'desc');
  1259. break;
  1260. case 4: //最新资讯
  1261. $query = Article::where($where)->orderBy('updated_at', 'desc');
  1262. break;
  1263. case 5: //资讯推荐
  1264. $query = Article::where($where)
  1265. ->where('updated_at', '>', $month);
  1266. break;
  1267. case 7: //资讯分类
  1268. if (isset($data['id']) && !empty($data['id'])) {
  1269. $keyword = Article::where('id', $data['id'])->value('keyword');
  1270. $keywordArray = explode(',', $keyword);
  1271. $whereL7 = [];
  1272. foreach ($keywordArray as $k => $v) {
  1273. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1274. }
  1275. $query = Article::where($where)->where($whereL7)->orderBy('updated_at', 'desc');;
  1276. break;
  1277. } else {
  1278. return Result::error("请输入资讯ID", 0);
  1279. break;
  1280. }
  1281. default:
  1282. break;
  1283. }
  1284. // $whereL7 = [];
  1285. // if(isset($data['id']) && !empty($data['id'])){
  1286. // $keyword = Article::where('id', $data['id'])->value('keyword');
  1287. // $keywordArray = explode(',', $keyword);
  1288. // foreach ($keywordArray as $k => $v) {
  1289. // $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1290. // }
  1291. // }
  1292. // $query = Article::where($where)
  1293. // ->when(isset($data['level']) && !empty($data['level']), function ($query) use ($data,$whereL7) {
  1294. // if($data['level'] == 1 || $data['level'] == 2 || $data['level'] == 3 || $data['level'] == 6){
  1295. // $query = $query->where('article.level','like','%'.$data['level'].'%')->orderBy('updated_at','desc');
  1296. // }
  1297. // if($data['level'] == 7){
  1298. // $query = $query->where($whereL7)->orderBy('updated_at','desc');
  1299. // }
  1300. // if($data['level'] == 4){
  1301. // $query = $query->inRandomOrder()
  1302. // ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  1303. // }
  1304. // if($data['level'] == 5){
  1305. // $query = $query->orderBy('updated_at','desc');
  1306. // }
  1307. // });
  1308. if ($data['textnum'] > 0) {
  1309. $query = clone $query;
  1310. $result['text'] = $query
  1311. ->whereIn('catid', $categoryIds)
  1312. ->leftJoinSub(function ($query) use ($website_id) {
  1313. $query->from('article_ignore')
  1314. ->where('website_id', $website_id);
  1315. }, 'article_ignore', function ($join) {
  1316. $join->on('article_ignore.article_id', '=', 'article.id');
  1317. })
  1318. ->where(function ($query) {
  1319. $query->whereNull('article_ignore.article_id')
  1320. ->orWhere(function ($subQuery) {
  1321. $subQuery->whereNotNull('article_ignore.article_id')
  1322. ->where('article_ignore.is_ignore', 0)
  1323. ->where(function ($subSubQuery) {
  1324. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1325. ->orWhereNull('article_ignore.c_show_time');
  1326. });
  1327. });
  1328. })
  1329. // ->where(function ($query) use ($website_id) {
  1330. // $query->whereNull('article_ignore.article_id')
  1331. // ->orWhere('article_ignore.website_id', '!=', $website_id);
  1332. // })
  1333. ->select(
  1334. 'article.id',
  1335. 'article.title',
  1336. 'article.author',
  1337. 'article.updated_at',
  1338. 'article.introduce',
  1339. 'article.islink',
  1340. 'article.linkurl',
  1341. 'article.copyfrom',
  1342. 'article.cat_arr_id',
  1343. 'article.catid',
  1344. 'article.level',
  1345. // 'article_ignore.is_ignore',
  1346. // 'article_ignore.c_show_time',
  1347. )
  1348. ->offset($data['placeid'])
  1349. ->limit($data['textnum'])
  1350. ->get()->all();
  1351. foreach ($result['text'] as $k => $v) {
  1352. $result['text'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1353. $result['text'][$k]->alias = $catiall[$v->catid]['alias'];
  1354. }
  1355. }
  1356. if ($data['imgnum'] > 0) {
  1357. $query = clone $query;
  1358. if ($data['textnum'] == 0) {
  1359. $query = $query->leftJoinSub(function ($query) use ($website_id) {
  1360. $query->from('article_ignore')
  1361. ->where('website_id', $website_id);
  1362. }, 'article_ignore', function ($join) {
  1363. $join->on('article_ignore.article_id', '=', 'article.id');
  1364. })
  1365. ->where(function ($query) {
  1366. $query->whereNull('article_ignore.article_id')
  1367. ->orWhere(function ($subQuery) {
  1368. $subQuery->whereNotNull('article_ignore.article_id')
  1369. ->where('article_ignore.is_ignore', 0)
  1370. ->where(function ($subSubQuery) {
  1371. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1372. ->orWhereNull('article_ignore.c_show_time');
  1373. });
  1374. });
  1375. });
  1376. }
  1377. $result['img'] = $query
  1378. ->whereIn('catid', $categoryIds)
  1379. ->where('article.imgurl', '!=', '')
  1380. ->select(
  1381. 'article.id',
  1382. 'article.title',
  1383. 'article.imgurl',
  1384. 'article.author',
  1385. 'article.updated_at',
  1386. 'article.introduce',
  1387. 'article.islink',
  1388. 'article.linkurl',
  1389. 'article.copyfrom',
  1390. 'article.cat_arr_id',
  1391. 'article.catid',
  1392. 'article.level',
  1393. // 'article_ignore.is_ignore',
  1394. // 'article_ignore.c_show_time',
  1395. )
  1396. ->offset($data['placeid'])
  1397. ->limit($data['imgnum'])
  1398. ->get()->all();
  1399. foreach ($result['img'] as $k => $v) {
  1400. $result['img'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1401. $result['img'][$k]->alias = $catiall[$v->catid]['alias'];
  1402. }
  1403. }
  1404. if (empty($result)) {
  1405. return Result::error("暂无相关资讯", 0);
  1406. }
  1407. return Result::success($result);
  1408. }
  1409. /**
  1410. * 获取模块新闻
  1411. * @param array $data
  1412. * @return array
  1413. */
  1414. public function getWebsiteModelArticles(array $data): array
  1415. {
  1416. $catid = $data['catid'];
  1417. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  1418. $category = $category->toArray();
  1419. if (!empty($category)) {
  1420. $where = [
  1421. 'status' => 1,
  1422. 'catid' => $catid,
  1423. ];
  1424. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  1425. // 1:文字新闻;2:轮播图;3:图文;
  1426. // 级别:0:未分类
  1427. // 3:推荐图片
  1428. if ($data['level'] == 1) {
  1429. $data['level'] = 0;
  1430. }
  1431. $result = Article::where($where)
  1432. ->where(function ($query) use ($data) {
  1433. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  1434. ->orWhereNull("level")
  1435. ->orWhereRaw("level = '[]'");
  1436. })
  1437. ->leftJoinSub(function ($query) use ($data) {
  1438. $query->from('article_ignore')
  1439. ->where('website_id', $data['website_id']);
  1440. }, 'article_ignore', function ($join) {
  1441. $join->on('article_ignore.article_id', '=', 'article.id');
  1442. })
  1443. ->where(function ($query) {
  1444. $query->whereNull('article_ignore.article_id')
  1445. ->orWhere(function ($subQuery) {
  1446. $subQuery->whereNotNull('article_ignore.article_id')
  1447. ->where('article_ignore.is_ignore', 0)
  1448. ->where(function ($subSubQuery) {
  1449. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1450. ->orWhereNull('article_ignore.c_show_time');
  1451. });
  1452. });
  1453. })
  1454. // ->where(function ($query) use ($data) {
  1455. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1456. // ->orWhereNull("ignore_ids");
  1457. // })
  1458. ->orderBy("updated_at", "desc")
  1459. ->offset($placeid)
  1460. ->limit($data['pagesize'])
  1461. ->get();
  1462. if (empty($result)) {
  1463. return Result::error("此栏目暂无相关新闻", 0);
  1464. }
  1465. } else {
  1466. return Result::error("此网站暂无此栏目", 0);
  1467. }
  1468. return Result::success($result);
  1469. }
  1470. /**
  1471. *获取新闻列表
  1472. * @param array $data
  1473. * @return array
  1474. */
  1475. public function getWebsiteArticleList(array $data): array
  1476. {
  1477. // return Result::success($data);
  1478. $where[] = ['status', '=', 1];
  1479. $website_id = $data['website_id'];
  1480. $website = Website::where('id', $data['website_id'])->first();
  1481. if (empty($website)) {
  1482. return Result::error("网站不存在", 0);
  1483. }
  1484. // $website_column = $website['column'];
  1485. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1486. $website_column = json_decode($website['website_column_arr_id'], true);
  1487. }
  1488. $categorys = $this->processArticlePro($website_id);
  1489. $cat_1st_arr = $categorys['cat_1st_arr'];
  1490. $catiall = $categorys['catiall'];
  1491. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1492. // return Result::success($diff_pid_categoryIds);
  1493. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1494. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1495. }
  1496. if (isset($data['catid']) && !empty($data['catid'])) {
  1497. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  1498. if (empty($category)) {
  1499. return Result::error("此网站暂无此栏目", 0);
  1500. }
  1501. array_push($where, ['catid', '=', $data['catid']]);
  1502. }
  1503. // return Result::success($where);
  1504. $query = Article::where($where)
  1505. ->leftJoinSub(function ($query) use ($website_id) {
  1506. $query->from('article_ignore')
  1507. ->where('website_id', $website_id);
  1508. }, 'article_ignore', function ($join) {
  1509. $join->on('article_ignore.article_id', '=', 'article.id');
  1510. })
  1511. ->where(function ($query) {
  1512. $query->whereNull('article_ignore.article_id')
  1513. ->orWhere(function ($subQuery) {
  1514. $subQuery->whereNotNull('article_ignore.article_id')
  1515. ->where('article_ignore.is_ignore', 0)
  1516. ->where(function ($subSubQuery) {
  1517. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1518. ->orWhereNull('article_ignore.c_show_time');
  1519. });
  1520. });
  1521. })
  1522. ->select(
  1523. 'article.id',
  1524. 'article.title',
  1525. 'article.imgurl',
  1526. 'article.author',
  1527. 'article.updated_at',
  1528. 'article.introduce',
  1529. 'article.islink',
  1530. 'article.linkurl',
  1531. 'article.copyfrom',
  1532. 'article.cat_arr_id',
  1533. 'article.catid'
  1534. );
  1535. $count = $query->count();
  1536. $rep = $query->orderBy("updated_at", "desc")
  1537. ->offset(($data['page'] - 1) * $data['pageSize'])
  1538. ->limit($data['pageSize'])
  1539. ->get()->all();
  1540. $categorys = $this->processArticlePro($website_id);
  1541. $cat_1st_arr = $categorys['cat_1st_arr'];
  1542. $catiall = $categorys['catiall'];
  1543. // $web['website_id'] = $data['website_id'];
  1544. foreach ($rep as $k => $v) {
  1545. $rep[$k]->category_name = $catiall[$v->catid]['alias'];
  1546. $rep[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1547. }
  1548. // $rep = $this->processArticles($rep,$web);
  1549. $data = [
  1550. 'rows' => $rep,
  1551. 'count' => $count,
  1552. ];
  1553. if (empty($rep)) {
  1554. return Result::error("没有信息数据");
  1555. }
  1556. return Result::success($data);
  1557. }
  1558. /**
  1559. * 前端-获取新闻详情
  1560. * @param array $data
  1561. * @return array
  1562. */
  1563. public function selectWebsiteArticleInfo(array $data): array
  1564. {
  1565. $where = [
  1566. 'article.id' => $data['id'],
  1567. 'article.status' => 1,
  1568. ];
  1569. $result = Article::where($where)
  1570. ->leftJoin("article_data", "article.id", "article_data.article_id")
  1571. ->leftJoin("article_extend", "article_extend.article_id", "article.id")
  1572. // ->where(function ($query) use ($data) {
  1573. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1574. // ->orWhereNull("ignore_ids");
  1575. // })
  1576. ->leftJoinSub(function ($query) use ($data) {
  1577. $query->from('article_ignore')
  1578. ->where('website_id', $data['website_id']);
  1579. }, 'article_ignore', function ($join) {
  1580. $join->on('article_ignore.article_id', '=', 'article.id');
  1581. })
  1582. ->where(function ($query) {
  1583. $query->whereNull('article_ignore.article_id')
  1584. ->orWhere(function ($subQuery) {
  1585. $subQuery->whereNotNull('article_ignore.article_id')
  1586. ->where('article_ignore.is_ignore', 0)
  1587. ->where(function ($subSubQuery) {
  1588. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1589. ->orWhereNull('article_ignore.c_show_time');
  1590. });
  1591. });
  1592. })
  1593. ->select(
  1594. 'article.*',
  1595. 'article_data.content',
  1596. 'article_data.article_id',
  1597. 'article_extend.website_url',
  1598. 'article_extend.email',
  1599. 'article_extend.contacts',
  1600. 'article_extend.contacts_mobile',
  1601. 'article_extend.contacts_address',
  1602. 'article_extend.zip_code',
  1603. 'article_extend.enterprise_name'
  1604. )
  1605. ->first();
  1606. if (empty($result)) {
  1607. return Result::error("暂无此新闻!", 0);
  1608. }
  1609. if (!empty($result['publiced_at'])) {
  1610. $result['updated_at'] = $result['publiced_at'];
  1611. }
  1612. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  1613. ->select('website_category.*', 'website.website_name', 'website.suffix')
  1614. ->where('website_category.website_id', $data['website_id'])
  1615. ->where(['website_category.category_id' => $result['catid']])
  1616. ->first();
  1617. if (empty($category)) {
  1618. return Result::error("查询失败", 0);
  1619. }
  1620. //手动推荐文章
  1621. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  1622. if (empty($commend_ids)) {
  1623. $commendArticle = [];
  1624. } else {
  1625. //去除不存在的文章ID
  1626. $commendArticle = Article::whereIn('article.id', $commend_ids)
  1627. ->leftjoin('website_category', 'website_category.category_id', '=', 'article.catid')
  1628. ->leftJoinSub(function ($query) use ($data) {
  1629. $query->from('article_ignore')
  1630. ->where('website_id', $data['website_id']);
  1631. }, 'article_ignore', function ($join) {
  1632. $join->on('article_ignore.article_id', '=', 'article.id');
  1633. })
  1634. ->where(function ($query) {
  1635. $query->whereNull('article_ignore.article_id')
  1636. ->orWhere(function ($subQuery) {
  1637. $subQuery->whereNotNull('article_ignore.article_id')
  1638. ->where('article_ignore.is_ignore', 0)
  1639. ->where(function ($subSubQuery) {
  1640. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1641. ->orWhereNull('article_ignore.c_show_time');
  1642. });
  1643. });
  1644. })
  1645. ->where('article.status', 1)
  1646. ->where('website_category.website_id', $data['website_id'])
  1647. ->select('article.id', 'article.cat_arr_id', 'article.title', 'article.catid', 'article.imgurl', 'article.hits', 'article.created_at', 'website_category.alias', 'website_category.alias_pinyin', 'website_category.website_id')
  1648. ->orderByRaw("FIELD(article.id, " . implode(',', $commend_ids) . ")")
  1649. // ->orderBy('article.updated_at', 'desc')
  1650. ->limit(5)
  1651. ->get();
  1652. //循环数组,取出cat_arr_id中的不重复值,再从website_category取出alias_pinyin,再将cat_arr_id的json转成路径/隔开
  1653. foreach ($commendArticle as $k => $v) {
  1654. $cat_arr_id = json_decode($v->cat_arr_id, true);
  1655. if (!empty($cat_arr_id) && is_array($cat_arr_id)) {
  1656. $cat_arr_id = array_unique($cat_arr_id);
  1657. // 从website_category取出alias_pinyin
  1658. $cat_arr = WebsiteCategory::where('website_id', $data['website_id'])
  1659. ->whereIn('category_id', $cat_arr_id)
  1660. ->pluck('alias_pinyin', 'category_id')
  1661. ->toArray();
  1662. // 将cat_arr_id的json转成路径/隔开
  1663. $path_parts = [];
  1664. foreach ($cat_arr_id as $cat_id) {
  1665. if (isset($cat_arr[$cat_id])) {
  1666. $path_parts[] = $cat_arr[$cat_id];
  1667. }
  1668. }
  1669. $v->alias_pinyin = implode('/', $path_parts);
  1670. } else {
  1671. $v->alias_pinyin = '';
  1672. }
  1673. }
  1674. }
  1675. $result['category_id'] = $category['category_id'];
  1676. $result['cat_name'] = $category['alias'];
  1677. $result['website_name'] = $category['website_name'] ?? "";
  1678. $result['suffix'] = $category['suffix'] ?? "";
  1679. $result['commendArticle'] = $commendArticle;
  1680. $result['commend_ids'] = $commend_ids;
  1681. return Result::success($result);
  1682. }
  1683. /**
  1684. * 前端-获取网站调查问卷
  1685. * @param array $data
  1686. * @return array
  1687. */
  1688. public function getWebsiteSurvey(array $data): array
  1689. {
  1690. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1691. $website = Website::where('id', $data['website_id'])->first();
  1692. if (empty($website)) {
  1693. return Result::error("暂无此网站", 0);
  1694. }
  1695. }
  1696. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1697. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1698. if (empty($article)) {
  1699. return Result::error("暂无此文章", 0);
  1700. }
  1701. // return Result::error($data,0);
  1702. $where['art_id'] = $data['art_id'];
  1703. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1704. } else {
  1705. $survey = Article::where(function ($query) {
  1706. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1707. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1708. })
  1709. ->where('status', 1)
  1710. ->where('is_survey', 1)
  1711. ->select('survey_id')
  1712. ->orderBy('updated_at', 'desc')
  1713. ->first();
  1714. if (empty($survey)) {
  1715. return Result::error("暂无调查问卷", 0);
  1716. }
  1717. $where['sur_id'] = $survey['survey_id'];
  1718. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1719. }
  1720. // return Result::success($where);
  1721. $result = ArticleSurvey::where($where)
  1722. ->where(function ($query) {
  1723. $query->where('is_other', 0)
  1724. ->orWhere(function ($subQuery) {
  1725. $subQuery->where('is_other', 1)
  1726. ->where('other_id', 0);
  1727. });
  1728. })
  1729. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1730. ->select('article_survey.*', 'article.survey_type')
  1731. ->get()->all();
  1732. if (empty($result)) {
  1733. return Result::error("此文章暂无调查问卷", 0);
  1734. }
  1735. return Result::success($result);
  1736. }
  1737. /**
  1738. * 前端-添加网站调查问卷选项
  1739. * @param array $data
  1740. * @return array
  1741. */
  1742. public function addWebsiteSurveyOption(array $data): array
  1743. {
  1744. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1745. $website = Website::where('id', $data['website_id'])->first();
  1746. if (empty($website)) {
  1747. return Result::error("暂无此网站", 0);
  1748. }
  1749. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1750. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1751. if (empty($survey)) {
  1752. return Result::error("此调查问卷不可添加选项", 0);
  1753. }
  1754. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1755. $choice = [
  1756. 'art_id' => $survey['art_id'],
  1757. 'website_id' => $data['website_id'],
  1758. 'survey_name' => $survey['survey_name'],
  1759. 'choice_name' => $data['choice_name'],
  1760. 'sur_id' => $survey['sur_id'],
  1761. 'is_other' => 1,
  1762. 'other_id' => $survey['id'],
  1763. ];
  1764. $result = ArticleSurvey::insertGetId($choice);
  1765. if (empty($result)) {
  1766. return Result::error("添加失败", 0);
  1767. }
  1768. return Result::success($result);
  1769. }
  1770. }
  1771. return Result::error("添加失败", 0);
  1772. }
  1773. return Result::error("添加失败", 0);
  1774. }
  1775. /**
  1776. * 前端-调查问卷投票
  1777. * @param array $data
  1778. * @return array
  1779. */
  1780. public function addWebsiteSurveyVote(array $data): array
  1781. {
  1782. // return Result::success($data);
  1783. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1784. $website = Website::where('id', $data['website_id'])->first();
  1785. if (empty($website)) {
  1786. return Result::error("暂无此网站", 0);
  1787. }
  1788. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1789. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1790. // return Result::success($survey);
  1791. if (empty($is_survey)) {
  1792. return Result::error("此调查问卷不存在", 0);
  1793. }
  1794. // return Result::success($survey);
  1795. // 调查问卷类型
  1796. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1797. //多选 若是json型则转化成数组类型
  1798. if (strpos($data['choice_id'], '[') === 0) {
  1799. $data['choice_id'] = json_decode($data['choice_id'], true);
  1800. } else {
  1801. // 单选 也转换成数组
  1802. $data['choice_id'] = [$data['choice_id']];
  1803. }
  1804. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1805. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1806. // ->where('website_id',$data['website_id'])
  1807. ->where('is_other', 1)
  1808. ->where('other_id', 0)
  1809. ->first();
  1810. if (!empty($other)) {
  1811. return Result::error("请选择已有的选项!", 0);
  1812. }
  1813. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1814. // ->where('website_id',$data['website_id'])
  1815. ->where('is_other', 1)
  1816. ->where('other_id', '!=', 0)
  1817. ->first();
  1818. // return Result::success($choice['other']);
  1819. $choice_id = $data['choice_id'];
  1820. if (!empty($choice['other'])) {
  1821. // array_push($data['choice_id'],$choice['other']['other_id']);
  1822. if (!empty($choice_id)) {
  1823. $key = array_search($choice['other']['id'], $choice_id);
  1824. if ($key !== false) {
  1825. unset($choice_id[$key]);
  1826. $choice_id = array_values($choice_id);
  1827. }
  1828. array_push($choice_id, $choice['other']['other_id']);
  1829. } else {
  1830. $choice_id[0] = $choice['other']['other_id'];
  1831. }
  1832. array_push($data['choice_id'], $choice['other']['other_id']);
  1833. }
  1834. // return Result::success($data);
  1835. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1836. // ->where('website_id',$data['website_id'])
  1837. ->increment('results', 1);
  1838. if (empty($choice)) {
  1839. return Result::error("请选择已有的选项!", 0);
  1840. }
  1841. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1842. // ->where('website_id',$data['website_id'])
  1843. ->where('other_id', 0)
  1844. ->get();
  1845. $survey['choice'] = $choice_id;
  1846. return Result::success($survey);
  1847. }
  1848. return Result::error("参数必填!");
  1849. }
  1850. return Result::error("此调查问卷不存在", 0);
  1851. }
  1852. return Result::error("参数必填!");
  1853. }
  1854. /**
  1855. * 后端-获取网站调查问卷列表
  1856. * @param array $data
  1857. * @return array
  1858. */
  1859. public function getSurveyList(array $data): array
  1860. {
  1861. $where = [];
  1862. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1863. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1864. }
  1865. $survey_type = isset($data['survey_type']) && $data['survey_type'] !== '' ? $data['survey_type'] : null;
  1866. if (!empty($where)) {
  1867. // 修复:先关联 article 再按 survey_type 过滤,避免查不到数据
  1868. $query = ArticleSurvey::select(
  1869. 'art_id as id',
  1870. Db::raw('MAX(id) as surid'),
  1871. Db::raw('MAX(survey_name) as survey_name'),
  1872. Db::raw('MAX(sur_id) as survey_id')
  1873. )
  1874. ->groupBy('art_id')
  1875. ->where($where)
  1876. ->when(!is_null($survey_type), function ($q) use ($survey_type) {
  1877. $q->whereIn('art_id', function ($sub) use ($survey_type) {
  1878. $sub->select('id')
  1879. ->from('article')
  1880. ->where('survey_type', $survey_type);
  1881. });
  1882. })
  1883. ->with(['article' => function ($query) {
  1884. $query->select('id', 'survey_type','created_at','updated_at','created_at');
  1885. }]);
  1886. ;
  1887. }else{
  1888. $query = ArticleSurvey::select(
  1889. 'art_id as id',
  1890. Db::raw('MAX(id) as surid'),
  1891. Db::raw('MAX(survey_name) as survey_name'),
  1892. Db::raw('MAX(sur_id) as survey_id'),
  1893. )
  1894. ->groupBy('art_id')
  1895. ->when(!is_null($survey_type), function ($q) use ($survey_type) {
  1896. $q->whereIn('art_id', function ($sub) use ($survey_type) {
  1897. $sub->select('id')
  1898. ->from('article')
  1899. ->where('survey_type', $survey_type);
  1900. });
  1901. })
  1902. ->with(['article' => function ($query) {
  1903. $query->select('id', 'survey_type','created_at','updated_at','created_at');
  1904. }]);
  1905. }
  1906. $count = $query->get()->count();
  1907. // 简单写法:直接统计分组后的 art_id 数量
  1908. $survey = $query->orderBy('id', 'desc')
  1909. ->limit($data['pageSize'])
  1910. ->offset(($data['page'] - 1) * $data['pageSize'])
  1911. ->get();
  1912. if (empty($survey->toArray())) {
  1913. return Result::error("暂无调查问卷!", 0);
  1914. }
  1915. $survey = array_map(function ($item) {
  1916. if (isset($item['article'])) {
  1917. $item['survey_type'] = $item['article']['survey_type'];
  1918. $item['created_at'] = $item['article']['created_at'];
  1919. $item['updated_at'] = $item['article']['updated_at'];
  1920. } else {
  1921. // 处理article为null的情况,设置默认值
  1922. $item['survey_type'] = null;
  1923. $item['created_at'] = null;
  1924. $item['updated_at'] = null;
  1925. }
  1926. unset($item['article']);
  1927. return $item;
  1928. }, $survey->toArray());
  1929. $result = [
  1930. 'rows' => $survey,
  1931. 'count' => $count,
  1932. ];
  1933. return Result::success($result);
  1934. }
  1935. /**
  1936. * 后端-获取网站调查问卷详情
  1937. * @param array $data
  1938. * @return array
  1939. */
  1940. public function getSurveyInfo(array $data): array
  1941. {
  1942. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1943. $where = ['sur_id' => $data['sur_id']];
  1944. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1945. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1946. ->select('article_survey.*', 'article.survey_type')
  1947. ->get()->all();
  1948. if (empty($choose)) {
  1949. return Result::error("此调查问卷不存在", 0);
  1950. }
  1951. $resultsArray = array_column($choose, 'results');
  1952. $total = array_sum($resultsArray);
  1953. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1954. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1955. // $total = 0;
  1956. if (!empty($other)) {
  1957. $total = $total + $other['results'];
  1958. $other['choice_name'] = '(其他)';
  1959. if (!empty($others)) {
  1960. $other['hasChildren'] = true;
  1961. // array_push($other,['hasChildren','=',true]);
  1962. $other['children'] = $others;
  1963. $other_choices = [$other->toArray()];
  1964. $mer_choice = array_merge($choose, $other_choices);
  1965. $value_choice = array_values($mer_choice);
  1966. } else {
  1967. // return Result::error('1111');
  1968. $other_choices = [$other->toArray()];
  1969. $other_choices = array_merge($choose, $other_choices);
  1970. $value_choice = array_values($other_choices);
  1971. // return Result::success($result);
  1972. }
  1973. } else {
  1974. $value_choice = $choose;
  1975. }
  1976. $result = [
  1977. 'choose' => $value_choice,
  1978. 'total' => $total,
  1979. ];
  1980. }
  1981. return Result::success($result);
  1982. }
  1983. /**
  1984. * 前端-搜索新闻列表
  1985. * @param array $data
  1986. * @return array
  1987. */
  1988. public function selectWebsiteArticle(array $data): array
  1989. {
  1990. $website = Website::where('id', $data['website_id'])->first();
  1991. if (empty($website)) {
  1992. return Result::error("网站不存在", 0);
  1993. }
  1994. // $website_column = $website['column'];
  1995. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1996. $website_column = json_decode($website['website_column_arr_id'], true);
  1997. }
  1998. $website_id = $data['website_id'];
  1999. $categorys = $this->processArticlePro($website_id);
  2000. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  2001. // return Result::success($diff_pid_categoryIds);
  2002. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2003. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2004. }
  2005. // return Result::success(reset($diff_pid_categoryIds) == 0);
  2006. // $cat_1st_arr = $categorys['cat_1st_arr'];
  2007. $catiall = $categorys['catiall'];
  2008. $categoryIds = $categorys['categoryIds'];
  2009. // return Result::success($categoryIds);
  2010. $query = Article::where('status', 1)
  2011. ->whereIn('catid', $categoryIds)
  2012. ->leftJoinSub(function ($query) use ($website_id) {
  2013. $query->from('article_ignore')
  2014. ->where('website_id', $website_id);
  2015. }, 'article_ignore', function ($join) {
  2016. $join->on('article_ignore.article_id', '=', 'article.id');
  2017. })
  2018. ->where(function ($query) {
  2019. $query->whereNull('article_ignore.article_id')
  2020. ->orWhere(function ($subQuery) {
  2021. $subQuery->whereNotNull('article_ignore.article_id')
  2022. ->where('article_ignore.is_ignore', 0)
  2023. ->where(function ($subSubQuery) {
  2024. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2025. ->orWhereNull('article_ignore.c_show_time');
  2026. });
  2027. });
  2028. });
  2029. // ->get()->all();
  2030. // return Result::success($query);
  2031. if (isset($data['cityid']) && !empty($data['cityid'])) {
  2032. $query->whereRaw("JSON_CONTAINS(article.city_arr_id, '" . intval($data['cityid']) . "')");
  2033. }
  2034. if (isset($data['department_id']) && !empty($data['department_id'])) {
  2035. $query->whereRaw("JSON_CONTAINS(article.department_arr_id, '" . intval($data['department_id']) . "')");
  2036. }
  2037. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2038. $query->where('article.title', 'like', '%' . $data['keyword'] . '%');
  2039. }
  2040. // 计算总数
  2041. $count = $query->count();
  2042. // return Result::success($count);
  2043. // 分页查询
  2044. $articles = $query
  2045. ->select(
  2046. 'article.id',
  2047. 'article.title',
  2048. 'article.imgurl',
  2049. 'article.author',
  2050. 'article.updated_at',
  2051. 'article.introduce',
  2052. 'article.islink',
  2053. 'article.linkurl',
  2054. 'article.copyfrom',
  2055. 'article.cat_arr_id',
  2056. 'article.catid',
  2057. 'article.department_arr_id',
  2058. 'article.city_arr_id',
  2059. // 'article_ignore.c_show_time',
  2060. // 'article_ignore.is_ignore'
  2061. )
  2062. ->orderBy("updated_at", "desc")
  2063. ->offset(($data['page'] - 1) * $data['pageSize'])
  2064. ->limit($data['pageSize'])
  2065. ->get();
  2066. // return Result::success($articles);
  2067. foreach ($articles as $k => $v) {
  2068. $articles[$k]->category_name = $catiall[$v->catid]['alias'];
  2069. $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2070. }
  2071. if (empty($articles)) {
  2072. return Result::error("没有符合条件的资讯数据");
  2073. }
  2074. $result = [
  2075. 'rows' => $articles,
  2076. 'count' => $count,
  2077. ];
  2078. return Result::success($result);
  2079. }
  2080. /**
  2081. * 模块新闻加强版
  2082. * @param array $data
  2083. * @return array
  2084. */
  2085. public function getWebsiteCatidArticle(array $data): array
  2086. {
  2087. $where = [
  2088. 'website_category.category_id' => $data['catid'],
  2089. 'website_category.website_id' => $data['website_id'],
  2090. ];
  2091. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  2092. $child_catnum = $data['child_catnum'] ?? 1;
  2093. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  2094. $childCategoryIds = array_column($category['child'], 'category_id');
  2095. if (empty($childCategoryIds)) {
  2096. return Result::error("暂无子栏目", 0);
  2097. }
  2098. $imgArticles = [];
  2099. $textArticles = [];
  2100. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  2101. // 初始化子分类图片新闻和文字新闻数组
  2102. // 查询所有子级栏目的图文新闻
  2103. $imgArticles = Article::where('catid', $childCategoryIds[0])
  2104. ->where(function ($query) use ($data) {
  2105. $query->where(function ($subQuery) use ($data) {
  2106. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  2107. })->orWhereNull("ignore_ids");
  2108. })
  2109. ->where('status', 1)
  2110. ->where('imgurl', '!=', '')
  2111. ->select('*')
  2112. ->orderBy('updated_at', 'desc')
  2113. ->limit($data['child_imgnum'])
  2114. ->get();
  2115. }
  2116. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  2117. // 查询所有子级栏目的文字新闻
  2118. $textArticles = Article::where('catid', $childCategoryIds[0])
  2119. ->where('status', 1)
  2120. ->where(function ($query) use ($data) {
  2121. $query->where(function ($subQuery) use ($data) {
  2122. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  2123. })->orWhereNull("ignore_ids");
  2124. })
  2125. ->select('*')
  2126. ->orderBy('updated_at', 'desc')
  2127. ->limit($data['child_textnum'])
  2128. ->get();
  2129. }
  2130. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  2131. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  2132. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  2133. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  2134. return $child;
  2135. }, $category['child']);
  2136. }
  2137. // }
  2138. if (isset($data['img_num']) && !empty($data['img_num'])) {
  2139. $category['img'] = WebsiteCategory::where($where)
  2140. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  2141. ->where('article.status', 1)
  2142. ->where('article.imgurl', '!=', '')
  2143. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  2144. ->orderBy('article.updated_at', 'desc')
  2145. ->limit($data['img_num'])
  2146. ->get();
  2147. }
  2148. if (isset($data['text_num']) && !empty($data['text_num'])) {
  2149. $category['text'] = WebsiteCategory::where($where)
  2150. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  2151. ->where('article.status', 1)
  2152. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  2153. ->orderBy('article.updated_at', 'desc')
  2154. ->limit($data['text_num'])
  2155. ->get();
  2156. }
  2157. // $category = $category->get();
  2158. if (empty($category)) {
  2159. return Result::error("查询失败", 0);
  2160. }
  2161. return Result::success($category);
  2162. }
  2163. /**
  2164. * 模块新闻加强plus版
  2165. * @param array $data
  2166. * @return array
  2167. */
  2168. public function getWebsiteAllArticle(array $data): array
  2169. {
  2170. // return Result::success($data);
  2171. $time1 = microtime(true);
  2172. $wetbsite_id = $data['website_id'] ?? 2;
  2173. $data = json_decode($data['id'], true);
  2174. $website = Website::where('id', $wetbsite_id)->first();
  2175. if (empty($website)) {
  2176. return Result::error("网站不存在", 0);
  2177. }
  2178. // return Result::success($website);
  2179. $website_column = $website['website_column_arr_id'] ?? '[]';
  2180. $website_column = json_decode($website_column, true);
  2181. $categorys = $this->processArticlePro($wetbsite_id);
  2182. $cat_1st_arr = $categorys['cat_1st_arr'];
  2183. $catiall = $categorys['catiall'];
  2184. // return Result::success($catiall);
  2185. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  2186. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2187. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2188. }
  2189. $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
  2190. // return Result::success($categorys);
  2191. $parent_category = array_column($data, 'parent');
  2192. $parent_cat = [];
  2193. $child_category = array_column($data, 'child');
  2194. if (!empty($parent_category)) {
  2195. foreach ($parent_category as $key => $value) {
  2196. $arr = array_map('intval', explode(',', $value));
  2197. $parent_cat[$key] = $arr[0] ?? 0;
  2198. $parent_category = $arr[0] ?? 0;
  2199. $article_imgnum = $arr[1] ?? 0;
  2200. $article_textnum = $arr[2] ?? 0;
  2201. if ($parent_category != 0) {
  2202. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2203. // return Result::success($category_arr);
  2204. if ($article_imgnum != 0) {
  2205. $img_article = Article::whereIn('catid', $category_arr)
  2206. ->where('status', 1)
  2207. ->where('imgurl', '!=', '')
  2208. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2209. $query->from('article_ignore')
  2210. ->where('website_id', $wetbsite_id);
  2211. }, 'article_ignore', function ($join) {
  2212. $join->on('article_ignore.article_id', '=', 'article.id');
  2213. })
  2214. ->where(function ($query) {
  2215. $query->whereNull('article_ignore.article_id')
  2216. ->orWhere(function ($subQuery) {
  2217. $subQuery->whereNotNull('article_ignore.article_id')
  2218. ->where('article_ignore.is_ignore', 0)
  2219. ->where(function ($subSubQuery) {
  2220. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2221. ->orWhereNull('article_ignore.c_show_time');
  2222. });
  2223. });
  2224. })
  2225. ->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')
  2226. ->orderBy('updated_at', 'desc')
  2227. ->limit($article_imgnum)
  2228. ->get()->all();
  2229. foreach ($img_article as $k => $v) {
  2230. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2231. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2232. }
  2233. } else {
  2234. $img_article = [];
  2235. }
  2236. if ($article_textnum != 0) {
  2237. $text_article = Article::whereIn('catid', $category_arr)
  2238. ->where('status', 1)
  2239. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2240. $query->from('article_ignore')
  2241. ->where('website_id', $wetbsite_id);
  2242. }, 'article_ignore', function ($join) {
  2243. $join->on('article_ignore.article_id', '=', 'article.id');
  2244. })
  2245. ->where(function ($query) {
  2246. $query->whereNull('article_ignore.article_id')
  2247. ->orWhere(function ($subQuery) {
  2248. $subQuery->whereNotNull('article_ignore.article_id')
  2249. ->where('article_ignore.is_ignore', 0)
  2250. ->where(function ($subSubQuery) {
  2251. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2252. ->orWhereNull('article_ignore.c_show_time');
  2253. });
  2254. });
  2255. })
  2256. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2257. ->orderBy('updated_at', 'desc')
  2258. ->limit($article_textnum)
  2259. ->get()->all();
  2260. foreach ($text_article as $k => $v) {
  2261. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2262. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2263. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2264. }
  2265. } else {
  2266. $text_article = [];
  2267. }
  2268. $catiall[$parent_category]['imgnum'] = $img_article;
  2269. $catiall[$parent_category]['textnum'] = $text_article;
  2270. $parent[$key] = $catiall[$parent_category];
  2271. } else {
  2272. $parent[$key] = '';
  2273. }
  2274. }
  2275. }
  2276. if (!empty($child_category)) {
  2277. foreach ($child_category as $key => $value) {
  2278. $arr = array_map('intval', explode(',', $value));
  2279. $parent_category = $parent_cat[$key];
  2280. $child_category = $arr[0] ?? 0;
  2281. $article_imgnum = $arr[1] ?? 0;
  2282. $article_textnum = $arr[2] ?? 0;
  2283. if ($child_category != 0) {
  2284. $all_childcat = $cat_1st_arr[$parent_category];
  2285. $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
  2286. // 从 $websiteInfoIndexed 中获取对应的数据
  2287. $info = $websiteInfoIndexed[$v];
  2288. // 返回一个包含所需信息的数组
  2289. return [
  2290. 'alias' => $info->alias,
  2291. 'category_id' => $info->category_id,
  2292. 'aLIas_pinyin' => $info->aLIas_pinyin,
  2293. 'pid' => $info->pid,
  2294. 'type' => $info->type,
  2295. 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
  2296. 'pinyin' => $info->pinyin,
  2297. ];
  2298. }, $all_childcat);
  2299. if ($article_imgnum != 0) {
  2300. $img_article = Article::where('catid', $child_category)
  2301. ->where('status', 1)
  2302. ->where('imgurl', '!=', '')
  2303. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2304. $query->from('article_ignore')
  2305. ->where('website_id', $wetbsite_id);
  2306. }, 'article_ignore', function ($join) {
  2307. $join->on('article_ignore.article_id', '=', 'article.id');
  2308. })
  2309. ->where(function ($query) {
  2310. $query->whereNull('article_ignore.article_id')
  2311. ->orWhere(function ($subQuery) {
  2312. $subQuery->whereNotNull('article_ignore.article_id')
  2313. ->where('article_ignore.is_ignore', 0)
  2314. ->where(function ($subSubQuery) {
  2315. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2316. ->orWhereNull('article_ignore.c_show_time');
  2317. });
  2318. });
  2319. })
  2320. ->select('id', 'title', 'imgurl', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2321. ->orderBy('updated_at', 'desc')
  2322. ->limit($article_imgnum)
  2323. ->get()->all();
  2324. foreach ($img_article as $k => $v) {
  2325. // var_dump($v);
  2326. // var_dump($k);
  2327. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2328. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2329. }
  2330. } else {
  2331. $img_article = [];
  2332. }
  2333. if ($article_textnum != 0) {
  2334. $text_article = Article::where('catid', $child_category)
  2335. ->where('status', 1)
  2336. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2337. $query->from('article_ignore')
  2338. ->where('website_id', $wetbsite_id);
  2339. }, 'article_ignore', function ($join) {
  2340. $join->on('article_ignore.article_id', '=', 'article.id');
  2341. })
  2342. ->where(function ($query) {
  2343. $query->whereNull('article_ignore.article_id')
  2344. ->orWhere(function ($subQuery) {
  2345. $subQuery->whereNotNull('article_ignore.article_id')
  2346. ->where('article_ignore.is_ignore', 0)
  2347. ->where(function ($subSubQuery) {
  2348. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2349. ->orWhereNull('article_ignore.c_show_time');
  2350. });
  2351. });
  2352. })
  2353. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2354. ->orderBy('updated_at', 'desc')
  2355. ->limit($article_textnum)
  2356. ->get()->all();
  2357. foreach ($text_article as $k => $v) {
  2358. // var_dump($v);
  2359. // var_dump($k);
  2360. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2361. // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2362. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2363. }
  2364. } else {
  2365. $text_article = [];
  2366. }
  2367. $catiall[$child_category]['all_childcat'] = $processedChildCat;
  2368. $catiall[$child_category]['imgnum'] = $img_article;
  2369. $catiall[$child_category]['textnum'] = $text_article;
  2370. $child[$key] = $catiall[$child_category];
  2371. // var_dump($pids);
  2372. } else {
  2373. $child[$key] = '';
  2374. }
  2375. }
  2376. }
  2377. foreach ($parent as $key => $value) {
  2378. $result[$key] = $value;
  2379. if (!empty($child[$key])) {
  2380. // var_dump($child[$key]);
  2381. $result[$key]['child'] = $child[$key];
  2382. // $value[$key]['child'] = $child[$key];
  2383. } else {
  2384. $result[$key]['child'] = [
  2385. "alias" => null,
  2386. "category_id" => null,
  2387. "type" => null,
  2388. "pinyin" => null,
  2389. "all_childcat" => [],
  2390. "imgnum" => [],
  2391. "textnum" => []
  2392. ];
  2393. }
  2394. }
  2395. return Result::success($result);
  2396. }
  2397. /**
  2398. * 辅助方法:获取文章列表
  2399. */
  2400. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  2401. {
  2402. sleep(1);
  2403. $query = Article::where('article.status', 1)
  2404. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  2405. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  2406. ->where(function ($query) use ($website) {
  2407. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  2408. })
  2409. ->leftJoin('website_category', function ($join) use ($website) {
  2410. $join->on('article.catid', '=', 'website_category.category_id')
  2411. ->where('website_category.website_id', '=', $website['website_id']);
  2412. })
  2413. ->select(
  2414. 'article.id',
  2415. 'article.title',
  2416. 'article.imgurl',
  2417. 'article.author',
  2418. 'article.updated_at',
  2419. 'article.introduce',
  2420. 'article.islink',
  2421. 'article.linkurl',
  2422. 'article.copyfrom',
  2423. 'article.cat_arr_id',
  2424. 'article.catid',
  2425. 'website_category.alias as category_name'
  2426. )
  2427. ->orderBy('updated_at', 'desc')
  2428. ->limit($limit);
  2429. // 如果是图片文章,添加图片URL条件
  2430. if ($isImageArticle) {
  2431. $query->where('imgurl', '!=', '');
  2432. } else {
  2433. // 文字文章不需要imgurl字段
  2434. $query->addSelect('article.introduce');
  2435. }
  2436. $articles = $query->get();
  2437. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  2438. }
  2439. /**
  2440. * 乡村网-获取特殊新闻模块
  2441. * @param array $data
  2442. * @return array
  2443. */
  2444. public function getWebsiteArticles(array $data): array
  2445. {
  2446. $website_id = $data['website_id'];
  2447. $website = Website::where('id', $website_id)->first();
  2448. if (empty($website)) {
  2449. return Result::error("网站不存在", 0);
  2450. }
  2451. // return Result::success($website);
  2452. $website_column = $website['website_column_arr_id'] ?? '[]';
  2453. $website_column = json_decode($website_column, true);
  2454. $catids = json_decode($data['id'], true);
  2455. $parent_category = array_column($catids, 'parent');
  2456. if (!empty($parent_category) && is_array($parent_category)) {
  2457. $categorys = $this->processArticlePro($website_id);
  2458. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  2459. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2460. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2461. }
  2462. $catiall = $categorys['catiall'];
  2463. $cat_1st_arr = $categorys['cat_1st_arr'];
  2464. // return Result::success($categorys);
  2465. foreach ($parent_category as $key => $value) {
  2466. $arr = array_map('intval', explode(',', $value));
  2467. $parent_category = $arr[0] ?? 0;
  2468. $article_imgnum = $arr[1] ?? 0;
  2469. $article_textnum = $arr[2] ?? 0;
  2470. if ($parent_category != 0) {
  2471. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2472. // return Result::success($category_arr);
  2473. if ($article_imgnum != 0) {
  2474. $img_article = Article::whereIn('article.catid', $category_arr)
  2475. ->where('article.status', 1)
  2476. ->where('article.imgurl', '!=', '')
  2477. ->leftJoinSub(function ($query) use ($website_id) {
  2478. $query->from('article_ignore')
  2479. ->where('website_id', $website_id);
  2480. }, 'article_ignore', function ($join) {
  2481. $join->on('article_ignore.article_id', '=', 'article.id');
  2482. })
  2483. ->where(function ($query) {
  2484. $query->whereNull('article_ignore.article_id')
  2485. ->orWhere(function ($subQuery) {
  2486. $subQuery->whereNotNull('article_ignore.article_id')
  2487. ->where('article_ignore.is_ignore', 0)
  2488. ->where(function ($subSubQuery) {
  2489. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2490. ->orWhereNull('article_ignore.c_show_time');
  2491. });
  2492. });
  2493. })
  2494. ->select(
  2495. 'article.id',
  2496. 'article.title',
  2497. 'article.imgurl',
  2498. 'article.author',
  2499. 'article.updated_at',
  2500. 'article.introduce',
  2501. 'article.islink',
  2502. 'article.linkurl',
  2503. 'article.copyfrom',
  2504. 'article.cat_arr_id',
  2505. 'article.catid as category_id'
  2506. )
  2507. ->orderBy('updated_at', 'desc')
  2508. ->limit($article_imgnum)
  2509. ->get()->all();
  2510. foreach ($img_article as $k => $v) {
  2511. $img_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2512. // return Result::success($v);
  2513. $img_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2514. }
  2515. } else {
  2516. $img_article = [];
  2517. }
  2518. if ($article_textnum != 0) {
  2519. $text_article = Article::whereIn('article.catid', $category_arr)
  2520. ->where('article.status', 1)
  2521. ->leftJoinSub(function ($query) use ($website_id) {
  2522. $query->from('article_ignore')
  2523. ->where('website_id', $website_id);
  2524. }, 'article_ignore', function ($join) {
  2525. $join->on('article_ignore.article_id', '=', 'article.id');
  2526. })
  2527. ->where(function ($query) {
  2528. $query->whereNull('article_ignore.article_id')
  2529. ->orWhere(function ($subQuery) {
  2530. $subQuery->whereNotNull('article_ignore.article_id')
  2531. ->where('article_ignore.is_ignore', 0)
  2532. ->where(function ($subSubQuery) {
  2533. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2534. ->orWhereNull('article_ignore.c_show_time');
  2535. });
  2536. });
  2537. })
  2538. ->select(
  2539. 'article.id',
  2540. 'article.title',
  2541. 'article.author',
  2542. 'article.updated_at',
  2543. 'article.introduce',
  2544. 'article.islink',
  2545. 'article.linkurl',
  2546. 'article.copyfrom',
  2547. 'article.cat_arr_id',
  2548. 'article.catid as category_id'
  2549. )
  2550. ->orderBy('updated_at', 'desc')
  2551. ->limit($article_textnum)
  2552. ->get()->all();
  2553. foreach ($text_article as $k => $v) {
  2554. $text_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2555. $text_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2556. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2557. }
  2558. } else {
  2559. $text_article = [];
  2560. }
  2561. $catiall[$parent_category]['imgnum'] = $img_article ?? [];
  2562. $catiall[$parent_category]['textnum'] = $text_article ?? [];
  2563. $parent[$key] = $catiall[$parent_category];
  2564. } else {
  2565. $parent[$key] = [];
  2566. }
  2567. }
  2568. }
  2569. return Result::success($parent);
  2570. }
  2571. // 封装处理商品的路由问题
  2572. function processGoods($goods, $data)
  2573. {
  2574. return $goods->map(function ($good) use ($data) {
  2575. $catid = $good->catid ?? 0;
  2576. // $pinyin = '';
  2577. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2578. if (!empty($category->pid) && $category->pid != 0) {
  2579. $level = json_decode($category->category_arr_id, true);
  2580. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  2581. ->whereIn('category_id', $level)
  2582. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2583. ->get(['aLIas_pinyin'])
  2584. ->pluck('aLIas_pinyin')
  2585. ->implode('/');
  2586. } else {
  2587. $pinyin = $category->aLIas_pinyin ?? '';
  2588. }
  2589. if (isset($good->city_id) && !empty($good->city_id)) {
  2590. $city = District::where('id', $good->city_id)->first(['name']);
  2591. $good->city_name = $city->name ?? '';
  2592. }
  2593. // 解析imgurl JSON并取第一条数据
  2594. $imgUrls = json_decode($good->imgurl, true);
  2595. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  2596. $good->pinyin = $pinyin;
  2597. return $good;
  2598. });
  2599. }
  2600. /**
  2601. * 获取商城首页-根据栏目id
  2602. * @param array $data
  2603. * @return array
  2604. * */
  2605. function getWebsiteCatidshop(array $data): array
  2606. {
  2607. $input['catid'] = $data['catid'];
  2608. $input['website_id'] = $data['website_id'];
  2609. $data = json_decode($input['catid'] ?? '', true) ?? [];
  2610. $result = array_map(function ($item) use ($input) {
  2611. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  2612. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  2613. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  2614. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  2615. if (empty($category) || $category->type != 2) {
  2616. return Result::error("暂无此栏目", 0);
  2617. } else {
  2618. $website['website_id'] = $input['website_id'];
  2619. $goods = Good::where('good.status', 2)
  2620. ->where('good.website_id', $website['website_id'])
  2621. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  2622. ->select(
  2623. 'good.id',
  2624. 'good.name',
  2625. 'good.imgurl',
  2626. 'good.description',
  2627. 'good.updated_at',
  2628. 'good.catid',
  2629. 'good.type_id',
  2630. 'good.price',
  2631. 'good.com',
  2632. 'good.level',
  2633. 'good.unit'
  2634. )
  2635. ->orderBy('updated_at', 'desc')
  2636. ->offset($goodStart)
  2637. ->limit($goodNum);
  2638. $all_goods = $goods->get();
  2639. $all_goods = $this->processGoods($all_goods, $website);
  2640. }
  2641. return $all_goods ?? [];
  2642. }
  2643. }, $data);
  2644. return Result::success($result);
  2645. }
  2646. /**
  2647. * 获取商品模块
  2648. * @param array $data
  2649. * @return array
  2650. * */
  2651. public function getWebsiteshop(array $data): array
  2652. {
  2653. $input['id'] = $data['id'];
  2654. $input['website_id'] = $data['website_id'];
  2655. $catid = $data['catid'];
  2656. $data = json_decode($input['id'] ?? '', true) ?? [];
  2657. $result['goods'] = array_map(function ($item) use ($input) {
  2658. // 检查parent元素是否存在且不是undefined
  2659. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  2660. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  2661. $website = $input['website_id'];
  2662. $query = Good::where('good.status', 2)
  2663. ->where('good.website_id', $website);
  2664. switch ($Levelid) {
  2665. case 1:
  2666. case 2:
  2667. case 3:
  2668. $goods = $query->where(function ($q) use ($Levelid) {
  2669. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  2670. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  2671. });
  2672. break;
  2673. case 4:
  2674. $goods = $query;
  2675. break;
  2676. case 5:
  2677. $goods = $query->where('type_id', 1);
  2678. break;
  2679. case 6:
  2680. $goods = $query->where('type_id', 2);
  2681. break;
  2682. default:
  2683. return [];
  2684. }
  2685. $all_goods = $goods
  2686. ->select(
  2687. 'good.id',
  2688. 'good.name',
  2689. 'good.imgurl',
  2690. 'good.description',
  2691. 'good.updated_at',
  2692. 'good.catid',
  2693. 'good.type_id',
  2694. 'good.price',
  2695. 'good.level',
  2696. 'good.website_id'
  2697. )
  2698. ->orderBy('updated_at', 'desc')
  2699. ->offset($goodStart)
  2700. ->limit($goodNum)
  2701. ->get();
  2702. $web['website_id'] = $website;
  2703. $all_goods = $this->processGoods($all_goods, $web);
  2704. }
  2705. return $all_goods;
  2706. }, $data);
  2707. $website = $input['website_id'];
  2708. $result['article'] = Article::where(function ($query) use ($website) {
  2709. $query->where(function ($subQuery) use ($website) {
  2710. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  2711. })->orWhereNull("ignore_ids");
  2712. })
  2713. ->where('catid', $catid)
  2714. ->where('article.status', 1)
  2715. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  2716. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  2717. ->orderBy('article.updated_at', 'desc')
  2718. ->first();
  2719. return Result::success($result);
  2720. }
  2721. /**
  2722. * 获取商品分类
  2723. * @param array $data
  2724. * @return array
  2725. * */
  2726. public function getWebsiteshopCat(array $data): array
  2727. {
  2728. $website = $data['website_id'];
  2729. $category = WebsiteCategory::where('website_id', $website)
  2730. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  2731. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  2732. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  2733. ->orderBy('sort')
  2734. ->get();
  2735. $cat = $category->map(function ($item) use ($website) {
  2736. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  2737. $pid = $item->pid ?? 0;
  2738. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  2739. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  2740. ->where('website_id', $website)
  2741. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  2742. ->get(['aLIas_pinyin'])
  2743. ->pluck('aLIas_pinyin')
  2744. ->implode('/');
  2745. } else {
  2746. $pinyin = $item->aLIas_pinyin ?? '';
  2747. }
  2748. $item->pinyin = $pinyin;
  2749. });
  2750. if (empty($category)) {
  2751. return Result::error("栏目查询失败", 0);
  2752. }
  2753. $cat_tree = Result::buildMenuTree($category);
  2754. $web['website_id'] = $website;
  2755. $goods = Good::where('website_id', $website)
  2756. ->where('status', 2)
  2757. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  2758. ->latest('updated_at')
  2759. ->offset(($data['page'] - 1) * $data['pageSize'])
  2760. ->limit($data['pageSize'])
  2761. ->get();
  2762. if (!empty($goods)) {
  2763. if ($goods->count() > 1 && !empty($goods)) {
  2764. $goods = $this->processGoods($goods, $web);
  2765. }
  2766. } else {
  2767. $goods = [];
  2768. }
  2769. $result = [
  2770. 'category' => $cat_tree,
  2771. 'goods' => $goods,
  2772. ];
  2773. // $resul['goods'] = $goods;
  2774. if (empty($result)) {
  2775. return Result::error("查询失败", 0);
  2776. }
  2777. return Result::success($result);
  2778. }
  2779. /*
  2780. * 获取商品列表
  2781. * @param array $data
  2782. * @return array
  2783. * */
  2784. public function getWebsiteshopList(array $data): array
  2785. {
  2786. // return Result::success($data);
  2787. $where = [
  2788. 'status' => 2,
  2789. 'website_id' => $data['website_id'],
  2790. ];
  2791. // if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  2792. // return Result::error("查询失败", 0);
  2793. // }
  2794. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  2795. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  2796. $data['catid'] = $category->category_id ?? 0;
  2797. }
  2798. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2799. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  2800. }
  2801. if (isset($data['type_id']) && !empty($data['type_id'])) {
  2802. array_push($where, ['type_id', $data['type_id']]);
  2803. }
  2804. $query = Good::where($where)
  2805. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2806. $query->where(function ($q) use ($data) {
  2807. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  2808. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  2809. });
  2810. })
  2811. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2812. $query->where(function ($q) use ($data) {
  2813. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  2814. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  2815. });
  2816. })
  2817. ->select(
  2818. 'good.id',
  2819. 'good.name',
  2820. 'good.imgurl',
  2821. 'good.description',
  2822. 'good.updated_at',
  2823. 'good.com',
  2824. 'good.catid',
  2825. 'good.type_id',
  2826. 'good.website_id',
  2827. 'good.cat_arr_id',
  2828. 'good.created_at',
  2829. 'good.city_id'
  2830. )
  2831. ->latest('updated_at');
  2832. if (isset($data['ismix']) && $data['ismix'] == 1) {
  2833. $result['count'] = $query->clone()->count();
  2834. $result['goods'] = $this->processGoods(
  2835. $query->clone()
  2836. ->offset(($data['page'] - 1) * $data['pageSize'])
  2837. ->limit($data['pageSize'])
  2838. ->get(),
  2839. $data
  2840. );
  2841. } else {
  2842. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  2843. // 获取 type_id 为 1 的数据
  2844. $result['type1'] = $this->processGoods(
  2845. $query->clone()
  2846. ->where('type_id', 1)
  2847. ->offset(($data['page'] - 1) * $data['pageSize'])
  2848. ->limit($data['pageSize'])
  2849. ->get(),
  2850. $data
  2851. );
  2852. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2853. // 获取 type_id 为 2 的数据
  2854. $result['type2'] = $this->processGoods(
  2855. $query->clone()
  2856. ->where('type_id', 2)
  2857. ->offset(($data['page'] - 1) * $data['pageSize'])
  2858. ->limit($data['pageSize'])
  2859. ->get(),
  2860. $data
  2861. );
  2862. }
  2863. if (empty($result)) {
  2864. return Result::error("查询失败", 0);
  2865. }
  2866. return Result::success($result);
  2867. }
  2868. /**
  2869. * 获取商品详情
  2870. * @param array $data
  2871. * @return array
  2872. * */
  2873. public function getWebsiteshopInfo(array $data): array
  2874. {
  2875. $where = [
  2876. 'good.status' => 2,
  2877. 'good.website_id' => $data['website_id'],
  2878. 'good.id' => $data['id'],
  2879. ];
  2880. $goods = Good::where($where)
  2881. ->where('good.id', $data['id'])
  2882. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2883. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2884. ->first();
  2885. if (empty($goods)) {
  2886. return Result::error("查询失败", 0);
  2887. }
  2888. $goods->imgurl = json_decode($goods->imgurl, true);
  2889. return Result::success($goods);
  2890. }
  2891. /**
  2892. * plus pro 处理文章路由问题
  2893. */
  2894. function processArticlePro($website_id)
  2895. {
  2896. // $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2897. // // $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2898. // // 取出category_id 对应的aLIas_pinyin
  2899. // $categoryIds = array_column($categorys, 'category_id');
  2900. // $categoryPIds = array_column($categorys, 'pid');
  2901. // $aliasPinyins = array_column($categorys, 'path');
  2902. // $alias = array_column($categorys, 'alias');
  2903. // $cat_arr = array_combine($categoryIds, $aliasPinyins);
  2904. // $cat_alias_arr = array_combine($categoryIds, $categoryPIds);
  2905. // // return Result::success($cat_arr);
  2906. // // $catiall = [];
  2907. // //一级所有子级的记录
  2908. // $cat_alias_arr = array_combine($categoryIds, $alias);
  2909. // return [
  2910. // 'cat_1st_arr' => $cat_alias_arr,
  2911. // 'catiall' => $cat_arr,
  2912. // // 'websiteInfoIndexed' => $websiteInfoIndexed,
  2913. // 'categoryIds' => $categoryIds,
  2914. // ];
  2915. $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2916. $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2917. // 取出category_id 对应的aLIas_pinyin
  2918. $categoryIds = array_column($categorys, 'category_id');
  2919. $categoryPIds = array_values(array_unique(array_filter(array_column($categorys, 'pid'), function ($pid) {
  2920. return $pid != 0;
  2921. })));
  2922. $category_path = array_column($categorys, 'path');
  2923. $cat_arr = array_combine($categoryIds, $category_path);
  2924. // return Result::success(array_diff($categoryIds, $categoryPIds));
  2925. $catiall = [];
  2926. //一级所有子级的记录
  2927. $cat_1st_arr = [];
  2928. foreach ($categorys as $key => $value) {
  2929. // $category_arr_id = json_decode($value->category_arr_id);
  2930. // $pinyin_str = '';
  2931. // // 算出一级 并且算出子级
  2932. if ($value->pid != 0 && in_array($value->pid, $categoryIds)) {
  2933. $cat_1st_arr[$value->pid][] = $value->category_id;
  2934. }
  2935. // foreach ($category_arr_id as $k => $v) {
  2936. // $pinyin_str .= $cat_arr[$v] . '/';
  2937. // }
  2938. // $pinyin_str = rtrim($pinyin_str, '/');
  2939. $catiall[$value->category_id]['alias'] = $value->alias;
  2940. $catiall[$value->category_id]['category_id'] = $value->category_id;
  2941. $catiall[$value->category_id]['type'] = $value->type;
  2942. $catiall[$value->category_id]['pinyin'] = $cat_arr[$value->category_id];
  2943. $websiteInfoIndexed[$value->category_id]->pinyin = $cat_arr[$value->category_id];
  2944. }
  2945. return [
  2946. 'cat_1st_arr' => $cat_1st_arr,
  2947. 'catiall' => $catiall,
  2948. 'websiteInfoIndexed' => $websiteInfoIndexed,
  2949. 'categoryIds' => $categoryIds,
  2950. 'diff_pid_categoryIds' => array_diff($categoryPIds, $categoryIds),
  2951. 'categoryPIds' => $categoryPIds,
  2952. ];
  2953. }
  2954. /**
  2955. * 封装处理文章的路由问题
  2956. * */
  2957. function processArticles($articles, $data)
  2958. {
  2959. // 检查 $articles 是否为数组或可迭代对象
  2960. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  2961. return $articles->map(function ($article) use ($data) {
  2962. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  2963. $catid = $article->cat_arr_id ?? '';
  2964. }
  2965. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  2966. $catid = $article->category_arr_id ?? '';
  2967. }
  2968. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  2969. $level = json_decode($catid, true);
  2970. if (!is_array($level)) {
  2971. return $article;
  2972. } else {
  2973. $level = array_map('intval', $level);
  2974. }
  2975. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2976. ->where($data)
  2977. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2978. ->pluck('aLIas_pinyin')
  2979. ->implode('/');
  2980. $article->pinyin = $pinyin ?? '';
  2981. return $article;
  2982. });
  2983. } else {
  2984. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2985. $catid = $articles->cat_arr_id ?? '';
  2986. $level = json_decode($catid, true);
  2987. if (!is_array($level)) {
  2988. return $articles;
  2989. } else {
  2990. $level = array_map('intval', $level);
  2991. }
  2992. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2993. ->where($data)
  2994. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2995. ->pluck('aLIas_pinyin')
  2996. ->implode('/');
  2997. $articles->pinyin = $pinyin ?? '';
  2998. return $articles;
  2999. }
  3000. }
  3001. // 封装处理由问题
  3002. function processJob($job, $data)
  3003. {
  3004. return $job->map(function ($job) use ($data) {
  3005. $category = $job->cat_arr_id ?? '';
  3006. $cityid = $job->city_arr_id ?? '';
  3007. $city = json_decode($cityid, true);
  3008. $pinyin = '';
  3009. $level = json_decode($category, true);
  3010. // 路由
  3011. if (!empty($level) && is_array($level)) {
  3012. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  3013. ->where('website_id', $data['website_id']) // 添加网站ID条件
  3014. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  3015. ->get(['aLIas_pinyin'])
  3016. ->pluck('aLIas_pinyin')
  3017. ->implode('/');
  3018. if (empty($pinyin)) {
  3019. $pinyin = $pinyin->aLIas_pinyin ?? '';
  3020. }
  3021. $job->pinyin = $pinyin;
  3022. }
  3023. // 取职位-城市 市??省
  3024. if (!empty($city) && is_array($city)) {
  3025. if (isset($city[1]) && !empty($city[1])) {
  3026. $city = District::where('id', $city[1])->first(['name']);
  3027. $job->city_name = $city->name ?? '';
  3028. } else if (isset($city[0]) && !empty($city[0])) {
  3029. $city = District::where('id', $city[0])->first(['name']);
  3030. $job->city_name = $city->name ?? '';
  3031. } else {
  3032. $job->city_name = '全国';
  3033. }
  3034. }
  3035. // 获取简历最后一级地区
  3036. if (isset($job->city_id) && !empty($job->city_id)) {
  3037. $city = District::where('id', $job->city_id)->first(['name']);
  3038. $job->hunt_cityname = $city->name ?? '';
  3039. }
  3040. // 组合详细地址
  3041. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  3042. $address_id = json_decode($job->address_arr_id, true) ?? [];
  3043. if (is_array($address_id) && !empty($address_id)) {
  3044. $address = District::whereIn('id', $address_id)
  3045. ->orderBy('level', 'asc')
  3046. ->get(['name'])
  3047. ->pluck('name')
  3048. ->implode('');
  3049. // $job->address_name = $address ?? '';
  3050. $job->address_name = ($address ?? '') . ($job->address ?? '');
  3051. }
  3052. }
  3053. // 取行业
  3054. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  3055. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  3056. if (!empty($job->industry)) {
  3057. $query->where('hyid', $job->industry);
  3058. } else if (!empty($job->hy_id)) {
  3059. $query->where('hyid', $job->hy_id);
  3060. } else if (!empty($job->company_hy_id)) {
  3061. $query->where('hyid', $job->company_hy_id);
  3062. } else {
  3063. $query->where('hyid', $job->job_industry);
  3064. }
  3065. })->first(['hyname']);
  3066. $job->hy_name = $hy_name->hyname ?? '';
  3067. }
  3068. // 取职位类别
  3069. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  3070. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  3071. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  3072. $job->zw_name = $zw_name->zwname ?? '';
  3073. }
  3074. // 取具体职位
  3075. 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))) {
  3076. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  3077. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  3078. $job->jtzw_name = $jtzw_name->zwname ?? '';
  3079. }
  3080. // 取工作经验
  3081. if (isset($job->experience) && !empty($job->experience)) {
  3082. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  3083. $job->experience_name = $experience->ename ?? '';
  3084. }
  3085. // 取学历
  3086. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  3087. $education = $job->educational ?? $job->school_education;
  3088. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  3089. $job->education_name = $education->ename ?? '';
  3090. }
  3091. // 语言
  3092. if (isset($job->language) && !empty($job->language)) {
  3093. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  3094. $job->language_name = $language->ename ?? '';
  3095. }
  3096. // 薪资
  3097. if (isset($job->salary) && !empty($job->salary)) {
  3098. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  3099. $job->salary_name = $salary->ename ?? '';
  3100. }
  3101. // 职位性质
  3102. if (isset($job->nature_id) && !empty($job->nature_id)) {
  3103. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  3104. $job->job_nature_name = $job_nature->ename ?? '';
  3105. }
  3106. // 公司规模
  3107. if (isset($job->company_size) && !empty($job->company_size)) {
  3108. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  3109. $job->company_size_name = $company_size->ename ?? '';
  3110. }
  3111. // 公司性质
  3112. if (isset($job->company_nature) && !empty($job->company_nature)) {
  3113. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  3114. $job->company_nature_name = $company_nature->nature_name ?? '';
  3115. }
  3116. // $job->pinyin = $pinyin;
  3117. return $job;
  3118. });
  3119. }
  3120. /**
  3121. * 获取书籍模块
  3122. * @param array $data
  3123. * @return array
  3124. * */
  3125. public function getWebsiteBook(array $data): array
  3126. {
  3127. $input['id'] = $data['id'];
  3128. $input['website_id'] = $data['website_id'];
  3129. // 将 JSON 字符串转换为 PHP 数组
  3130. $data = json_decode($input['id'], true);
  3131. // 使用 array_map 处理每个元素
  3132. $result = array_map(function ($item) use ($input) {
  3133. // 检查parent元素是否存在且不是undefined
  3134. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  3135. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  3136. $website = [
  3137. 'website_id' => $input['website_id'],
  3138. ];
  3139. // 查询栏目名称
  3140. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  3141. if (empty($category)) {
  3142. $parent_alias = '';
  3143. $parent_pinyin = null;
  3144. $imgBooks = [];
  3145. $textBooks = [];
  3146. } else {
  3147. $parent_alias = $category->alias ?? '';
  3148. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  3149. // 查找子分类ID数组
  3150. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  3151. array_push($childCategoryIds, $parentCatId);
  3152. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  3153. if ($parentImgNum != 0) {
  3154. // 查询图片新闻
  3155. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  3156. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  3157. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  3158. })
  3159. ->where('book.status', 2)
  3160. ->where('book.img_url', '!=', '')
  3161. ->where('book.website_id', $website['website_id'])
  3162. ->leftJoin('website_category', function ($join) use ($website) {
  3163. $join->on('book.cat_id', '=', 'website_category.category_id')
  3164. ->where('website_category.website_id', '=', $website['website_id']);
  3165. })
  3166. ->select(
  3167. 'book.id',
  3168. 'book.title',
  3169. 'book.img_url',
  3170. 'book.price',
  3171. 'book.market_price',
  3172. 'book.description',
  3173. 'book.cat_id',
  3174. 'book.description',
  3175. 'book.updated_at',
  3176. 'website_category.alias as category_name',
  3177. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3178. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3179. )
  3180. ->orderBy('updated_at', 'desc')
  3181. ->limit($parentImgNum)
  3182. ->get()->all();
  3183. // 查询文字新闻
  3184. }
  3185. if ($parentTextNum != 0) {
  3186. $textBooks = [];
  3187. $textBooks = Book::where(function ($query) use ($parentCatId) {
  3188. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  3189. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  3190. })
  3191. ->where('book.status', 2)
  3192. ->where('book.website_id', $website['website_id'])
  3193. ->leftJoin('website_category', function ($join) use ($website) {
  3194. $join->on('book.cat_id', '=', 'website_category.category_id')
  3195. ->where('website_category.website_id', '=', $website['website_id']);
  3196. })
  3197. ->select(
  3198. 'book.id',
  3199. 'book.title',
  3200. 'book.img_url',
  3201. 'book.price',
  3202. 'book.market_price',
  3203. 'book.description',
  3204. 'book.cat_id',
  3205. 'book.description',
  3206. 'book.updated_at',
  3207. 'website_category.alias as category_name',
  3208. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3209. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3210. )
  3211. ->orderBy('updated_at', 'desc')
  3212. ->limit($parentTextNum)
  3213. ->get()->all();
  3214. }
  3215. }
  3216. }
  3217. $resultItem = [
  3218. 'alias' => $parent_alias ?? '',
  3219. 'category_id' => $parentCatId ?? 0,
  3220. 'pinyin' => $parent_pinyin ?? null,
  3221. 'imgnum' => $imgBooks ?? [],
  3222. 'textnum' => $textBooks ?? [],
  3223. ];
  3224. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  3225. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  3226. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  3227. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3228. ->get()->all();
  3229. if (!empty($childCategory)) {
  3230. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  3231. // 查询子栏目名称
  3232. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  3233. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3234. ->first();
  3235. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  3236. $childImgArticles = [];
  3237. $childTextArticles = [];
  3238. $resultItem['child'] = [];
  3239. } else {
  3240. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  3241. // 查询子栏目图片新闻
  3242. $childImgArticles = Book::where('cat_id', $childCatId)
  3243. ->where('status', 2)
  3244. ->where('img_url', '!=', '')
  3245. ->where('book.website_id', $website['website_id'])
  3246. ->leftJoin('website_category', function ($join) use ($website) {
  3247. $join->on('book.cat_id', '=', 'website_category.category_id')
  3248. ->where('website_category.website_id', '=', $website['website_id']);
  3249. })
  3250. ->select(
  3251. 'book.id',
  3252. 'book.title',
  3253. 'book.img_url',
  3254. 'book.price',
  3255. 'book.market_price',
  3256. 'book.description',
  3257. 'book.cat_id',
  3258. 'book.description',
  3259. 'book.updated_at',
  3260. DB::raw("'$child_pinyin' as pinyin")
  3261. )
  3262. ->orderBy('updated_at', 'desc')
  3263. ->limit($childImgNum)
  3264. ->get()->all();
  3265. // 查询子栏目文字新闻
  3266. $childTextArticles = Book::where('cat_id', $childCatId)
  3267. ->where('status', 2)
  3268. ->where('book.website_id', $website['website_id'])
  3269. ->leftJoin('website_category', function ($join) use ($website) {
  3270. $join->on('book.cat_id', '=', 'website_category.category_id')
  3271. ->where('website_category.website_id', '=', $website['website_id']);
  3272. })
  3273. ->select(
  3274. 'book.id',
  3275. 'book.title',
  3276. 'book.img_url',
  3277. 'book.price',
  3278. 'book.market_price',
  3279. 'book.description',
  3280. 'book.cat_id',
  3281. 'book.description',
  3282. 'book.updated_at',
  3283. DB::raw("'$child_pinyin' as pinyin")
  3284. )
  3285. ->orderBy('updated_at', 'desc')
  3286. ->limit($childTextNum)
  3287. ->get()->all();
  3288. $resultItem['child'] = [
  3289. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  3290. 'category_id' => $childCatId,
  3291. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  3292. 'all_childcat' => $childCategory,
  3293. 'imgnum' => $childImgArticles,
  3294. 'textnum' => $childTextArticles,
  3295. ];
  3296. }
  3297. }
  3298. } else {
  3299. $resultItem['child'] = [];
  3300. }
  3301. return $resultItem;
  3302. }, $data);
  3303. return Result::success($result);
  3304. }
  3305. /**
  3306. * 获取书刊列表
  3307. * @param array $data
  3308. * @return array
  3309. * */
  3310. public function getWebsiteBookList(array $data): array
  3311. {
  3312. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3313. if (empty($web)) {
  3314. return Result::error("查询失败", 0);
  3315. }
  3316. $catid = $data['id'];
  3317. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  3318. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  3319. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  3320. $category_pinyin = $category ? $category->aLias_pinyin : '';
  3321. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  3322. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  3323. ->where('pid', $category['pid'])
  3324. ->select(
  3325. 'category_id',
  3326. 'alias',
  3327. 'aLIas_pinyin',
  3328. 'pid',
  3329. 'sort',
  3330. 'is_url',
  3331. 'web_url',
  3332. 'seo_title',
  3333. 'seo_keywords',
  3334. 'seo_description',
  3335. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  3336. )
  3337. ->orderBy('sort')
  3338. ->get()->all();
  3339. if (empty($category)) {
  3340. return Result::error("查询失败", 0);
  3341. }
  3342. $query = Book::where('book.status', 2)
  3343. ->where('book.website_id', $data['website_id'])
  3344. ->where('book.cat_id', $catid)
  3345. ->select(
  3346. 'book.id',
  3347. 'book.title',
  3348. 'book.img_url',
  3349. 'book.description',
  3350. 'book.updated_at',
  3351. 'book.cat_id',
  3352. DB::raw("'$pinyin' as pinyin")
  3353. )
  3354. ->orderBy('book.updated_at', 'desc');
  3355. $count = $query->count();
  3356. $query = clone $query;
  3357. $Book = $query
  3358. ->limit($data['pageSize'])
  3359. ->offset(($data['page'] - 1) * $data['pageSize'])
  3360. ->get()->all();
  3361. $result = [
  3362. 'category' => $categorys,
  3363. 'books' => $Book,
  3364. 'count' => $count,
  3365. ];
  3366. // if(empty($result)){
  3367. // return Result::error("查询失败", 0);
  3368. // }
  3369. return Result::success($result);
  3370. }
  3371. /**
  3372. * 获取书刊详情
  3373. * @param array $data
  3374. * @return array
  3375. * */
  3376. public function getWebsiteBookInfo(array $data): array
  3377. {
  3378. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3379. if (empty($web)) {
  3380. return Result::error("查询失败", 0);
  3381. }
  3382. $book = Book::where('status', 2)
  3383. ->where('website_id', $data['website_id'])
  3384. ->where('id', $data['id'])
  3385. ->select(
  3386. 'book.*',
  3387. )
  3388. ->orderBy('updated_at', 'desc')
  3389. ->first();
  3390. if (empty($book)) {
  3391. return Result::error("查询失败", 0);
  3392. }
  3393. // 先查询当前分类的 pid
  3394. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  3395. ->where('category_id', $book['cat_id'])
  3396. ->first(['pid', 'category_id']);
  3397. $query = WebsiteCategory::where('website_id', $data['website_id']);
  3398. if (!empty($carpid)) {
  3399. if ($carpid->pid != 0) {
  3400. $pid = $carpid['pid'];
  3401. // $parent_pinyin = '';
  3402. } else {
  3403. $pid = $carpid['category_id'];
  3404. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  3405. }
  3406. }
  3407. $categorys = $query->where('pid', $pid)
  3408. ->select(
  3409. 'category_id',
  3410. 'alias',
  3411. 'aLIas_pinyin',
  3412. 'pid',
  3413. 'sort',
  3414. 'is_url',
  3415. 'web_url',
  3416. 'category_arr_id as cat_arr_id',
  3417. )
  3418. ->orderBy('sort')
  3419. ->get();
  3420. $category = $this->processArticle($categorys, $data);
  3421. $result = [
  3422. 'category' => $category,
  3423. 'books' => $book,
  3424. ];
  3425. return Result::success($result);
  3426. }
  3427. /**
  3428. * 尝试
  3429. * @param array $data
  3430. * @return array
  3431. * */
  3432. public function test(array $data): array
  3433. {
  3434. $input['id'] = $data['id'];
  3435. $input['website_id'] = $data['website_id'];
  3436. // 将 JSON 字符串转换为 PHP 数组
  3437. $data = json_decode($input['id'], true);
  3438. $result = [];
  3439. $article = $data;
  3440. $result = array_map(function ($item) use ($input) {
  3441. $website = [
  3442. 'website_id' => $input['website_id'],
  3443. ];
  3444. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  3445. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  3446. $parent = [
  3447. 0 => $category['category_id'] ?? [],
  3448. 1 => $parentImgNum ?? [],
  3449. 2 => $parentTextNum ?? [],
  3450. ];
  3451. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  3452. $child = [];
  3453. $resultItem = [
  3454. // 'alias' => $parent_alias ?? '',
  3455. 'category_id' => $parentCatId ?? 0,
  3456. 'pinyin' => $parentImgNum ?? null,
  3457. 'imgnum' => $parentTextNum ?? [],
  3458. // 'textnum' => $textArticles ?? [],
  3459. ];
  3460. return $parent;
  3461. }, $data);
  3462. return Result::success($result);
  3463. // });
  3464. }
  3465. /**
  3466. * 封装处理文章的路由问题
  3467. * */
  3468. function processArticle($article, $data)
  3469. {
  3470. return $article->map(function ($article) use ($data) {
  3471. $catid = $article->cat_arr_id ?? '';
  3472. $level = json_decode($catid, true);
  3473. $pinyin = '';
  3474. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  3475. if (!empty($level) && is_array($level)) {
  3476. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  3477. ->where('website_id', $data['website_id'])
  3478. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  3479. ->get(['aLIas_pinyin'])
  3480. ->pluck('aLIas_pinyin')
  3481. ->implode('/');
  3482. } else {
  3483. $pinyin = '';
  3484. }
  3485. $article->pinyin = $pinyin;
  3486. return $article;
  3487. });
  3488. }
  3489. /**
  3490. * c端-获取招工招聘下拉选框
  3491. * @param array $data
  3492. * @return array
  3493. * */
  3494. public function getWebsiteJobSelect(array $data): array
  3495. {
  3496. $web = Website::where('id', $data['website_id'])->first();
  3497. if (empty($web)) {
  3498. return Result::error("该网站不存在", 0);
  3499. }
  3500. $hy = JobIndustry::get()->all();
  3501. $zw = JobPosition::where('zwpid', 0)->get()->all();
  3502. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  3503. $result = [
  3504. 'hy' => $hy,
  3505. 'zw' => $zw,
  3506. 'jtzw' => $jtzw,
  3507. ];
  3508. if (empty($result)) {
  3509. return Result::error("查询失败", 0);
  3510. }
  3511. return Result::success($result);
  3512. }
  3513. /**
  3514. * c端-获取招工招聘
  3515. * @param array $data
  3516. * @return array
  3517. * */
  3518. public function getWebsiteJob(array $data): array
  3519. {
  3520. $web = Website::where('id', $data['website_id'])->first();
  3521. if (empty($web)) {
  3522. return Result::error("该网站不存在", 0);
  3523. }
  3524. $job_hunting = JobHunting::where('job_hunting.status', 2)
  3525. ->where('job_hunting.website_id', $data['website_id'])
  3526. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3527. $query->where(function ($q) use ($data) {
  3528. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3529. });
  3530. })
  3531. ->select(
  3532. 'job_hunting.id',
  3533. 'job_hunting.catid',
  3534. 'job_hunting.cat_arr_id',
  3535. 'job_hunting.job_name_get',
  3536. 'job_hunting.industry',
  3537. 'job_hunting.name',
  3538. 'job_hunting.sexy',
  3539. 'job_hunting.origin',
  3540. 'job_hunting.city_arr_id',
  3541. 'job_hunting.experience',
  3542. 'job_hunting.updated_at',
  3543. 'job_hunting.salary',
  3544. 'job_hunting.skillList',
  3545. 'job_hunting.slelf_evaluation',
  3546. )
  3547. ->orderBy('updated_at', 'desc')
  3548. ->limit($data['job1_num'])
  3549. ->get();
  3550. $web['website_id'] = $data['website_id'];
  3551. if (empty($job_hunting)) {
  3552. $job_huntings = "未查询到相关简历信息";
  3553. } else {
  3554. $job_huntings = $this->processJob($job_hunting, $web);
  3555. }
  3556. // 0:待审核 1:已通过 2:已拒绝
  3557. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3558. ->where('job_recruiting.website_id', $data['website_id'])
  3559. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3560. $query->where(function ($q) use ($data) {
  3561. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3562. });
  3563. })
  3564. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3565. ->select(
  3566. 'job_recruiting.id',
  3567. 'job_recruiting.catid',
  3568. 'job_recruiting.cat_arr_id',
  3569. 'job_recruiting.title',
  3570. 'job_recruiting.jtzw_id',
  3571. 'job_recruiting.hy_id',
  3572. 'job_recruiting.city_arr_id',
  3573. 'job_recruiting.due_data',
  3574. 'job_recruiting.updated_at',
  3575. 'job_recruiting.experience',
  3576. 'job_recruiting.educational',
  3577. 'job_recruiting.salary',
  3578. 'job_recruiting.zw_id',
  3579. 'job_company.business_name',
  3580. 'job_recruiting.keyword',
  3581. 'job_recruiting.description',
  3582. )
  3583. ->orderBy('updated_at', 'desc')
  3584. ->limit($data['job2_num'])
  3585. ->get();
  3586. if (empty($job_recruiting->toArray())) {
  3587. $job_recruitings = "未查询到相关职位信息";
  3588. } else {
  3589. $job_recruitings = $this->processJob($job_recruiting, $web);
  3590. }
  3591. $result = [
  3592. 'job_hunting' => $job_huntings,
  3593. 'job_recuiting' => $job_recruitings,
  3594. ];
  3595. return Result::success($result);
  3596. }
  3597. /**
  3598. * c端-获取招工招聘列表
  3599. * @param array $data
  3600. * @return array
  3601. * */
  3602. public function getWebsiteJobList(array $data): array
  3603. {
  3604. $recruit_where = [];
  3605. $hunt_where = [];
  3606. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3607. if (empty($web)) {
  3608. return Result::error("此网站不存在", 0);
  3609. }
  3610. $website_id['website_id'] = $data['website_id'];
  3611. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  3612. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3613. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  3614. }
  3615. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3616. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  3617. }
  3618. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3619. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  3620. }
  3621. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3622. array_push($recruit_where, ['title', 'like', '%' . $data['keyword'] . '%']);
  3623. }
  3624. $query = JobRecruiting::where('job_recruiting.status', 1)
  3625. ->where('job_recruiting.website_id', $data['website_id'])
  3626. ->where($recruit_where)
  3627. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3628. $query->where(function ($q) use ($data) {
  3629. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3630. });
  3631. })
  3632. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  3633. $query->where(function ($q) use ($data) {
  3634. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  3635. });
  3636. })
  3637. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3638. ->select(
  3639. 'job_recruiting.id',
  3640. 'job_recruiting.catid',
  3641. 'job_recruiting.hy_id',
  3642. 'job_recruiting.title',
  3643. 'job_recruiting.zw_id',
  3644. 'job_recruiting.educational',
  3645. 'job_recruiting.jtzw_id',
  3646. 'job_recruiting.city_arr_id',
  3647. 'job_recruiting.due_data',
  3648. 'job_recruiting.experience',
  3649. 'job_recruiting.cat_arr_id',
  3650. 'job_recruiting.updated_at',
  3651. 'job_company.business_name',
  3652. 'job_recruiting.keyword',
  3653. 'job_recruiting.description',
  3654. )
  3655. ->orderBy('job_recruiting.updated_at', 'desc');
  3656. $recruit_count = $query->count();
  3657. $query = clone $query;
  3658. $JobRecruiting = $query
  3659. ->offset(($data['page'] - 1) * $data['pageSize'])
  3660. ->limit($data['pageSize'])
  3661. ->get();
  3662. if (empty($JobRecruiting)) {
  3663. $JobRecruiting = "暂无相关职位信息";
  3664. } else {
  3665. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  3666. }
  3667. }
  3668. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  3669. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3670. array_push($hunt_where, ['job_hunting.job', $data['zw_id']]);
  3671. }
  3672. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3673. array_push($hunt_where, ['job_hunting.job_name_get', $data['jtzw_id']]);
  3674. }
  3675. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3676. array_push($hunt_where, ['job_hunting.industry', $data['hy_id']]);
  3677. }
  3678. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3679. array_push($hunt_where, ['job_position.zwname', 'like', '%' . $data['keyword'] . '%']);
  3680. }
  3681. $query = JobHunting::where('job_hunting.status', 2)
  3682. ->where('job_hunting.website_id', $data['website_id'])
  3683. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3684. ->where($hunt_where)
  3685. // ->when(isset($data['keyword']) &&!empty($data['keyword']), function ($query) use ($data) {
  3686. // $query->where('job_position.zwname','like','%'.$data['keyword'].'%');
  3687. // })
  3688. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3689. $query->where(function ($q) use ($data) {
  3690. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3691. });
  3692. })
  3693. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  3694. $query->where(function ($q) use ($data) {
  3695. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  3696. });
  3697. })
  3698. ->select(
  3699. 'job_hunting.id',
  3700. 'job_hunting.catid',
  3701. 'job_hunting.sexy',
  3702. 'job_hunting.experience',
  3703. 'job_hunting.origin',
  3704. 'job_hunting.industry',
  3705. 'job_hunting.name',
  3706. 'job_hunting.job',
  3707. 'job_hunting.job_name_get',
  3708. 'job_hunting.city_arr_id',
  3709. 'job_hunting.cat_arr_id',
  3710. 'job_hunting.created_at',
  3711. 'job_hunting.updated_at',
  3712. 'job_position.zwname as job_name',
  3713. 'job_hunting.skillList',
  3714. 'job_hunting.slelf_evaluation',
  3715. )
  3716. ->orderBy('job_hunting.updated_at', 'desc');
  3717. $hunt_count = $query->count();
  3718. $query = clone $query;
  3719. $JobHunting = $query
  3720. ->offset(($data['page'] - 1) * $data['pageSize'])
  3721. ->limit($data['pageSize'])
  3722. ->get();
  3723. if (empty($JobHunting)) {
  3724. $JobRecruiting = "暂无相关简历信息";
  3725. } else {
  3726. $JobHunting = $this->processJob($JobHunting, $website_id);
  3727. }
  3728. }
  3729. $result = [
  3730. 'JobRecruiting' => $JobRecruiting ?? [],
  3731. 'recruit_count' => $recruit_count ?? 0,
  3732. 'JobHunting' => $JobHunting ?? [],
  3733. 'hunt_count' => $hunt_count ?? 0,
  3734. ];
  3735. return Result::success($result);
  3736. }
  3737. /**
  3738. * c端-获取招工招聘详情
  3739. * @param array $data
  3740. * @return array
  3741. * */
  3742. public function getWebsiteJobInfo(array $data): array
  3743. {
  3744. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3745. if (empty($web)) {
  3746. return Result::error("该网站不存在", 0);
  3747. }
  3748. $webid = [
  3749. 'website_id' => $data['website_id'],
  3750. ];
  3751. // 职位相关信息
  3752. if ($data['type'] == 1) {
  3753. $query = JobRecruiting::where('status', 1)
  3754. ->where('website_id', $data['website_id'])
  3755. ->select('*');
  3756. $job = $query->where('job_recruiting.id', $data['id'])->get();
  3757. $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();
  3758. if (!empty($company)) {
  3759. $result['company'] = $this->processJob($company, $webid);
  3760. }
  3761. $other_job = JobRecruiting::where('status', 1)
  3762. ->where('website_id', $data['website_id'])
  3763. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  3764. ->where('id', '!=', $data['id'])
  3765. ->where('user_id', '=', $job[0]['user_id'])
  3766. ->limit($data['pageSize'])
  3767. ->get();
  3768. if (!empty($other_job)) {
  3769. $result['other_job'] = $this->processJob($other_job, $webid);
  3770. }
  3771. } else {
  3772. // 简历相关信息
  3773. $job = JobHunting::where('job_hunting.status', 2)
  3774. ->where('job_hunting.website_id', $data['website_id'])
  3775. ->where('job_hunting.id', $data['id'])
  3776. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3777. ->select('job_hunting.*', 'user_name')
  3778. ->get();
  3779. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  3780. if (!empty($resume->toArray())) {
  3781. $result['resume'] = 1;
  3782. } else {
  3783. $result['resume'] = 0;
  3784. }
  3785. }
  3786. if (empty($job->toArray())) {
  3787. return Result::error("id参数错误", 0);
  3788. }
  3789. if (!empty($job[0]['job_experience'])) {
  3790. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  3791. if (!empty($job_experience)) {
  3792. // $hy = [];
  3793. foreach ($job_experience as $key => $value) {
  3794. // $id = $value['id'];
  3795. $hy[$key] = $value['job_industry'];
  3796. $zw_id[$key] = $value['job_typename'];
  3797. $jtzw_id[$key] = $value['job_name'];
  3798. }
  3799. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  3800. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  3801. // 先将关联表转换为索引数组,提高查找效率
  3802. $hyLookup = [];
  3803. foreach ($hy_table as $item) {
  3804. $hyLookup[$item['hyid']] = $item['hyname'];
  3805. }
  3806. $zwLookup = [];
  3807. foreach ($zw_table as $item) {
  3808. $zwLookup[$item['zwid']] = $item['zwname'];
  3809. }
  3810. foreach ($job_experience as $key => &$value) {
  3811. // 处理行业名称
  3812. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  3813. $value['hy_name'] = $hyLookup[$hy[$key]];
  3814. }
  3815. // 处理职位名称
  3816. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  3817. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  3818. }
  3819. // 处理具体职位名称
  3820. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  3821. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  3822. }
  3823. }
  3824. // 释放引用,防止意外修改后续代码
  3825. unset($value);
  3826. }
  3827. $result['job_experience'] = $job_experience ?? [];
  3828. }
  3829. if (!empty($job[0]['education_experience'])) {
  3830. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  3831. if (!empty($education_experience)) {
  3832. foreach ($education_experience as $key => $value) {
  3833. // $id = $value['id'];
  3834. $education[$key] = $value['school_education'];
  3835. }
  3836. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  3837. // // 先将关联表转换为索引数组,提高查找效率
  3838. $educationLookup = [];
  3839. foreach ($education_table as $item) {
  3840. $educationLookup[$item['evalue']] = $item['ename'];
  3841. }
  3842. foreach ($education_experience as $key => &$value) {
  3843. // 处理学历名称
  3844. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  3845. $value['education_name'] = $educationLookup[$education[$key]];
  3846. }
  3847. }
  3848. }
  3849. $result['education_experience'] = $job_experience ?? [];
  3850. }
  3851. $result['job'] = $this->processJob($job, $webid);
  3852. // // 返现对应的栏目
  3853. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  3854. $category = WebsiteCategory::where('website_id', $data['website_id'])
  3855. ->whereIn('category_id', $catid)
  3856. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  3857. ->orderBy('pid')->get()->all();
  3858. if (!empty($category)) {
  3859. $result['category'] = $category;
  3860. }
  3861. $result['job'] = $job;
  3862. $result['job_experience'] = $job_experience ?? [];
  3863. $result['education_experience'] = $education_experience ?? [];
  3864. if (empty($result)) {
  3865. return Result::error("参数错误", 0);
  3866. }
  3867. return Result::success($result);
  3868. }
  3869. /**
  3870. * c端-申请职位
  3871. * @param array $data
  3872. * @return array
  3873. * */
  3874. public function getWebsiteJobApply(array $data): array
  3875. {
  3876. // 首先验证网站是否存在
  3877. // return Result::success($data);
  3878. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3879. if (empty($web)) {
  3880. return Result::error("该网站不存在", 0);
  3881. }
  3882. // 验证用户是否存在且为个人会员/管理员
  3883. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3884. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3885. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  3886. return Result::error("用户不存在", 0);
  3887. }
  3888. // 去除重复元素和空元素,并保持原始顺序
  3889. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  3890. return !empty($value);
  3891. }));
  3892. // 验证职位是否存在 1:审核通过
  3893. $recruiting = JobRecruiting::where('status', 1)
  3894. ->where('website_id', $data['website_id'])
  3895. ->whereIn('id', $data['recruit_id'])
  3896. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  3897. if (empty($recruiting)) {
  3898. return Result::error("该职位不存在", 0);
  3899. }
  3900. // 简历是否存在
  3901. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  3902. if (empty($hunt_id)) {
  3903. return Result::error("该简历不存在", 0);
  3904. }
  3905. $data['hunt_id'] = $hunt_id['hunt_id'];
  3906. // // 验证是否已投递过该职位
  3907. $apply = JobApply::where('user_id', $data['user_id'])
  3908. ->where('hunt_id', $data['hunt_id'])
  3909. ->where('website_id', $data['website_id'])
  3910. ->whereIn('recruit_id', $data['recruit_id'])
  3911. ->get(['recruit_id']);
  3912. if (!empty($apply->toArray())) {
  3913. return Result::error("您已投递过该职位!");
  3914. }
  3915. $insertData = array_map(function ($recruiting) use ($data) {
  3916. return [
  3917. 'user_id' => $data['user_id'],
  3918. 'hunt_id' => $data['hunt_id'],
  3919. 'website_id' => $data['website_id'],
  3920. 'recruit_id' => $recruiting['recruit_id'],
  3921. 'receiver_id' => $recruiting['receiver_id'],
  3922. 'status' => 1,
  3923. ];
  3924. }, $recruiting);
  3925. // 批量插入数据
  3926. $result = JobApply::insert($insertData);
  3927. if (empty($result)) {
  3928. return Result::error("投递失败", 0);
  3929. }
  3930. return Result::success($result);
  3931. }
  3932. /**
  3933. * 招工招聘-沟通简历
  3934. * @param array $data
  3935. * @return array
  3936. * */
  3937. public function getWebsiteJobResume(array $data): array
  3938. {
  3939. // 首先验证网站是否存在
  3940. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3941. if (empty($web)) {
  3942. return Result::error("该网站不存在", 0);
  3943. }
  3944. // return Result::success($data);
  3945. // 验证用户是否存在且为企业会员/管理员
  3946. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3947. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3948. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3949. return Result::error("用户不存在", 0);
  3950. }
  3951. // 去除重复元素和空元素,并保持原始顺序
  3952. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  3953. return !empty($value);
  3954. }));
  3955. // 验证简历是否存在
  3956. $hunting = JobHunting::where('status', 2)
  3957. ->where('website_id', $data['website_id'])
  3958. ->whereIn('id', $data['hunt_id'])
  3959. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  3960. if (empty($hunting)) {
  3961. return Result::error("该简历不存在", 0);
  3962. }
  3963. // 验证是否已沟通过该简历
  3964. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3965. ->where('recruit_id', $data['recruit_id'])
  3966. ->where('website_id', $data['website_id'])
  3967. ->whereIn('hunt_id', $data['hunt_id'])
  3968. ->get(['hunt_id']);
  3969. if (!empty($remuse->toArray())) {
  3970. return Result::error("您已沟通过该简历!");
  3971. }
  3972. // 准备要插入的数据数组
  3973. $insertData = array_map(function ($hunting) use ($data) {
  3974. return [
  3975. 'user_id' => $data['user_id'],
  3976. 'recruit_id' => $data['recruit_id'],
  3977. 'website_id' => $data['website_id'],
  3978. 'hunt_id' => $hunting['hunt_id'],
  3979. 'receiver_id' => $hunting['receiver_id'],
  3980. 'status' => 1,
  3981. ];
  3982. }, $hunting);
  3983. // 批量插入数据
  3984. $result = JobRemuse::insert($insertData);
  3985. if (empty($result)) {
  3986. return Result::error("沟通失败", 0);
  3987. }
  3988. return Result::success($result);
  3989. }
  3990. /**
  3991. * 招工招聘 -我的职位(企业会员)
  3992. * @param array $data
  3993. * @return array
  3994. */
  3995. public function getWebsiteJobRecruiting(array $data): array
  3996. {
  3997. $web = Website::where('id', $data['website_id'])->first('id');
  3998. if (empty($web)) {
  3999. return Result::error("该网站不存在", 0);
  4000. }
  4001. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  4002. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  4003. return Result::error("用户暂无权限!", 0);
  4004. }
  4005. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  4006. $result = JobRecruiting::where('website_id', $data['website_id'])
  4007. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  4008. $query->where('user_id', $user['id']);
  4009. })
  4010. ->where('status', 1)
  4011. ->select('id', 'title', 'website_id', 'user_id', 'updated_at', 'keyword', 'catid', 'description')
  4012. ->orderBy('updated_at', 'desc')
  4013. ->limit($data['pageSize'])
  4014. ->get();
  4015. if (empty($result)) {
  4016. return Result::error("暂无相关职位信息", 0);
  4017. }
  4018. return Result::success($result);
  4019. }
  4020. /**
  4021. * c端 - 验证路由
  4022. * @param array $data
  4023. * @return array
  4024. */
  4025. /**
  4026. * c端 - 验证路由
  4027. * @param array $data
  4028. * @return array
  4029. */
  4030. public function checkWebsiteRoute(array $data): array
  4031. {
  4032. // 测试001111111222
  4033. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name', 'status']);
  4034. if (empty($web)) {
  4035. return Result::error("该网站不存在", 0);
  4036. } elseif ($web['status'] != 1) {
  4037. return Result::error("网站已经关闭", 0);
  4038. }
  4039. if (isset($data['other_route']) && !empty($data['other_route'])) {
  4040. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  4041. // 验证路由是否存在
  4042. if (empty($whiteRouterInfo)) {
  4043. $whiteRouterInfo = WhiteRouter::where("router_type", 1)->where('router_url', $data['other_route'])->first();
  4044. }
  4045. if (!empty($whiteRouterInfo)) {
  4046. return Result::success($whiteRouterInfo->toArray());
  4047. }
  4048. }
  4049. // 验证栏目路由
  4050. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  4051. ->where('path', $data['all_route'])
  4052. ->get()->all();
  4053. if (count($last_category) == 0) {
  4054. return Result::error("该栏目不存在", 0);
  4055. }
  4056. if (count($last_category) > 1) {
  4057. return Result::error("该栏目路由存在多个,路由验证失败!", 0);
  4058. }
  4059. if (count($last_category) == 1) {
  4060. $last_category = $last_category[0];
  4061. }
  4062. // return Result::success($last_category);
  4063. if (isset($data['id']) && !empty($data['id'])) {
  4064. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  4065. switch ($last_category['type']) {
  4066. case 1:
  4067. // 文章
  4068. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  4069. $article = Article::where('status', 1)
  4070. ->where('id', $data['id'])
  4071. ->where(function ($query) use ($data) {
  4072. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  4073. ->orWhereNull("ignore_ids");
  4074. })
  4075. ->first(['catid']);
  4076. if (empty($article)) {
  4077. return Result::error("该文章不存在", 0);
  4078. }
  4079. // return Result::success($article);
  4080. break;
  4081. case 2:
  4082. // 商品
  4083. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  4084. $article = Good::where('website_id', $data['website_id'])
  4085. ->where('status', 2)
  4086. ->where('id', $data['id'])
  4087. ->first(['cat_arr_id']);
  4088. if (empty($article)) {
  4089. return Result::error("该商品不存在", 0);
  4090. }
  4091. break;
  4092. case 3:
  4093. // 书刊信息
  4094. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  4095. $article = Book::where('website_id', $data['website_id'])
  4096. ->where('status', 2)
  4097. ->where('id', $data['id'])
  4098. ->first(['id', 'cat_arr_id']);
  4099. if (empty($article)) {
  4100. return Result::error("该书刊不存在", 0);
  4101. }
  4102. break;
  4103. case 4:
  4104. // 招聘
  4105. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核通过;(只有企业会员需要审核)',
  4106. $article = JobRecruiting::where('website_id', $data['website_id'])
  4107. ->where('status', 1)
  4108. ->where('id', $data['id'])
  4109. ->first(['cat_arr_id']);
  4110. if (empty($article)) {
  4111. return Result::error("该招聘不存在", 0);
  4112. }
  4113. break;
  4114. case 5:
  4115. // 求职
  4116. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  4117. $article = JobHunting::where('website_id', $data['website_id'])
  4118. ->where('status', 2)
  4119. ->where('id', $data['id'])
  4120. ->first(['cat_arr_id']);
  4121. if (empty($article)) {
  4122. return Result::error("该求职不存在", 0);
  4123. }
  4124. break;
  4125. case 6:
  4126. // 企业
  4127. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  4128. $article = Company::
  4129. // where('website_id', $data['website_id'])
  4130. // ->
  4131. where('status', 1)
  4132. ->where('id', $data['id'])
  4133. ->first(['cat_arr_id']);
  4134. if (empty($article)) {
  4135. return Result::error("该企业不存在", 0);
  4136. }
  4137. break;
  4138. case 7:
  4139. // 项目
  4140. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  4141. $article = Project::where('website_id', $data['website_id'])
  4142. ->where('status', 1)
  4143. ->where('id', $data['id'])
  4144. ->first(['cat_arr_id']);
  4145. if (empty($article)) {
  4146. return Result::error("该项目不存在", 0);
  4147. }
  4148. break;
  4149. default:
  4150. return Result::error("该数据不存在", 0);
  4151. break;
  4152. }
  4153. // return Result::success($article);
  4154. // $catid =0 ;
  4155. if (!isset($article['cat_arr_id'])) {
  4156. $catid = isset($article['catid']) ? $article['catid'] : (isset($article['category_id']) ? $article['category_id'] : null);
  4157. } else {
  4158. $catidArray = json_decode($article['cat_arr_id'], true);
  4159. $catid = !empty($catidArray) ? end($catidArray) : null;
  4160. }
  4161. // return Result::success($catid);
  4162. // // return Result::success($article['cat_arr_id']);
  4163. if (empty($catid)) {
  4164. return Result::error("该栏目路径不存在", 0);
  4165. }
  4166. $path = WebsiteCategory::where('website_id', $data['website_id'])
  4167. ->where('category_id', $catid)
  4168. ->first('path');
  4169. }
  4170. // else{
  4171. // // if ($last_category['pid'] != 0) {
  4172. // $cat_arr = json_decode($last_category['category_arr_id'], true);
  4173. // $catid = !empty($cat_arr) && is_array($cat_arr) ? end($cat_arr) : null;
  4174. // $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  4175. // ->where('category_id',$catid)
  4176. // ->where('path',$data['all_route'])
  4177. // ->first('path');
  4178. // // } else {
  4179. // // $pinyin[0] = $last_category['aLIas_pinyin'];
  4180. // // }
  4181. // }
  4182. // return Result::success($path);
  4183. if (!empty($path) && $path['path'] != $data['all_route']) {
  4184. return Result::error('非法路径!');
  4185. } else {
  4186. return Result::success($last_category['path']);
  4187. }
  4188. }
  4189. /**
  4190. * 招工招聘 - 获取推荐职位
  4191. * @param array $data
  4192. * @return array
  4193. */
  4194. public function getWebsiteLevelJob(array $data): array
  4195. {
  4196. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  4197. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  4198. ->where('job_recruiting.status', 1)
  4199. ->where('job_level', $data['job_level'])
  4200. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4201. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  4202. ->orderBy('job_recruiting.updated_at', 'desc')
  4203. ->limit($data['pageSize'])
  4204. ->get();
  4205. $web = ['website_id' => $data['website_id']];
  4206. if (!empty($job)) {
  4207. $result = $this->processJob($job, $web);
  4208. }
  4209. if (empty($result)) {
  4210. return Result::error("暂无相关职位信息", 0);
  4211. }
  4212. return Result::success($result);
  4213. }
  4214. /**
  4215. * 验证导航名称是否重复
  4216. * @return void
  4217. */
  4218. //20250226 产品列表
  4219. public function getGoodList(array $data): array
  4220. {
  4221. var_dump($data, '---------1-2--');
  4222. $type_id = isset($data['user_type_id']) ? $data['user_type_id'] : '';
  4223. unset($data['user_type_id']);
  4224. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4225. $where = [];
  4226. if ($type_id != '10000') {
  4227. $where = [
  4228. 'good.user_id' => $user_id,
  4229. ];
  4230. }
  4231. //类型
  4232. if (isset($data['type_id']) && $data['type_id']) {
  4233. $where['good.type_id'] = $data['type_id'];
  4234. }
  4235. //名称
  4236. if (isset($data['name']) && $data['name']) {
  4237. $where[] = ['good.name', 'like', '%' . $data['name'] . '%'];
  4238. }
  4239. //status
  4240. if (isset($data['status']) && $data['status'] != '') {
  4241. $where['good.status'] = $data['status'];
  4242. }
  4243. //status1
  4244. // if (isset($data['status1']) && $data['status1'] == 1) {
  4245. // $status1 = 1;
  4246. // }
  4247. $where1 = [];
  4248. //website_id
  4249. // if (isset($data['website_id']) && $data['website_id']) {
  4250. // $where1 = [
  4251. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  4252. // ];
  4253. // }
  4254. // website_name
  4255. if (isset($data['website_name']) && $data['website_name']) {
  4256. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  4257. }
  4258. // catid
  4259. if (isset($data['category_name']) && $data['category_name']) {
  4260. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  4261. }
  4262. // $result = Good::where($where)
  4263. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  4264. var_dump($where, '---------1---');
  4265. $result = Good::where($where)
  4266. ->when(!empty($where1), function ($query) use ($where1) {
  4267. return $query->where($where1);
  4268. })
  4269. //status 1待审核2已审核3已拒绝
  4270. ->when(isset($data['status1']), function ($query) {
  4271. return $query->whereIn('good.status', [1, 3]);
  4272. })
  4273. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4274. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4275. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4276. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4277. ->orderBy("updated_at", "desc")
  4278. ->limit($data['page_size'])
  4279. ->offset(($data['page'] - 1) * $data['page_size'])
  4280. ->get();
  4281. $count = Good::where($where)
  4282. ->when(!empty($where1), function ($query) use ($where1) {
  4283. return $query->where($where1);
  4284. })
  4285. //status 1待审核2已审核3已拒绝
  4286. ->when(isset($data['status1']), function ($query) {
  4287. return $query->whereIn('good.status', [1, 3]);
  4288. })
  4289. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4290. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4291. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4292. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4293. ->orderBy("updated_at", "desc")->count();
  4294. $data = [
  4295. 'rows' => $result->toArray(),
  4296. 'count' => $count,
  4297. ];
  4298. if (empty($result)) {
  4299. return Result::error("此栏目暂无相关产品", 0);
  4300. }
  4301. return Result::success($data);
  4302. }
  4303. public function getGoodInfo(array $data): array
  4304. {
  4305. $result = Good::where('id', $data['id'])->first();
  4306. if (empty($result)) {
  4307. return Result::error("此产品不存在", 0);
  4308. }
  4309. return Result::success($result);
  4310. }
  4311. public function addGood(array $data): array
  4312. {
  4313. // unset($data['city_arr_id']);
  4314. // unset($data['cat_arr_id']);
  4315. $data['city_id'] = end($data['city_arr_id']);
  4316. $data['catid'] = end($data['cat_arr_id']);
  4317. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4318. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4319. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4320. unset($data['imgUrl']); //大小写
  4321. if (isset($data['price']) && $data['price'] == '') {
  4322. $data['price'] = 0;
  4323. }
  4324. if ($data['imgurl'] == '') {
  4325. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4326. preg_match_all($reg, $data['detail'], $matches);
  4327. if (isset($matches[1][0])) {
  4328. //截取varchar240
  4329. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4330. }
  4331. }
  4332. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4333. //提取标题+内容中的关键词
  4334. $data['keyword'] = $data['name'];
  4335. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4336. Jieba::init(); // 初始化 jieba-php
  4337. Finalseg::init();
  4338. $segList = Jieba::cut($data['keyword']);
  4339. $segList1 = array_slice($segList, 0, 8);
  4340. $data['keyword'] = implode(',', $segList1);
  4341. }
  4342. if ($data['description'] == '') {
  4343. //提取内容中的描述
  4344. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4345. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4346. // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  4347. }
  4348. if ($data['status'] == 1) {
  4349. $this->sendMessage([
  4350. 'talk_type' => 200,
  4351. 'title' => $data['name'],
  4352. 'content' => '提交了审核',
  4353. 'messageType' => 3,
  4354. ]);
  4355. }
  4356. $result = Good::insert($data);
  4357. if (empty($result)) {
  4358. return Result::error("添加失败", 0);
  4359. }
  4360. return Result::success($result);
  4361. }
  4362. public function updateGood(array $data): array
  4363. {
  4364. $data['city_id'] = end($data['city_arr_id']);
  4365. $data['catid'] = end($data['cat_arr_id']);
  4366. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4367. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4368. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4369. //设置东八区
  4370. date_default_timezone_set('Asia/Shanghai');
  4371. $data['updated_at'] = date('Y-m-d H:i:s');
  4372. if (isset($data['price']) && $data['price'] == '') {
  4373. $data['price'] = 0;
  4374. }
  4375. if ($data['imgurl'] == '') {
  4376. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4377. preg_match_all($reg, $data['detail'], $matches);
  4378. if (isset($matches[1][0])) {
  4379. //截取varchar240
  4380. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4381. }
  4382. }
  4383. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4384. //提取标题+内容中的关键词
  4385. $data['keyword'] = $data['name'];
  4386. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4387. Jieba::init(); // 初始化 jieba-php
  4388. Finalseg::init();
  4389. $segList = Jieba::cut($data['keyword']);
  4390. $segList1 = array_slice($segList, 0, 8);
  4391. $data['keyword'] = implode(',', $segList1);
  4392. }
  4393. if ($data['description'] == '') {
  4394. //提取内容中的描述
  4395. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4396. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4397. }
  4398. if ($data['status'] == 1) {
  4399. $this->sendMessage([
  4400. 'talk_type' => 200,
  4401. 'title' => $data['name'],
  4402. 'content' => '提交了审核',
  4403. 'messageType' => 3,
  4404. ]);
  4405. }
  4406. $result = Good::where('id', $data['id'])->update($data);
  4407. if (empty($result)) {
  4408. return Result::error("更新失败", 0);
  4409. }
  4410. return Result::success($result);
  4411. }
  4412. public function delGood(array $data): array
  4413. {
  4414. $result = Good::where('id', $data['id'])->delete();
  4415. if (empty($result)) {
  4416. return Result::error("删除失败", 0);
  4417. }
  4418. return Result::success($result);
  4419. }
  4420. //20250226 产品列表
  4421. //20250306 求职信息
  4422. public function getJobHuntingList(array $data): array
  4423. {
  4424. $where = [];
  4425. if (isset($data['username']) && !empty($data['username'])) {
  4426. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4427. }
  4428. //status 1待审核2已审核3已拒绝
  4429. if (isset($data['status']) && $data['status'] != '') {
  4430. $where = [
  4431. 'job_hunting.status' => $data['status'],
  4432. ];
  4433. }
  4434. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4435. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4436. unset($data['type_id']);
  4437. if ($type_id != '10000') {
  4438. $where[] = ['job_hunting.user_id', '=', $user_id];
  4439. }
  4440. $result = JobHunting::where($where)
  4441. ->when(!empty($data['status1']), function ($query) use ($data) {
  4442. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4443. })
  4444. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4445. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4446. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  4447. ->orderBy("updated_at", "desc")
  4448. ->limit($data['page_size'])
  4449. ->offset(($data['page'] - 1) * $data['page_size'])
  4450. ->get();
  4451. if (empty($result)) {
  4452. return Result::error("查询失败", 0);
  4453. }
  4454. $count = JobHunting::where($where)
  4455. ->when(!empty($data['status1']), function ($query) use ($data) {
  4456. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4457. })
  4458. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4459. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4460. ->count();
  4461. $data = [
  4462. 'rows' => $result->toArray(),
  4463. 'count' => $count,
  4464. ];
  4465. return Result::success($data);
  4466. }
  4467. public function getJobHuntingApply(array $data): array
  4468. {
  4469. var_dump($data, '-----------------test--------1-');
  4470. $where = [];
  4471. if (isset($data['username']) && !empty($data['username'])) {
  4472. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4473. }
  4474. if (isset($data['salary']) && !empty($data['salary'])) {
  4475. $where[] = [
  4476. 'job_hunting.salary',
  4477. '=',
  4478. $data['salary'],
  4479. ];
  4480. }
  4481. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4482. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4483. unset($data['type_id']);
  4484. if ($type_id != '10000') {
  4485. $where[] = ['job_apply.receiver_id', '=', $user_id];
  4486. }
  4487. var_dump($where, '-----------------test---------');
  4488. $result = jobApply::where($where)
  4489. // ->when(!empty($data['status1']), function ($query) use ($data) {
  4490. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4491. // })
  4492. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  4493. ->where('job_enum.egroup', '=', 'income')
  4494. ->where('job_hunting.status', 2) //已审核
  4495. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4496. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4497. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4498. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4499. //职位----是申请职位
  4500. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4501. ->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')
  4502. ->orderBy("job_hunting.updated_at", "desc")
  4503. ->limit($data['page_size'])
  4504. ->offset(($data['page'] - 1) * $data['page_size'])
  4505. ->get();
  4506. if (empty($result)) {
  4507. return Result::error("查询失败", 0);
  4508. }
  4509. $count = jobApply::where($where)
  4510. ->where('job_enum.egroup', '=', 'income')
  4511. ->where('job_hunting.status', 2) //已审核
  4512. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4513. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4514. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4515. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4516. //职位----是申请职位
  4517. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4518. ->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')
  4519. ->count();
  4520. $data = [
  4521. 'rows' => $result->toArray(),
  4522. 'count' => $count,
  4523. ];
  4524. return Result::success($data);
  4525. }
  4526. public function addJobHunting(array $data): array
  4527. {
  4528. date_default_timezone_set('Asia/Shanghai');
  4529. unset($data['company_name']);
  4530. unset($data['job_industry']);
  4531. unset($data['job_name']);
  4532. unset($data['department']);
  4533. unset($data['job_timeList']);
  4534. unset($data['job_content']);
  4535. unset($data['job_typename']); //不知道这是啥,
  4536. $data['created_at'] = date('Y-m-d H:i:s');
  4537. $data['updated_at'] = date('Y-m-d H:i:s');
  4538. //根据用户 user_id 只能添加一次
  4539. $result = JobHunting::where('user_id', $data['user_id'])->first();
  4540. if (!empty($result)) {
  4541. return Result::error("您已添加过求职信息", 0);
  4542. }
  4543. var_dump($result, '-----------------test---------');
  4544. if (isset($data['city_arr_id']) && !empty($data['city_arr_id'])) {
  4545. if (is_string($data['city_arr_id'])) {
  4546. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4547. $cityArr = json_decode($data['city_arr_id'], true);
  4548. // 确保 $cityArr 是数组
  4549. if (is_array($cityArr)) {
  4550. $data['city_id'] = end($cityArr);
  4551. }
  4552. } else {
  4553. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4554. if (is_array($data['city_arr_id'])) {
  4555. $data['city_id'] = end($data['city_arr_id']);
  4556. }
  4557. }
  4558. }
  4559. // 处理求职所绑定栏目
  4560. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id'])) {
  4561. if (is_string($data['cat_arr_id'])) {
  4562. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4563. // 先清理可能存在的无效 JSON 字符
  4564. $cleanedCatArrStr = trim($data['cat_arr_id']);
  4565. $catArr = json_decode($cleanedCatArrStr, true);
  4566. // 检查 JSON 解码是否成功且结果是数组
  4567. if (json_last_error() === JSON_ERROR_NONE && is_array($catArr)) {
  4568. $data['catid'] = end($catArr);
  4569. }
  4570. } else {
  4571. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4572. if (is_array($data['cat_arr_id'])) {
  4573. $data['catid'] = end($data['cat_arr_id']);
  4574. }
  4575. }
  4576. }
  4577. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4578. $this->sendMessage([
  4579. 'talk_type' => 600,
  4580. 'title' => $data['name'],
  4581. 'content' => '提交了审核',
  4582. 'messageType' => 11,
  4583. ]);
  4584. }
  4585. $result = JobHunting::create($data);
  4586. if (empty($result)) {
  4587. return Result::error("添加失败", 0);
  4588. }
  4589. return Result::success($result);
  4590. }
  4591. public function delJobHunting(array $data): array
  4592. {
  4593. $result = JobHunting::where('id', $data['id'])->delete();
  4594. if (empty($result)) {
  4595. return Result::error("删除失败", 0);
  4596. }
  4597. return Result::success($result);
  4598. }
  4599. public function updateJobHunting(array $data): array
  4600. {
  4601. //设置东八区
  4602. date_default_timezone_set('Asia/Shanghai');
  4603. unset($data['company_name']);
  4604. unset($data['job_industry']);
  4605. unset($data['job_name']);
  4606. unset($data['department']);
  4607. unset($data['job_timeList']);
  4608. unset($data['job_content']);
  4609. unset($data['job_typename']); //不知道这是啥,
  4610. $data['created_at'] = date('Y-m-d H:i:s');
  4611. $data['updated_at'] = date('Y-m-d H:i:s');
  4612. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  4613. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4614. $cityArr = json_decode($data['city_arr_id'], true);
  4615. $data['city_id'] = end($cityArr);
  4616. } else {
  4617. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4618. $data['city_id'] = end($data['city_arr_id']);
  4619. }
  4620. // 处理求职所绑定栏目
  4621. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_string($data['cat_arr_id'])) {
  4622. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4623. $catArr = json_decode($data['cat_arr_id'], true);
  4624. $data['catid'] = end($catArr);
  4625. } else {
  4626. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4627. $data['catid'] = end($data['cat_arr_id']);
  4628. }
  4629. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4630. $this->sendMessage([
  4631. 'talk_type' => 600,
  4632. 'title' => $data['name'],
  4633. 'content' => '提交了审核',
  4634. 'messageType' => 11,
  4635. ]);
  4636. }
  4637. $result = JobHunting::where('id', $data['id'])->update($data);
  4638. if (empty($result)) {
  4639. return Result::error("更新失败", 0);
  4640. }
  4641. return Result::success($result);
  4642. }
  4643. public function getJobHuntingInfo(array $data): array
  4644. {
  4645. $result = JobHunting::where('id', $data['id'])->first();
  4646. if (empty($result)) {
  4647. return Result::error("查询失败", 0);
  4648. }
  4649. return Result::success($result);
  4650. }
  4651. public function getJobHuntingData(array $data): array
  4652. {
  4653. $jobEnum = JobEnum::get();
  4654. $jobIndustry = JobIndustry::get();
  4655. $jobNature = JobNature::get();
  4656. $jobPosition = JobPosition::get();
  4657. $data = [
  4658. 'jobEnum' => $jobEnum,
  4659. 'jobIndustry' => $jobIndustry,
  4660. 'jobNature' => $jobNature,
  4661. 'jobPosition' => $jobPosition,
  4662. ];
  4663. return Result::success($data);
  4664. }
  4665. public function delJobHuntingInfo(array $data): array
  4666. {
  4667. $result = JobHunting::where('id', $data['id'])->delete();
  4668. return Result::success();
  4669. }
  4670. //20250324 通知,公告,消息
  4671. public function delNotice(array $data): array
  4672. {
  4673. $result = Notice::where('id', $data['id'])->delete();
  4674. if ($result) {
  4675. return Result::success();
  4676. } else {
  4677. return Result::error("删除失败", 0);
  4678. }
  4679. }
  4680. public function getNoticeInfo(array $data): array
  4681. {
  4682. $result = Notice::where('id', $data['id'])->first();
  4683. // var_dump($result['re_user_ids'], '--------------------');
  4684. if (empty($result)) {
  4685. return Result::error("查询失败", 0);
  4686. }
  4687. return Result::success($result);
  4688. }
  4689. public function readNotice(array $data): array
  4690. {
  4691. $result = Notice::where('id', $data['id'])->first();
  4692. // var_dump($result['re_user_ids'], '--------------------');
  4693. if (empty($result)) {
  4694. return Result::error("查询失败", 0);
  4695. }
  4696. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4697. $re_user_ids = json_decode($result['re_user_ids'], true);
  4698. var_dump($re_user_ids, '--------------1---test---------');
  4699. var_dump($data, '--------------1---test---------');
  4700. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4701. //如果已经存在,就不再添加
  4702. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4703. $read_id = json_decode($result['read_id'], true);
  4704. if (!is_array($read_id)) {
  4705. $read_id = [];
  4706. }
  4707. if (!in_array($data['user_id'], $read_id)) {
  4708. $read_id[] = $data['user_id'];
  4709. $result['read_id'] = json_encode($read_id);
  4710. Notice::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4711. }
  4712. } else {
  4713. //如果不存在,就添加
  4714. $result['read_id'] = json_encode([$data['user_id']]);
  4715. Notice::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4716. }
  4717. }
  4718. return Result::success($result);
  4719. }
  4720. public function addNotice(array $data): array
  4721. {
  4722. date_default_timezone_set('Asia/Shanghai');
  4723. $data['created_at'] = date('Y-m-d H:i:s');
  4724. $data['updated_at'] = date('Y-m-d H:i:s');
  4725. // $data['level'] = "1,2,3,4,5";
  4726. $level = json_decode($data['level'], true);
  4727. $user_id = UserInfo::
  4728. //city_id不是null
  4729. whereNotNull('city_id')
  4730. ->whereNotNull('department_id')
  4731. ->where(function ($query) use ($data) {
  4732. $query->where(function ($subQuery) use ($data) {
  4733. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4734. });
  4735. })
  4736. ->where(function ($query) use ($data) {
  4737. $query->where(function ($subQuery) use ($data) {
  4738. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4739. });
  4740. })
  4741. ->when(isset($level) && is_array($level), function ($query) use ($level) {
  4742. $query->whereIn('level', $level);
  4743. })
  4744. ->pluck('user_id')->toArray();
  4745. $user_id = array_unique($user_id);
  4746. $chat_ids = $user_id;
  4747. $user_id = json_encode($user_id);
  4748. $data['re_user_ids'] = $user_id;
  4749. $this->sendMessage([
  4750. 'talk_type' => 700,
  4751. 'title' => $data['title'],
  4752. 'content' => '提交了审核',
  4753. 'messageType' => 5,
  4754. ]);
  4755. $result = Notice::insertGetId($data);
  4756. if (empty($result)) {
  4757. return Result::error("添加失败", 0);
  4758. }
  4759. return Result::success($result);
  4760. }
  4761. public function updateNotice(array $data): array
  4762. {
  4763. date_default_timezone_set('Asia/Shanghai');
  4764. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  4765. $user_id = UserInfo::
  4766. //city_id不是null
  4767. whereNotNull('city_id')
  4768. ->whereNotNull('department_id')
  4769. ->where(function ($query) use ($data) {
  4770. $query->where(function ($subQuery) use ($data) {
  4771. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4772. });
  4773. })
  4774. ->where(function ($query) use ($data) {
  4775. $query->where(function ($subQuery) use ($data) {
  4776. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4777. });
  4778. })
  4779. ->pluck('user_id')->toArray();
  4780. $user_id = array_unique($user_id);
  4781. $user_id = json_encode($user_id);
  4782. $data['re_user_ids'] = $user_id;
  4783. $data['updated_at'] = date('Y-m-d H:i:s');
  4784. $this->sendMessage([
  4785. 'talk_type' => 700,
  4786. 'title' => $data['title'],
  4787. 'content' => '提交了审核',
  4788. 'messageType' => 5,
  4789. ]);
  4790. $result = Notice::where('id', $data['id'])->update($data);
  4791. return Result::success($result);
  4792. }
  4793. public function getNoticeList(array $data): array
  4794. {
  4795. $where = [];
  4796. //title
  4797. if (isset($data['title']) && !empty($data['title'])) {
  4798. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4799. }
  4800. //level
  4801. if (isset($data['level']) && !empty($data['level'])) {
  4802. $where[] = ['notice.level', '=', $data['level']];
  4803. }
  4804. //status
  4805. if (isset($data['status']) && !empty($data['status'])) {
  4806. $where[] = ['notice.status', '=', $data['status']];
  4807. }
  4808. //type
  4809. if (isset($data['type']) && !empty($data['type'])) {
  4810. $where[] = ['notice.type', '=', $data['type']];
  4811. }
  4812. var_dump($data, '------------11111-2----test---------');
  4813. if ($data['type_id'] == 10000) {
  4814. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4815. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4816. })
  4817. ->where($where)
  4818. ->orderBy('updated_at', 'desc')
  4819. ->limit($data['page_size'])
  4820. ->offset(($data['page'] - 1) * $data['page_size'])
  4821. ->get();
  4822. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4823. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4824. })
  4825. ->where($where)
  4826. ->orderBy('updated_at', 'desc')
  4827. ->count();
  4828. } else {
  4829. $result = Notice::where($where)
  4830. // ->where('user_id', $data['user_id'])
  4831. ->Where(function ($query) use ($data) {
  4832. $query->Where(function ($q) use ($data) {
  4833. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4834. ->orWhere('notice.user_id', $data['user_id']);
  4835. });
  4836. })
  4837. ->when(!empty($data['status1']), function ($query) use ($data) {
  4838. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4839. })
  4840. ->orderBy('updated_at', 'desc')
  4841. ->limit($data['page_size'])
  4842. ->offset(($data['page'] - 1) * $data['page_size'])
  4843. ->get();
  4844. $total = Notice::where($where)
  4845. ->when(!empty($data['status1']), function ($query) use ($data) {
  4846. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4847. })
  4848. // ->where('user_id', $data['user_id'])
  4849. ->Where(function ($query) use ($data) {
  4850. $query->Where(function ($q) use ($data) {
  4851. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4852. ->orWhere('notice.user_id', $data['user_id']);
  4853. });
  4854. })
  4855. ->count();
  4856. }
  4857. if (empty($result)) {
  4858. return Result::error("查询失败", 0);
  4859. }
  4860. $data = [
  4861. 'rows' => $result,
  4862. 'count' => $total,
  4863. ];
  4864. return Result::success($data);
  4865. }
  4866. public function noticeList(array $data): array
  4867. {
  4868. $where = [];
  4869. //title
  4870. if (isset($data['title']) && !empty($data['title'])) {
  4871. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4872. }
  4873. //level
  4874. if (isset($data['level']) && !empty($data['level'])) {
  4875. $where[] = ['notice.level', '=', $data['level']];
  4876. }
  4877. //status
  4878. if (isset($data['status']) && !empty($data['status'])) {
  4879. $where[] = ['notice.status', '=', $data['status']];
  4880. }
  4881. //type
  4882. if (isset($data['type']) && !empty($data['type'])) {
  4883. $where[] = ['notice.type', '=', $data['type']];
  4884. }
  4885. var_dump($data, '------------11111-2----test---------');
  4886. if ($data['type_id'] == 10000) {
  4887. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4888. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4889. })
  4890. ->where($where)
  4891. ->orderBy('updated_at', 'desc')
  4892. ->limit($data['page_size'])
  4893. ->offset(($data['page'] - 1) * $data['page_size'])
  4894. ->get();
  4895. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4896. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4897. })
  4898. ->where($where)
  4899. ->orderBy('updated_at', 'desc')
  4900. ->count();
  4901. } else {
  4902. $result = Notice::where($where)
  4903. // ->where('user_id', $data['user_id'])
  4904. ->Where(function ($query) use ($data) {
  4905. $query->Where(function ($q) use ($data) {
  4906. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4907. ->orWhere('notice.user_id', $data['user_id']);
  4908. });
  4909. })
  4910. ->when(!empty($data['status1']), function ($query) use ($data) {
  4911. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4912. })
  4913. ->orderBy('updated_at', 'desc')
  4914. ->limit($data['page_size'])
  4915. ->offset(($data['page'] - 1) * $data['page_size'])
  4916. ->get();
  4917. $total = Notice::where($where)
  4918. ->when(!empty($data['status1']), function ($query) use ($data) {
  4919. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4920. })
  4921. // ->where('user_id', $data['user_id'])
  4922. ->Where(function ($query) use ($data) {
  4923. $query->Where(function ($q) use ($data) {
  4924. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4925. ->orWhere('notice.user_id', $data['user_id']);
  4926. });
  4927. })
  4928. ->count();
  4929. }
  4930. if (empty($result)) {
  4931. return Result::error("查询失败", 0);
  4932. }
  4933. $data = [
  4934. 'rows' => $result,
  4935. 'count' => $total,
  4936. ];
  4937. return Result::success($data);
  4938. }
  4939. public function getNoticeDetail(array $data): array
  4940. {
  4941. $result = Notice::where('id', $data['id'])->first();
  4942. if (empty($result)) {
  4943. return Result::error("查询失败", 0);
  4944. }
  4945. return Result::success($result);
  4946. }
  4947. public function deleteNotice(array $data): array
  4948. {
  4949. $notice = Notice::where('id', $data['id'])->first();
  4950. if (empty($notice)) {
  4951. return Result::error("删除失败", 0);
  4952. }
  4953. $chat_group_id = $notice->group_id;
  4954. if ($chat_group_id) {
  4955. //删除群聊
  4956. ChatGroups::where('id', $chat_group_id)->delete();
  4957. //删除群成员
  4958. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  4959. //删除群聊记录
  4960. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  4961. }
  4962. $result = Notice::where('id', $data['id'])->delete();
  4963. return Result::success($result);
  4964. }
  4965. public function complaintList(array $data): array
  4966. {
  4967. var_dump($data, '---------1---------');
  4968. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4969. unset($data['type_id']);
  4970. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4971. $where = [];
  4972. if ($type_id != 10000 && empty($data['deal_user'])) {
  4973. // $where['complaint.user_id'] = $user_id;
  4974. }
  4975. if (!empty($data['title'])) {
  4976. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4977. }
  4978. if (!empty($data['department_id'])) {
  4979. $where['complaint.department_id'] = $data['department_id'];
  4980. }
  4981. if (!empty($data['deal'])) {
  4982. $where['complaint.deal'] = $data['deal'];
  4983. }
  4984. if (!empty($data['status'])) {
  4985. $where['complaint.status'] = $data['status'];
  4986. }
  4987. var_dump(!empty($data['deal_user']), '----------1');
  4988. var_dump($where, '----------2');
  4989. $result = Complaint::where($where)
  4990. ->when(!empty($data['status1']), function ($query) use ($data) {
  4991. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4992. })
  4993. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4994. //json re_user_ids data[user_id]是不是在里面
  4995. $query->Where(function ($q) use ($data) {
  4996. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4997. ->where('complaint.status', 2);
  4998. });
  4999. })
  5000. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  5001. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  5002. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  5003. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  5004. ->orderBy('updated_at', 'desc')
  5005. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  5006. //sql输出
  5007. if (empty($result)) {
  5008. return Result::error("暂无投诉信息", 0);
  5009. }
  5010. // 取出数据
  5011. $rows = $result->items();
  5012. $count = $result->total();
  5013. $responseData = [
  5014. 'rows' => $rows,
  5015. 'count' => $count,
  5016. ];
  5017. return Result::success($responseData);
  5018. }
  5019. public function getComplaintList(array $data): array
  5020. {
  5021. var_dump($data, '00000001000000000000');
  5022. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  5023. unset($data['type_id']);
  5024. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  5025. $where = [];
  5026. if ($type_id != 10000 && empty($data['deal_user'])) {
  5027. $where['complaint.user_id'] = $user_id;
  5028. }
  5029. if (!empty($data['title'])) {
  5030. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  5031. }
  5032. if (!empty($data['department_id'])) {
  5033. $where['complaint.department_id'] = $data['department_id'];
  5034. }
  5035. if (!empty($data['deal'])) {
  5036. $where['complaint.deal'] = $data['deal'];
  5037. }
  5038. if (!empty($data['status'])) {
  5039. $where['complaint.status'] = $data['status'];
  5040. }
  5041. var_dump(!empty($data['deal_user']), '----------1');
  5042. var_dump($where, '----------2');
  5043. $result = Complaint::where($where)
  5044. ->when(!empty($data['status1']), function ($query) use ($data) {
  5045. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  5046. })
  5047. // ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  5048. // //json re_user_ids data[user_id]是不是在里面
  5049. // $query->Where(function ($q) use ($data) {
  5050. // $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  5051. // ->where('complaint.status', 2);
  5052. // });
  5053. // })
  5054. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  5055. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  5056. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  5057. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  5058. ->orderBy('updated_at', 'desc')
  5059. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  5060. //sql输出
  5061. if (empty($result)) {
  5062. return Result::error("暂无投诉信息", 0);
  5063. }
  5064. // 取出数据
  5065. $rows = $result->items();
  5066. $count = $result->total();
  5067. $responseData = [
  5068. 'rows' => $rows,
  5069. 'count' => $count,
  5070. ];
  5071. return Result::success($responseData);
  5072. }
  5073. public function getComplaintInfo(array $data): array
  5074. {
  5075. $result = Complaint::where('id', $data['id'])->first();
  5076. if (empty($result)) {
  5077. return Result::error("查询失败", 0);
  5078. }
  5079. return Result::success($result);
  5080. }
  5081. public function readComplaint(array $data): array
  5082. {
  5083. $result = Complaint::where('id', $data['id'])->first();
  5084. if (empty($result)) {
  5085. return Result::error("查询失败", 0);
  5086. }
  5087. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  5088. $re_user_ids = json_decode($result['re_user_ids'], true);
  5089. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  5090. //如果已经存在,就不再添加
  5091. if (isset($result['read_id']) && !empty($result['read_id'])) {
  5092. $read_id = json_decode($result['read_id'], true);
  5093. if (!is_array($read_id)) {
  5094. $read_id = [];
  5095. }
  5096. if (!in_array($data['user_id'], $read_id)) {
  5097. $read_id[] = $data['user_id'];
  5098. $result['read_id'] = json_encode($read_id);
  5099. Complaint::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  5100. }
  5101. } else {
  5102. //如果不存在,就添加
  5103. $result['read_id'] = json_encode([$data['user_id']]);
  5104. Complaint::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  5105. }
  5106. }
  5107. return Result::success($result);
  5108. }
  5109. public function addComplaint(array $data): array
  5110. {
  5111. date_default_timezone_set('Asia/Shanghai');
  5112. $data['created_at'] = date('Y-m-d H:i:s');
  5113. $data['updated_at'] = date('Y-m-d H:i:s');
  5114. $this->sendMessage([
  5115. 'talk_type' => 800,
  5116. 'title' => $data['title'],
  5117. 'content' => '提交了审核',
  5118. 'messageType' => 6,
  5119. ]);
  5120. $result = Complaint::create($data);
  5121. return Result::success($result);
  5122. }
  5123. public function updateComplaint(array $data): array
  5124. {
  5125. date_default_timezone_set('Asia/Shanghai');
  5126. $data['updated_at'] = date('Y-m-d H:i:s');
  5127. $user_id = $data['user_id'] ?? 0;
  5128. $type_id = $data['type_id'] ?? 0;
  5129. unset($data['user_id']);
  5130. unset($data['type_id']);
  5131. $this->sendMessage([
  5132. 'talk_type' => 800,
  5133. 'title' => $data['title'],
  5134. 'content' => '提交了审核',
  5135. 'messageType' => 6,
  5136. ]);
  5137. $result = Complaint::where('id', $data['id'])->update($data);
  5138. return Result::success($result);
  5139. }
  5140. public function deleteComplaint(array $data): array
  5141. {
  5142. $result = Complaint::where('id', $data['id'])->delete();
  5143. return Result::success($result);
  5144. }
  5145. public function getComplainInfo(array $data): array
  5146. {
  5147. $result = Complaint::where('id', $data['id'])->first();
  5148. if (empty($result)) {
  5149. return Result::error("查询失败", 0);
  5150. }
  5151. return Result::success($result);
  5152. }
  5153. public function updateComplaintStatus(array $data): array
  5154. {
  5155. date_default_timezone_set('Asia/Shanghai');
  5156. $data['updated_at'] = date('Y-m-d H:i:s');
  5157. $user_id = $data['user_id'] ?? 0;
  5158. $type_id = $data['type_id'] ?? 0;
  5159. unset($data['user_id']);
  5160. unset($data['type_id']);
  5161. //处理, 写入处理人
  5162. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  5163. $data['real_deal_user'] = $user_id;
  5164. }
  5165. //如果是deal 23,则判断是不是处理人
  5166. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  5167. $complaintInof = Complaint::where('id', $data['id'])
  5168. ->where('real_deal_user', $user_id)
  5169. ->first();
  5170. if (empty($complaintInof)) {
  5171. return Result::error("处理人错误", 0);
  5172. }
  5173. }
  5174. $complaintInfo = Complaint::where('id', $data['id'])->first();
  5175. if ($data['status'] == 1) {
  5176. $this->sendMessage([
  5177. 'talk_type' => 800,
  5178. 'title' => $complaintInfo['title'],
  5179. 'content' => '提交了审核',
  5180. 'messageType' => 6,
  5181. ]);
  5182. }
  5183. if ($data['status'] == 2 && !isset($data['deal'])) {
  5184. $this->sendMessage([
  5185. 'talk_type' => 801,
  5186. 'title' => $complaintInfo['title'],
  5187. 'content' => '审核通过',
  5188. 'messageType' => 6,
  5189. 'user_id' => $complaintInfo['user_id'],
  5190. ]);
  5191. $this->sendMessage([
  5192. 'talk_type' => 802,
  5193. 'title' => $complaintInfo['title'],
  5194. 'content' => '待处理',
  5195. 'messageType' => 6,
  5196. 'user_id' => $complaintInfo['re_user_ids'],
  5197. ]);
  5198. }
  5199. if ($data['status'] == 3 && !isset($data['deal'])) {
  5200. $this->sendMessage([
  5201. 'talk_type' => 801,
  5202. 'title' => $complaintInfo['title'],
  5203. 'content' => '审核拒绝',
  5204. 'messageType' => 6,
  5205. 'user_id' => $complaintInfo['user_id'],
  5206. ]);
  5207. }
  5208. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 2) {
  5209. $this->sendMessage([
  5210. 'talk_type' => 802,
  5211. 'title' => $complaintInfo['title'],
  5212. 'content' => '处理中',
  5213. 'messageType' => 6,
  5214. 'user_id' => $complaintInfo['re_user_ids'],
  5215. ]);
  5216. }
  5217. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 4) {
  5218. $this->sendMessage([
  5219. 'talk_type' => 802,
  5220. 'title' => $complaintInfo['title'],
  5221. 'content' => '不予处理',
  5222. 'messageType' => 6,
  5223. 'user_id' => $complaintInfo['re_user_ids'],
  5224. ]);
  5225. }
  5226. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 3) {
  5227. $this->sendMessage([
  5228. 'talk_type' => 802,
  5229. 'title' => $complaintInfo['title'],
  5230. 'content' => '已完结',
  5231. 'messageType' => 6,
  5232. 'user_id' => $complaintInfo['re_user_ids'],
  5233. ]);
  5234. }
  5235. $result = complaint::where('id', $data['id'])->update($data);
  5236. return Result::success($result);
  5237. }
  5238. public function updateGoodStatus(array $data): array
  5239. {
  5240. $user_id = $data['user_id'] ?? 0;
  5241. $type_id = $data['type_id'] ?? 0;
  5242. unset($data['user_id']);
  5243. unset($data['type_id']);
  5244. $goodInfo = Good::where('id', $data['id'])->first();
  5245. if ($data['status'] == 2) {
  5246. $this->sendMessage([
  5247. 'talk_type' => 201,
  5248. 'title' => $goodInfo['name'],
  5249. 'content' => '审核通过',
  5250. 'messageType' => 3,
  5251. 'user_id' => $goodInfo['user_id'],
  5252. ]);
  5253. }
  5254. if ($data['status'] == 3) {
  5255. $this->sendMessage([
  5256. 'talk_type' => 201,
  5257. 'title' => $goodInfo['name'],
  5258. 'content' => '审核拒绝',
  5259. 'messageType' => 3,
  5260. 'user_id' => $goodInfo['user_id'],
  5261. ]);
  5262. }
  5263. if ($data['status'] == 1) {
  5264. $this->sendMessage([
  5265. 'talk_type' => 200,
  5266. 'title' => $goodInfo['name'],
  5267. 'content' => '提交了审核',
  5268. 'messageType' => 3,
  5269. ]);
  5270. }
  5271. $result = Good::where('id', $data['id'])->update($data);
  5272. return Result::success($result);
  5273. }
  5274. public function updateJobHuntingStatus(array $data): array
  5275. {
  5276. $user_id = $data['user_id'] ?? 0;
  5277. $type_id = $data['type_id'] ?? 0;
  5278. unset($data['user_id']);
  5279. unset($data['type_id']);
  5280. $jogHuntingInfo = JobHunting::where('id', $data['id'])->first();
  5281. if ($data['status'] == 2) {
  5282. $this->sendMessage([
  5283. 'talk_type' => 601,
  5284. 'title' => $jogHuntingInfo['name'],
  5285. 'content' => '审核通过',
  5286. 'messageType' => 11,
  5287. 'user_id' => $jogHuntingInfo['user_id'],
  5288. ]);
  5289. }
  5290. if ($data['status'] == 3) {
  5291. $this->sendMessage([
  5292. 'talk_type' => 601,
  5293. 'title' => $jogHuntingInfo['name'],
  5294. 'content' => '审核拒绝',
  5295. 'messageType' => 11,
  5296. 'user_id' => $jogHuntingInfo['user_id'],
  5297. ]);
  5298. }
  5299. if ($data['status'] == 1) {
  5300. $this->sendMessage([
  5301. 'talk_type' => 600,
  5302. 'title' => $jogHuntingInfo['name'],
  5303. 'content' => '提交了审核',
  5304. 'messageType' => 11,
  5305. ]);
  5306. }
  5307. $result = JobHunting::where('id', $data['id'])->update($data);
  5308. return Result::success($result);
  5309. }
  5310. public function updateNoticeStatus(array $data): array
  5311. {
  5312. $user_id = $data['user_id'] ?? 0;
  5313. $type_id = $data['type_id'] ?? 0;
  5314. unset($data['user_id']);
  5315. unset($data['type_id']);
  5316. //查询公告
  5317. $notice = Notice::where('id', $data['id'])->first();
  5318. if (empty($notice)) {
  5319. return Result::error("公告不存在", 0);
  5320. }
  5321. //$chat_ids 去除掉$data['user_id']
  5322. $chat_ids = json_decode($notice['re_user_ids'], true);
  5323. $chat_ids = array_diff($chat_ids, [$notice['user_id']]);
  5324. //如果公告的状态是2,且是群聊公告,且状态是1,则创建群聊,第一次审核通过的时候处理成群聊
  5325. if ($data['status'] == 2 && $notice['is_group'] == 1 && ($notice['status'] == 1 || $notice['status'] == 3) && empty($notice['group_id'])) {
  5326. //chat_group
  5327. $group_id = PublicData::uuid();
  5328. $groupData = [
  5329. 'id' => $group_id,
  5330. 'creator_id' => $notice['user_id'],
  5331. 'group_name' => $notice['group_name'] ?? '',
  5332. 'profile' => $notice['profile'] ?? 0,
  5333. ];
  5334. var_dump($groupData, '-----------------groupData-------');
  5335. $groupResult = ChatGroups::insertGetId($groupData);
  5336. var_dump($groupResult, '-----------------groupid-------');
  5337. $groupMemberData = [
  5338. 'id' => PublicData::uuid(),
  5339. 'user_id' => $notice['user_id'],
  5340. 'group_id' => $group_id,
  5341. 'leader' => 2,
  5342. ];
  5343. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  5344. //插入群成员表
  5345. $groupMemberDataUser = [];
  5346. $chatData = [];
  5347. foreach ($chat_ids as $key => $value) {
  5348. $groupMemberDataUser[] = [
  5349. 'id' => PublicData::uuid(),
  5350. 'user_id' => $value,
  5351. 'group_id' => $group_id,
  5352. 'leader' => 1,
  5353. ];
  5354. $chatData[] = [
  5355. 'user_id' => $value,
  5356. 'msg_type' => 1,
  5357. 'receiver_id' => $group_id,
  5358. 'content' => '通过通知创建群聊',
  5359. 'group_receiver_id' => $notice['user_id'],
  5360. 'action' => 'recieved',
  5361. 'created_at' => date('Y-m-d H:i:s'),
  5362. ];
  5363. }
  5364. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  5365. ChatGroupsMember::insert($groupMemberDataUser);
  5366. //插入一条管理员聊天记录
  5367. $chatData[] = [
  5368. 'user_id' => $notice['user_id'],
  5369. 'msg_type' => 1,
  5370. 'receiver_id' => $group_id,
  5371. 'content' => '通过通知创建群聊',
  5372. 'group_receiver_id' => $notice['user_id'],
  5373. 'action' => 'said',
  5374. 'created_at' => date('Y-m-d H:i:s'),
  5375. ];
  5376. var_dump($chatData, '-----------------chatData-------');
  5377. $chatResult = ChatRecords::insert($chatData);
  5378. //处理imp
  5379. $group = [
  5380. 'type' => 1,
  5381. 'name' => $notice['group_name'] ?? '',
  5382. 'profile' => '',
  5383. 'avatar' => '',
  5384. 'creator_id' => $notice['user_id'],
  5385. ];
  5386. $groupResult = GroupImp::insertGetId($group);
  5387. var_dump($groupResult, '获取imp group_id');
  5388. $groupMember = [
  5389. 'user_id' => $notice['user_id'],
  5390. 'group_id' => $groupResult,
  5391. 'leader' => 1,
  5392. 'join_time' => Date('Y-m-d H:i:s')
  5393. ];
  5394. $groupMemberResult = GroupMemberImp::insertGetId($groupMember);
  5395. $talk_session = [
  5396. 'user_id' => $notice['user_id'],
  5397. 'to_from_id' => $groupResult,
  5398. 'talk_mode' => 2,
  5399. 'created_at' => Date('Y-m-d H:i:s'),
  5400. 'updated_at' => Date('Y-m-d H:i:s'),
  5401. ];
  5402. $talk_session_result = GroupTalkImp::insertGetId($talk_session);
  5403. //被通知人员处理
  5404. foreach ($chat_ids as $key => $value) {
  5405. $groupMemberdata[] = [
  5406. 'user_id' => $value,
  5407. 'group_id' => $groupResult,
  5408. 'leader' => 3,
  5409. 'join_time' => Date('Y-m-d H:i:s')
  5410. ];
  5411. $talk_sessionData[] = [
  5412. 'user_id' => $value,
  5413. 'to_from_id' => $groupResult,
  5414. 'talk_mode' => 2,
  5415. 'created_at' => Date('Y-m-d H:i:s'),
  5416. 'updated_at' => Date('Y-m-d H:i:s'),
  5417. ];
  5418. }
  5419. $groupResult1 = GroupMemberImp::insert($groupMemberdata);
  5420. $talk_sessionResult = GroupTalkImp::insert($talk_sessionData);
  5421. $group_id = $groupResult;
  5422. //更新result的 group_id
  5423. $data['group_id'] = $group_id;
  5424. Notice::where(['id' => $data['id']])->update($data);
  5425. }
  5426. if (($data['status'] == 1 || $data['status'] == 3) && $notice['is_group'] == 1 && $notice['status'] == 2 && !empty($notice['group_id'])) {
  5427. //删除掉信息
  5428. GroupImp::where('id', $notice['group_id'])->delete();
  5429. GroupMemberImp::where('group_id', $notice['group_id'])->delete();
  5430. GroupTalkImp::where('to_from_id', $notice['group_id'])->delete();
  5431. foreach ($chat_ids as $key => $value) {
  5432. }
  5433. //聊天记录删除
  5434. //如果是群聊公告,且已经有群聊id,则更新公告的group_id
  5435. $data['group_id'] = null;
  5436. Notice::where(['id' => $data['id']])->update($data);
  5437. }
  5438. $result = Notice::where('id', $data['id'])->update($data);
  5439. $noticeInfo = Notice::where('id', $data['id'])->first();
  5440. if ($data['status'] == 2) {
  5441. $this->sendMessage([
  5442. 'talk_type' => 701,
  5443. 'title' => $noticeInfo['title'],
  5444. 'content' => '审核通过',
  5445. 'messageType' => 3,
  5446. 'user_id' => $noticeInfo['user_id'],
  5447. ]);
  5448. }
  5449. if ($data['status'] == 3) {
  5450. $this->sendMessage([
  5451. 'talk_type' => 701,
  5452. 'title' => $noticeInfo['title'],
  5453. 'content' => '审核拒绝',
  5454. 'messageType' => 3,
  5455. 'user_id' => $noticeInfo['user_id'],
  5456. ]);
  5457. }
  5458. if ($data['status'] == 1) {
  5459. $this->sendMessage([
  5460. 'talk_type' => 700,
  5461. 'title' => $noticeInfo['title'],
  5462. 'content' => '提交了审核',
  5463. 'messageType' => 3,
  5464. ]);
  5465. }
  5466. return Result::success($result);
  5467. }
  5468. public function getDUser(array $data): array
  5469. {
  5470. if (!empty($data['ids'])) {
  5471. $user = User::whereIn('id', $data['ids'])->getall();
  5472. if (empty($user)) {
  5473. return Result::error('无数据', 0);
  5474. }
  5475. return Result::success($user);
  5476. }
  5477. $where = [];
  5478. if (!empty($data['department_id'])) {
  5479. $where['department_id'] = $data['department_id'];
  5480. }
  5481. if (!empty($data['city_id'])) {
  5482. $where['city_id'] = $data['city_id'];
  5483. }
  5484. $result = User::where('type_id', 2)
  5485. ->where('status', 1)
  5486. ->where($where)
  5487. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  5488. ->get();
  5489. if (empty($result)) {
  5490. return Result::error("查询失败", 0);
  5491. }
  5492. return Result::success($result);
  5493. }
  5494. /**
  5495. * 验证导航名称是否重复
  5496. * @return void
  5497. */
  5498. public function checkCategoryName(array $data): array
  5499. {
  5500. $result = Category::when($data, function ($query) use ($data) {
  5501. if (isset($data['name']) && $data['name']) {
  5502. $query->where("name", $data['name']);
  5503. }
  5504. if (isset($data['id']) && $data['id']) {
  5505. $query->where("id", "!=", $data['id']);
  5506. }
  5507. })->first();
  5508. if ($result) {
  5509. return Result::error("已存在");
  5510. } else {
  5511. return Result::success();
  5512. }
  5513. }
  5514. //20250226 产品列表
  5515. // 20250306 -------招聘--------fr
  5516. /*
  5517. * 招聘列表
  5518. * */
  5519. public function getJobRecruitingList(array $data): array
  5520. {
  5521. $where = [];
  5522. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  5523. if ($data['checkout'] == 0) {
  5524. $job_status = [0, 2];
  5525. } else {
  5526. $job_status = [1];
  5527. }
  5528. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5529. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  5530. }
  5531. $user = User::where('id', $data['user_id'])->first();
  5532. if (empty($user)) {
  5533. return Result::error("用户不存在", 0);
  5534. }
  5535. // 3:企业会员
  5536. if ($user['type_id'] == 3) {
  5537. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  5538. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  5539. }
  5540. // 如果 $where 为空,则不添加 where 条件
  5541. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5542. return $query->where($where);
  5543. })
  5544. ->whereIn('job_recruiting.status', $job_status)
  5545. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5546. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  5547. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  5548. ->orderBy("updated_at", "desc")
  5549. ->offset(($data['page'] - 1) * $data['page_size'])
  5550. ->limit($data['page_size'])
  5551. ->get()
  5552. ->all();
  5553. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5554. return $query->where($where);
  5555. })
  5556. ->whereIn('job_recruiting.status', $job_status)
  5557. ->count();
  5558. if (empty($result)) {
  5559. return Result::error("暂无招聘信息", 0);
  5560. }
  5561. return Result::success($result);
  5562. }
  5563. /*
  5564. * 招聘信息添加
  5565. * */
  5566. public function addJobRecruiting(array $data): array
  5567. {
  5568. // var_dump('添加招聘进入news------data',$data);
  5569. // return Result::success($data);
  5570. $user = User::where('user.id', $data['user_id'])
  5571. ->where('user.status', 1)
  5572. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5573. ->select(
  5574. 'user.type_id',
  5575. 'user.mobile',
  5576. 'user.email',
  5577. 'user_info.business_name',
  5578. 'user_info.company_hy_id',
  5579. 'user_info.company_nature',
  5580. 'user_info.company_size',
  5581. 'user_info.introduction',
  5582. 'user_info.real_name',
  5583. 'user_info.company_url',
  5584. 'user_info.address_arr_id',
  5585. 'user_info.address'
  5586. )
  5587. ->first();
  5588. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5589. return Result::error("用户不存在", 0);
  5590. }
  5591. $web = Website::where('id', $data['website_id'])->first();
  5592. if (empty($web)) {
  5593. return Result::error("网站不存在", 0);
  5594. }
  5595. // var_dump('添加招聘进入news---user---user',$user);
  5596. // 处理招聘关键词
  5597. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5598. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5599. } else {
  5600. Jieba::init(); // 初始化 jieba-php
  5601. Finalseg::init();
  5602. $segList = Jieba::cut($data['title']);
  5603. $segList1 = array_slice($segList, 0, 8);
  5604. $data['keyword'] = implode(',', $segList1);
  5605. }
  5606. if (!isset($data['seo_description']) || empty($data['seo_description'])) {
  5607. $content = $data['description'];
  5608. // 去除 <style> 和 <script> 标签及其内容
  5609. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5610. // 去除所有 HTML 标签
  5611. $content = strip_tags($content);
  5612. // 去除 HTML 实体
  5613. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5614. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5615. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5616. // 去除多余空白
  5617. $content = preg_replace('/\s+/u', '', $content);
  5618. // 截取 100 个字符
  5619. $data['seo_description'] = mb_substr($content, 0, 100);
  5620. }
  5621. // return Result::success($user);
  5622. $data['action_id'] = $data['user_id'] ?? null;
  5623. $data['user_type'] = $user['type_id'] ?? null;
  5624. $data['cat_arr_id'] = isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) ? array_values(array_unique($data['cat_arr_id'])) : [];
  5625. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5626. $data['catid'] = end($data['cat_arr_id']);
  5627. } else {
  5628. $data['catid'] = 0;
  5629. }
  5630. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? array_values(array_unique($data['city_arr_id'])) : [];
  5631. $data['cat_arr_id'] = isset($data['cat_arr_id']) && $data['cat_arr_id'] != [] ? json_encode(array_map('intval', $data['cat_arr_id'])) : '[]';
  5632. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '[]';
  5633. // 公司地址 管理员必填
  5634. $data['address_arr_id'] = isset($data['address_arr_id']) && !empty($data['address_arr_id']) ? array_values(array_unique($data['address_arr_id'])) : [];
  5635. $data['address_arr_id'] = isset($data['address_arr_id']) && $data['address_arr_id'] != [] ? json_encode(array_map('intval', $data['address_arr_id'])) : '[]';
  5636. // 管理员-企业相关信息
  5637. $company = [
  5638. // 'user_id' => $data['user_id']?? null,
  5639. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5640. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5641. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5642. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5643. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5644. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5645. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5646. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5647. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5648. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5649. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5650. ];
  5651. //去掉相关企业信息
  5652. $job = array_diff_key($data, array_flip(array_keys($company)));
  5653. // var_dump('添加招聘进入news---job---user',$job);
  5654. Db::beginTransaction();
  5655. try {
  5656. // // 先添加职位相关信息
  5657. if ($user['type_id'] == 10000) {
  5658. $job['status'] = 1;
  5659. }
  5660. $job['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5661. $job['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5662. $job['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5663. $job['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5664. $job['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5665. $job['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5666. $job['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5667. // return Result::success($job);
  5668. $jobId = JobRecruiting::insertGetId($job);
  5669. if (empty($jobId)) {
  5670. Db::rollBack();
  5671. return Result::error("添加失败");
  5672. }
  5673. // 添加公司信息
  5674. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5675. $company['job_id'] = $jobId;
  5676. $company['user_type'] = isset($user['type_id']) && $user['type_id'] !== '' ? $user['type_id'] : null;
  5677. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5678. if ($user['type_id'] == 10000) {
  5679. // 管理员添加企业信息
  5680. $companyId = JobCompany::insertGetId($company);
  5681. if (empty($companyId)) {
  5682. Db::rollBack();
  5683. return Result::error("添加失败");
  5684. }
  5685. } else {
  5686. // 企业会员添加企业信息
  5687. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5688. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5689. $company['user_type'] = isset($data['user_type']) && $data['user_type'] !== '' ? $data['user_type'] : null;
  5690. $company['job_id'] = $jobId;
  5691. $companyId = JobCompany::insertGetId($company);
  5692. if (empty($companyId)) {
  5693. Db::rollBack();
  5694. return Result::error("添加失败");
  5695. }
  5696. }
  5697. Db::commit();
  5698. $result = [
  5699. 'job_id' => $jobId,
  5700. 'company_id' => $companyId,
  5701. ];
  5702. return Result::success($result);
  5703. } catch (\Exception $e) {
  5704. Db::rollBack();
  5705. return Result::error($e->getMessage(), 0);
  5706. }
  5707. // return Result::success($result);
  5708. }
  5709. /*
  5710. * 获取招聘信息详情
  5711. * */
  5712. public function getJobRecruitingInfo(array $data): array
  5713. {
  5714. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  5715. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5716. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5717. ->select(
  5718. 'job_recruiting.*',
  5719. 'website.website_name as website_name',
  5720. 'job_company.business_name',
  5721. 'job_company.company_hy_id',
  5722. 'job_company.company_size',
  5723. 'job_company.company_nature',
  5724. 'job_company.introduction',
  5725. 'job_company.real_name',
  5726. 'job_company.mobile',
  5727. 'job_company.company_url',
  5728. 'job_company.address_arr_id',
  5729. 'job_company.address',
  5730. 'job_company.email'
  5731. )
  5732. ->first();
  5733. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  5734. if (!empty($cityId)) {
  5735. if (isset($cityId[1]) && $cityId[1] != null) {
  5736. $city = District::where('id', $cityId[1])->first(['name']);
  5737. } else {
  5738. $city = District::where('id', $cityId[0])->first(['name']);
  5739. }
  5740. $result['city'] = $city['name'] ?? '';
  5741. }
  5742. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  5743. if (is_array($addressId) && !empty($addressId)) {
  5744. $address = District::whereIn('id', $addressId)
  5745. ->orderBy('level', 'asc')
  5746. ->get(['name'])
  5747. ->pluck('name')
  5748. ->implode('');
  5749. // $job->address_name = $address ?? '';
  5750. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  5751. }
  5752. if (empty($result)) {
  5753. return Result::error("招聘信息不存在", 0);
  5754. }
  5755. // return Result::success($job);
  5756. return Result::success($result);
  5757. }
  5758. /*
  5759. * 修改招聘信息
  5760. * */
  5761. public function upJobRecruiting(array $data): array
  5762. {
  5763. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  5764. // return Result::success($job);
  5765. if (empty($job)) {
  5766. return Result::error("招聘信息不存在", 0);
  5767. }
  5768. $user = User::where('id', $data['user_id'])->first();
  5769. // return Result::success($user);
  5770. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5771. return Result::error("用户不存在", 0);
  5772. }
  5773. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5774. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5775. }
  5776. // 处理招聘关键词
  5777. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5778. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5779. } else {
  5780. Jieba::init(); // 初始化 jieba-php
  5781. Finalseg::init();
  5782. $segList = Jieba::cut($data['title']);
  5783. $segList1 = array_slice($segList, 0, 8);
  5784. $data['keyword'] = implode(',', $segList1);
  5785. }
  5786. if (!isset($data['seo_description']) || empty($data['seo_description'])) {
  5787. $content = $data['description'];
  5788. // 去除 <style> 和 <script> 标签及其内容
  5789. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5790. // 去除所有 HTML 标签
  5791. $content = strip_tags($content);
  5792. // 去除 HTML 实体
  5793. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5794. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5795. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5796. // 去除多余空白
  5797. $content = preg_replace('/\s+/u', '', $content);
  5798. // 截取 100 个字符
  5799. $data['seo_description'] = mb_substr($content, 0, 100);
  5800. }
  5801. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  5802. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5803. $data['catid'] = end($data['cat_arr_id']);
  5804. } else {
  5805. }
  5806. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  5807. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  5808. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  5809. // 公司地址 管理员必填
  5810. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  5811. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5812. // 管理员-企业相关信息
  5813. $company = [
  5814. // 'user_id' => $data['user_id']?? null,
  5815. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5816. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5817. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5818. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5819. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5820. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5821. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5822. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5823. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5824. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5825. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5826. ];
  5827. //去掉相关企业信息
  5828. $data = array_diff_key($data, array_flip(array_keys($company)));
  5829. $jobId = $data['id'];
  5830. $web = $data['website_id'];
  5831. $data['action_id'] = $data['user_id'];
  5832. unset($data['user_id']);
  5833. unset($data['user_type']);
  5834. unset($data['id']);
  5835. unset($data['website_id']);
  5836. // return Result::success($data);
  5837. Db::beginTransaction();
  5838. try {
  5839. // 管理员修改招聘信息
  5840. if ($user['type_id'] == 10000) {
  5841. $data['website_id'] = $web;
  5842. $company['website_id'] = $data['website_id'];
  5843. $data['status'] = 1;
  5844. } else {
  5845. $data['status'] = 0;
  5846. }
  5847. $data['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5848. $data['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5849. $data['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5850. $data['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5851. $data['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5852. $data['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5853. $data['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5854. // return Result::success($job);
  5855. // Db::rollBack();
  5856. // return Result::success($company);
  5857. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  5858. $this->sendMessage([
  5859. 'talk_type' => 500,
  5860. 'title' => $data['title'],
  5861. 'content' => '提交了审核',
  5862. 'messageType' => 10,
  5863. ]);
  5864. }
  5865. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  5866. if (empty($result['job'])) {
  5867. Db::rollBack();
  5868. return Result::error("修改招聘信息失败");
  5869. }
  5870. // 管理员修改企业相关信息
  5871. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  5872. if (empty($result['company'])) {
  5873. Db::rollBack();
  5874. return Result::error("修改企业相关信息失败");
  5875. }
  5876. Db::commit();
  5877. // return Result::success($result);
  5878. } catch (\Exception $e) {
  5879. Db::rollBack();
  5880. return Result::error($e->getMessage(), 0);
  5881. }
  5882. return Result::success($result);
  5883. }
  5884. /*
  5885. * 招聘信息删除
  5886. * */
  5887. public function delJobRecruiting(array $data): array
  5888. {
  5889. $user = User::where('id', $data['user_id'])->first();
  5890. if (empty($user)) {
  5891. return Result::error("用户不存在", 0);
  5892. }
  5893. $job = JobRecruiting::where('id', $data['id'])->first();
  5894. if (empty($job)) {
  5895. return Result::error("招聘信息不存在", 0);
  5896. }
  5897. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5898. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5899. }
  5900. Db::beginTransaction();
  5901. try {
  5902. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  5903. if (empty($result['job'])) {
  5904. Db::rollBack();
  5905. return Result::error("删除招聘信息失败");
  5906. }
  5907. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  5908. if (empty($result['company'])) {
  5909. Db::rollBack();
  5910. return Result::error("删除企业相关信息失败");
  5911. }
  5912. Db::commit();
  5913. } catch (\Exception $e) {
  5914. Db::rollBack();
  5915. return Result::error($e->getMessage(), 0);
  5916. }
  5917. return Result::success($result);
  5918. }
  5919. /*
  5920. * 获取公司信息
  5921. * */
  5922. public function getJobCompany(array $data): array
  5923. {
  5924. $user = User::where('user.id', $data['user_id'])
  5925. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5926. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  5927. ->first();
  5928. // return Result::success($user);
  5929. if (empty($user)) {
  5930. return Result::error("用户不存在", 0);
  5931. }
  5932. if ($user['type_id'] == 3) {
  5933. $result = [
  5934. // 'id' => 0,
  5935. 'user_id' => $data['user_id'],
  5936. 'website_id' => $data['website_id'],
  5937. 'business_name' => $user['business_name'], // 企业名称
  5938. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  5939. 'company_nature' => $user['company_nature'], // 公司性质
  5940. 'company_size' => $user['company_size'], // 公司规模
  5941. 'introduction' => $user['introduction'], // 公司简介
  5942. 'real_name' => $user['real_name'], // 企业联系人
  5943. 'mobile' => $user['mobile'], // 企业联系电话
  5944. 'company_url' => $user['company_url'], // 企业网址
  5945. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  5946. 'address' => $user['address'], // 企业地址
  5947. 'email' => $user['email'], // 企业邮箱
  5948. ];
  5949. } else {
  5950. return Result::error("用户类型错误", 0);
  5951. }
  5952. if (empty($result)) {
  5953. return Result::error("公司信息不存在", 0);
  5954. }
  5955. return Result::success($result);
  5956. }
  5957. /*
  5958. * 修改公司信息
  5959. * */
  5960. public function upJobCompany(array $data): array
  5961. {
  5962. // return Result::success($data);
  5963. $user = User::where('user.id', $data['user_id'])
  5964. ->where('user.status', 1)
  5965. ->select('user.user_name', 'user.type_id')
  5966. ->first();
  5967. if (empty($user)) {
  5968. return Result::error("用户不存在", 0);
  5969. }
  5970. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5971. $job_company = JobCompany::where('user_id', $data['user_id'])->first();
  5972. $company = [
  5973. 'business_name' => $data['business_name'], // 企业名称
  5974. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5975. 'company_nature' => $data['company_nature'], // 公司性质
  5976. 'company_size' => $data['company_size'], // 公司规模
  5977. 'introduction' => $data['introduction'], // 公司简介
  5978. // 'real_name' => $data['real_name'], // 企业联系人
  5979. 'company_url' => $data['company_url'], // 企业网址
  5980. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5981. 'address' => $data['address'], // 企业详细地址
  5982. // 'email' => $data['email'], // 企业邮箱
  5983. ];
  5984. if ($user['type_id'] == 3) {
  5985. Db::beginTransaction();
  5986. try {
  5987. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  5988. 'business_name' => $data['business_name'], // 企业名称
  5989. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5990. 'company_nature' => $data['company_nature'], // 公司性质
  5991. 'company_size' => $data['company_size'], // 公司规模
  5992. 'introduction' => $data['introduction'], // 公司简介
  5993. // 'real_name' => $data['real_name'], // 企业联系人
  5994. 'company_url' => $data['company_url'], // 企业网址
  5995. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5996. 'address' => $data['address'], // 企业详细地址
  5997. ]);
  5998. if (empty($result['userinfo'])) {
  5999. Db::rollBack();
  6000. return Result::error('修改企业会员信息失败!');
  6001. }
  6002. $result['user'] = User::where('id', $data['user_id'])->update([
  6003. 'email' => $data['email'], // 企业邮箱
  6004. ]);
  6005. if (empty($result['user'])) {
  6006. Db::rollBack();
  6007. return Result::error('修改个人中心信息失败!');
  6008. }
  6009. // 该企业会员若是未发布招聘信息则暂无该企业会员的企业信息
  6010. if (!empty($job_company)) {
  6011. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  6012. if (empty($result['job_company'])) {
  6013. Db::rollBack();
  6014. return Result::error('修改企业会员信息失败!');
  6015. }
  6016. }
  6017. Db::commit();
  6018. return Result::success($result);
  6019. } catch (\Exception $e) {
  6020. Db::rollBack();
  6021. return Result::error($e->getMessage(), 0);
  6022. }
  6023. } else {
  6024. return Result::error("用户类型错误", 0);
  6025. }
  6026. }
  6027. /*
  6028. * 获取省-市
  6029. * */
  6030. public function getJobRecruitingArea(array $data): array
  6031. {
  6032. if (isset($data['pid']) && $data['pid'] != null) {
  6033. $result = District::where('pid', $data['pid'])->get()->all();
  6034. } else {
  6035. $result = District::where('level', 1)->get()->all();
  6036. }
  6037. if (empty($result)) {
  6038. return Result::error("暂无此省市", 0);
  6039. }
  6040. return Result::success($result);
  6041. }
  6042. /*
  6043. * 获取行业分类
  6044. * */
  6045. public function getIndustry(array $data): array
  6046. {
  6047. $result = JobIndustry::get()->all();
  6048. if (empty($result)) {
  6049. return Result::error("暂无行业分类", 0);
  6050. }
  6051. return Result::success($result);
  6052. }
  6053. /*
  6054. * 获取职位
  6055. * */
  6056. public function getPositionList(array $data): array
  6057. {
  6058. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  6059. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  6060. } else {
  6061. $result = JobPosition::where('zwpid', 0)->get()->all();
  6062. }
  6063. if (empty($result)) {
  6064. return Result::error("暂无此职位", 0);
  6065. }
  6066. return Result::success($result);
  6067. }
  6068. /*
  6069. * 获取工作性质-菜单
  6070. * */
  6071. public function getJobNature(array $data): array
  6072. {
  6073. $result = JobEnum::where('egroup', 'nature')->get()->all();
  6074. if (empty($result)) {
  6075. return Result::error("暂无工作性质", 0);
  6076. }
  6077. return Result::success($result);
  6078. }
  6079. /*
  6080. * 获取工作经验-菜单
  6081. * */
  6082. public function getExperience(array $data): array
  6083. {
  6084. $result = JobEnum::where('egroup', 'years')->get()->all();
  6085. if (empty($result)) {
  6086. return Result::error("暂无工作经验", 0);
  6087. }
  6088. return Result::success($result);
  6089. }
  6090. /*
  6091. * 获取学历-菜单
  6092. * */
  6093. public function getEducation(array $data): array
  6094. {
  6095. $result = JobEnum::where('egroup', 'education')->get()->all();
  6096. if (empty($result)) {
  6097. return Result::error("暂无学历", 0);
  6098. }
  6099. return Result::success($result);
  6100. }
  6101. /*
  6102. * 获取薪资-菜单
  6103. * */
  6104. public function getSalary(array $data): array
  6105. {
  6106. $result = JobEnum::where('egroup', 'income')->get()->all();
  6107. if (empty($result)) {
  6108. return Result::error("暂无薪资", 0);
  6109. }
  6110. return Result::success($result);
  6111. }
  6112. /*
  6113. * 获取语言-菜单
  6114. * */
  6115. public function getLanguage(array $data): array
  6116. {
  6117. $result = JobEnum::where('egroup', 'language')->get()->all();
  6118. if (empty($result)) {
  6119. return Result::error("暂无语言", 0);
  6120. }
  6121. return Result::success($result);
  6122. }
  6123. /*
  6124. * 获取掌握程度-菜单
  6125. * */
  6126. public function getLevel(array $data): array
  6127. {
  6128. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  6129. if (empty($result)) {
  6130. return Result::error("暂无工作性质", 0);
  6131. }
  6132. return Result::success($result);
  6133. }
  6134. // 公司信息
  6135. /*
  6136. * 获取公司性质-菜单
  6137. * */
  6138. public function getCompanyNature(array $data): array
  6139. {
  6140. $result = JobNature::get()->all();
  6141. if (empty($result)) {
  6142. return Result::error("暂无公司性质", 0);
  6143. }
  6144. return Result::success($result);
  6145. }
  6146. /*
  6147. * 获取公司规模-菜单
  6148. * */
  6149. public function getCompanySize(array $data): array
  6150. {
  6151. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  6152. if (empty($result)) {
  6153. return Result::error("暂无公司规模", 0);
  6154. }
  6155. return Result::success($result);
  6156. }
  6157. /*
  6158. * 招聘信息审核
  6159. * */
  6160. public function checkJobRecruiting(array $data): array
  6161. {
  6162. $user = User::where('id', $data['user_id'])->first();
  6163. if (empty($user)) {
  6164. return Result::error("用户不存在", 0);
  6165. }
  6166. $job = JobRecruiting::where('id', $data['id'])->first();
  6167. if (empty($job)) {
  6168. return Result::error("招聘信息不存在", 0);
  6169. }
  6170. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  6171. if ($user['type_id'] != 10000) {
  6172. return Result::error("用户暂无权限审核此招聘信息!", 0);
  6173. }
  6174. // 驳回原因
  6175. if ($data['status'] == 2) {
  6176. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  6177. }
  6178. $data['action_id'] = $data['user_id'];
  6179. unset($data['user_id']);
  6180. if ($data['status'] == 1) {
  6181. $this->sendMessage([
  6182. 'talk_type' => 501,
  6183. 'title' => $job['title'],
  6184. 'content' => '审核通过',
  6185. 'messageType' => 10,
  6186. 'user_id' => $job['user_id'],
  6187. ]);
  6188. }
  6189. if ($data['status'] == 2) {
  6190. $this->sendMessage([
  6191. 'talk_type' => 501,
  6192. 'title' => $job['title'],
  6193. 'content' => '审核拒绝',
  6194. 'messageType' => 10,
  6195. 'user_id' => $job['user_id'],
  6196. ]);
  6197. }
  6198. if ($data['status'] == 0) {
  6199. $this->sendMessage([
  6200. 'talk_type' => 500,
  6201. 'title' => $job['title'],
  6202. 'content' => '提交了审核',
  6203. 'messageType' => 10,
  6204. ]);
  6205. }
  6206. $result = JobRecruiting::where('id', $data['id'])->update($data);
  6207. if (empty($result)) {
  6208. return Result::error("审核失败", 0);
  6209. }
  6210. return Result::success($result);
  6211. }
  6212. public function myApplyList(array $data): array
  6213. {
  6214. var_dump($data, '------参数');
  6215. $user = User::where('id', $data['user_id'])->first();
  6216. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6217. return Result::error("用户不存在", 0);
  6218. }
  6219. // 1:个人会员 职场机会
  6220. if ($user['type_id'] == 1) {
  6221. $where['user_id'] = $user['id'];
  6222. }
  6223. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  6224. $query->where('user_id', $user['id']);
  6225. })
  6226. ->pluck('recruit_id');
  6227. $where = [];
  6228. if (isset($data['salary']) && $data['salary'] != null) {
  6229. $where['job_recruiting.salary'] = $data['salary'];
  6230. }
  6231. if (isset($data['experience']) && $data['experience'] != null) {
  6232. $where['job_recruiting.experience'] = $data['experience'];
  6233. }
  6234. if (isset($data['business_name']) && $data['business_name'] != null) {
  6235. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6236. }
  6237. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6238. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6239. ->where($where);
  6240. // ->count();
  6241. $count = $query->count();
  6242. $query = clone $query;
  6243. $job = $query
  6244. ->leftJoin('job_enum as income_enum', function ($join) {
  6245. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6246. ->where('income_enum.egroup', 'income');
  6247. })
  6248. ->leftJoin('job_enum as years_enum', function ($join) {
  6249. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6250. ->where('years_enum.egroup', 'years');
  6251. })
  6252. // ->where($where)
  6253. ->orderBy('job_recruiting.updated_at', 'desc')
  6254. ->select(
  6255. 'job_recruiting.id',
  6256. 'job_recruiting.title',
  6257. 'job_company.business_name',
  6258. 'income_enum.evalue as salary_evalue',
  6259. 'income_enum.ename as salary_ename',
  6260. 'years_enum.evalue as experience_evalue',
  6261. 'years_enum.ename as experience_ename',
  6262. 'job_recruiting.updated_at'
  6263. )
  6264. ->offset(($data['page'] - 1) * $data['pageSize'])
  6265. ->limit($data['pageSize'])
  6266. ->get()
  6267. ->all();
  6268. if (empty($job)) {
  6269. return Result::error("暂无招聘信息", 0);
  6270. }
  6271. $result = [
  6272. 'row' => $job,
  6273. 'count' => $count,
  6274. ];
  6275. return Result::success($result);
  6276. }
  6277. public function readJobApply(array $data): array
  6278. {
  6279. $result = JobApply::where('id', $data['id'])->first();
  6280. if (empty($result)) {
  6281. return Result::error("查询失败", 0);
  6282. }
  6283. $result = JobApply::where('id', $data['id'])->update([
  6284. 'status' => 2,
  6285. ]);
  6286. return Result::success($result);
  6287. }
  6288. /*
  6289. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  6290. * */
  6291. public function getRecruitingList(array $data): array
  6292. {
  6293. $user = User::where('id', $data['user_id'])->first();
  6294. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6295. return Result::error("用户不存在", 0);
  6296. }
  6297. // 1:个人会员 职场机会
  6298. if ($user['type_id'] == 1) {
  6299. $where['user_id'] = $user['id'];
  6300. }
  6301. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  6302. $query->where('receiver_id', $user['id']);
  6303. })
  6304. ->pluck('recruit_id');
  6305. // return Result::success($recruitingId);
  6306. $where = [];
  6307. if (isset($data['salary']) && $data['salary'] != null) {
  6308. $where['job_recruiting.salary'] = $data['salary'];
  6309. }
  6310. if (isset($data['experience']) && $data['experience'] != null) {
  6311. $where['job_recruiting.experience'] = $data['experience'];
  6312. }
  6313. if (isset($data['business_name']) && $data['business_name'] != null) {
  6314. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6315. }
  6316. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6317. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6318. ->where($where);
  6319. // ->count();
  6320. $count = $query->count();
  6321. $query = clone $query;
  6322. $job = $query
  6323. ->leftJoin('job_enum as income_enum', function ($join) {
  6324. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6325. ->where('income_enum.egroup', 'income');
  6326. })
  6327. ->leftJoin('job_enum as years_enum', function ($join) {
  6328. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6329. ->where('years_enum.egroup', 'years');
  6330. })
  6331. // ->where($where)
  6332. ->orderBy('job_recruiting.updated_at', 'desc')
  6333. ->select(
  6334. 'job_recruiting.id',
  6335. 'job_recruiting.title',
  6336. 'job_company.business_name',
  6337. 'income_enum.evalue as salary_evalue',
  6338. 'income_enum.ename as salary_ename',
  6339. 'years_enum.evalue as experience_evalue',
  6340. 'years_enum.ename as experience_ename',
  6341. 'job_recruiting.updated_at'
  6342. )
  6343. ->offset(($data['page'] - 1) * $data['pageSize'])
  6344. ->limit($data['pageSize'])
  6345. ->get()
  6346. ->all();
  6347. if (empty($job)) {
  6348. return Result::error("暂无招聘信息", 0);
  6349. }
  6350. $result = [
  6351. 'row' => $job,
  6352. 'count' => $count,
  6353. ];
  6354. return Result::success($result);
  6355. }
  6356. /*
  6357. * 获取企业会员-招聘信息列表
  6358. * */
  6359. public function getRecruitingInfo(array $data): array
  6360. {
  6361. $user = User::where('id', $data['user_id'])->first();
  6362. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6363. return Result::error("用户不存在", 0);
  6364. }
  6365. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  6366. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6367. ->select(
  6368. 'job_recruiting.*',
  6369. 'job_company.business_name',
  6370. 'job_company.company_hy_id',
  6371. 'job_company.company_size',
  6372. 'job_company.company_nature',
  6373. 'job_company.introduction',
  6374. 'job_company.real_name',
  6375. 'job_company.mobile',
  6376. 'job_company.company_url',
  6377. 'job_company.address_arr_id',
  6378. 'job_company.address',
  6379. 'job_company.email'
  6380. )
  6381. ->get();
  6382. if (empty($recruiting)) {
  6383. return Result::error("暂无招聘信息", 0);
  6384. }
  6385. return Result::success($recruiting);
  6386. }
  6387. /*
  6388. * 获取企业会员-我的沟通
  6389. * */
  6390. public function getJobResumeList(array $data): array
  6391. {
  6392. $user = User::where('id', $data['user_id'])->first();
  6393. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  6394. return Result::error("用户不存在", 0);
  6395. }
  6396. $where = [];
  6397. if (isset($data['salary']) && $data['salary'] != null) {
  6398. $where['job_hunting.salary'] = $data['salary'];
  6399. }
  6400. if (isset($data['user_name']) && $data['user_name'] != null) {
  6401. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  6402. }
  6403. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  6404. $query->where('job_resume.user_id', $user['id']);
  6405. })
  6406. ->when(!empty($where), function ($query) use ($where) {
  6407. $query->where($where);
  6408. })
  6409. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  6410. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  6411. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  6412. ->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');
  6413. $count = $job->count();
  6414. if ($count == 0) {
  6415. return Result::error("暂无沟通记录", 0);
  6416. }
  6417. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  6418. ->offset(($data['page'] - 1) * $data['pageSize'])
  6419. ->limit($data['pageSize'])
  6420. ->get();
  6421. if (empty($jobs)) {
  6422. return Result::error("暂无沟通记录", 0);
  6423. }
  6424. $result['row'] = $this->processJob($jobs, '');
  6425. $result['count'] = $count;
  6426. return Result::success($result);
  6427. }
  6428. public function readJobResume(array $data): array
  6429. {
  6430. $result = JobResume::where('id', $data['id'])->first();
  6431. if (empty($result)) {
  6432. return Result::error("查询失败", 0);
  6433. }
  6434. $result = JobResume::where('id', $data['id'])->update([
  6435. 'status' => 2,
  6436. ]);
  6437. return Result::success($result);
  6438. }
  6439. // 20250306 招聘
  6440. //20250422 书刊音像
  6441. public function addBook(array $data): array
  6442. {
  6443. $user_id = $data['user_id'] ?? 0;
  6444. $type_id = $data['type_id'] ?? 0;
  6445. // $website_id = $data['website_id'] ?? 0;
  6446. // unset($data['user_id']);
  6447. unset($data['type_id']);
  6448. // unset($data['website_id']);
  6449. //处理数组
  6450. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6451. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6452. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6453. if ($data['img_url'] == '') {
  6454. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6455. preg_match_all($reg, $data['detail'], $matches);
  6456. if (isset($matches[1][0])) {
  6457. //截取varchar240
  6458. $data['img_url'] = substr($matches[1][0], 0, 240);
  6459. }
  6460. }
  6461. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  6462. //提取标题+内容中的关键词
  6463. $data['keyword'] = $data['title'];
  6464. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6465. Jieba::init(); // 初始化 jieba-php
  6466. Finalseg::init();
  6467. $segList = Jieba::cut($data['keyword']);
  6468. $segList1 = array_slice($segList, 0, 8);
  6469. $data['keyword'] = implode(',', $segList1);
  6470. }
  6471. if ($data['description'] == '') {
  6472. //提取内容中的描述
  6473. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6474. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6475. }
  6476. var_dump($data, '--');
  6477. if ($data['status'] == 1) {
  6478. $this->sendMessage([
  6479. 'talk_type' => 400,
  6480. 'title' => $data['title'],
  6481. 'content' => '提交了审核',
  6482. 'messageType' => 7,
  6483. ]);
  6484. }
  6485. $result = Book::insertGetId($data);
  6486. if (empty($result)) {
  6487. return Result::error("添加失败", 0);
  6488. }
  6489. return Result::success($result);
  6490. }
  6491. public function getBookList(array $data): array
  6492. {
  6493. $where = [];
  6494. if (!empty($data["title"])) {
  6495. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  6496. }
  6497. if (!empty($data['website_name'])) {
  6498. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  6499. }
  6500. if (!empty($data['status'])) {
  6501. $where[] = ['book.status', '=', $data['status']];
  6502. }
  6503. $user_id = $data['user_id'];
  6504. $type_id = $data['type_id'];
  6505. // $type_id = 4;
  6506. var_dump($type_id, '------1--------');
  6507. if ($type_id != 10000) {
  6508. $where[] = ['book.user_id', '=', $user_id];
  6509. }
  6510. var_dump(!empty($data['status1']), '=-===1');
  6511. $result = Book::where($where)
  6512. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  6513. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  6514. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  6515. ->when(isset($data['status1']), function ($query) use ($data) {
  6516. $query->whereIn('book.status', [1, 3]);
  6517. })
  6518. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  6519. ->orderBy("updated_at", "desc")
  6520. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  6521. if (empty($result)) {
  6522. return Result::error("暂无数据", 0);
  6523. }
  6524. // 取出数据
  6525. $rows = $result->items();
  6526. $count = $result->total();
  6527. $responseData = [
  6528. 'rows' => $rows,
  6529. 'count' => $count,
  6530. ];
  6531. return Result::success($responseData);
  6532. }
  6533. public function deleteBook(array $data): array
  6534. {
  6535. $result = Book::where('id', $data['id'])->delete();
  6536. if (empty($result)) {
  6537. return Result::error("删除失败", 0);
  6538. }
  6539. return Result::success($result);
  6540. }
  6541. public function updateBook(array $data): array
  6542. {
  6543. // $user_id = $data['user_id'] ?? 0;
  6544. $type_id = $data['type_id'] ?? 0;
  6545. // $website_id = $data['website_id'] ?? 0;
  6546. unset($data['user_id']);
  6547. unset($data['type_id']);
  6548. // unset($data['website_id']);
  6549. //处理数组
  6550. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6551. if ($data['img_url'] == '') {
  6552. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6553. preg_match_all($reg, $data['detail'], $matches);
  6554. if (isset($matches[1][0])) {
  6555. //截取varchar240
  6556. $data['img_url'] = substr($matches[1][0], 0, 240);
  6557. }
  6558. }
  6559. if ($data['keyword'] == '') {
  6560. //提取标题+内容中的关键词
  6561. $data['keyword'] = $data['title'];
  6562. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6563. Jieba::init(); // 初始化 jieba-php
  6564. Finalseg::init();
  6565. $segList = Jieba::cut($data['keyword']);
  6566. $segList1 = array_slice($segList, 0, 8);
  6567. $data['keyword'] = implode(',', $segList1);
  6568. }
  6569. if ($data['description'] == '') {
  6570. //提取内容中的描述
  6571. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6572. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6573. }
  6574. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6575. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6576. if ($data['status'] == 1) {
  6577. $this->sendMessage([
  6578. 'talk_type' => 400,
  6579. 'title' => $data['title'],
  6580. 'content' => '提交了审核',
  6581. 'messageType' => 7,
  6582. ]);
  6583. }
  6584. $result = Book::where("id", $data["id"])->update($data);
  6585. if (empty($result)) {
  6586. return Result::error("更新失败", 0);
  6587. }
  6588. return Result::success($result);
  6589. }
  6590. public function getBookInfo(array $data): array
  6591. {
  6592. $result = Book::where("id", $data["id"])->first();
  6593. if (empty($result)) {
  6594. return Result::error("获取失败", 0);
  6595. }
  6596. return Result::success($result);
  6597. }
  6598. public function updateBookStatus(array $data): array
  6599. {
  6600. //审核
  6601. unset($data['user_id']);
  6602. $bookInfo = Book::where("id", $data["id"])->first();
  6603. var_dump($bookInfo, '----');
  6604. if ($data['status'] == 2) {
  6605. $this->sendMessage([
  6606. 'talk_type' => 401,
  6607. 'title' => $bookInfo['title'],
  6608. 'content' => '审核通过',
  6609. 'messageType' => 7,
  6610. 'user_id' => $bookInfo['user_id'],
  6611. ]);
  6612. }
  6613. if ($data['status'] == 3) {
  6614. $this->sendMessage([
  6615. 'talk_type' => 401,
  6616. 'title' => $bookInfo['title'],
  6617. 'content' => '审核拒绝',
  6618. 'messageType' => 7,
  6619. 'user_id' => $bookInfo['user_id'],
  6620. ]);
  6621. }
  6622. if ($data['status'] == 1) {
  6623. $this->sendMessage([
  6624. 'talk_type' => 400,
  6625. 'title' => $bookInfo['title'],
  6626. 'content' => '提交了审核',
  6627. 'messageType' => 7,
  6628. // 'user_id'=>$bookInfo['user_id'],
  6629. ]);
  6630. }
  6631. $result = Book::where("id", $data["id"])->update($data);
  6632. if (empty($result)) {
  6633. return Result::error("更新失败", 0);
  6634. }
  6635. return Result::success($result);
  6636. }
  6637. //20250422 书刊音像
  6638. /**
  6639. * 贴身宝贝
  6640. * @param array $data
  6641. * @return array
  6642. */
  6643. public function getWebsiteTsbb(array $data): array
  6644. {
  6645. $month = $data['month'] ?? date('m');
  6646. $day = $data['day'] ?? date('d');
  6647. // 使用缓存键
  6648. $cacheKey = "tsbb_data_{$month}_{$day}";
  6649. // 尝试从缓存获取数据
  6650. $container = \Hyperf\Context\ApplicationContext::getContainer();
  6651. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  6652. if ($cachedData = $cache->get($cacheKey)) {
  6653. return Result::success(unserialize($cachedData));
  6654. }
  6655. //查询老黄历
  6656. try {
  6657. $date = date('Y-m-d');
  6658. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  6659. // 使用 curl 替代 file_get_contents
  6660. $ch = curl_init();
  6661. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  6662. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  6663. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  6664. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  6665. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  6666. 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');
  6667. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  6668. 'Accept: application/json',
  6669. 'Content-Type: application/json',
  6670. 'Referer: https://www.36jxs.com/'
  6671. ]);
  6672. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  6673. curl_setopt($ch, CURLOPT_ENCODING, '');
  6674. $almanacResponse = curl_exec($ch);
  6675. var_dump("====:", $almanacResponse);
  6676. if (curl_errno($ch)) {
  6677. var_dump('Curl error:', curl_error($ch));
  6678. throw new \Exception('Curl error: ' . curl_error($ch));
  6679. }
  6680. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  6681. curl_close($ch);
  6682. if ($almanacResponse === false) {
  6683. throw new \Exception('Failed to fetch almanac data');
  6684. }
  6685. $almanacData = json_decode($almanacResponse, true);
  6686. if (json_last_error() !== JSON_ERROR_NONE) {
  6687. throw new \Exception('Failed to parse almanac data');
  6688. }
  6689. $almanacInfo = $almanacData['data'] ?? [];
  6690. } catch (\Exception $e) {
  6691. var_dump('Exception:', $e->getMessage());
  6692. $almanacInfo = [];
  6693. }
  6694. // 获取历史上的今天数据
  6695. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6696. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  6697. ->orderBy('year', 'asc')
  6698. ->select("title", "id", "year", DB::raw('1 as type'))
  6699. ->limit(16)
  6700. ->get();
  6701. // 获取节日数据 - 从今天开始获取未来4条
  6702. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  6703. ->orderBy('showtime', 'asc')
  6704. ->select("title", "id", "showtime", DB::raw('2 as type'))
  6705. ->limit(16)
  6706. ->get();
  6707. //说文解字
  6708. $chartacterList = Character::orderBy('updated_at', 'desc')
  6709. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  6710. ->limit(6)
  6711. ->get();
  6712. //谜语沙龙
  6713. $riddletList = Riddle::orderBy('updated_at', 'desc')
  6714. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  6715. ->limit(4)
  6716. ->get();
  6717. //成语欣赏
  6718. $idiomList = Idiom::orderBy('updated_at', 'desc')
  6719. ->select("id", "title", "duyin", DB::raw('5 as type'))
  6720. ->limit(32)
  6721. ->get();
  6722. //名联赏析
  6723. $coupletList = Couplet::orderBy('updated_at', 'desc')
  6724. ->select("id", "first", "second", DB::raw('6 as type'))
  6725. ->limit(6)
  6726. ->get();
  6727. // 获取分类文章数据
  6728. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  6729. ->pluck('category_id')
  6730. ->toArray();
  6731. $articlesList = [];
  6732. foreach ($categoryIds as $catid) {
  6733. // 先查有图片的
  6734. $withImg = DB::table('article')
  6735. ->where('status', 1)
  6736. ->where('catid', $catid)
  6737. ->whereNotNull('imgurl')
  6738. ->where('imgurl', '!=', '')
  6739. ->orderBy('updated_at', 'desc')
  6740. ->limit(6)
  6741. ->get();
  6742. $count = $withImg->count();
  6743. if ($count < 6) {
  6744. // 不足6条再查无图片的补足
  6745. $withoutImg = DB::table('article')
  6746. ->where('status', 1)
  6747. ->where('catid', $catid)
  6748. ->where(function ($q) {
  6749. $q->whereNull('imgurl')->orWhere('imgurl', '');
  6750. })
  6751. ->orderBy('updated_at', 'desc')
  6752. ->limit(6 - $count)
  6753. ->get();
  6754. $articles = $withImg->concat($withoutImg);
  6755. } else {
  6756. $articles = $withImg;
  6757. }
  6758. // 组装
  6759. $category = \App\Model\Category::find($catid);
  6760. $websiteCategory = WebsiteCategory::where('category_id', $catid)->first();
  6761. $articlesList[] = [
  6762. 'category_name' => $category ? $category->name : '',
  6763. 'catid' => $catid,
  6764. 'pinyin' => $websiteCategory ? $websiteCategory->aLIas_pinyin : '',
  6765. 'type' => 100,
  6766. 'list' => $articles->map(function ($item) {
  6767. return [
  6768. 'id' => $item->id,
  6769. 'title' => $item->title,
  6770. 'imgurl' => $item->imgurl,
  6771. 'created_at' => $item->created_at
  6772. ];
  6773. })->values()
  6774. ];
  6775. }
  6776. $result = [
  6777. 'almanac' => $almanacInfo,
  6778. 'historyTodayList' => [
  6779. 'category_name' => '历史上的今天',
  6780. 'list' => $historyTodayList,
  6781. 'type' => 1
  6782. ],
  6783. 'festivalList' => [
  6784. 'category_name' => '节日预告',
  6785. 'list' => $festivalList,
  6786. 'type' => 2
  6787. ],
  6788. 'chartacterList' => [
  6789. 'category_name' => '说文解字',
  6790. 'list' => $chartacterList,
  6791. 'type' => 3
  6792. ],
  6793. 'coupletList' => [
  6794. 'category_name' => '名联赏析',
  6795. 'list' => $coupletList,
  6796. 'type' => 6
  6797. ],
  6798. 'riddletList' => [
  6799. 'category_name' => '谜语沙龙',
  6800. 'list' => $riddletList,
  6801. 'type' => 4
  6802. ],
  6803. 'idiomList' => [
  6804. 'category_name' => '成语欣赏',
  6805. 'list' => $idiomList,
  6806. 'type' => 5
  6807. ],
  6808. 'articlesList' => $articlesList
  6809. ];
  6810. // 缓存结果,设置1小时过期
  6811. $cache->set($cacheKey, serialize($result), 3600);
  6812. return Result::success($result);
  6813. }
  6814. /**
  6815. * 获取资讯列表
  6816. */
  6817. public function getWebsiteTsbbList(array $data): array
  6818. {
  6819. $page = $data['page'] ?? 1;
  6820. $pageSize = $data['pageSize'] ?? 10;
  6821. // 如果没有传入月份和日期,则使用今天的日期
  6822. $month = $data['month'] ?? date('m');
  6823. $day = $data['day'] ?? date('d');
  6824. $total = 0;
  6825. $result = [];
  6826. $data['type'] = intval($data['type']);
  6827. var_dump("接收参数:", $data);
  6828. switch ($data['type']) {
  6829. case 1:
  6830. $query = HistoryToday::where(function ($q) use ($month, $day) {
  6831. // 当前月份之后的数据
  6832. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  6833. // 或者当前月份且日期大于等于当前日期的数据
  6834. ->orWhere(function ($q) use ($month, $day) {
  6835. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6836. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  6837. });
  6838. })
  6839. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  6840. $total = $query->count();
  6841. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  6842. ->offset(($page - 1) * $pageSize)
  6843. ->limit($pageSize)
  6844. ->get();
  6845. break;
  6846. case 2:
  6847. $query = Festival::where(function ($q) use ($month, $day) {
  6848. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  6849. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  6850. ->orWhere(function ($q) use ($month, $day) {
  6851. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  6852. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  6853. });
  6854. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  6855. $total = $query->count();
  6856. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  6857. ->offset(($page - 1) * $pageSize)
  6858. ->limit($pageSize)
  6859. ->get();
  6860. break;
  6861. case 3:
  6862. $query = Character::orderBy("updated_at", "desc");
  6863. $total = $query->count();
  6864. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  6865. ->offset(($page - 1) * $pageSize)
  6866. ->limit($pageSize)
  6867. ->get();
  6868. break;
  6869. case 4:
  6870. $query = Riddle::orderBy("updated_at", "desc");
  6871. $total = $query->count();
  6872. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  6873. ->offset(($page - 1) * $pageSize)
  6874. ->limit($pageSize)
  6875. ->get();
  6876. break;
  6877. case 5:
  6878. $query = Idiom::orderBy("updated_at", "desc");
  6879. $total = $query->count();
  6880. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  6881. ->offset(($page - 1) * $pageSize)
  6882. ->limit($pageSize)
  6883. ->get();
  6884. break;
  6885. case 6:
  6886. $query = Couplet::orderBy("updated_at", "desc");
  6887. $total = $query->count();
  6888. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  6889. ->offset(($page - 1) * $pageSize)
  6890. ->limit($pageSize)
  6891. ->get();
  6892. break;
  6893. default:
  6894. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  6895. $total = $query->count();
  6896. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  6897. ->offset(($page - 1) * $pageSize)
  6898. ->limit($pageSize)
  6899. ->get();
  6900. }
  6901. return Result::success([
  6902. 'list' => $result,
  6903. 'total' => $total,
  6904. 'page' => (int)$page,
  6905. 'pageSize' => (int)$pageSize,
  6906. 'month' => $month,
  6907. 'day' => $day
  6908. ]);
  6909. }
  6910. /**
  6911. * 1:历史上的今天
  6912. * 2:节日
  6913. * 3:文章
  6914. *
  6915. * 资讯详情信息
  6916. */
  6917. public function getWebsiteTsbbDetail(array $data): array
  6918. {
  6919. $data['type'] = intval($data['type']);
  6920. switch ($data['type']) {
  6921. case 1:
  6922. $result = HistoryToday::where("id", $data['id'])->first();
  6923. break;
  6924. case 2:
  6925. $result = Festival::where("id", $data['id'])->first();
  6926. break;
  6927. case 3:
  6928. $result = Character::where("id", $data['id'])->first();
  6929. break;
  6930. case 4:
  6931. $result = Riddle::where("id", $data['id'])->first();
  6932. break;
  6933. case 5:
  6934. $result = Idiom::where("id", $data['id'])->first();
  6935. break;
  6936. case 6:
  6937. $result = Couplet::where("id", $data['id'])->first();
  6938. break;
  6939. default:
  6940. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  6941. break;
  6942. }
  6943. return Result::success($result);
  6944. }
  6945. /**
  6946. * 农网导航首页数据
  6947. */
  6948. public function getWebsiteNwHomeList(array $data): array
  6949. {
  6950. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  6951. ->pluck('category_id')
  6952. ->toArray();
  6953. // 使用子查询优化
  6954. $articlesList = DB::table('article')
  6955. ->select([
  6956. 'article.id',
  6957. 'article.title',
  6958. 'article.imgurl',
  6959. 'article.created_at',
  6960. 'category.name as category_name',
  6961. 'category.id as category_id',
  6962. 'website_category.aLIas_pinyin as pinyin',
  6963. 'parent_wc.aLIas_pinyin as parent_pinyin',
  6964. DB::raw('100 as type')
  6965. ])
  6966. ->join('category', 'article.catid', '=', 'category.id')
  6967. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  6968. ->leftJoin('website_category as parent_wc', function ($join) {
  6969. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  6970. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  6971. })
  6972. ->where('website_category.website_id', $data['website_id'])
  6973. ->where('article.status', 1)
  6974. ->whereIn('category.id', $categoryIds)
  6975. ->orderBy('article.created_at', 'desc')
  6976. ->get()
  6977. ->groupBy('category_id')
  6978. ->map(function ($group) {
  6979. // 确保第一条数据有图片
  6980. $firstWithImage = $group->first(function ($item) {
  6981. return !empty($item->imgurl);
  6982. });
  6983. if ($firstWithImage) {
  6984. // 如果有带图片的文章,将其放在第一位
  6985. $group = $group->filter(function ($item) use ($firstWithImage) {
  6986. return $item->id !== $firstWithImage->id;
  6987. })->prepend($firstWithImage);
  6988. }
  6989. return [
  6990. 'category_name' => $group->first()->category_name,
  6991. 'catid' => $group->first()->category_id,
  6992. 'pinyin' => $group->first()->pinyin,
  6993. 'parent_pinyin' => $group->first()->parent_pinyin,
  6994. 'list' => $group->take(4)->map(function ($item) {
  6995. return [
  6996. 'id' => $item->id,
  6997. 'title' => $item->title,
  6998. ];
  6999. })->values()
  7000. ];
  7001. })
  7002. ->values()
  7003. ->toArray();
  7004. return Result::success($articlesList);
  7005. }
  7006. /**
  7007. * 企业管理
  7008. * @param array $data
  7009. * @return array
  7010. */
  7011. public function getCompanyList(array $data): array
  7012. {
  7013. // return Result::success($data);
  7014. $where = [];
  7015. $user = User::where('id', $data['user_id'])->first();
  7016. if (empty($user)) {
  7017. return Result::error('用户不存在!');
  7018. }
  7019. if ($user['type_id'] != 10000) {
  7020. $where['user_id'] = $data['user_id'];
  7021. }
  7022. if (isset($data['title']) && !empty($data['title'])) {
  7023. array_push($where, ['company.title', 'like', '%' . $data['title'] . '%']);
  7024. }
  7025. if (isset($data['website_id']) && !empty($data['website_id'])) {
  7026. array_push($where, ['website.id', $data['website_id']]);
  7027. }
  7028. if (isset($data['ischeck']) && !empty($data['ischeck'])) {
  7029. if ($data['ischeck'] == 1) {
  7030. if (isset($data['status']) && $data['status'] != '') {
  7031. array_push($where, ['company.status', $data['status']]);
  7032. $query = Company::where($where);
  7033. } else {
  7034. $query = Company::whereIn('company.status', [0, 2]);
  7035. }
  7036. } else {
  7037. $query = Company::where('company.status', 1);
  7038. }
  7039. }
  7040. $result = $query->where($where)
  7041. ->leftJoin('website_category', function ($query) {
  7042. $query->on('website_category.category_id', '=', 'company.category_id')
  7043. ->on('website_category.website_id', '=', 'company.website_id');
  7044. })
  7045. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  7046. ->select(
  7047. 'company.id',
  7048. 'company.title',
  7049. 'company.website_id',
  7050. 'company.category_id',
  7051. 'website.website_name',
  7052. 'website_category.alias as category_name',
  7053. 'company.status',
  7054. 'company.updated_at',
  7055. 'company.user_id'
  7056. )
  7057. ->orderBy('company.updated_at', 'desc')
  7058. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  7059. if ($result->isEmpty()) {
  7060. return Result::error("暂无企业", 0);
  7061. }
  7062. return Result::success($result);
  7063. }
  7064. /**
  7065. * 添加企业
  7066. * @param array $data
  7067. * @return array
  7068. */
  7069. public function addCompany(array $data): array
  7070. {
  7071. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  7072. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  7073. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  7074. $data['cat_arr_id'] = json_encode($car_arr_id);
  7075. } else {
  7076. $data['cat_arr_id'] = '';
  7077. }
  7078. if ($data['imgurl'] == '') {
  7079. //content中提取图片第一个图,正则提取
  7080. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  7081. preg_match_all($reg, $data['content'], $matches);
  7082. if (isset($matches[1][0])) {
  7083. //截取varchar240
  7084. $data['imgurl'] = substr($matches[1][0], 0, 240);
  7085. }
  7086. }
  7087. if ($data['keyword'] == '') {
  7088. //提取标题+内容中的关键词
  7089. $data['keyword'] = $data['title'];
  7090. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7091. Jieba::init(); // 初始化 jieba-php
  7092. Finalseg::init();
  7093. $segList = Jieba::cut($data['keyword']);
  7094. $segList1 = array_slice($segList, 0, 8);
  7095. $data['keyword'] = implode(',', $segList1);
  7096. }
  7097. if ($data['introduce'] == '' || empty($data['introduce'])) {
  7098. //提取内容中的描述
  7099. $content = $data['content'];
  7100. // 去除 <style> 和 <script> 标签及其内容
  7101. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7102. // 去除所有 HTML 标签
  7103. $content = strip_tags($content);
  7104. // 去除 HTML 实体
  7105. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7106. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7107. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7108. // 去除多余空白
  7109. $content = preg_replace('/\s+/u', '', $content);
  7110. // 截取 100 个字符
  7111. $data['introduce'] = mb_substr($content, 0, 100);
  7112. }
  7113. $user = User::where('id', $data['user_id'])->first();
  7114. if (empty($user)) {
  7115. return Result::error('用户不存在!');
  7116. }
  7117. if ($user['type_id'] == 10000) {
  7118. $data['status'] = 1;
  7119. }
  7120. if (isset($data['level']) && $data['level'] != null) {
  7121. $data['level'] = intval($data['level']);
  7122. } else {
  7123. $data['level'] = null;
  7124. }
  7125. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  7126. $this->sendMessage([
  7127. 'talk_type' => 900,
  7128. 'title' => $data['title'],
  7129. 'content' => '提交了审核',
  7130. 'messageType' => 8,
  7131. ]);
  7132. }
  7133. $result = Company::insertGetId($data);
  7134. if ($result) {
  7135. return Result::success($result);
  7136. } else {
  7137. return Result::error('添加失败');
  7138. }
  7139. }
  7140. /**
  7141. * 更新企业
  7142. * @param array $data
  7143. * @return array
  7144. */
  7145. public function upCompany(array $data): array
  7146. {
  7147. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  7148. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  7149. $data['cat_arr_id'] = json_encode($car_arr_id);
  7150. $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
  7151. } else {
  7152. $data['cat_arr_id'] = '';
  7153. }
  7154. if ($data['imgurl'] == '') {
  7155. //content中提取图片第一个图,正则提取
  7156. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  7157. preg_match_all($reg, $data['content'], $matches);
  7158. if (isset($matches[1][0])) {
  7159. //截取varchar
  7160. $data['imgurl'] = substr($matches[1][0], 0, 240);
  7161. }
  7162. }
  7163. if ($data['keyword'] == '') {
  7164. //提取标题+内容中的关键词
  7165. $data['keyword'] = $data['title'];
  7166. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7167. Jieba::init(); // 初始化 jieba-php
  7168. Finalseg::init();
  7169. $segList = Jieba::cut($data['keyword']);
  7170. $segList1 = array_slice($segList, 0, 8);
  7171. $data['keyword'] = implode(',', $segList1);
  7172. }
  7173. if ($data['introduce'] == '') {
  7174. //提取内容中的描述
  7175. $content = $data['content'];
  7176. // 去除 <style> 和 <script> 标签及其内容
  7177. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7178. // 去除所有 HTML 标签
  7179. $content = strip_tags($content);
  7180. // 去除 HTML 实体
  7181. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7182. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7183. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7184. // 去除多余空白
  7185. $content = preg_replace('/\s+/u', '', $content);
  7186. // 截取 100 个字符
  7187. $data['introduce'] = mb_substr($content, 0, 100);
  7188. }
  7189. if (isset($data['level']) && $data['level'] != null) {
  7190. $data['level'] = intval($data['level']);
  7191. } else {
  7192. $data['level'] = null;
  7193. }
  7194. $user = User::where('id', $data['user_id'])->first();
  7195. if (empty($user)) {
  7196. return Result::error('用户不存在!');
  7197. }
  7198. if ($user['type_id'] == 10000) {
  7199. $data['status'] = 1;
  7200. } else {
  7201. $data['status'] = 0;
  7202. }
  7203. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  7204. $this->sendMessage([
  7205. 'talk_type' => 900,
  7206. 'title' => $data['title'],
  7207. 'content' => '提交了审核',
  7208. 'messageType' => 8,
  7209. ]);
  7210. }
  7211. $result = Company::where('id', $data['id'])->update($data);
  7212. if ($result) {
  7213. return Result::success($result);
  7214. } else {
  7215. return Result::error('修改失败');
  7216. }
  7217. }
  7218. /**
  7219. * 删除企业
  7220. * @param array $data
  7221. * @return array
  7222. */
  7223. public function delCompany(array $data): array
  7224. {
  7225. $result = Company::where('id', $data['id'])->delete();
  7226. if ($result) {
  7227. return Result::success($result);
  7228. } else {
  7229. return Result::error('删除失败');
  7230. }
  7231. }
  7232. /**
  7233. * 审核企业
  7234. * @param array $data
  7235. * @return array
  7236. */
  7237. public function checkCompany(array $data): array
  7238. {
  7239. $user = User::where('id', $data['user_id'])->first();
  7240. if (empty($user)) {
  7241. return Result::error('用户不存在!');
  7242. }
  7243. $company = Company::where('id', $data['id'])->first();
  7244. if (empty($company)) {
  7245. return Result::error('企业不存在!');
  7246. }
  7247. // 状态:0:未审核 1:已审核 2:已拒绝
  7248. if ($data['status'] == 2 || $data['status'] == '2') {
  7249. $this->sendMessage([
  7250. 'talk_type' => 901,
  7251. 'title' => $company['title'],
  7252. 'content' => '审核拒绝',
  7253. 'messageType' => 8,
  7254. 'user_id' => $company['user_id'],
  7255. ]);
  7256. $result = Company::where('id', $data['id'])->update(['status' => $data['status'], 'reject_reason' => $data['reason']]);
  7257. } else {
  7258. if ($data['status'] == 1) {
  7259. $this->sendMessage([
  7260. 'talk_type' => 901,
  7261. 'title' => $company['title'],
  7262. 'content' => '审核通过',
  7263. 'messageType' => 8,
  7264. 'user_id' => $company['user_id'],
  7265. ]);
  7266. } else if ($data['status'] == 0) {
  7267. $this->sendMessage([
  7268. 'talk_type' => 900,
  7269. 'title' => $company['title'],
  7270. 'content' => '提交了审核',
  7271. 'messageType' => 8,
  7272. ]);
  7273. }
  7274. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  7275. }
  7276. if (empty($result)) {
  7277. return Result::error('审核失败!');
  7278. } else {
  7279. return Result::success($result);
  7280. }
  7281. }
  7282. /**
  7283. * 获取企业信息
  7284. * @param array $data
  7285. * @return array
  7286. */
  7287. public function getCompanyInfo(array $data): array
  7288. {
  7289. $result = Company::where('id', $data['id'])->first();
  7290. $city_arr = json_decode($result['city_arr_id']);
  7291. $result['city_name'] = District::whereIn('id', $city_arr)
  7292. ->pluck('name')
  7293. ->implode('-');
  7294. if (empty($result)) {
  7295. return Result::error('企业不存在!');
  7296. } else {
  7297. return Result::success($result);
  7298. }
  7299. }
  7300. /**
  7301. * @param array $data
  7302. * @return array
  7303. */
  7304. public function getWebsiteCompany(array $data): array
  7305. {
  7306. $categorys = json_decode($data['id'], true);
  7307. $category_arr = $this->processArticlePro($data['website_id']);
  7308. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7309. $catiall = $category_arr['catiall'];
  7310. $categoryIds = $category_arr['categoryIds'];
  7311. // return Result::success($category_arr);
  7312. foreach ($categorys as $key => $value) {
  7313. if (array_key_exists('level', $value)) {
  7314. $parts = explode(',', $value['level']);
  7315. $level = $parts[0] ?? null;
  7316. $imgnum = $parts[1] ?? null;
  7317. $textnum = $parts[2] ?? null;
  7318. if (!empty($textnum) && $textnum > 0) {
  7319. $text_num = Company::where('level', $level)
  7320. ->whereIn('category_id', $categoryIds)
  7321. ->where('status', 1)
  7322. ->select(
  7323. 'company.id',
  7324. 'company.title',
  7325. 'company.description',
  7326. 'company.updated_at',
  7327. 'company.category_id',
  7328. 'company.cat_arr_id'
  7329. )
  7330. ->orderBy('updated_at', 'desc')
  7331. ->limit($textnum)
  7332. ->get()->all();
  7333. }
  7334. if (!empty($imgnum) && $imgnum > 0) {
  7335. $img_num = Company::where('level', $level)
  7336. ->whereIn('category_id', $categoryIds)
  7337. ->where('status', 1)
  7338. ->where('imgurl', '!=', '')
  7339. ->whereNotNull('imgurl')
  7340. ->select(
  7341. 'company.id',
  7342. 'company.title',
  7343. 'company.description',
  7344. 'company.updated_at',
  7345. 'company.imgurl as imgs',
  7346. 'company.category_id',
  7347. 'company.cat_arr_id'
  7348. )
  7349. ->orderBy('updated_at', 'desc')
  7350. ->limit($imgnum)
  7351. ->get()->all();
  7352. }
  7353. }
  7354. if (array_key_exists('id', $value)) {
  7355. $parts = explode(',', $value['id']);
  7356. $category_id = $parts[0] ?? null;
  7357. $imgnum = $parts[1] ?? null;
  7358. $textnum = $parts[2] ?? null;
  7359. $category_arr = array_merge([$category_id], $cat_1st_arr[$category_id] ?? [0]);
  7360. if (!empty($textnum) && $textnum > 0) {
  7361. $text_num = Company::whereIn('category_id', $category_arr)
  7362. // ->where('website_id', $data['website_id'])
  7363. ->where('status', 1)
  7364. ->select(
  7365. 'company.id',
  7366. 'company.title',
  7367. 'company.description',
  7368. 'company.updated_at',
  7369. 'company.category_id',
  7370. 'company.cat_arr_id'
  7371. )
  7372. ->orderBy('updated_at', 'desc')
  7373. ->limit($textnum)
  7374. ->get()->all();
  7375. }
  7376. if (!empty($imgnum) && $imgnum > 0) {
  7377. $img_num = Company::whereIn('category_id', $category_arr)
  7378. // ->where('website_id', $data['website_id'])
  7379. ->where('status', 1)
  7380. ->where('imgurl', '!=', '')
  7381. ->whereNotNull('imgurl')
  7382. ->select(
  7383. 'company.id',
  7384. 'company.title',
  7385. 'company.description',
  7386. 'company.updated_at',
  7387. 'company.imgurl as imgs',
  7388. 'company.category_id',
  7389. 'company.cat_arr_id'
  7390. )
  7391. ->orderBy('updated_at', 'desc')
  7392. ->limit($imgnum)
  7393. ->get()->all();
  7394. }
  7395. }
  7396. if (!empty($text_num)) {
  7397. foreach ($text_num as $k => $v) {
  7398. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7399. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7400. }
  7401. }
  7402. if (!empty($img_num)) {
  7403. foreach ($img_num as $k => $v) {
  7404. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7405. $imgurl = json_decode($v['imgs'], true);
  7406. if (!empty($imgurl)) {
  7407. $img_num[$k]->imgurl = $imgurl[0];
  7408. }
  7409. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7410. }
  7411. }
  7412. $company[$key]['img_num'] = $img_num ?? [];
  7413. $company[$key]['text_num'] = $text_num ?? [];
  7414. }
  7415. if (empty($company)) {
  7416. return Result::error("暂无相关企业信息", 0);
  7417. }
  7418. return Result::success($company);
  7419. }
  7420. /**
  7421. * @param array $data
  7422. * @return array
  7423. */
  7424. public function getWebsiteCompanyList(array $data): array
  7425. {
  7426. $where['website_id'] = $data['website_id'];
  7427. $where['status'] = 1;
  7428. $categoryIds = [];
  7429. if (isset($data['category_id']) && !empty($data['category_id'])) {
  7430. $category_id = $data['category_id'];
  7431. }
  7432. $category_arr = $this->processArticlePro($data['website_id']);
  7433. $categoryIds = $category_arr['categoryIds'];
  7434. // return Result::success($cat_1st_arr);
  7435. $company = Company::when(isset($data['keyword']) && !empty($data['keyword']), function ($query) use ($data) {
  7436. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  7437. })
  7438. ->when(!isset($category_id) || empty($category_id), function ($query) use ($categoryIds) {
  7439. $query->whereIn('category_id', $categoryIds);
  7440. })
  7441. ->when(isset($data['category_id']) && !empty($data['category_id']), function ($query) use ($category_id) {
  7442. $query->where('category_id', $category_id);
  7443. })
  7444. ->where('status',1)
  7445. ->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id', 'updated_at')
  7446. ->orderBy('updated_at', 'desc')
  7447. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  7448. if (empty($company)) {
  7449. return Result::error("暂无相关公司信息", 0);
  7450. }
  7451. $result = [
  7452. 'count' => $company->total(),
  7453. 'data' => $company->items(), // 使用 items() 方法替代不存在的 data() 方法
  7454. ];
  7455. return Result::success($result);
  7456. }
  7457. /**
  7458. * 获取项目列表
  7459. * @param array $data
  7460. * @return array
  7461. */
  7462. public function getProjectList(array $data): array
  7463. {
  7464. $where = [];
  7465. $user = User::where('id', $data['user_id'])->first();
  7466. if (empty($user)) {
  7467. return Result::error('用户不存在!');
  7468. }
  7469. if ($user->type_id != 10000) {
  7470. array_push($where, ['project.user_id', $data['user_id']]);
  7471. }
  7472. $query = Project::query();
  7473. if (isset($data['website_id']) && !empty($data['website_id'])) {
  7474. array_push($where, ['project.website_id', $data['website_id']]);
  7475. }
  7476. if (isset($data['title']) && !empty($data['title'])) {
  7477. array_push($where, ['project.title', 'like', '%' . $data['title'] . '%']);
  7478. }
  7479. if ($data['status'] != 3) {
  7480. array_push($where, ['project.status', $data['status']]);
  7481. }
  7482. $query = Project::where($where)
  7483. ->when($data['status'] == 3, function ($query) {
  7484. $query->whereIn('project.status', [0, 2]);
  7485. });
  7486. $count = $query->clone()
  7487. ->count();
  7488. $rows = $query->clone()
  7489. ->leftJoin('website', 'project.website_id', 'website.id')
  7490. ->leftJoin('website_category', function ($join) {
  7491. $join->on('project.website_id', '=', 'website_category.website_id')
  7492. ->on('project.category_id', '=', 'website_category.category_id');
  7493. })
  7494. ->select(
  7495. 'project.id',
  7496. 'project.title',
  7497. 'project.updated_at',
  7498. 'project.status',
  7499. 'website.website_name',
  7500. 'website_category.alias as category_name',
  7501. 'project.website_id',
  7502. 'project.user_id'
  7503. )
  7504. ->orderBy('project.updated_at', 'desc')
  7505. ->offset(($data['page'] - 1) * $data['pageSize'])
  7506. ->limit($data['pageSize'])
  7507. ->get();
  7508. if ($rows->isEmpty()) {
  7509. return Result::error("暂无相关项目信息", 0);
  7510. }
  7511. $result = [
  7512. 'count' => $count,
  7513. 'rows' => $rows,
  7514. ];
  7515. return Result::success($result);
  7516. }
  7517. /**
  7518. * 添加项目
  7519. * @param array $data
  7520. * @return array
  7521. */
  7522. public function addProject(array $data): array
  7523. {
  7524. $user = User::where('id', $data['user_id'])->first();
  7525. if (empty($user)) {
  7526. return Result::error("暂无相关用户信息", 0);
  7527. }
  7528. if ($user->type_id == 10000) {
  7529. $data['status'] = 1;
  7530. } else {
  7531. $data['status'] = 0;
  7532. }
  7533. if ($data['keyword'] == '') {
  7534. //提取标题+内容中的关键词
  7535. $data['keyword'] = $data['title'];
  7536. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7537. Jieba::init(); // 初始化 jieba-php
  7538. Finalseg::init();
  7539. $segList = Jieba::cut($data['keyword']);
  7540. $segList1 = array_slice($segList, 0, 8);
  7541. $data['keyword'] = implode(',', $segList1);
  7542. }
  7543. if ($data['description'] == '') {
  7544. //提取内容中的描述
  7545. // var_dump(11111);
  7546. //提取内容中的描述
  7547. $content = $data['introduce'];
  7548. // 去除 <style> 和 <script> 标签及其内容
  7549. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7550. // 去除所有 HTML 标签
  7551. $content = strip_tags($content);
  7552. // 去除 HTML 实体
  7553. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7554. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7555. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7556. // 去除多余空白
  7557. $content = preg_replace('/\s+/u', '', $content);
  7558. // 截取 100 个字符
  7559. $data['description'] = mb_substr($content, 0, 100);
  7560. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7561. }
  7562. if ($data['status'] == 0) {
  7563. $this->sendMessage([
  7564. 'talk_type' => 1000,
  7565. 'title' => $data['title'],
  7566. 'content' => '提交了审核',
  7567. 'messageType' => 9,
  7568. ]);
  7569. }
  7570. $project = Project::insertGetId($data);
  7571. if (empty($project)) {
  7572. return Result::error("暂无相关项目信息", 0);
  7573. }
  7574. return Result::success($project);
  7575. }
  7576. /**
  7577. * 更新项目
  7578. * @param array $data
  7579. * @return array
  7580. */
  7581. public function upProject(array $data): array
  7582. {
  7583. $project = Project::where('id', $data['id'])->first();
  7584. if (empty($project)) {
  7585. return Result::error("暂无相关项目信息", 0);
  7586. }
  7587. $id = $data['id'];
  7588. unset($data['id']);
  7589. $user = User::where('id', $data['user_id'])->first();
  7590. if (empty($user)) {
  7591. return Result::error("暂无相关用户信息", 0);
  7592. }
  7593. if ($user->type_id == 10000) {
  7594. $data['status'] = 1;
  7595. } else {
  7596. $data['status'] = 0;
  7597. }
  7598. unset($data['user_id']);
  7599. if ($data['keyword'] == '') {
  7600. //提取标题+内容中的关键词
  7601. $data['keyword'] = $data['title'];
  7602. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7603. Jieba::init(); // 初始化 jieba-php
  7604. Finalseg::init();
  7605. $segList = Jieba::cut($data['keyword']);
  7606. $segList1 = array_slice($segList, 0, 8);
  7607. $data['keyword'] = implode(',', $segList1);
  7608. }
  7609. if ($data['description'] == '') {
  7610. //提取内容中的描述
  7611. // var_dump(11111);
  7612. //提取内容中的描述
  7613. $content = $data['introduce'];
  7614. // 去除 <style> 和 <script> 标签及其内容
  7615. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7616. // 去除所有 HTML 标签
  7617. $content = strip_tags($content);
  7618. // 去除 HTML 实体
  7619. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7620. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7621. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7622. // 去除多余空白
  7623. $content = preg_replace('/\s+/u', '', $content);
  7624. // 截取 100 个字符
  7625. $data['description'] = mb_substr($content, 0, 100);
  7626. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7627. }
  7628. if ($data['status'] == 0) {
  7629. $this->sendMessage([
  7630. 'talk_type' => 1000,
  7631. 'title' => $data['title'],
  7632. 'content' => '提交了审核',
  7633. 'messageType' => 9,
  7634. ]);
  7635. }
  7636. $result = Project::where('id', $id)->update($data);
  7637. if (empty($result)) {
  7638. return Result::error("更新失败", 0);
  7639. }
  7640. return Result::success($result);
  7641. }
  7642. /**
  7643. * 删除项目
  7644. * @param array $data
  7645. * @return array
  7646. */
  7647. public function delProject(array $data): array
  7648. {
  7649. $user = User::where('id', $data['user_id'])->first();
  7650. if (empty($user)) {
  7651. return Result::error("暂无相关用户信息", 0);
  7652. }
  7653. $project = Project::where('id', $data['id'])->first();
  7654. if (empty($project)) {
  7655. return Result::error("暂无相关项目信息", 0);
  7656. }
  7657. $result = Project::where('id', $data['id'])->delete();
  7658. if (empty($result)) {
  7659. return Result::error("删除失败", 0);
  7660. }
  7661. return Result::success($result);
  7662. }
  7663. /**
  7664. * 审核项目
  7665. * @param array $data
  7666. * @return array
  7667. */
  7668. public function checkProject(array $data): array
  7669. {
  7670. $user = User::where('id', $data['user_id'])->first();
  7671. if (empty($user)) {
  7672. return Result::error("暂无相关用户信息", 0);
  7673. }
  7674. // 0:未审核; 1:已审核; 2:已拒绝;
  7675. if ($user->type_id != 10000) {
  7676. if ($data['status'] == 1 || $data['status'] == 2) {
  7677. return Result::error("此用户权限不足", 0);
  7678. }
  7679. }
  7680. $project = Project::where('id', $data['id'])->first();
  7681. if (empty($project)) {
  7682. return Result::error("暂无相关项目信息", 0);
  7683. }
  7684. if ($data['status'] == 2) {
  7685. $this->sendMessage([
  7686. 'talk_type' => 1001,
  7687. 'title' => $project['title'],
  7688. 'content' => '审核拒绝',
  7689. 'messageType' => 9,
  7690. 'user_id' => $project['user_id'],
  7691. ]);
  7692. $result = Project::where('id', $data['id'])->update(['status' => $data['status'], 'refuse_reason' => $data['refuse_reason']]);
  7693. } else {
  7694. if ($data['status'] == 1) {
  7695. $this->sendMessage([
  7696. 'talk_type' => 1001,
  7697. 'title' => $project['title'],
  7698. 'content' => '审核通过',
  7699. 'messageType' => 9,
  7700. 'user_id' => $project['user_id'],
  7701. ]);
  7702. } else if ($data['status'] == 0) {
  7703. $this->sendMessage([
  7704. 'talk_type' => 1000,
  7705. 'title' => $project['title'],
  7706. 'content' => '提交了审核',
  7707. 'messageType' => 9,
  7708. ]);
  7709. }
  7710. $result = Project::where('id', $data['id'])->update(['status' => $data['status']]);
  7711. }
  7712. if (empty($result)) {
  7713. return Result::error("审核失败", 0);
  7714. }
  7715. return Result::success($result);
  7716. }
  7717. /**
  7718. * 获取项目详情
  7719. * @param array $data
  7720. * @return array
  7721. */
  7722. public function getProjectInfo(array $data): array
  7723. {
  7724. $project = Project::where('id', $data['id'])->first();
  7725. if (empty($project)) {
  7726. return Result::error("暂无相关项目信息", 0);
  7727. }
  7728. return Result::success($project);
  7729. }
  7730. public function getWebsiteCompanyInfo(array $data): array
  7731. {
  7732. $company = Company::where('id', $data['id'])
  7733. ->leftJoin('job_industry', 'job_industry.hyid', 'company.hy_id')
  7734. ->where('status', 1)
  7735. // ->where('website_id', $data['website_id'])
  7736. ->select('company.*', 'job_industry.hyname as hy_name')
  7737. ->first();
  7738. // 企业性质:0:市场监管;1:信访纪检;2:公检法司;3:高关注机构
  7739. $jobnature_id = $company['jobnature_id'] ?? null;
  7740. if ($jobnature_id !== null) {
  7741. switch ($jobnature_id) {
  7742. case 0:
  7743. $company->jobnature_name = '市场监督';
  7744. break;
  7745. case 1:
  7746. $company->jobnature_name = '信访纪检';
  7747. break;
  7748. case 2:
  7749. $company->jobnature_name = '公检法司';
  7750. break;
  7751. case 3:
  7752. $company->jobnature_name = '高关注机构';
  7753. break;
  7754. default:
  7755. $company->jobnature_name = '';
  7756. break;
  7757. }
  7758. } else {
  7759. $company->jobnature_name = '';
  7760. }
  7761. $city_arr = $company->city_arr_id;
  7762. if (!empty($city_arr)) {
  7763. $city_arr = json_decode($city_arr, true);
  7764. $cityNames = District::whereIn('id', $city_arr)
  7765. ->pluck('name')
  7766. ->implode('-');
  7767. $company->city_name = $cityNames;
  7768. } else {
  7769. $company->city_name = '';
  7770. }
  7771. if (empty($company)) {
  7772. return Result::error("暂无相关公司信息", 0);
  7773. }
  7774. return Result::success($company);
  7775. }
  7776. public function getMSG(array $data): array
  7777. {
  7778. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  7779. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  7780. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  7781. $result = [];
  7782. if ($type_id == 1 or $type_id == 2 or $type_id == 3 or $type_id == 4) {
  7783. //最近的5篇已审的文章
  7784. $apply_articale = Article::where('status', 1)
  7785. ->where('admin_user_id', $user_id)
  7786. ->orderBy('updated_at', 'desc')
  7787. // ->limit(5)
  7788. ->get();
  7789. //获取5条用户的已审核商品
  7790. $good = Good::where('status', 2)
  7791. ->where('user_id', $user_id)
  7792. ->orderBy('updated_at', 'desc')
  7793. // ->limit(5)
  7794. ->get();
  7795. //获取5条用户待审核的公告
  7796. $notice = Notice::where('status', 2)
  7797. ->where('user_id', $user_id)
  7798. ->orderBy('updated_at', 'desc')
  7799. ->limit(5)->get();
  7800. //获取5条用户的待审核投诉
  7801. $complaint = Complaint::where('status', 2)
  7802. ->where('user_id', $user_id)
  7803. ->orderBy('updated_at', 'desc')
  7804. // ->limit(5)
  7805. ->get();
  7806. //获取5条用户的book
  7807. $book = Book::where('status', 2)
  7808. ->where('user_id', $user_id)
  7809. ->orderBy('updated_at', 'desc')
  7810. // ->limit(5)
  7811. ->get();
  7812. //获取5条用户的求职
  7813. //获取5条用户的求职 1
  7814. $job_hunting = JobHunting::where('job_hunting.status', 2)
  7815. ->where('job_hunting.user_id', $user_id)
  7816. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7817. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7818. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7819. ->orderBy('updated_at', 'desc')
  7820. // ->limit(5)
  7821. ->get();
  7822. //获取5条用户的求职 2
  7823. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  7824. ->where('job_recruiting.user_id', $user_id)
  7825. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7826. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7827. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7828. ->orderBy('updated_at', 'desc')
  7829. // ->limit(5)
  7830. ->get();
  7831. //人才库 1
  7832. $job_apply = JobApply::where('job_apply.status', 1)
  7833. ->where('job_apply.receiver_id', $user_id)
  7834. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7835. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7836. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7837. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7838. ->select('job_recruiting', 'job_recruiting.', '', '')
  7839. ->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')
  7840. ->orderBy('updated_at', 'desc')
  7841. // ->limit(5)
  7842. ->get();
  7843. // 职场机会 2
  7844. $job_resume = JobResume::where('job_resume.status', 1)
  7845. ->where('job_resume.receiver_id', $user_id)
  7846. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7847. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7848. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7849. ->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')
  7850. ->orderBy('updated_at', 'desc')
  7851. // ->limit(5)
  7852. ->get();
  7853. //获取5条用户待处理的投诉
  7854. $complaint_deal = Complaint::where('status', 2)
  7855. ->where('deal', 1)
  7856. ->whereJsonContains('re_user_ids', $user_id)
  7857. ->orderBy('updated_at', 'desc')
  7858. // ->limit(5)
  7859. ->get();
  7860. //获取 被通知者未读信息
  7861. $notice_unread = Notice::where('status', 2)
  7862. ->whereJsonContains('re_user_ids', $user_id)
  7863. //未读消息
  7864. ->where(function ($query) use ($user_id) {
  7865. $query->whereJsonDoesntContain('read_id', $user_id)
  7866. ->orWhereNull('read_id');
  7867. })
  7868. ->orderBy('updated_at', 'desc')
  7869. ->get();
  7870. $complaint_unread = Complaint::where('status', 2)
  7871. ->whereJsonContains('re_user_ids', $user_id)
  7872. //未读消息
  7873. ->where(function ($query) use ($user_id) {
  7874. $query->whereJsonDoesntContain('read_id', $user_id)
  7875. ->orWhereNull('read_id');
  7876. })
  7877. ->orderBy('updated_at', 'desc')
  7878. ->get();
  7879. //获取5条用户的yijing审核公司 :0:未审核;1:已审核;2:已拒绝
  7880. $complany = Company::where('status', 1)
  7881. ->where('user_id', $user_id)
  7882. ->orderBy('updated_at', 'desc')
  7883. // ->limit(5)
  7884. ->get();
  7885. //获取5条单聊未读聊天消息
  7886. // $chat = ChatRecords::where('is_read', 0)
  7887. // ->where('user_id', $user_id)
  7888. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7889. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7890. // ->where('action', 'recieved')
  7891. // ->where('talk_type', 1)
  7892. // ->orderBy('created_at', 'desc')
  7893. // // ->limit(5)
  7894. // ->get();
  7895. //获取5条未读群聊信息
  7896. // $chat_group = ChatRecords::where('is_read', 0)
  7897. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7898. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7899. // ->where('user_id', $user_id)
  7900. // ->where('talk_type', 2)
  7901. // ->orderBy('created_at', 'desc')
  7902. // // ->limit(5)
  7903. // ->get();
  7904. //获取5条用户的待审核项目
  7905. $project = Project::where('status', 1)
  7906. ->where('user_id', $user_id)
  7907. ->orderBy('updated_at', 'desc')
  7908. // ->limit(5)
  7909. ->get();
  7910. // count($chat) + count($chat_group) +
  7911. $count = count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting) + count($job_apply) + count($job_resume) + count($complaint_deal)
  7912. + count($complany)
  7913. + count($project)
  7914. + count($notice_unread)
  7915. + count($complaint_unread)
  7916. // + count($chat) + count($chat_group)
  7917. ;
  7918. $result = [
  7919. 'apply_articale' => $apply_articale,
  7920. // 'chat' => $chat,
  7921. // 'chat_group' => $chat_group,
  7922. 'good' => $good,
  7923. 'notice' => $notice,
  7924. 'complaint' => $complaint,
  7925. 'book' => $book,
  7926. 'job_hunting' => $job_hunting,
  7927. 'job_recruiting' => $job_recruiting,
  7928. 'job_apply' => $job_apply,
  7929. 'job_resume' => $job_resume,
  7930. 'complaint_deal' => $complaint_deal,
  7931. 'complany' => $complany,
  7932. 'project' => $project,
  7933. 'notice_unread' => $notice_unread,
  7934. 'complaint_unread' => $complaint_unread,
  7935. 'count' => $count,
  7936. ];
  7937. } elseif ($type_id == 12) {
  7938. //最近的5篇已审的文章
  7939. $apply_articale = Article::where('status', 1)
  7940. ->where('admin_user_id', $user_id)
  7941. ->limit(5)->get();
  7942. //获取5条单聊未读聊天消息
  7943. $chat = ChatRecords::where('is_read', 0)
  7944. ->where('user_id', $user_id)
  7945. ->where('talk_type', 1)
  7946. ->orderBy('created_at', 'desc')
  7947. ->limit(5)->get();
  7948. //获取5条未读群聊信息
  7949. $chat_group = ChatRecords::where('is_read', 0)
  7950. ->where('user_id', $user_id)
  7951. ->where('talk_type', 2)
  7952. ->orderBy('created_at', 'desc')
  7953. ->limit(5)->get();
  7954. //获取5条用户的已审核商品
  7955. $good = Good::where('status', 2)
  7956. ->where('user_id', $user_id)
  7957. ->orderBy('updated_at', 'desc')
  7958. ->limit(5)->get();
  7959. //获取5条用户的book
  7960. $book = Book::where('status', 2)
  7961. ->where('user_id', $user_id)
  7962. ->orderBy('updated_at', 'desc')
  7963. ->limit(5)->get();
  7964. //获取5条用户的求职
  7965. //获取5条用户的求职 1
  7966. //count($chat) + count($chat_group)
  7967. $count = count($apply_articale) + count($good);
  7968. $result = [
  7969. 'apply_articale' => $apply_articale,
  7970. 'chat' => $chat,
  7971. 'chat_group' => $chat_group,
  7972. 'good' => $good,
  7973. 'book' => $book,
  7974. 'count' => $count,
  7975. ];
  7976. } elseif ($type_id == 13) {
  7977. //最近的5篇已审的文章
  7978. $apply_articale = Article::where('status', 1)
  7979. ->where('admin_user_id', $user_id)
  7980. ->limit(5)->get();
  7981. //获取5条单聊未读聊天消息
  7982. $chat = ChatRecords::where('is_read', 0)
  7983. ->where('user_id', $user_id)
  7984. ->where('talk_type', 1)
  7985. ->orderBy('created_at', 'desc')
  7986. ->limit(5)->get();
  7987. //获取5条未读群聊信息
  7988. $chat_group = ChatRecords::where('is_read', 0)
  7989. ->where('user_id', $user_id)
  7990. ->where('talk_type', 2)
  7991. ->orderBy('created_at', 'desc')
  7992. ->limit(5)->get();
  7993. //获取5条用户的已审核商品
  7994. $good = Good::where('status', 2)
  7995. ->where('user_id', $user_id)
  7996. ->orderBy('updated_at', 'desc')
  7997. ->limit(5)->get();
  7998. //count($chat) + count($chat_group) +
  7999. $count = count($apply_articale) + count($good);
  8000. $result = [
  8001. 'apply_articale' => $apply_articale,
  8002. 'chat' => $chat,
  8003. 'chat_group' => $chat_group,
  8004. 'good' => $good,
  8005. 'count' => $count,
  8006. ];
  8007. } elseif ($type_id == 14) {
  8008. //最近的5篇已审的文章
  8009. $apply_articale = Article::where('status', 1)
  8010. ->where('admin_user_id', $user_id)
  8011. // ->limit(5)
  8012. ->get();
  8013. //获取5条用户的已审核商品
  8014. $good = Good::where('status', 2)
  8015. ->where('user_id', $user_id)
  8016. ->orderBy('updated_at', 'desc')
  8017. // ->limit(5)
  8018. ->get();
  8019. $count = count($apply_articale) + count($good);
  8020. $result = [
  8021. 'apply_articale' => $apply_articale,
  8022. 'chat' => '',
  8023. 'chat_group' => '',
  8024. 'good' => $good,
  8025. 'count' => $count,
  8026. ];
  8027. } elseif ($type_id == 10000) {
  8028. //获取未审核的5篇文章
  8029. $apply_articale = Article::where('status', 0)
  8030. ->orderBy('updated_at', 'desc')
  8031. // ->limit(5)
  8032. ->get();
  8033. //获取5条单聊未读聊天消息
  8034. //获取5条单聊未读聊天消息
  8035. // $chat = ChatRecords::where('is_read', 0)
  8036. // ->where('user_id', $user_id)
  8037. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  8038. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  8039. // ->where('action', 'recieved')
  8040. // ->where('talk_type', 1)
  8041. // ->orderBy('created_at', 'desc')
  8042. // // ->limit(5)
  8043. // ->get();
  8044. // //获取5条未读群聊信息
  8045. // $chat_group = ChatRecords::where('is_read', 0)
  8046. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  8047. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  8048. // ->where('user_id', $user_id)
  8049. // ->where('talk_type', 2)
  8050. // ->orderBy('created_at', 'desc')
  8051. // // ->limit(5)
  8052. // ->get();
  8053. //获取5条用户的已审核商品
  8054. $good = Good::where('status', 1)
  8055. // ->where('user_id', $user_id)
  8056. ->orderBy('updated_at', 'desc')
  8057. // ->limit(5)
  8058. ->get();
  8059. //获取5条用户待审核的公告
  8060. $notice = Notice::where('status', 1)
  8061. ->orderBy('updated_at', 'desc')
  8062. // ->limit(5)
  8063. ->get();
  8064. //获取5条用户的待审核投诉
  8065. $complaint = Complaint::where('status', 1)
  8066. ->orderBy('updated_at', 'desc')
  8067. // ->limit(5)
  8068. ->get();
  8069. //获取5条用户的book
  8070. $book = Book::where('status', 1)
  8071. ->orderBy('updated_at', 'desc')
  8072. // ->limit(5)
  8073. ->get();
  8074. //获取5条用户的求职 1
  8075. $job_hunting = JobHunting::where('job_hunting.status', 1)
  8076. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  8077. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  8078. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  8079. ->orderBy('updated_at', 'desc')
  8080. // ->limit(5)
  8081. ->get();
  8082. //获取5条用户的求职 2
  8083. $job_recruiting = JobRecruiting::where('job_recruiting.status', 0)
  8084. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  8085. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  8086. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  8087. ->orderBy('updated_at', 'desc')
  8088. // ->limit(5)
  8089. ->get();
  8090. //人才库 1
  8091. $job_apply = JobApply::where('job_apply.status', 1)
  8092. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  8093. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  8094. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  8095. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  8096. ->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')
  8097. ->orderBy('updated_at', 'desc')
  8098. // ->limit(5)
  8099. ->get();
  8100. // 职场机会 2
  8101. $job_resume = JobResume::where('job_resume.status', 1)
  8102. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  8103. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  8104. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  8105. ->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')
  8106. ->orderBy('updated_at', 'desc')
  8107. // ->limit(5)
  8108. ->get();
  8109. //待审核数据com pro
  8110. $complany = Company::where('status', 0)
  8111. ->orderBy('updated_at', 'desc')
  8112. // ->limit(5)
  8113. ->get();
  8114. $project = Project::where('status', 0)
  8115. ->orderBy('updated_at', 'desc')
  8116. // ->limit(5)
  8117. ->get();
  8118. $count =
  8119. // count($chat) +
  8120. // count($chat_group) +
  8121. count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting)
  8122. // + count($job_apply)
  8123. // + count($job_resume)
  8124. + count($complany)
  8125. + count($project);
  8126. $result = [
  8127. 'apply_articale' => $apply_articale,
  8128. // 'chat' => $chat,
  8129. // 'chat_group' => $chat_group,
  8130. 'good' => $good,
  8131. 'notice' => $notice,
  8132. 'complaint' => $complaint,
  8133. 'book' => $book,
  8134. 'job_hunting' => $job_hunting,
  8135. 'job_recruiting' => $job_recruiting,
  8136. // 'job_apply' => $job_apply,
  8137. // 'job_resume' => $job_resume,
  8138. 'complany' => $complany,
  8139. 'project' => $project,
  8140. 'count' => $count,
  8141. ];
  8142. } elseif ($type_id == 20000) {
  8143. }
  8144. var_dump($type_id, '-----------------test---------');
  8145. return Result::success($result);
  8146. }
  8147. /**
  8148. * @param array $data
  8149. * @return array
  8150. */
  8151. public function getWebsiteProject(array $data): array
  8152. {
  8153. $categorys = json_decode($data['id'], true);
  8154. if (!empty($categorys)) {
  8155. $category_arr = $this->processArticlePro($data['website_id']);
  8156. $cat_1st_arr = $category_arr['cat_1st_arr'];
  8157. $catiall = $category_arr['catiall'];
  8158. // return Result::success($catiall);
  8159. foreach ($categorys as $key => $val) {
  8160. if (isset($val['level'][0]) && !empty($val['level'][0])) {
  8161. $level = explode(',', $val['level'])[0];
  8162. $imgnum = explode(',', $val['level'])[1] ?? null;
  8163. $textnum = explode(',', $val['level'])[2] ?? null;
  8164. if ($level == 1) {
  8165. if (!empty($textnum) && $textnum > 0) {
  8166. $text_num = Project::where('level', $level)
  8167. ->where('website_id', $data['website_id'])
  8168. ->where('status', 1)
  8169. ->select(
  8170. 'project.id',
  8171. 'project.title',
  8172. 'project.description',
  8173. 'project.updated_at',
  8174. 'project.category_id',
  8175. 'project.cat_arr_id'
  8176. )
  8177. ->orderBy('updated_at', 'desc')
  8178. ->limit($textnum)
  8179. ->get()->all();
  8180. }
  8181. if (!empty($imgnum) && $imgnum > 0) {
  8182. $img_num = Project::where('level', $level)
  8183. ->where('website_id', $data['website_id'])
  8184. ->where('status', 1)
  8185. ->where('imgurl', '!=', '')
  8186. ->whereNotNull('imgurl')
  8187. ->select(
  8188. 'project.id',
  8189. 'project.title',
  8190. 'project.description',
  8191. 'project.updated_at',
  8192. 'project.imgurl as imgs',
  8193. 'project.category_id',
  8194. 'project.cat_arr_id'
  8195. )
  8196. ->orderBy('updated_at', 'desc')
  8197. ->limit($imgnum)
  8198. ->get()->all();
  8199. }
  8200. } else {
  8201. if (!empty($textnum) && $textnum > 0) {
  8202. $text_num = Project::where('website_id', $data['website_id'])
  8203. ->where('status', 1)
  8204. ->select(
  8205. 'project.id',
  8206. 'project.title',
  8207. 'project.description',
  8208. 'project.updated_at',
  8209. 'project.category_id',
  8210. 'project.cat_arr_id',
  8211. 'project.website_id',
  8212. 'project.updated_at',
  8213. 'project.created_at'
  8214. )
  8215. ->orderBy('updated_at', 'desc')
  8216. ->limit($textnum)
  8217. ->get()->all();
  8218. }
  8219. if (!empty($imgnum) && $imgnum > 0) {
  8220. $img_num = Project::where('website_id', $data['website_id'])
  8221. ->where('status', 1)
  8222. ->where('imgurl', '!=', '')
  8223. ->whereNotNull('imgurl')
  8224. ->select(
  8225. 'project.id',
  8226. 'project.title',
  8227. 'project.description',
  8228. 'project.updated_at',
  8229. 'project.imgurl as imgs',
  8230. 'project.category_id',
  8231. 'project.cat_arr_id'
  8232. )
  8233. ->orderBy('updated_at', 'desc')
  8234. ->limit($imgnum)
  8235. ->get()->all();
  8236. }
  8237. }
  8238. }
  8239. if (isset($val['id'][0]) && !empty($val['id'][0])) {
  8240. $category_ids = explode(',', $val['id'])[0];
  8241. $cat_imgnum = explode(',', $val['id'])[1] ?? null;
  8242. $cat_textnum = explode(',', $val['id'])[2] ?? null;
  8243. $category_arr = array_merge([$category_ids], $cat_1st_arr[$category_ids] ?? [0]);
  8244. if (!empty($cat_textnum) && $cat_textnum > 0) {
  8245. $text_num = Project::whereIn('category_id', $category_arr)
  8246. ->where('website_id', $data['website_id'])
  8247. ->where('status', 1)
  8248. ->select(
  8249. 'project.id',
  8250. 'project.title',
  8251. 'project.description',
  8252. 'project.updated_at',
  8253. 'project.category_id',
  8254. 'project.cat_arr_id'
  8255. )
  8256. ->orderBy('updated_at', 'desc')
  8257. ->limit($cat_textnum)
  8258. ->get()->all();
  8259. }
  8260. if (!empty($cat_imgnum) && $cat_imgnum > 0) {
  8261. $img_num = Project::whereIn('category_id', $category_arr)
  8262. ->where('website_id', $data['website_id'])
  8263. ->where('status', 1)
  8264. ->where('imgurl', '!=', '')
  8265. ->whereNotNull('imgurl')
  8266. ->select(
  8267. 'project.id',
  8268. 'project.title',
  8269. 'project.description',
  8270. 'project.updated_at',
  8271. 'project.imgurl as imgs',
  8272. 'project.category_id',
  8273. 'project.cat_arr_id'
  8274. )
  8275. ->orderBy('updated_at', 'desc')
  8276. ->limit($cat_imgnum)
  8277. ->get()->all();
  8278. }
  8279. }
  8280. if (!empty($img_num)) {
  8281. foreach ($img_num as $k => $v) {
  8282. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8283. $imgurl = json_decode($v['imgs'], true);
  8284. if (!empty($imgurl)) {
  8285. $img_num[$k]->imgurl = $imgurl[0];
  8286. }
  8287. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8288. }
  8289. }
  8290. if (!empty($text_num)) {
  8291. foreach ($text_num as $k => $v) {
  8292. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8293. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8294. }
  8295. }
  8296. $project[$key]['img_num'] = $img_num ?? [];
  8297. $project[$key]['text_num'] = $text_num ?? [];
  8298. }
  8299. }
  8300. if (empty($project)) {
  8301. return Result::error("暂无相关项目信息", 0);
  8302. }
  8303. return Result::success($project);
  8304. }
  8305. /**
  8306. * @param array $data
  8307. * @return array
  8308. */
  8309. public function getWebsiteProjectInfo(array $data): array
  8310. {
  8311. $project = Project::where('id', $data['id'])
  8312. ->where('status', 1)
  8313. ->where('website_id', $data['website_id'])
  8314. ->select('project.*')
  8315. ->first();
  8316. if (empty($project)) {
  8317. return Result::error("暂无相关项目信息", 0);
  8318. }
  8319. return Result::success($project);
  8320. }
  8321. /**
  8322. * @param array $data
  8323. * @return array
  8324. */
  8325. public function getWebsiteProjectList(array $data): array
  8326. {
  8327. $where = [];
  8328. if (isset($data['category_id']) && !empty($data['category_id'])) {
  8329. $where['category_id'] = $data['category_id'];
  8330. }
  8331. if (isset($data['keyword']) && !empty($data['keyword'])) {
  8332. $where[] = ['title', 'like', '%' . $data['keyword'] . '%'];
  8333. }
  8334. $query = Project::where($where)
  8335. ->where('status', 1)
  8336. ->where('website_id', $data['website_id'])
  8337. ->select(
  8338. 'project.id',
  8339. 'project.title',
  8340. 'project.description',
  8341. 'project.imgurl as imgs',
  8342. 'project.category_id',
  8343. 'project.cat_arr_id'
  8344. )
  8345. ->orderBy('updated_at', 'desc');
  8346. $count = $query->count();
  8347. $project = $query->clone()
  8348. ->offset(($data['page'] - 1) * $data['pageSize'])
  8349. ->limit($data['pageSize'])
  8350. ->get()->all();
  8351. if (empty($project)) {
  8352. return Result::error("暂无相关项目信息", 0);
  8353. }
  8354. $categorys = $this->processArticlePro($data['website_id']);
  8355. $catiall = $categorys['catiall'];
  8356. foreach ($project as $key => $val) {
  8357. $project[$key]->category_name = $catiall[$val->category_id]['alias'];
  8358. if (!empty($val['imgs'])) {
  8359. $imgurl = json_decode($val['imgs'], true);
  8360. if (!empty($imgurl)) {
  8361. $project[$key]->imgurl = $imgurl[0];
  8362. }
  8363. } else {
  8364. $project[$key]->imgurl = '';
  8365. }
  8366. $project[$key]->pinyin = $catiall[$val->category_id]['pinyin'];
  8367. }
  8368. $result = [
  8369. 'rows' => $project,
  8370. 'count' => $count,
  8371. ];
  8372. return Result::success($result);
  8373. }
  8374. /**
  8375. * @param array $data
  8376. * @return array
  8377. */
  8378. public function getWebsiteCategoryJob(array $data): array
  8379. {
  8380. $categorys = json_decode($data['id'], true);
  8381. if (!empty($categorys)) {
  8382. $category_arr = $this->processArticlePro($data['website_id']);
  8383. $cat_1st_arr = $category_arr['cat_1st_arr'];
  8384. $catiall = $category_arr['catiall'];
  8385. foreach ($categorys as $key => $val) {
  8386. if (isset($val['id']) && !empty($val['id'])) {
  8387. $catid = explode(',', $val['id'])[0] ?? null;
  8388. $type = explode(',', $val['id'])[1] ?? null;
  8389. $textnum = explode(',', $val['id'])[2] ?? null;
  8390. }
  8391. // 4:招聘;5:求职;
  8392. if ($textnum > 0 && $type == 4 && !empty($catid)) {
  8393. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  8394. $job = JobRecruiting::WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($catid) . "') = 1")
  8395. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  8396. ->where('job_recruiting.status', 1)
  8397. ->where('job_recruiting.website_id', $data['website_id'])
  8398. ->select(
  8399. 'job_recruiting.id',
  8400. 'job_recruiting.title',
  8401. 'job_company.business_name',
  8402. 'job_recruiting.updated_at',
  8403. 'job_recruiting.cat_arr_id',
  8404. 'job_recruiting.keyword',
  8405. 'job_recruiting.description'
  8406. )
  8407. ->orderBy('job_recruiting.updated_at', 'desc')
  8408. ->limit($textnum)
  8409. ->get()->all();
  8410. } else if ($textnum > 0 && $type == 5 && !empty($catid)) {
  8411. // 状态 审核状态,1待审核2已审核3已拒绝
  8412. $job = JobHunting::WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($catid) . "') = 1")
  8413. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  8414. ->where('job_hunting.status', 2)
  8415. ->where('job_hunting.website_id', $data['website_id'])
  8416. ->select(
  8417. 'job_hunting.id',
  8418. 'job_hunting.name',
  8419. 'job_hunting.cat_arr_id',
  8420. 'job_position.zwname as job_name',
  8421. 'job_hunting.updated_at',
  8422. // 'job_hunting.keyword',
  8423. 'job_hunting.slelf_evaluation'
  8424. )
  8425. ->orderBy('updated_at', 'desc')
  8426. ->limit($textnum)
  8427. ->get()->all();
  8428. } else {
  8429. $job = [];
  8430. }
  8431. // var_dump($catid.'222uuuuuuu'.$key);
  8432. if (!empty($job)) {
  8433. foreach ($job as $k => $value) {
  8434. if (isset($value->cat_arr_id)) {
  8435. $catArr = json_decode($value->cat_arr_id, true);
  8436. $catId = end($catArr);
  8437. } else {
  8438. continue;
  8439. }
  8440. if (isset($catiall[$catId])) {
  8441. $job[$k]->pinyin = $catiall[$catId]['pinyin'];
  8442. }
  8443. }
  8444. }
  8445. // var_dump($catid.'xxxxx'.$key);
  8446. $result[$key] = $job ?? [];
  8447. }
  8448. }
  8449. if (empty($result)) {
  8450. return Result::error("暂无相关分类信息", 0);
  8451. }
  8452. return Result::success($result);
  8453. }
  8454. /**
  8455. * 发送消息
  8456. * @param array $messageData
  8457. * @return void
  8458. */
  8459. public function sendMessage($messageData)
  8460. {
  8461. $msg = [
  8462. 'talk_type' => $messageData['talk_type'],
  8463. 'title' => $messageData['title'],
  8464. 'content' => $messageData['content'],
  8465. 'messageType' => $messageData['messageType'],
  8466. 'user_id' => $messageData['user_id'] ?? '',
  8467. 'time' => microtime(),
  8468. ];
  8469. $message = new MqProducer($msg);
  8470. $producer = ContextApplicationContext::getContainer()->get(Producer::class);
  8471. $producer->produce($message);
  8472. }
  8473. /**
  8474. * 行业分类管理 ------1121
  8475. * @param array $data
  8476. * @return array
  8477. */
  8478. public function getJobIndustryList(array $data): array
  8479. {
  8480. $page = $data['page'] ?? 1;
  8481. $page_size = $data['page_size'] ?? 10;
  8482. if (isset($data['hyname']) && !empty($data['hyname'])) {
  8483. $where = ['hyname', 'like', '%' . $data['hyname'] . '%'];
  8484. } else {
  8485. $where = [];
  8486. }
  8487. $rs_query = JobIndustry::when(!empty($where), function ($query) use ($where) {
  8488. $query->where([$where]); // 修复:将条件包装成二维数组
  8489. })
  8490. ->orderBy('updated_at', 'desc');
  8491. $count = $rs_query->count();
  8492. $hy = $rs_query->offset(($page - 1) * $page_size)->limit($page_size)->get()->all();
  8493. $result = [
  8494. 'count' => $count,
  8495. 'list' => $hy,
  8496. ];
  8497. if (empty($hy)) {
  8498. return Result::success('暂无数据');
  8499. }
  8500. return Result::success($result);
  8501. }
  8502. /**
  8503. * 添加行业分类
  8504. * @param array $data
  8505. * @return array
  8506. */
  8507. public function addJobIndustry(array $data): array
  8508. {
  8509. $hy_name = JobIndustry::where('hyname', $data['hyname'])->first(['hyid']);
  8510. if (!empty($hy_name)) {
  8511. return Result::error('行业分类已存在');
  8512. }
  8513. $hy = JobIndustry::insertGetId($data);
  8514. if (empty($hy)) {
  8515. return Result::error('添加失败');
  8516. }
  8517. return Result::success($hy);
  8518. }
  8519. /**
  8520. * 更新行业分类
  8521. * @param array $data
  8522. * @return array
  8523. */
  8524. public function upJobIndustry(array $data): array
  8525. {
  8526. $hy_query = JobIndustry::get();
  8527. $hy_ids = $hy_query->pluck('hyid')->toArray();
  8528. $hy_names = $hy_query->pluck('hyname')->toArray();
  8529. if (!in_array($data['hyid'], $hy_ids)) {
  8530. return Result::error('行业分类不存在');
  8531. }
  8532. if (isset($data['hyname']) && !empty($data['hyname'])) {
  8533. $other_key_hy = array_search($data['hyid'], $hy_ids);
  8534. // return Result::success($other_key_hy);
  8535. unset($hy_names[$other_key_hy]);
  8536. if (in_array($data['hyname'], $hy_names)) {
  8537. return Result::error('行业分类名称已存在');
  8538. }
  8539. }
  8540. $hy = JobIndustry::where('hyid', $data['hyid'])->update($data);
  8541. if (empty($hy)) {
  8542. return Result::error('更新失败');
  8543. }
  8544. return Result::success($hy);
  8545. }
  8546. /**
  8547. * 删除行业分类
  8548. * @param array $data
  8549. * @return array
  8550. */
  8551. public function delJobIndustry(array $data): array
  8552. {
  8553. $hy_id = JobIndustry::where('hyid', $data['hyid'])->first(['hyid']);
  8554. if (empty($hy_id)) {
  8555. return Result::error('行业分类不存在');
  8556. }
  8557. $hy = JobIndustry::where('hyid', $data['hyid'])->delete();
  8558. if (empty($hy)) {
  8559. return Result::error('删除失败');
  8560. }
  8561. return Result::success($hy);
  8562. }
  8563. /**
  8564. * 职位分类-列表
  8565. * @param array $data
  8566. * @return array
  8567. */
  8568. public function getJobPositionList(array $data): array
  8569. {
  8570. $page = $data['page'] ?? 1;
  8571. $page_size = $data['page_size'] ?? 10;
  8572. $where = [];
  8573. if (isset($data['zwname']) && !empty($data['zwname'])) {
  8574. $zwids = JobPosition::where('zwpid', 0)
  8575. ->when(!empty($data['zwname']), function ($query) use ($data) {
  8576. $query->where('zwname', 'like', '%' . $data['zwname'] . '%');
  8577. })
  8578. ->orderBy('updated_at', 'desc')
  8579. ->pluck('zwid')
  8580. // ->get()
  8581. ->toArray();
  8582. }
  8583. if (isset($data['childname']) && !empty($data['childname'])) {
  8584. $child_zwids = JobPosition::where('zwpid', '!=', 0)
  8585. ->when(!empty($data['childname']), function ($query) use ($data) {
  8586. $query->where('zwname', 'like', '%' . $data['childname'] . '%');
  8587. })
  8588. ->orderBy('updated_at', 'desc')
  8589. ->pluck('zwpid')
  8590. // ->get()
  8591. ->toArray();
  8592. if (isset($zwids) && is_array($zwids) && is_array($child_zwids)) {
  8593. $child_zwids = array_intersect($zwids, $child_zwids);
  8594. }
  8595. $zwids = array_values(array_unique($child_zwids));
  8596. }
  8597. $zwids = $zwids ?? null;
  8598. $count = JobPosition::when(!empty($zwids), function ($query) use ($zwids) {
  8599. $query->whereIn('zwid', $zwids);
  8600. })
  8601. ->where('zwpid', 0)
  8602. ->count();
  8603. $position = JobPosition::when(!empty($zwids), function ($query) use ($zwids) {
  8604. $query->whereIn('zwid', $zwids);
  8605. })
  8606. ->where('zwpid', 0)
  8607. ->orderBy('updated_at', 'desc')
  8608. ->offset(($page - 1) * $page_size)
  8609. ->limit($page_size)->get()
  8610. ->map(function ($item) use ($data) {
  8611. $item->children = $item->where('zwpid', $item->zwid)
  8612. ->when(!empty($data['childname']), function ($query) use ($data) {
  8613. $query->where('zwname', 'like', '%' . $data['childname'] . '%');
  8614. })
  8615. ->orderBy('updated_at', 'desc')
  8616. ->get();
  8617. return $item;
  8618. })
  8619. ->all();
  8620. $result = [
  8621. 'count' => $count,
  8622. 'list' => $position,
  8623. ];
  8624. if (empty($result)) {
  8625. return Result::success('暂无数据');
  8626. }
  8627. return Result::success($result);
  8628. }
  8629. /**
  8630. * 职位分类-添加
  8631. * @param array $data
  8632. * @return array
  8633. */
  8634. public function addJobPosition(array $data): array
  8635. {
  8636. $zw_name = JobPosition::where('zwpid', $data['zwpid'])
  8637. ->where('zwname', $data['zwname'])->first(['zwid']);
  8638. if (!empty($zw_name)) {
  8639. return Result::error('职位分类已存在');
  8640. }
  8641. $zw = JobPosition::insertGetId($data);
  8642. if(empty($zw)){
  8643. return Result::error('添加失败');
  8644. }
  8645. return Result::success($zw);
  8646. }
  8647. /**
  8648. * 更新职位分类
  8649. * @param array $data
  8650. * @return array
  8651. */
  8652. public function upJobPosition(array $data): array
  8653. {
  8654. $zw_position = JobPosition::get();
  8655. if (!in_array($data['zwid'], $zw_position->pluck('zwid')->toArray())) {
  8656. return Result::error('职位分类不存在');
  8657. }
  8658. $zw_name = $zw_position->where('zwid', '!=', $data['zwid'])
  8659. ->where('zwpid', $data['zwpid'])
  8660. ->where('zwname', $data['zwname'])->first();
  8661. if (!empty($zw_name)) {
  8662. return Result::error('职位分类已存在');
  8663. }
  8664. $result = JobPosition::where('zwid', $data['zwid'])->update($data);
  8665. if (empty($result)) {
  8666. return Result::error('更新失败');
  8667. }
  8668. return Result::success($result);
  8669. }
  8670. /**
  8671. * 删除职位分类
  8672. * @param array $data
  8673. * @return array
  8674. */
  8675. public function delJobPosition(array $data): array
  8676. {
  8677. $zw_jobposition = JobPosition::get();
  8678. $zw_id = $zw_jobposition->where('zwid', $data['zwid'])->first();
  8679. if (empty($zw_id)) {
  8680. return Result::error('职位分类不存在');
  8681. }
  8682. if($zw_id->zwpid == 0){
  8683. $zw_job = JobPosition::where('zwpid', $zw_id->zwid)->first();
  8684. if(!empty($zw_job)){
  8685. return Result::error('请先删除子分类');
  8686. }
  8687. }
  8688. $result = JobPosition::where('zwid', $data['zwid'])->delete();
  8689. if (empty($result)) {
  8690. return Result::error('删除失败');
  8691. }
  8692. return Result::success($result);
  8693. }
  8694. /**
  8695. * 网民留言-添加
  8696. * @param array $data
  8697. * @return array
  8698. */
  8699. public function addMessage(array $data): array
  8700. {
  8701. $user = User::where('id', $data['user_id'])->first();
  8702. if (empty($user)) {
  8703. return Result::error('用户不存在');
  8704. }
  8705. if($user['type_id'] == 10000){
  8706. $data['status'] = 1;
  8707. }else{
  8708. $data['status'] = 0;
  8709. }
  8710. if ($data['keyword'] == '') {
  8711. //提取标题+内容中的关键词
  8712. $data['keyword'] = $data['title'];
  8713. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  8714. Jieba::init(); // 初始化 jieba-php
  8715. Finalseg::init();
  8716. $segList = Jieba::cut($data['keyword']);
  8717. $segList1 = array_slice($segList, 0, 8);
  8718. $data['keyword'] = implode(',', $segList1);
  8719. }
  8720. if ($data['description'] == '') {
  8721. //提取内容中的描述
  8722. $content = $data['content'];
  8723. // 去除 <style> 和 <script> 标签及其内容
  8724. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  8725. // 去除所有 HTML 标签
  8726. $content = strip_tags($content);
  8727. // 去除 HTML 实体
  8728. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  8729. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  8730. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  8731. // 去除多余空白
  8732. $content = preg_replace('/\s+/u', '', $content);
  8733. // 截取 100 个字符
  8734. $data['description'] = mb_substr($content, 0, 100);
  8735. }
  8736. if(!empty($data['reply'])){
  8737. $data['reply_userid'] = $data['user_id'];
  8738. }
  8739. $result = Message::insertGetId($data);
  8740. if(empty($result)){
  8741. return Result::error('添加失败');
  8742. }
  8743. return Result::success($result);
  8744. }
  8745. /**
  8746. * 网民留言-更新
  8747. * @param array $data
  8748. * @return array
  8749. */
  8750. public function upMessage(array $data): array
  8751. {
  8752. $user = User::where('id', $data['user_id'])->first();
  8753. if (empty($user)) {
  8754. return Result::error('用户不存在');
  8755. }
  8756. if($user['type_id'] == 10000){
  8757. $data['status'] = 1;
  8758. }else{
  8759. $data['status'] = 0;
  8760. }
  8761. $message = Message::where('id', $data['id'])->first();
  8762. if (empty($message)) {
  8763. return Result::error('留言不存在');
  8764. }
  8765. if($data['user_id'] != $message['user_id'] && $user['type_id'] != 10000){
  8766. return Result::error('非留言人不能更新');
  8767. }
  8768. if ($data['keyword'] == '') {
  8769. //提取标题+内容中的关键词
  8770. $data['keyword'] = $data['title'];
  8771. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  8772. Jieba::init(); // 初始化 jieba-php
  8773. Finalseg::init();
  8774. $segList = Jieba::cut($data['keyword']);
  8775. $segList1 = array_slice($segList, 0, 8);
  8776. $data['keyword'] = implode(',', $segList1);
  8777. }
  8778. if ($data['description'] == '') {
  8779. //提取内容中的描述
  8780. $content = $data['content'];
  8781. // 去除 <style> 和 <script> 标签及其内容
  8782. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  8783. // 去除所有 HTML 标签
  8784. $content = strip_tags($content);
  8785. // 去除 HTML 实体
  8786. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  8787. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  8788. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  8789. // 去除多余空白
  8790. $content = preg_replace('/\s+/u', '', $content);
  8791. // 截取 100 个字符
  8792. $data['description'] = mb_substr($content, 0, 100);
  8793. }
  8794. unset($data['id']);
  8795. if(!empty($data['reply'])){
  8796. $data['reply_userid'] = $data['user_id'];
  8797. unset($data['user_id']);
  8798. }
  8799. $result = Message::where('id', $message['id'])->update($data);
  8800. if (empty($result)) {
  8801. return Result::error('更新失败');
  8802. }
  8803. return Result::success($result);
  8804. }
  8805. /**
  8806. * 网民留言-删除
  8807. * @param array $data
  8808. * @return array
  8809. */
  8810. public function delMessage(array $data): array
  8811. {
  8812. $result = Message::where('id', $data['id'])->delete();
  8813. if (empty($result)) {
  8814. return Result::error('删除失败');
  8815. }
  8816. return Result::success($result);
  8817. }
  8818. /**
  8819. * 网民留言-更新状态
  8820. * @param array $data
  8821. * @return array
  8822. */
  8823. public function upMessageStatus(array $data): array
  8824. {
  8825. $message = Message::where('id', $data['id'])->first();
  8826. if (empty($message)) {
  8827. return Result::error('留言不存在!');
  8828. }
  8829. unset($data['id']);
  8830. unset($data['user_id']);
  8831. if($data['status'] != 2){
  8832. $data['reason'] = null;
  8833. }
  8834. $result = Message::where('id', $message['id'])->update($data);
  8835. if (empty($result)) {
  8836. return Result::error('留言更新失败!');
  8837. }
  8838. return Result::success($result);
  8839. }
  8840. /**
  8841. * 网民留言-获取详情
  8842. * @param array $data
  8843. * @return array
  8844. */
  8845. public function getMessageInfo(array $data): array
  8846. {
  8847. $result = Message::where('message.id', $data['id'])
  8848. ->leftJoin('website_column', 'message.column_id', '=', 'website_column.id')
  8849. ->select('message.*', 'website_column.column_arr_id')
  8850. ->first();
  8851. if (empty($result)) {
  8852. return Result::error('留言不存在!');
  8853. }
  8854. $result['column_arr_id'] = json_decode($result['column_arr_id'] ?? [], true);
  8855. return Result::success($result);
  8856. }
  8857. /**
  8858. * 网民留言-获取列表
  8859. * @param array $data
  8860. * @return array
  8861. */
  8862. public function getMessageList(array $data): array
  8863. {
  8864. $where = [];
  8865. if($data['is_master'] == 1){
  8866. $where['message.status'] = 1;
  8867. }else if($data['is_master'] == 2){
  8868. $where['message.status'] = 2;
  8869. }else if($data['is_master'] == 3){
  8870. $where['message.status'] = 0;
  8871. }
  8872. $user = User::where('id', $data['user_id'])->first();
  8873. if (empty($user)) {
  8874. return Result::error('用户不存在');
  8875. }
  8876. $column_arr_id = [];
  8877. if($user['type_id'] != 10000 && !empty($data['website_id'])){
  8878. $where['message.user_id'] = $data['user_id'];
  8879. $web = Website::where('id',$data['website_id'])->first('website_column_arr_id');
  8880. if(empty($web)){
  8881. return Result::error('此网站未关联任何网站属性!');
  8882. }
  8883. $column_arr_id = json_decode($web['website_column_arr_id'],true);
  8884. }
  8885. if(!empty($data['title'])){
  8886. array_push($where, ['message.title', 'like', '%'.$data['title'].'%']);
  8887. }
  8888. $result = Message::when($data['is_master'] == 0, function ($query) {
  8889. $query->whereIn('message.status', [0, 2]);
  8890. })
  8891. ->when(!empty($where), function ($query) use ($where) {
  8892. $query->where($where);
  8893. })
  8894. ->leftJoin('user', 'message.user_id', '=', 'user.id')
  8895. ->select('message.*', 'user.nickname')
  8896. ->orderBy('message.updated_at', 'desc')
  8897. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  8898. if(empty($result->items())) {
  8899. return Result::error('留言不存在!');
  8900. }
  8901. $result = [
  8902. 'data' => $result->items(),
  8903. 'count' => $result->total(),
  8904. ];
  8905. if(!empty($column_arr_id) && $user['type_id'] != 10000){
  8906. foreach($result['data'] as $key => $value){
  8907. if(in_array($value['column_id'], $column_arr_id)){
  8908. $result['data'][$key]['is_update'] = 1;
  8909. }else{
  8910. $result['data'][$key]['is_update'] = 0;
  8911. }
  8912. }
  8913. }
  8914. return Result::success($result);
  8915. }
  8916. /**
  8917. * 网民留言-检查是否可编辑
  8918. * @param array $data
  8919. * @return array
  8920. */
  8921. public function checkMessageEdit(array $data): array
  8922. {
  8923. $message = Message::where('id', $data['id'])->first();
  8924. if (empty($message)) {
  8925. return Result::error('留言不存在!');
  8926. }
  8927. $web = Website::where('id', $data['website_id'])->first();
  8928. if (empty($web)) {
  8929. return Result::error('网站不存在!');
  8930. }
  8931. $column_arr = json_decode($web['website_column_arr_id'] ?? [], true);
  8932. if(empty($column_arr)){
  8933. return Result::error('该网站未关联任何属性!');
  8934. }
  8935. if(!in_array($message['column_id'], $column_arr)){
  8936. return Result::error('不可编辑');
  8937. }
  8938. return Result::success('可编辑');
  8939. }
  8940. /**
  8941. * 调研选题-获取所有Researchers
  8942. * @param array $data
  8943. * @return array
  8944. */
  8945. public function getAllResearcher(array $data): array
  8946. {
  8947. $where['role_user.role_id'] = 21;
  8948. if(!empty($data['id'])){
  8949. $where['user.id'] = $data['id'];
  8950. }
  8951. if(!empty($data['real_name'])){
  8952. array_push($where, ['user_info.real_name', 'like', '%'.$data['real_name'].'%']);
  8953. }
  8954. $users = User::leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  8955. ->leftJoin('role_user', 'user.id', '=', 'role_user.user_id')
  8956. ->where($where)
  8957. ->select('user.id', 'user_info.real_name','user_info.number')
  8958. ->get()->toArray();
  8959. if (empty($users)) {
  8960. return Result::error('此调研员不存在!');
  8961. }
  8962. $user_number = array_search($data['user_id'], array_column($users, 'id'));
  8963. if($user_number == false){
  8964. $result['number'] = null;
  8965. }else{
  8966. $result['number'] = $users[$user_number]['number'];
  8967. }
  8968. $result['users'] = $users;
  8969. $result['user_id'] = $data['user_id'];
  8970. return Result::success($result);
  8971. }
  8972. /**
  8973. * 调研选题-添加
  8974. * @param array $data
  8975. * @return array
  8976. */
  8977. public function addResearchTopic(array $data): array
  8978. {
  8979. $user = User::where('id', $data['user_id'])->first();
  8980. if (empty($user)) {
  8981. return Result::error('用户不存在');
  8982. }
  8983. if($user['type_id'] == 10000){
  8984. $data['status'] = 1;
  8985. }else{
  8986. $data['status'] = 0;
  8987. }
  8988. if ($data['keyword'] == '') {
  8989. //提取标题+内容中的关键词
  8990. $data['keyword'] = $data['title'];
  8991. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  8992. Jieba::init(); // 初始化 jieba-php
  8993. Finalseg::init();
  8994. $segList = Jieba::cut($data['keyword']);
  8995. $segList1 = array_slice($segList, 0, 8);
  8996. $data['keyword'] = implode(',', $segList1);
  8997. }
  8998. if ($data['description'] == '') {
  8999. //提取内容中的描述
  9000. $content = $data['content'];
  9001. // 去除 <style> 和 <script> 标签及其内容
  9002. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  9003. // 去除所有 HTML 标签
  9004. $content = strip_tags($content);
  9005. // 去除 HTML 实体
  9006. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  9007. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  9008. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  9009. // 去除多余空白
  9010. $content = preg_replace('/\s+/u', '', $content);
  9011. // 截取 100 个字符
  9012. $data['description'] = mb_substr($content, 0, 100);
  9013. }
  9014. $data['level'] = empty($data['level']) ? null : $data['level'];
  9015. $data['province_id'] = empty($data['province_id']) ? null : $data['province_id'];
  9016. $data['city_id'] = empty($data['city_id']) ? null : $data['city_id'];
  9017. $data['county_id'] = empty($data['county_id']) ? null : $data['county_id'];
  9018. $data['due_time'] = empty($data['due_time']) ? null : $data['due_time'];
  9019. $users_id = empty($data['users_id']) ? null : $data['users_id'];
  9020. unset($data['users_id']);
  9021. // return Result::success($data);
  9022. Db::beginTransaction();
  9023. try{
  9024. $result = ResearchTopic::insertGetId($data);
  9025. if (empty($result)) {
  9026. Db::rollBack();
  9027. return Result::error('添加失败');
  9028. }
  9029. if(!empty($users_id) && is_string($users_id)){
  9030. $users = json_decode($users_id ?? '[]',true);
  9031. }
  9032. $users_type4 = User::where('type_id', 4)->pluck('id');
  9033. $type4_num = array_intersect($users, $users_type4->toArray());
  9034. if(count($users) != count($type4_num)){
  9035. Db::rollBack();
  9036. return Result::error('请选择调研员!');
  9037. }
  9038. // return Result::success($users);
  9039. if(!empty($users) && is_array($users)){
  9040. // 去重:确保同一 retopic_id + user_id 组合唯一
  9041. $users = array_values(array_unique($users));
  9042. // 组装关联数据
  9043. $users_topic = [];
  9044. foreach ($users as $key => $value) {
  9045. $users_topic[$key] = [
  9046. 'user_id' => $value,
  9047. 'retopic_id' => $result,
  9048. ];
  9049. }
  9050. // 使用 insertOrIgnore 忽略重复主键/唯一索引冲突
  9051. $retopic_user = RetopicUser::insert($users_topic);
  9052. if(empty($retopic_user)){
  9053. Db::rollBack();
  9054. return Result::error('添加失败');
  9055. }
  9056. }
  9057. Db::commit();
  9058. return Result::success($result);
  9059. }catch(\Exception $e){
  9060. Db::rollBack();
  9061. return Result::error($e->getMessage());
  9062. }
  9063. }
  9064. /**
  9065. * 调研选题-编辑
  9066. * @param array $data
  9067. * @return array
  9068. */
  9069. public function upResearchTopic(array $data): array
  9070. {
  9071. $user = User::where('id', $data['user_id'])->first();
  9072. if (empty($user)) {
  9073. return Result::error('用户不存在');
  9074. }
  9075. if($user['type_id'] == 10000){
  9076. $data['status'] = 1;
  9077. }else{
  9078. $data['status'] = 0;
  9079. }
  9080. $topic = ResearchTopic::where('id', $data['id'])->first();
  9081. if (empty($topic)) {
  9082. return Result::error('此调研选题不存在');
  9083. }
  9084. if ($data['keyword'] == '') {
  9085. //提取标题+内容中的关键词
  9086. $data['keyword'] = $data['title'];
  9087. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  9088. Jieba::init(); // 初始化 jieba-php
  9089. Finalseg::init();
  9090. $segList = Jieba::cut($data['keyword']);
  9091. $segList1 = array_slice($segList, 0, 8);
  9092. $data['keyword'] = implode(',', $segList1);
  9093. }
  9094. if ($data['description'] == '') {
  9095. //提取内容中的描述
  9096. $content = $data['content'];
  9097. // 去除 <style> 和 <script> 标签及其内容
  9098. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  9099. // 去除所有 HTML 标签
  9100. $content = strip_tags($content);
  9101. // 去除 HTML 实体
  9102. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  9103. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  9104. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  9105. // 去除多余空白
  9106. $content = preg_replace('/\s+/u', '', $content);
  9107. // 截取 100 个字符
  9108. $data['description'] = mb_substr($content, 0, 100);
  9109. }
  9110. $data['level'] = empty($data['level']) ? null : $data['level'];
  9111. $data['province_id'] = empty($data['province_id']) ? null : $data['province_id'];
  9112. $data['city_id'] = empty($data['city_id']) ? null : $data['city_id'];
  9113. $data['county_id'] = empty($data['county_id']) ? null : $data['county_id'];
  9114. $data['due_time'] = empty($data['due_time']) ? null : $data['due_time'];
  9115. $users_id = empty($data['users_id']) ? null : $data['users_id'];
  9116. $id = $data['id'];
  9117. unset($data['users_id']);
  9118. unset($data['id']);
  9119. // return Result::success($data);
  9120. Db::beginTransaction();
  9121. try{
  9122. $result = ResearchTopic::where('id', $id)->update($data);
  9123. if (empty($result)) {
  9124. Db::rollBack();
  9125. return Result::error('编辑调研选题失败!');
  9126. }
  9127. if(!empty($users_id) && is_string($users_id)){
  9128. $users = json_decode($users_id ?? '[]',true);
  9129. }
  9130. // return Result::success($users);
  9131. $retopic_users = RetopicUser::where('retopic_id', $id)->pluck('user_id')->toArray();
  9132. if(!empty($retopic_users)){
  9133. $del_users = RetopicUser::where('retopic_id', $id)->delete();
  9134. if(empty($del_users)){
  9135. Db::rollBack();
  9136. return Result::error('编辑同行人员失败!');
  9137. }
  9138. }
  9139. if(!empty($users) && is_array($users)){
  9140. // 去重:确保同一 retopic_id + user_id 组合唯一
  9141. $users = array_values(array_unique($users));
  9142. // 组装关联数据
  9143. $users_topic = [];
  9144. foreach ($users as $key => $value) {
  9145. $users_topic[$key] = [
  9146. 'user_id' => $value,
  9147. 'retopic_id' => $id,
  9148. ];
  9149. }
  9150. // 使用 insertOrIgnore 忽略重复主键/唯一索引冲突
  9151. $retopic_user = RetopicUser::insert($users_topic);
  9152. if(empty($retopic_user)){
  9153. Db::rollBack();
  9154. return Result::error('编辑失败');
  9155. }
  9156. }
  9157. Db::commit();
  9158. return Result::success($result);
  9159. }catch(\Exception $e){
  9160. Db::rollBack();
  9161. return Result::error($e->getMessage());
  9162. }
  9163. }
  9164. /**
  9165. * 调研选题-删除
  9166. * @param array $data
  9167. * @return array
  9168. */
  9169. public function delResearchTopic(array $data): array
  9170. {
  9171. $user = User::where('id', $data['user_id'])->first();
  9172. if (empty($user)) {
  9173. return Result::error('用户不存在');
  9174. }
  9175. $topic = ResearchTopic::where('id', $data['id'])->first();
  9176. if (empty($topic)) {
  9177. return Result::error('此调研选题不存在');
  9178. }
  9179. Db::beginTransaction();
  9180. try{
  9181. $result = ResearchTopic::where('id', $data['id'])->delete();
  9182. if (empty($result)) {
  9183. Db::rollBack();
  9184. return Result::error('删除调研选题失败!');
  9185. }
  9186. $topic_users = RetopicUser::where('retopic_id', $data['id'])->pluck('user_id')->toArray();
  9187. if(!empty($topic_users)){
  9188. $del_topic_users = RetopicUser::where('retopic_id', $data['id'])->delete();
  9189. if(empty($del_topic_users)){
  9190. Db::rollBack();
  9191. return Result::error('删除同行人员失败!');
  9192. }
  9193. }
  9194. Db::commit();
  9195. return Result::success($result);
  9196. }catch(\Exception $e){
  9197. Db::rollBack();
  9198. return Result::error($e->getMessage());
  9199. }
  9200. }
  9201. /**
  9202. * 调研选题-列表
  9203. * @param array $data
  9204. * @return array
  9205. */
  9206. public function getResearchTopicList(array $data): array
  9207. {
  9208. $user = User::where('id', $data['user_id'])->first();
  9209. if (empty($user)) {
  9210. return Result::error('用户不存在!');
  9211. }
  9212. $where = [];
  9213. if($user->type_id != 10000){
  9214. $where['research_topic.user_id'] = $data['user_id'];
  9215. $website = Website::where('id', $data['website_id'])->first();
  9216. if (empty($website)) {
  9217. return Result::error('网站不存在!');
  9218. }
  9219. $web_column = json_decode($website->website_column_arr_id ?? '[]',true);
  9220. if(empty($web_column)){
  9221. return Result::error('网站未配置栏目!');
  9222. }
  9223. }
  9224. if($data['is_master'] != 0){
  9225. if($data['is_master'] == 3){
  9226. $where['research_topic.status'] = 0;
  9227. }else{
  9228. $where['research_topic.status'] = $data['is_master'];
  9229. }
  9230. }
  9231. if(!empty($data['title'])){
  9232. array_push($where, ['research_topic.title', 'like', '%'.$data['title'].'%']);
  9233. }
  9234. $page = $data['page'] ?? 1;
  9235. $page_size = $data['page_size'] ?? 10;
  9236. $research_topic = ResearchTopic::when($data['is_master'] == 0, function($query) use($data){
  9237. $query->whereIn('research_topic.status', [0,2]);
  9238. })
  9239. ->when(!empty($where), function($query) use($where){
  9240. $query->where($where);
  9241. })
  9242. ->with(['retopicUsers' => function ($query) {
  9243. $query->select('id', 'user_id', 'retopic_id');
  9244. }
  9245. ])
  9246. ->leftJoin('user', 'user.id', '=', 'research_topic.user_id')
  9247. ->leftJoin('user_info', 'user_info.user_id', '=', 'research_topic.user_id')
  9248. ->select('research_topic.id','research_topic.title','research_topic.updated_at','research_topic.status',
  9249. 'research_topic.due_time','user_info.real_name','research_topic.column_id','research_topic.user_id',
  9250. 'user.user_name'
  9251. )
  9252. ->orderBy('research_topic.updated_at', 'desc')
  9253. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  9254. if(empty($research_topic->items())){
  9255. return Result::error('暂无调研选题!');
  9256. }
  9257. $result = [
  9258. 'rows' => $research_topic->items(),
  9259. 'count' => $research_topic->total()
  9260. ];
  9261. foreach($result['rows'] as $key => $value){
  9262. if($user->type_id != 10000){
  9263. if(in_array($value['column_id'], $web_column)){
  9264. $result['rows'][$key]['is_update'] = 1;
  9265. }else{
  9266. $result['rows'][$key]['is_update'] = 0;
  9267. }
  9268. }else{
  9269. if($value['user_id'] == $data['user_id']){
  9270. $result['rows'][$key]['is_update'] = 1;
  9271. }else{
  9272. $result['rows'][$key]['is_update'] = 0;
  9273. }
  9274. }
  9275. if(!isset($value['real_name']) || empty($value['real_name'])){
  9276. $result['rows'][$key]['real_name'] = $value['user_name'];
  9277. }
  9278. if(!empty($value['retopicUsers'])){
  9279. $retopic_users = $value['retopicUsers'];
  9280. $retopic_user = $retopic_users->pluck('user_id')->toArray();
  9281. $result['rows'][$key]['txry_users'] = implode(',', $retopic_user);
  9282. unset($result['rows'][$key]['retopicUsers']);
  9283. }
  9284. }
  9285. return Result::success($result);
  9286. }
  9287. /**
  9288. * 调研选题-修改状态
  9289. * @param array $data
  9290. * @return array
  9291. */
  9292. public function checkResearchTopic(array $data): array
  9293. {
  9294. $user = User::where('id', $data['user_id'])->first();
  9295. if (empty($user)) {
  9296. return Result::error('用户不存在!');
  9297. }
  9298. if($user->type_id != 10000 && ($data['status'] == 1 || $data['status'] == 2)){
  9299. return Result::error('此用户暂无权限!');
  9300. }
  9301. $topic = ResearchTopic::where('id', $data['id'])->first();
  9302. if (empty($topic)) {
  9303. return Result::error('此调研选题不存在');
  9304. }
  9305. $id = $data['id'];
  9306. unset($data['id']);
  9307. unset($data['user_id']);
  9308. $result = ResearchTopic::where('id', $id)->update($data);
  9309. if (empty($result)) {
  9310. return Result::error('修改调研选题状态失败!');
  9311. }
  9312. return Result::success($result);
  9313. }
  9314. /**
  9315. * 调研选题-详情
  9316. * @param array $data
  9317. * @return array
  9318. */
  9319. public function getResearchTopicInfo(array $data): array
  9320. {
  9321. $user = User::where('id', $data['user_id'])->first();
  9322. if (empty($user)) {
  9323. return Result::error('用户不存在!');
  9324. }
  9325. $research_topic = ResearchTopic::where('research_topic.id', $data['id'])
  9326. ->with(['retopicUsers' => function ($query) {
  9327. $query->select('user_id','retopic_id');
  9328. }
  9329. ])
  9330. ->leftJoin('user', 'user.id', '=', 'research_topic.user_id')
  9331. ->leftJoin('user_info', 'user_info.user_id', '=', 'research_topic.user_id')
  9332. ->select('research_topic.*','user_info.number')
  9333. ->first();
  9334. if(empty($research_topic)){
  9335. return Result::error('获取调研选题详情失败!');
  9336. }
  9337. $retopic_user = $research_topic['retopicUsers'];
  9338. if(!empty($retopic_user)){
  9339. $retopic_user = $retopic_user->pluck('user_id')->toArray();
  9340. foreach($retopic_user as $key => $value){
  9341. $real_name = UserInfo::where('user_id', $value)->value('real_name');
  9342. $research_topic['retopicUsers'][$key]['real_name'] = $real_name;
  9343. $research_topic['retopicUsers'][$key]['user_id'] = $value;
  9344. unset($research_topic['retopicUsers'][$key]['retopic_id']);
  9345. }
  9346. }
  9347. return Result::success($research_topic);
  9348. }
  9349. /**
  9350. * 添加网站导航
  9351. * @param array $data
  9352. */
  9353. public function addWebCateinfo(array $data): array
  9354. {
  9355. $user = User::where('id', $data['user_id'])->first();
  9356. if (empty($user)) {
  9357. return Result::error('用户不存在');
  9358. }
  9359. if($user['type_id'] == 10000){
  9360. $data['status'] = 1;
  9361. }else{
  9362. $data['status'] = 0;
  9363. }
  9364. if ($data['keyword'] == '') {
  9365. //提取标题+内容中的关键词
  9366. $data['keyword'] = $data['title'];
  9367. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  9368. Jieba::init(); // 初始化 jieba-php
  9369. Finalseg::init();
  9370. $segList = Jieba::cut($data['keyword']);
  9371. $segList1 = array_slice($segList, 0, 8);
  9372. $data['keyword'] = implode(',', $segList1);
  9373. }
  9374. if ($data['description'] == '') {
  9375. //提取内容中的描述
  9376. $content = $data['content'];
  9377. // 去除 <style> 和 <script> 标签及其内容
  9378. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  9379. // 去除所有 HTML 标签
  9380. $content = strip_tags($content);
  9381. // 去除 HTML 实体
  9382. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  9383. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  9384. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  9385. // 去除多余空白
  9386. $content = preg_replace('/\s+/u', '', $content);
  9387. // 截取 100 个字符
  9388. $data['description'] = mb_substr($content, 0, 100);
  9389. }
  9390. $data['cate_name'] = empty($data['cate_name']) ? '官网导航' : $data['cate_name'];
  9391. $data['province_id'] = empty($data['province_id']) ? null : $data['province_id'];
  9392. $data['city_id'] = empty($data['city_id']) ? null : $data['city_id'];
  9393. $data['county_id'] = empty($data['county_id']) ? null : $data['county_id'];
  9394. unset($data['users_id']);
  9395. $result = WebCateinfo::insertGetId($data);
  9396. if (empty($result)) {
  9397. return Result::error('添加失败');
  9398. }
  9399. return Result::success($result);
  9400. }
  9401. /**
  9402. * 更新网站导航
  9403. * @param array $data
  9404. */
  9405. public function upWebCateinfo(array $data): array
  9406. {
  9407. $webCateinfo = WebCateinfo::where('id', $data['id'])->first();
  9408. if (empty($webCateinfo)) {
  9409. return Result::error('导航不存在');
  9410. }
  9411. $user = User::where('id', $data['user_id'])->first();
  9412. if (empty($user)) {
  9413. return Result::error('用户不存在');
  9414. }
  9415. if($user['type_id'] == 10000){
  9416. $data['status'] = 1;
  9417. }else{
  9418. $data['status'] = 0;
  9419. }
  9420. if ($data['keyword'] == '') {
  9421. //提取标题+内容中的关键词
  9422. $data['keyword'] = $data['title'];
  9423. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  9424. Jieba::init(); // 初始化 jieba-php
  9425. Finalseg::init();
  9426. $segList = Jieba::cut($data['keyword']);
  9427. $segList1 = array_slice($segList, 0, 8);
  9428. $data['keyword'] = implode(',', $segList1);
  9429. }
  9430. if ($data['description'] == '') {
  9431. //提取内容中的描述
  9432. $content = $data['content'];
  9433. // 去除 <style> 和 <script> 标签及其内容
  9434. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  9435. // 去除所有 HTML 标签
  9436. $content = strip_tags($content);
  9437. // 去除 HTML 实体
  9438. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  9439. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  9440. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  9441. // 去除多余空白
  9442. $content = preg_replace('/\s+/u', '', $content);
  9443. // 截取 100 个字符
  9444. $data['description'] = mb_substr($content, 0, 100);
  9445. }
  9446. $data['cate_name'] = empty($data['cate_name']) ? '官网导航' : $data['cate_name'];
  9447. $data['province_id'] = empty($data['province_id']) ? null : $data['province_id'];
  9448. $data['city_id'] = empty($data['city_id']) ? null : $data['city_id'];
  9449. $data['county_id'] = empty($data['county_id']) ? null : $data['county_id'];
  9450. unset($data['users_id']);
  9451. $result = WebCateinfo::where('id', $data['id'])->update($data);
  9452. if (empty($result)) {
  9453. return Result::error('更新失败');
  9454. }
  9455. return Result::success($result);
  9456. }
  9457. /**
  9458. * 获取网站导航列表
  9459. * @param array $data
  9460. * @return array
  9461. */
  9462. public function getWebCateinfoList(array $data): array
  9463. {
  9464. $user = User::where('id', $data['user_id'])->first();
  9465. if (empty($user)) {
  9466. return Result::error('用户不存在');
  9467. }
  9468. $where = [];
  9469. if($user['type_id'] != 10000){
  9470. $where['web_cateinfo.user_id'] = $data['user_id'];
  9471. }
  9472. if(!empty($data['title'])){
  9473. array_push($where, ['web_cateinfo.title', 'like', '%'.$data['title'].'%']);
  9474. }
  9475. if($data['is_master'] != 0){
  9476. if($data['is_master'] == 3){
  9477. $where['web_cateinfo.status'] = 0;
  9478. }else{
  9479. $where['web_cateinfo.status'] = $data['is_master'];
  9480. }
  9481. }
  9482. $web_cateinfo = WebCateinfo::when(!empty($data['is_master'] == 0), function ($query) use ($where) {
  9483. $query->whereIn('web_cateinfo.status', [0, 2]);
  9484. })
  9485. ->when(!empty($where), function ($query) use ($where) {
  9486. $query->where($where);
  9487. })
  9488. ->leftJoin('user', 'web_cateinfo.user_id', '=', 'user.id')
  9489. ->select(['web_cateinfo.id', 'web_cateinfo.user_id', 'user.nickname', 'web_cateinfo.title', 'web_cateinfo.cate_name', 'web_cateinfo.status','web_cateinfo.updated_at'])
  9490. ->orderBy('updated_at', 'desc')
  9491. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  9492. if(empty($web_cateinfo->items())){
  9493. return Result::error('官网导航不存在');
  9494. }
  9495. $result = [
  9496. 'rows' => $web_cateinfo->items(),
  9497. 'total' => $web_cateinfo->total(),
  9498. ];
  9499. foreach($result['rows'] as $key => $value){
  9500. if($value['user_id'] == $data['user_id']){
  9501. $result['rows'][$key]['is_update'] = 1;
  9502. }else{
  9503. $result['rows'][$key]['is_update'] = 0;
  9504. }
  9505. }
  9506. return Result::success($result);
  9507. }
  9508. /**
  9509. * 删除网站导航
  9510. * @param array $data
  9511. */
  9512. public function delWebCateinfo(array $data): array
  9513. {
  9514. $webCateinfo = WebCateinfo::where('id', $data['id'])->first();
  9515. if (empty($webCateinfo)) {
  9516. return Result::error('导航不存在');
  9517. }
  9518. $result = WebCateinfo::where('id', $data['id'])->delete();
  9519. if (empty($result)) {
  9520. return Result::error('删除失败');
  9521. }
  9522. return Result::success($result);
  9523. }
  9524. /**
  9525. * 审核网站导航
  9526. * @param array $data
  9527. */
  9528. public function checkWebCateinfo(array $data): array
  9529. {
  9530. $webCateinfo = WebCateinfo::where('id', $data['id'])->first();
  9531. if (empty($webCateinfo)) {
  9532. return Result::error('导航不存在');
  9533. }
  9534. $user = User::where('id', $data['user_id'])->first();
  9535. if (empty($user)) {
  9536. return Result::error('用户不存在');
  9537. }
  9538. if($user['type_id'] != 10000 && $data['status'] == 1){
  9539. return Result::error('非管理员不能审核');
  9540. }
  9541. $update_data['status'] = $data['status'];
  9542. if($data['status'] == 2){
  9543. $update_data['reason'] = $data['reason'];
  9544. }
  9545. $result = WebCateinfo::where('id', $data['id'])->update($update_data);
  9546. if (empty($result)) {
  9547. return Result::error('审核失败');
  9548. }
  9549. return Result::success($result);
  9550. }
  9551. /**
  9552. * 获取网站导航详情
  9553. * @param array $data
  9554. */
  9555. public function getWebCateinfoDetail(array $data): array
  9556. {
  9557. $webCateinfo = WebCateinfo::where('id', $data['id'])->first();
  9558. if (empty($webCateinfo)) {
  9559. return Result::error('导航不存在');
  9560. }
  9561. $result = $webCateinfo->toArray();
  9562. return Result::success($result);
  9563. }
  9564. /**
  9565. * 推荐单页管理
  9566. * @param array $data
  9567. */
  9568. public function getAdviceSinglePages(array $data): array
  9569. {
  9570. $user = User::where('id', $data['user_id'])->first();
  9571. if (empty($user)) {
  9572. return Result::error('用户不存在');
  9573. }
  9574. if(empty($data['website_id']) && $user['type_id'] == 10000){
  9575. $category = [];
  9576. }else{
  9577. $where = [
  9578. 'website_id' => $data['website_id'] ?? $data['web_id'],
  9579. ];
  9580. $category = WebsiteCategory::where($where)->pluck('category_id')->toArray();
  9581. // var_dump($ids);
  9582. if (empty($ids)) {
  9583. return Result::error("推荐单页不存在");
  9584. }
  9585. }
  9586. $where = [];
  9587. if(!empty($data['title'])){
  9588. array_push($where, ['title', 'like', '%'.$data['title'].'%']);
  9589. }
  9590. $result = SinglePage::
  9591. when(!empty($category) ,function ($query) use $category){
  9592. $query->whereIn('id', $category);
  9593. }
  9594. ->when(!empty($where), function ($query) use ($where) {
  9595. $query->where($where);
  9596. })
  9597. // ->when(!isset($data['catid']), function ($query) use ($data) {
  9598. // $query->where('catid', $data['catid']);
  9599. // })
  9600. ->where('status', 1)
  9601. ->select(['id', 'title', 'catid','status','website_id','updated_at'])
  9602. ->orderBy('updated_at', 'desc')
  9603. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  9604. if(empty($result->items())){
  9605. return Result::error('推荐单页不存在');
  9606. }
  9607. $result = [
  9608. 'rows' => $result->items(),
  9609. 'total' => $result->total(),
  9610. ];
  9611. return Result::success($result);
  9612. }
  9613. /**
  9614. * 添加单页
  9615. * @param array $data
  9616. */
  9617. public function addSinglePage(array $data): array
  9618. {
  9619. $user = User::where('id', $data['user_id'])->first();
  9620. if (empty($user)) {
  9621. return Result::error('用户不存在');
  9622. }
  9623. if($user['type_id'] == 10000){
  9624. $data['status'] = 1;
  9625. }else{
  9626. $data['status'] = 0;
  9627. }
  9628. if(is_array($data['cat_arr_id'])){
  9629. $data['cat_arr_id'] = array_map(function($item){
  9630. return intval($item);
  9631. }, $data['cat_arr_id']);
  9632. $data['catid'] = end($data['cat_arr_id']);
  9633. $data['cat_arr_id'] = json_encode($data['cat_arr_id'], JSON_UNESCAPED_UNICODE);
  9634. }else{
  9635. return Result::error('请选择栏目;');
  9636. }
  9637. if(!empty($data['commend_id']) && is_array($data['commend_id'])){
  9638. $data['commend_id'] = json_encode($data['commend_id'], JSON_UNESCAPED_UNICODE);
  9639. }else{
  9640. $data['commend_id'] = null;
  9641. }
  9642. if ($data['keyword'] == '') {
  9643. //提取标题+内容中的关键词
  9644. $articleData['keyword'] = $data['title'];
  9645. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  9646. Jieba::init(); // 初始化 jieba-php
  9647. Finalseg::init();
  9648. $segList = Jieba::cut($articleData['keyword']);
  9649. $segList1 = array_slice($segList, 0, 8);
  9650. $data['keyword'] = implode(',', $segList1);
  9651. }
  9652. if ($data['description'] == '') {
  9653. //提取内容中的描述
  9654. $content = $data['content'];
  9655. // 去除 <style> 和 <script> 标签及其内容
  9656. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  9657. // 去除所有 HTML 标签
  9658. $content = strip_tags($content);
  9659. // 去除 HTML 实体
  9660. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  9661. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  9662. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  9663. // 去除多余空白
  9664. $content = preg_replace('/\s+/u', '', $content);
  9665. // 截取 100 个字符
  9666. $data['description'] = mb_substr($content, 0, 100);
  9667. }
  9668. if(empty($data['publiced_at'])){
  9669. $data['publiced_at'] = null;
  9670. }
  9671. $result = SinglePage::insertGetId($data);
  9672. if (empty($result)) {
  9673. return Result::error('添加失败');
  9674. }
  9675. return Result::success($result);
  9676. }
  9677. /**
  9678. * 更新单页
  9679. * @param array $data
  9680. */
  9681. public function upSinglePage(array $data): array
  9682. {
  9683. $singlePage = SinglePage::where('id', $data['id'])->where('user_id', $data['user_id'])->first();
  9684. if (empty($singlePage)) {
  9685. return Result::error('单页不存在');
  9686. }
  9687. $user = User::where('id', $data['user_id'])->first();
  9688. if (empty($user)) {
  9689. return Result::error('用户不存在');
  9690. }
  9691. $where['id'] = $data['id'];
  9692. unset($data['id']);
  9693. if($user['type_id'] == 10000){
  9694. $data['status'] = 1;
  9695. }else{
  9696. $data['status'] = 0;
  9697. }
  9698. if(is_array($data['cat_arr_id'])){
  9699. $data['cat_arr_id'] = array_map(function($item){
  9700. return intval($item);
  9701. }, $data['cat_arr_id']);
  9702. $data['catid'] = end($data['cat_arr_id']);
  9703. $data['cat_arr_id'] = json_encode($data['cat_arr_id'], JSON_UNESCAPED_UNICODE);
  9704. }else{
  9705. return Result::error('请选择栏目;');
  9706. }
  9707. if(!empty($data['commend_id']) && is_array($data['commend_id'])){
  9708. $data['commend_id'] = json_encode($data['commend_id'], JSON_UNESCAPED_UNICODE);
  9709. }else{
  9710. $data['commend_id'] = null;
  9711. }
  9712. if ($data['keyword'] == '') {
  9713. //提取标题+内容中的关键词
  9714. $articleData['keyword'] = $data['title'];
  9715. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  9716. Jieba::init(); // 初始化 jieba-php
  9717. Finalseg::init();
  9718. $segList = Jieba::cut($articleData['keyword']);
  9719. $segList1 = array_slice($segList, 0, 8);
  9720. $data['keyword'] = implode(',', $segList1);
  9721. }
  9722. if ($data['description'] == '') {
  9723. //提取内容中的描述
  9724. $content = $data['content'];
  9725. // 去除 <style> 和 <script> 标签及其内容
  9726. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  9727. // 去除所有 HTML 标签
  9728. $content = strip_tags($content);
  9729. // 去除 HTML 实体
  9730. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  9731. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  9732. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  9733. // 去除多余空白
  9734. $content = preg_replace('/\s+/u', '', $content);
  9735. // 截取 100 个字符
  9736. $data['description'] = mb_substr($content, 0, 100);
  9737. }
  9738. if(empty($data['publiced_at'])){
  9739. $data['publiced_at'] = null;
  9740. }
  9741. $result = SinglePage::where($where)->update($data);
  9742. if (empty($result)) {
  9743. return Result::error('更新失败');
  9744. }
  9745. return Result::success($result);
  9746. }
  9747. /**
  9748. * 删除单页
  9749. * @param array $data
  9750. */
  9751. public function delSinglePage(array $data): array
  9752. {
  9753. $singlePage = SinglePage::where('id', $data['id'])->first();
  9754. if (empty($singlePage)) {
  9755. return Result::error('单页不存在');
  9756. }
  9757. $user = User::where('id', $data['user_id'])->first();
  9758. if (empty($user)) {
  9759. return Result::error('用户不存在');
  9760. }
  9761. $where['id'] = $data['id'];
  9762. $result = SinglePage::where($where)->delete();
  9763. if (empty($result)) {
  9764. return Result::error('删除失败');
  9765. }
  9766. return Result::success($result);
  9767. }
  9768. /**
  9769. * 审核单页
  9770. * @param array $data
  9771. */
  9772. public function checkSinglePage(array $data): array
  9773. {
  9774. $user = User::where('id', $data['user_id'])->first();
  9775. if (empty($user)) {
  9776. return Result::error('用户不存在');
  9777. }
  9778. if($user['type_id'] != 10000 && in_array($data['status'], [1, 2])){
  9779. return Result::error('非管理员不能审核单页');
  9780. }
  9781. if($data['status'] == 2){
  9782. $update_data['reason'] = $data['reason'] ?? '';
  9783. }
  9784. $update_data['status'] = $data['status'];
  9785. $result = SinglePage::where('id', $data['id'])->update($update_data);
  9786. if (empty($result)) {
  9787. return Result::error('更新失败');
  9788. }
  9789. return Result::success($result);
  9790. }
  9791. /**
  9792. * 更新单页状态
  9793. * @param array $data
  9794. */
  9795. public function getSinglePageList(array $data): array
  9796. {
  9797. $user = User::where('id', $data['user_id'])->first();
  9798. if (empty($user)) {
  9799. return Result::error('用户不存在');
  9800. }
  9801. $where = [];
  9802. if($user['type_id'] != 10000){
  9803. $where['single_page.user_id'] = $data['user_id'];
  9804. }
  9805. if($data['is_master'] == 3){
  9806. $where['single_page.status'] = 0;
  9807. }else if($data['is_master'] != 0){
  9808. $where['single_page.status'] = $data['is_master'];
  9809. }
  9810. if(!empty($data['title'])){
  9811. array_push($where, ['single_page.title', 'like', '%'.$data['title'].'%']);
  9812. }
  9813. $result = SinglePage::when($data['is_master'] == 0, function($query) use($data){
  9814. $query->whereIn('single_page.status', [0, 2]);
  9815. })
  9816. ->when(!empty($where), function($query) use($where){
  9817. $query->where($where);
  9818. })
  9819. ->with([
  9820. 'websiteCategory' => function ($query) {
  9821. $query->select('website_id', 'category_id', 'alias');
  9822. },
  9823. 'user' => function ($query) {
  9824. $query->select('id', 'nickname');
  9825. }
  9826. ])
  9827. ->select(['single_page.id','single_page.title','single_page.content','single_page.updated_at',
  9828. 'single_page.status','single_page.catid','single_page.website_id','single_page.user_id'])
  9829. ->orderBy('single_page.updated_at', 'desc')
  9830. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  9831. if (empty($result->items())) {
  9832. return Result::error('暂无数据');
  9833. }
  9834. $result = [
  9835. 'rows' => $result->items(),
  9836. 'total' => $result->total(),
  9837. ];
  9838. foreach($result['rows'] as $key => $value){
  9839. $result['rows'][$key]['category_alias'] = $value['websiteCategory']['alias'] ?? '';
  9840. $result['rows'][$key]['user_nickname'] = $value['user']['nickname'] ?? '';
  9841. $result['rows'][$key]['websiteCategory'] = $value['websiteCategory']['alias'] ?? '';
  9842. unset($result['rows'][$key]['user']);
  9843. unset($result['rows'][$key]['websiteCategory']);
  9844. if($user['type_id'] == 10000){
  9845. if($value['user_id'] == $data['user_id']){
  9846. $result['rows'][$key]['is_update'] = 1;
  9847. }else{
  9848. $result['rows'][$key]['is_update'] = 0;
  9849. }
  9850. }else{
  9851. if($value['website_id'] == $data['website_id']){
  9852. $result['rows'][$key]['is_update'] = 1;
  9853. }else{
  9854. $result['rows'][$key]['is_update'] = 0;
  9855. }
  9856. }
  9857. }
  9858. return Result::success($result);
  9859. }
  9860. /**
  9861. * 获取单页详情
  9862. * @param array $data
  9863. */
  9864. public function getSinglePageInfo(array $data): array
  9865. {
  9866. $singlePage = SinglePage::where('id', $data['id'])->first();
  9867. if (empty($singlePage)) {
  9868. return Result::error('单页不存在');
  9869. }
  9870. $user = User::where('id', $data['user_id'])->first();
  9871. if (empty($user)) {
  9872. return Result::error('用户不存在');
  9873. }
  9874. $where['id'] = $data['id'];
  9875. $result = SinglePage::where($where)->first();
  9876. if (empty($result)) {
  9877. return Result::error('获取失败');
  9878. }
  9879. $result['cat_arr_id'] = json_decode($result['cat_arr_id'] ?? '[]' , true);
  9880. $result['commend_id'] = json_decode($result['commend_id'] ?? '[]' , true);
  9881. return Result::success($result);
  9882. }
  9883. }