NewsService.php 443 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525
  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\Glaw;
  26. use App\Model\Gonline;
  27. use App\Model\JobResume;
  28. use Hyperf\DbConnection\Db;
  29. use Hyperf\RpcServer\Annotation\RpcService;
  30. use App\Tools\Result;
  31. use Directory;
  32. use Ramsey\Uuid\Uuid;
  33. use Hyperf\Utils\Random;
  34. use Fukuball\Jieba\Jieba;
  35. use Fukuball\Jieba\Finalseg;
  36. use Hyperf\Utils\Collection;
  37. use function Hyperf\Support\retry;
  38. use App\Tools\PublicData;
  39. use App\Model\ChatGroups;
  40. use App\Model\ChatGroupsMember;
  41. use App\Model\ChatRecords;
  42. use App\Model\Complaint;
  43. use Hamcrest\Arrays\IsArray;
  44. use Hyperf\Codec\Json;
  45. use App\Tools\buildMenuTree;
  46. use App\Model\JobApply;
  47. use App\Model\JobHunting;
  48. use App\Model\JobRemuse;
  49. use Hyperf\Redis\Redis;
  50. use Hyperf\Di\Annotation\Inject;
  51. use App\Model\Festival;
  52. use App\Model\Character;
  53. use App\Model\Couplet;
  54. use App\Model\Riddle;
  55. use App\Model\Idiom;
  56. use App\Model\WhiteRouter;
  57. use Illuminate\Support\Facades\Cache;
  58. use App\Model\Company;
  59. use Hyperf\Paginator\Paginator;
  60. use App\Model\Project;
  61. use Hyperf\Context\Context;
  62. use Hyperf\Context\ApplicationContext as ContextApplicationContext;
  63. use Hyperf\Amqp\Producer;
  64. use App\Amqp\Producer\MqProducer;
  65. use App\Model\Web;
  66. use App\Model\GroupMemberImp;
  67. use App\Model\GroupImp;
  68. use App\Model\GroupTalkImp;
  69. use App\Model\GroupTalkMessagerImp;
  70. use App\Model\ArticleIgnore;
  71. use App\Model\Message;
  72. use App\Model\ResearchTopic;
  73. use App\Model\RetopicUser;
  74. use App\Model\WebCateinfo;
  75. use App\Model\SinglePage;
  76. use App\Model\WebsiteColumn;
  77. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  78. class NewsService implements NewsServiceInterface
  79. {
  80. #[Inject]
  81. protected Redis $redis;
  82. /**
  83. * 获取导航池列表
  84. * @param array $data
  85. * @return array
  86. */
  87. public function getCategoryList(array $data): array
  88. {
  89. $search = $data['name'] ?? '';
  90. $page = (int)($data['page'] ?? 1);
  91. $perPage = (int)($data['pageSize'] ?? 10);
  92. // 1. 查出所有匹配的分类id
  93. if ($search) {
  94. $matchedIds = Category::where('name', 'like', "%{$search}%")->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  95. if (empty($matchedIds)) {
  96. return Result::success(['rows' => [], 'total' => 0]);
  97. }
  98. // 2. 递归查所有父级,直到一级分类
  99. $idsStr = implode(',', $matchedIds);
  100. $sql = "
  101. WITH RECURSIVE parents AS (
  102. SELECT * FROM category WHERE id IN ($idsStr)
  103. UNION ALL
  104. SELECT c.* FROM category c
  105. INNER JOIN parents p ON c.id = p.pid
  106. )
  107. SELECT * FROM parents
  108. ";
  109. $parents = Db::select($sql);
  110. $parentIds = [];
  111. foreach ($parents as $row) {
  112. if ($row->pid == 0) {
  113. $parentIds[] = $row->id;
  114. }
  115. }
  116. $parentIds = array_unique($parentIds);
  117. } else {
  118. // 没有搜索,一级分类就是根
  119. $parentIds = Category::where('pid', 0)->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  120. }
  121. // 3. 一级分类分页
  122. $total = count($parentIds);
  123. $parentIds = array_slice($parentIds, ($page - 1) * $perPage, $perPage);
  124. if (empty($parentIds)) {
  125. return Result::success(['rows' => [], 'total' => $total]);
  126. }
  127. // 4. 递归查所有子孙
  128. $idsStr = implode(',', $parentIds);
  129. $sql = "
  130. WITH RECURSIVE subcategories AS (
  131. SELECT * FROM category WHERE id IN ($idsStr)
  132. UNION ALL
  133. SELECT c.* FROM category c
  134. INNER JOIN subcategories s ON c.pid = s.id
  135. )
  136. SELECT * FROM subcategories ORDER BY updated_at DESC
  137. ";
  138. $allCategories = Db::select($sql);
  139. // 5. 组装树结构
  140. $categoryMap = [];
  141. foreach ($allCategories as $cat) {
  142. $cat = (array)$cat;
  143. $cat['children'] = [];
  144. $categoryMap[$cat['id']] = $cat;
  145. }
  146. foreach ($categoryMap as $id => &$cat) {
  147. if ($cat['pid'] && isset($categoryMap[$cat['pid']])) {
  148. $categoryMap[$cat['pid']]['children'][] = &$cat;
  149. }
  150. }
  151. unset($cat);
  152. $categoryTree = [];
  153. foreach ($parentIds as $id) {
  154. if (isset($categoryMap[$id])) {
  155. $categoryTree[] = $categoryMap[$id];
  156. }
  157. }
  158. return Result::success([
  159. 'rows' => $categoryTree,
  160. 'total' => $total,
  161. ]);
  162. }
  163. private function findMatchedCategories($search)
  164. {
  165. if ($search) {
  166. return Category::where('name', 'like', "%{$search}%")
  167. ->orderBy('updated_at', 'desc')
  168. ->get();
  169. }
  170. return Category::orderBy('updated_at', 'desc') // 按 updated_at 字段倒序排序
  171. ->get();
  172. }
  173. private function findAllParents($categories)
  174. {
  175. $allCategories = [];
  176. foreach ($categories as $category) {
  177. $parentId = $category->pid;
  178. while ($parentId > 0) {
  179. $parent = Category::find($parentId);
  180. if ($parent) {
  181. $allCategories[$parent->id] = $parent;
  182. $parentId = $parent->pid;
  183. } else {
  184. break;
  185. }
  186. }
  187. $allCategories[$category->id] = $category;
  188. }
  189. return array_values($allCategories);
  190. }
  191. private function buildCategoryTree($category, $allRequiredCategories)
  192. {
  193. $categoryData = $category->toArray();
  194. $children = [];
  195. foreach ($allRequiredCategories as $c) {
  196. if ($c->pid === $category->id) {
  197. $children[] = $this->buildCategoryTree($c, $allRequiredCategories);
  198. }
  199. }
  200. if (!empty($children)) {
  201. $categoryData['children'] = $children;
  202. }
  203. return $categoryData;
  204. }
  205. public function myCategoryList(array $data): array
  206. {
  207. $sszq = $data['sszq'] ?? '';
  208. unset($data['sszq']);
  209. //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
  210. $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
  211. $where[] = [
  212. 'pid',
  213. '=',
  214. $data['pid'],
  215. ];
  216. if (isset($data['name'])) {
  217. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  218. }
  219. var_dump($where);
  220. //根据分类id,从category表中取出分类信息
  221. $result = Category::where($where)
  222. ->whereIn('category.id', $catorytids)
  223. ->select('category.*', 'category.id as category_id')->get();
  224. if (empty($result)) {
  225. return Result::error("没有栏目数据");
  226. }
  227. return Result::success($result);
  228. }
  229. /**
  230. * @param array $data
  231. * @return array
  232. */
  233. public function categoryList(array $data): array
  234. {
  235. $where[] = [
  236. 'pid',
  237. '=',
  238. $data['pid']
  239. ];
  240. if (isset($data['name'])) {
  241. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  242. }
  243. var_dump($where);
  244. $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
  245. if (empty($result)) {
  246. return Result::error("没有栏目数据");
  247. }
  248. return Result::success($result);
  249. }
  250. /**
  251. * @param array $data
  252. * @return array
  253. */
  254. public function addCategory(array $data): array
  255. {
  256. if (isset($data['id'])) {
  257. unset($data['id']);
  258. }
  259. $id = Category::insertGetId($data);
  260. if (empty($id)) {
  261. return Result::error("添加失败");
  262. }
  263. return Result::success(['id' => $id]);
  264. }
  265. /**
  266. * @param array $data
  267. * @return array
  268. */
  269. public function delCategory(array $data): array
  270. {
  271. Db::beginTransaction();
  272. try {
  273. $categoryList = Category::where(['pid' => $data['id']])->get();
  274. if ($categoryList->toArray()) {
  275. Db::rollBack();
  276. return Result::error("分类下面有子分类不能删除");
  277. }
  278. $articleList = Article::where(['catid' => $data['id']])->get();
  279. if ($articleList->toArray()) {
  280. Db::rollBack();
  281. return Result::error("分类下面有资讯不能删除");
  282. }
  283. $result = Category::where($data)->delete();
  284. WebsiteCategory::where(['category_id' => $data['id']])->delete();
  285. if (!$result) {
  286. Db::rollBack();
  287. return Result::error("删除失败");
  288. }
  289. Db::commit();
  290. return Result::success($result);
  291. } catch (\Exception $e) {
  292. Db::rollBack();
  293. return Result::error("删除失败" . $e->getMessage());
  294. }
  295. }
  296. /**
  297. * @param array $data
  298. * @return array
  299. */
  300. public function updateCategory(array $data): array
  301. {
  302. $where = [
  303. 'id' => $data['id'],
  304. ];
  305. $result = Category::where($where)->update($data);
  306. if ($result) {
  307. return Result::success($result);
  308. } else {
  309. return Result::error("更新失败");
  310. }
  311. }
  312. /**
  313. * 获取导航池信息
  314. * @param array $data
  315. * @return array
  316. */
  317. public function getCategoryInfo(array $data): array
  318. {
  319. $where = [
  320. 'id' => $data['id'],
  321. ];
  322. $result = Category::where($where)->first();
  323. if ($result) {
  324. return Result::success($result);
  325. } else {
  326. return Result::error("更新失败");
  327. }
  328. }
  329. public function getArticleCommend(array $data): array
  330. {
  331. $user = User::where('id', $data['user_id'])->first();
  332. if (empty($user)) {
  333. return Result::error('用户不存在!');
  334. }
  335. $ids = [];
  336. if (empty($data['website_id']) && $user['type_id'] == 10000) {
  337. $ids = [];
  338. } else {
  339. $where = [
  340. 'website_id' => $data['website_id'] ?? $data['web_id'],
  341. ];
  342. $ids = WebsiteCategory::where($where)->pluck('category_id')->toArray();
  343. // var_dump($ids);
  344. if (empty($ids)) {
  345. return Result::error("没有推荐数据");
  346. }
  347. }
  348. $whereArticle = [];
  349. if (isset($data['id']) && !empty($data['id'])) {
  350. $whereArticle['id'] = $data['id'];
  351. }
  352. //title like
  353. if (isset($data['title']) && !empty($data['id'])) {
  354. array_push($whereArticle, ['title', 'like', "%{$data['title']}%"]);
  355. }
  356. // 若存在过滤用的分类 id 数组,则加入 whereIn 条件,否则直接跳过
  357. $article = Article::when(!empty($ids) && is_array($ids), function ($query) use ($ids) {
  358. $query->whereIn('catid', $ids);
  359. })
  360. ->where('status', 1)
  361. ->when(!empty($whereArticle), function ($query) use ($whereArticle) {
  362. $query->where($whereArticle);
  363. })
  364. ->orderBy('updated_at', 'desc')
  365. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  366. if ($article) {
  367. $data = [
  368. 'rows' => $article->items(),
  369. 'count' => $article->total(),
  370. ];
  371. return Result::success($data);
  372. } else {
  373. return Result::error("获取失败失败");
  374. }
  375. }
  376. /**
  377. * @param array $data
  378. * @return array
  379. */
  380. public function getArticleList(array $data): array
  381. {
  382. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  383. $type_id = $data['type_id'];
  384. unset($data['type_id']);
  385. $user_id = $data['user_id'];
  386. unset($data['user_id']);
  387. $where = [];
  388. $status1 = [];
  389. if (isset($data['id']) && $data['id']) {
  390. array_push($where, ['article.id', '=', $data['id']]);
  391. }
  392. if (isset($data['title']) && $data['title']) {
  393. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  394. }
  395. if (isset($data['category_name']) && $data['category_name']) {
  396. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  397. }
  398. if (isset($data['catid']) && $data['catid']) {
  399. array_push($where, ['article.catid', '=', $data['catid']]);
  400. }
  401. if (isset($data['author']) && $data['author']) {
  402. array_push($where, ['article.author', '=', $data['author']]);
  403. }
  404. if (isset($data['islink']) && $data['islink'] !== "") {
  405. array_push($where, ['article.islink', '=', $data['islink']]);
  406. }
  407. if (isset($data['status']) && $data['status'] !== "") {
  408. array_push($where, ['article.status', '=', $data['status']]);
  409. }
  410. if (isset($data['status1'])) {
  411. $status1 = json_decode(($data['status1']));
  412. }
  413. //不是管理员展示个人数据;
  414. if ($type_id != 10000) {
  415. $where[] = ['article.admin_user_id', '=', $user_id];
  416. }
  417. $startTime = microtime(true);
  418. $rep = Article::query()
  419. // 预加载相关关联
  420. ->with([
  421. 'category' => function ($query) {
  422. $query->select('id', 'name');
  423. },
  424. 'websiteCategory' => function ($query) {
  425. $query->select('website_id', 'category_id', 'alias');
  426. },
  427. 'user' => function ($query) {
  428. $query->select('id', 'nickname');
  429. }
  430. ])
  431. // 构建where条件
  432. ->when(isset($data['id']) && $data['id'], function ($query) use ($data) {
  433. $query->where('article.id', '=', $data['id']);
  434. })
  435. ->when(isset($data['title']) && $data['title'], function ($query) use ($data) {
  436. $query->where('article.title', 'like', '%' . $data['title'] . '%');
  437. })
  438. ->when(isset($data['category_name']) && $data['category_name'], function ($query) use ($data) {
  439. // 使用子查询替代左连接进行模糊搜索
  440. $query->whereHas('category', function ($subQuery) use ($data) {
  441. $subQuery->where('name', 'like', '%' . $data['category_name'] . '%');
  442. });
  443. })
  444. ->when(isset($data['catid']) && $data['catid'], function ($query) use ($data) {
  445. $query->where('article.catid', '=', $data['catid']);
  446. })
  447. ->when(isset($data['author']) && $data['author'], function ($query) use ($data) {
  448. $query->where('article.author', '=', $data['author']);
  449. })
  450. ->when(isset($data['islink']) && $data['islink'] !== "", function ($query) use ($data) {
  451. $query->where('article.islink', '=', $data['islink']);
  452. })
  453. ->when(isset($data['status']) && $data['status'] !== "", function ($query) use ($data) {
  454. $query->where('article.status', '=', $data['status']);
  455. })
  456. ->when(isset($data['status1']) && $data['status1'], function ($query) use ($data) {
  457. // 安全地处理JSON字符串
  458. $status1 = is_array($data['status1']) ? $data['status1'] : json_decode($data['status1'], true) ?? [];
  459. if (!empty($status1)) {
  460. $query->whereIn('article.status', $status1);
  461. }
  462. })
  463. ->select('article.*')
  464. // 非管理员限制
  465. ->when($type_id != 10000, function ($query) use ($user_id) {
  466. // 非管理员只能看自己的文章,同时把 article_ignore 的 c_show_time 一起查出来
  467. $query->where('article.admin_user_id', $user_id)
  468. ->leftJoin('article_ignore', function ($join) {
  469. // 关联条件:article.id = article_ignore.article_id 且 article.web_site_id = article_ignore.website_id
  470. $join->on('article_ignore.article_id', '=', 'article.id')
  471. ->whereColumn('article_ignore.website_id', 'article.web_site_id');
  472. })
  473. ->addSelect('article_ignore.article_id', 'article_ignore.c_show_time'); // 用 addSelect 追加字段,避免覆盖原有 select
  474. })
  475. // 基础条件
  476. ->whereNotIn('article.status', [404])
  477. // 排序和分页
  478. ->orderBy('article.updated_at', 'desc')
  479. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  480. // 获取结果并格式化
  481. $data = [
  482. 'rows' => $rep->items(),
  483. 'count' => $rep->total(),
  484. ];
  485. // 执行查询
  486. $endTime = microtime(true);
  487. $executionTime = ($endTime - $startTime) * 1000;
  488. echo "查询执行时间: {$executionTime}ms\n";
  489. return Result::success($data);
  490. }
  491. /**
  492. * @param array $data
  493. * @return array
  494. */
  495. public function addArticle(array $data): array
  496. {
  497. var_dump($data, '----------12-----------1');
  498. // ------c_show_time********add***1****
  499. $is_collect = $data['is_collect'] ?? 0;
  500. $user_type = $data['user_type'];
  501. unset($data['is_collect']);
  502. unset($data['user_type']);
  503. // ------c_show_time********add***1****
  504. unset($data['nav_add_pool_id']);
  505. // unset($data['commend_id']);
  506. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  507. Db::beginTransaction();
  508. try {
  509. //处理投票
  510. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  511. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  512. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  513. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  514. unset($data['is_survey']);
  515. unset($data['survey_name']);
  516. unset($data['suvey_array']);
  517. // unset($data['website_id']);
  518. // unset($data['web_site_id']);
  519. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  520. if ($data['hits'] == '') {
  521. $data['hits'] = 0;
  522. }
  523. if ($data['is_original'] == '') {
  524. $data['is_original'] = 0;
  525. }
  526. if ($data['status'] == '') {
  527. $data['status'] = 0;
  528. }
  529. $articleData = $data;
  530. unset($articleData['content']);
  531. //自动处理缩略图、关键字、描述
  532. if ($articleData['imgurl'] == '') {
  533. //如果没有图,设置level=0
  534. $levelArr = json_decode($articleData['level'], true);
  535. var_dump($levelArr, '----------levelArr-----------1');
  536. //content中提取图片第一个图,正则提取
  537. // -------采集器相关优化-----
  538. // 优化正则表达式,仅匹配 src 属性值,避免匹配到多余内容
  539. if ($is_collect == 1) {
  540. $reg = '/<img.*?src=[\'"]?((?!.*\.gif)[^\'" >]+)[\'"]?.*?>/i';
  541. } else {
  542. $reg = '/<img.*?src=[\'"]?([^\'" >]+)[\'"]?.*?>/i';
  543. }
  544. // -------采集器相关优化-----
  545. preg_match_all($reg, $data['content'], $matches);
  546. if (isset($matches[1][0])) {
  547. //截取varchar240
  548. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  549. //如果有图,设置level=3
  550. if (!in_array(3, $levelArr)) {
  551. $levelArr[] = 3;
  552. }
  553. $articleData['level'] = json_encode($levelArr);
  554. } else {
  555. if (!in_array(0, $levelArr)) {
  556. $levelArr[] = 0;
  557. }
  558. $articleData['level'] = json_encode($levelArr);
  559. }
  560. }
  561. var_dump($articleData['level'], '----------$articleData[level]----------1');
  562. if ($articleData['keyword'] == '') {
  563. //提取标题+内容中的关键词
  564. $articleData['keyword'] = $data['title'];
  565. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  566. Jieba::init(); // 初始化 jieba-php
  567. Finalseg::init();
  568. $segList = Jieba::cut($articleData['keyword']);
  569. $segList1 = array_slice($segList, 0, 8);
  570. $articleData['keyword'] = implode(',', $segList1);
  571. }
  572. if ($articleData['introduce'] == '') {
  573. //提取内容中的描述
  574. $content = $data['content'];
  575. // 去除 <style> 和 <script> 标签及其内容
  576. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  577. // 去除所有 HTML 标签
  578. $content = strip_tags($content);
  579. // 去除 HTML 实体
  580. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  581. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  582. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  583. // 去除多余空白
  584. $content = preg_replace('/\s+/u', '', $content);
  585. // 截取 100 个字符
  586. $articleData['introduce'] = mb_substr($content, 0, 100);
  587. }
  588. if ($articleData['status'] == 0) {
  589. $this->sendMessage([
  590. 'talk_type' => 100,
  591. 'title' => $articleData['title'],
  592. 'content' => '提交了审核',
  593. 'messageType' => 2,
  594. ]);
  595. }
  596. if (!empty($data['fujian'])) {
  597. $articleData['fujian'] = $data['fujian'];
  598. }
  599. $id = Article::insertGetId($articleData);
  600. if (!$id) {
  601. throw new \Exception('文章插入失败');
  602. }
  603. $articleDataContent = [
  604. 'article_id' => $id,
  605. 'content' => $data['content'],
  606. ];
  607. // 采集器中的文章内容,在添加时,去掉div标签
  608. if ($is_collect == 1) {
  609. // 采集来的文章,content中可能包含div标签,需要先移除
  610. $pattern = '/<\/?div\b(?:[^"\'>]|"[^"]*"|\'[^\']*\')*>/is';
  611. $article_data = preg_replace($pattern, '', $data['content']);
  612. $$articleDataContent['content'] = $article_data;
  613. }
  614. $contentInsertId = ArticleData::insertGetId($articleDataContent);
  615. if (!$contentInsertId) {
  616. throw new \Exception('文章内容插入失败');
  617. }
  618. // ------c_show_time********add***2****
  619. // 直接使用当前系统时间,不再强制添加8小时
  620. $now = date('Y-m-d H:i:s');
  621. if ($user_type == 10000 || $is_collect == 1) {
  622. // 管理员添加文章时,核心站c端显示时间就是创建时间;非核心站c端显示时间就是此创建时间往后推二十分钟;
  623. // 非管理员添加文章时,不做操作只有在审核通过时获取c端显示时间
  624. if (!isset($data['catid'])) {
  625. throw new \Exception('缺少必要字段:catid');
  626. }
  627. $column_arr = WebsiteColumn::where('column_name', '官网')->pluck('id')->toArray();
  628. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  629. $web = WebsiteCategory::where('category_id', $data['catid'])
  630. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  631. ->select(
  632. 'website_id',
  633. DB::raw('
  634. CASE
  635. WHEN website.id IS NULL THEN 2
  636. WHEN website.website_column_id IN (' . implode(',', $column_arr) . ') THEN 1
  637. ELSE 0
  638. END as is_core
  639. ')
  640. )
  641. ->get();
  642. // $id = 225; -----测试开启
  643. // 采集来的文章,错开时间在两小时之内发布
  644. if ($user_type == 10000 && $is_collect == 1) {
  645. $web_num = $web->where('is_core', '!=', 2)->count();
  646. $waiting_interval = 10;
  647. if ($web_num > 12) {
  648. // 若网站数量大于12个,则每个网站间隔时间取均值
  649. // 防止除数为 0,虽然这里 $web_num 是 count 结果不会为 0,但做健壮性检查
  650. $waiting_interval = 120 / max(1, $web_num);
  651. }
  652. $time = 0;
  653. } else {
  654. // 非核心站与核心站----显示时间-----间隔
  655. $time = 20;
  656. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  657. $waiting_interval = 5;
  658. }
  659. // 将 Hyperf\Database\Model\Collection 转换为数组
  660. $webArray = $web->toArray();
  661. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $id, $waiting_interval, $is_collect) {
  662. // 检查 $item 对象是否有 is_core 属性
  663. if (!isset($item['is_core'])) {
  664. throw new \Exception('$item 对象缺少 is_core 属性');
  665. }
  666. // 当 is_core 为 2 时,则表示此网站不存在
  667. if ($item['is_core'] == 2) {
  668. return null;
  669. }
  670. if ($is_collect == 1) {
  671. // 采集来的文章,错开时间在两小时之内发布
  672. // $time = 0;
  673. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  674. $time += $waiting_interval;
  675. } else if ($item['is_core'] == 1) {
  676. // 当 is_core 为 1 时,则表示此网站是核心站
  677. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  678. } else {
  679. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  680. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  681. if ($item['is_core'] == 0) {
  682. $time += $waiting_interval;
  683. }
  684. }
  685. return [
  686. 'article_id' => $id,
  687. 'website_id' => $item['website_id'],
  688. 'c_show_time' => $c_show_time,
  689. // 'is_core' => $item['is_core'],
  690. // 'time' => $time
  691. ];
  692. }, array_keys($webArray), $webArray)));
  693. // Db::commit();
  694. // return Result::success($article_ignore);
  695. if (!empty($article_ignore)) {
  696. $article_ignores = ArticleIgnore::insert($article_ignore);
  697. if (!$article_ignores) {
  698. throw new \Exception('c端展示时间插入失败');
  699. }
  700. }
  701. }
  702. // ------c_show_time********add***2****
  703. //处理投票
  704. if ($is_survey == 1) {
  705. //生成年月日时分秒+8位随机数
  706. $uuid = date('YmdHis') . rand(10000000, 99999999);
  707. var_dump($suvey_array, 'suvey_array________');
  708. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  709. var_dump($suveys_array, '---------------------1');
  710. var_dump($suvey_array, '---------------------2');
  711. $suvey_data = [];
  712. foreach ($suveys_array as $key => $value) {
  713. if ($value == '') {
  714. continue;
  715. }
  716. if (is_array($value)) {
  717. $suvey_data[] = [
  718. 'sur_id' => $uuid,
  719. 'art_id' => $id,
  720. 'website_id' => $website_id ?? 2,
  721. 'survey_name' => $survey_name,
  722. 'choice_name' => $value[1],
  723. 'is_other' => 1,
  724. 'other_id' => 0,
  725. 'results' => 0,
  726. ];
  727. } else {
  728. $suvey_data[] = [
  729. 'sur_id' => $uuid,
  730. 'art_id' => $id,
  731. 'website_id' => $website_id ?? 2,
  732. 'survey_name' => $survey_name,
  733. 'choice_name' => $value,
  734. 'is_other' => 0,
  735. 'other_id' => 0,
  736. 'results' => 0,
  737. ];
  738. }
  739. if (empty($suvey_data)) {
  740. throw new \Exception("投票数据为空");
  741. }
  742. }
  743. $result = ArticleSurvey::insert($suvey_data);
  744. if (!$result) {
  745. throw new \Exception("投票失败,ArticleSurvey插入失败");
  746. }
  747. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  748. if (!$result) {
  749. throw new \Exception("投票失败,更新主表失败");
  750. }
  751. }
  752. Db::commit();
  753. return Result::success(['id' => $id]);
  754. } catch (\Throwable $ex) {
  755. Db::rollBack();
  756. var_dump($ex->getMessage());
  757. return Result::error("创建失败", 0);
  758. }
  759. }
  760. /**
  761. * @param array $data
  762. * @return array
  763. */
  764. public function delArticle(array $data): array
  765. {
  766. // ------c_show_time********del*******
  767. Db::beginTransaction();
  768. try {
  769. $article = Article::where(['id' => $data['id']])->delete();
  770. // 若文章删除失败,抛出异常,后续 SQL 语句不会执行
  771. if (!$article) {
  772. throw new \Exception("删除失败,文章删除失败");
  773. }
  774. //survey投票删除
  775. ArticleSurvey::where(['art_id' => $data['id']])->delete(); // 修正类名大小写
  776. $articleIgnore = ArticleIgnore::where(['article_id' => $data['id']])->delete();
  777. $article_data = ArticleData::where(['article_id' => $data['id']])->delete();
  778. // 若文章详情删除失败,抛出异常
  779. if (!$article_data) {
  780. throw new \Exception("删除失败,文章详情删除失败");
  781. }
  782. Db::commit(); // 所有操作成功,提交事务
  783. } catch (\Throwable $ex) {
  784. Db::rollBack();
  785. var_dump($ex->getMessage());
  786. return Result::error("删除失败: " . $ex->getMessage(), 0);
  787. }
  788. // ------c_show_time********del*******
  789. if (!$article) {
  790. return Result::error("删除失败");
  791. }
  792. return Result::success($article);
  793. }
  794. /**
  795. * @param array $data
  796. * @return array
  797. */
  798. public function updateArticle(array $data): array
  799. {
  800. var_dump($data, '----------12-----------1');
  801. Db::beginTransaction();
  802. // ------c_show_time********up*******
  803. $user_type = isset($data['user_type']) ? $data['user_type'] : 0;
  804. // 无论是否改变了c端显示时间或者栏目,都需要将未屏蔽的网站显示时间删除记录
  805. // 若是存在交集,则进行修改,若无,则合并(此表中的记录应该包含被屏蔽网站及涉及所有网站的展示时间)
  806. $web = WebsiteCategory::where('category_id', $data['catid'])
  807. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  808. ->select(
  809. 'website_id',
  810. 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')
  811. )
  812. ->get();
  813. // 根据错误信息,问题在于 $web 可能是一个包含对象的集合,不能直接用于 whereNotIn 方法
  814. // 先从 $web 集合中提取 website_id 字段的值,再进行删除操作
  815. $websiteIds = $web->pluck('website_id')->toArray();
  816. $del_article_ignore = ArticleIgnore::where('article_id', $data['id'])->whereNotIn('website_id', $websiteIds)->delete();
  817. if ($user_type == 0) {
  818. throw new \Exception("用户类型不能为空");
  819. }
  820. if ($user_type == 10000) {
  821. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  822. $web = WebsiteCategory::where('category_id', $data['catid'])
  823. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  824. ->select(
  825. 'website_id',
  826. 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')
  827. )
  828. ->get();
  829. // 非核心站与核心站----显示时间-----间隔
  830. $time = 20;
  831. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  832. $waiting_interval = 5;
  833. $webArray = $web->toArray();
  834. if (empty($webArray)) {
  835. throw new \Exception('网站分类不存在');
  836. }
  837. // 直接使用当前系统时间,不再强制添加8小时
  838. $now = date('Y-m-d H:i:s');
  839. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  840. // 检查 $item 对象是否有 is_core 属性
  841. if (!isset($item['is_core'])) {
  842. throw new \Exception('$item 对象缺少 is_core 属性');
  843. }
  844. // 当 is_core 为 2 时,则表示此网站不存在
  845. if ($item['is_core'] == 2) {
  846. return null;
  847. } else if ($item['is_core'] == 1) {
  848. // 当 is_core 为 1 时,则表示此网站是核心站
  849. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  850. } else {
  851. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  852. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  853. if ($item['is_core'] == 0) {
  854. $time += $waiting_interval;
  855. }
  856. }
  857. return [
  858. 'article_id' => $data['id'],
  859. 'website_id' => $item['website_id'],
  860. 'c_show_time' => $c_show_time,
  861. ];
  862. }, array_keys($webArray), $webArray)));
  863. if (!empty($article_ignore)) {
  864. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  865. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  866. $article_ignores = ArticleIgnore::upsert(
  867. $article_ignore,
  868. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  869. ['c_show_time'] // 需要更新的字段
  870. );
  871. if (!$article_ignores) {
  872. throw new \Exception('c端展示时间插入失败');
  873. }
  874. }
  875. // Db::commit();
  876. // return Result::success($article_ignore);
  877. }
  878. // ------c_show_time********up*******
  879. unset($data['user_type']);
  880. // unset($data['web_site_id']);
  881. unset($data['nav_add_pool_id']);
  882. try {
  883. //处理投票
  884. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  885. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  886. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  887. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  888. unset($data['is_survey']);
  889. unset($data['survey_name']);
  890. unset($data['suvey_array']);
  891. unset($data['website_id']);
  892. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  893. if ($data['hits'] == '') {
  894. $data['hits'] = 0;
  895. }
  896. if ($data['is_original'] == '') {
  897. $data['is_original'] = 0;
  898. }
  899. if ($data['status'] == '') {
  900. $data['status'] = 0;
  901. }
  902. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  903. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  904. $articleData = $data;
  905. unset($articleData['content']);
  906. unset($articleData['status_name']);
  907. unset($articleData['name']);
  908. unset($articleData['content']);
  909. unset($articleData['pid_arr']);
  910. unset($articleData['pid']);
  911. //自动处理缩略图、关键字、描述
  912. if ($articleData['imgurl'] == '') {
  913. //如果没有图,设置level=0
  914. $levelArr = json_decode($articleData['level'], true);
  915. var_dump($levelArr, '----------levelArr-----------1');
  916. //content中提取图片第一个图,正则提取
  917. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  918. preg_match_all($reg, $data['content'], $matches);
  919. if (isset($matches[1][0])) {
  920. //截取varchar240
  921. // 截取到第一个<
  922. $articleData['imgurl'] = $matches[1][0];
  923. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  924. $pos = strpos($articleData['imgurl'], '"');
  925. if ($pos !== false) {
  926. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  927. }
  928. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  929. //如果有图,设置level=3
  930. if (!in_array(3, $levelArr)) {
  931. $levelArr[] = 3;
  932. }
  933. $articleData['level'] = json_encode($levelArr);
  934. } else {
  935. if (!in_array(0, $levelArr)) {
  936. $levelArr[] = 0;
  937. }
  938. $articleData['level'] = json_encode($levelArr);
  939. }
  940. }
  941. var_dump($articleData['level'], '----------$articleData[level]----------1');
  942. if ($articleData['keyword'] == '') {
  943. //提取标题+内容中的关键词
  944. $articleData['keyword'] = $data['title'];
  945. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  946. Jieba::init(); // 初始化 jieba-php
  947. Finalseg::init();
  948. $segList = Jieba::cut($articleData['keyword']);
  949. $segList1 = array_slice($segList, 0, 8);
  950. $articleData['keyword'] = implode(',', $segList1);
  951. }
  952. if ($articleData['introduce'] == '') {
  953. //提取内容中的描述
  954. $content = $data['content'];
  955. // 去除 <style> 和 <script> 标签及其内容
  956. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  957. // 去除所有 HTML 标签
  958. $content = strip_tags($content);
  959. // 去除 HTML 实体
  960. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  961. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  962. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  963. // 去除多余空白
  964. $content = preg_replace('/\s+/u', '', $content);
  965. // 截取 100 个字符
  966. $articleData['introduce'] = mb_substr($content, 0, 100);
  967. }
  968. if ($articleData['status'] == 0) {
  969. $this->sendMessage([
  970. 'talk_type' => 100,
  971. 'title' => $articleData['title'],
  972. 'content' => '提交了审核',
  973. 'messageType' => 2,
  974. ]);
  975. }
  976. if (!empty($data['fujian'])) {
  977. $articleData['fujian'] = $data['fujian'];
  978. }
  979. $id = Article::where(['id' => $data['id']])->update($articleData);
  980. // $articleDataContent = [
  981. // 'content' => $data['content'],
  982. // ];
  983. // 采集来的文章,content中可能包含div标签,需要先移除
  984. $pattern = '/<\/?div\b(?:[^"\'>]|"[^"]*"|\'[^\']*\')*>/is';
  985. $article_data = preg_replace($pattern, '', $data['content']);
  986. $articleDataContent['content'] = $article_data;
  987. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  988. //处理投票
  989. $id = $data['id'];
  990. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  991. var_dump($suvey_array, 'suvey_array________delete');
  992. //处理投票
  993. if ($is_survey == 1) {
  994. //生成年月日时分秒+8位随机数
  995. $uuid = date('YmdHis') . rand(10000000, 99999999);
  996. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  997. var_dump($suveys_array, '---------------------1');
  998. $suvey_data = [];
  999. if (is_array($suveys_array)) {
  1000. foreach ($suveys_array as $key => $value) {
  1001. if ($value == '') {
  1002. continue;
  1003. }
  1004. if (is_array($value)) {
  1005. $suvey_data[] = [
  1006. 'sur_id' => $uuid,
  1007. 'art_id' => $id,
  1008. 'website_id' => $website_id ?? 2,
  1009. 'survey_name' => $survey_name,
  1010. 'choice_name' => $value[1],
  1011. 'is_other' => 1,
  1012. 'other_id' => 0,
  1013. 'results' => 0,
  1014. ];
  1015. } else {
  1016. $suvey_data[] = [
  1017. 'sur_id' => $uuid,
  1018. 'art_id' => $id,
  1019. 'website_id' => $website_id ?? 2,
  1020. 'survey_name' => $survey_name,
  1021. 'choice_name' => $value,
  1022. 'is_other' => 0,
  1023. 'other_id' => 0,
  1024. 'results' => 0,
  1025. ];
  1026. }
  1027. if (empty($suvey_data)) {
  1028. throw new \Exception("投票数据为空");
  1029. }
  1030. }
  1031. }
  1032. $result = ArticleSurvey::insert($suvey_data);
  1033. if (!$result) {
  1034. throw new \Exception("投票失败");
  1035. }
  1036. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  1037. if (!$result) {
  1038. throw new \Exception("投票失败");
  1039. }
  1040. } else {
  1041. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  1042. }
  1043. Db::commit();
  1044. return Result::success([]);
  1045. } catch (\Throwable $ex) {
  1046. Db::rollBack();
  1047. var_dump($ex->getMessage());
  1048. return Result::error("更新失败" . $ex->getMessage(), 0);
  1049. }
  1050. }
  1051. /**
  1052. * 更新资讯状态
  1053. * @param array $data
  1054. * @return array
  1055. */
  1056. public function upArticleStatus(array $data): array
  1057. {
  1058. $articleData = Article::where(['id' => $data['id']])->first();
  1059. //发送10次
  1060. // for ($i = 0; $i < 10; $i++) {
  1061. // $this->sendMessage([
  1062. // 'talk_type' => 100,
  1063. // 'title' => $i . $articleData['title'],
  1064. // 'content' => '审核通过',
  1065. // 'messageType' => 2,
  1066. // 'user_id' => $articleData['admin_user_id'],
  1067. // ]);
  1068. // }
  1069. // var_dump($data['status'], 'status');
  1070. // return Result::success();
  1071. if ($data['status'] == 1) {
  1072. $this->sendMessage([
  1073. 'talk_type' => 101,
  1074. 'title' => $articleData['title'],
  1075. 'content' => '审核通过',
  1076. 'messageType' => 2,
  1077. 'user_id' => $articleData['admin_user_id'],
  1078. ]);
  1079. }
  1080. if ($data['status'] == 2) {
  1081. $this->sendMessage([
  1082. 'talk_type' => 101,
  1083. 'title' => $articleData['title'],
  1084. 'content' => '审核拒绝',
  1085. 'messageType' => 2,
  1086. 'user_id' => $articleData['admin_user_id'],
  1087. ]);
  1088. }
  1089. if ($data['status'] == 0) {
  1090. $this->sendMessage([
  1091. 'talk_type' => 100,
  1092. 'title' => $articleData['title'],
  1093. 'content' => '提交了审核',
  1094. 'messageType' => 2,
  1095. ]);
  1096. }
  1097. $result = Article::where(['id' => $data['id']])->update($data);
  1098. // ------c_show_time********up_status*******
  1099. // 若是审核通过 则更新c_show_time
  1100. if ($data['status'] == 1) {
  1101. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  1102. $column_arr = WebsiteColumn::where('column_name', '官网')->pluck('id')->toArray();
  1103. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  1104. $web = WebsiteCategory::where('category_id', $data['catid'])
  1105. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  1106. ->select(
  1107. 'website_id',
  1108. DB::raw('
  1109. CASE
  1110. WHEN website.id IS NULL THEN 2
  1111. WHEN website.website_column_id IN (' . implode(',', $column_arr) . ') THEN 1
  1112. ELSE 0
  1113. END as is_core
  1114. ')
  1115. )
  1116. ->get();
  1117. // 非核心站与核心站----显示时间-----间隔
  1118. $time = 20;
  1119. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  1120. $waiting_interval = 5;
  1121. $webArray = $web->toArray();
  1122. if (empty($webArray)) {
  1123. throw new \Exception('网站分类不存在');
  1124. }
  1125. // 直接使用当前系统时间,不再强制添加8小时
  1126. $now = date('Y-m-d H:i:s');
  1127. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  1128. if (isset($data['ignore_ids'])) {
  1129. $ignore_website_ids = is_array($data['ignore_ids']) ? $data['ignore_ids'] : json_decode($data['ignore_ids'], true);
  1130. if (in_array($item['website_id'], $ignore_website_ids)) {
  1131. $is_ignore = 1;
  1132. } else {
  1133. $is_ignore = 0;
  1134. }
  1135. return [
  1136. 'article_id' => $data['id'],
  1137. 'website_id' => $item['website_id'],
  1138. 'is_ignore' => $is_ignore,
  1139. ];
  1140. } else {
  1141. // 检查 $item 对象是否有 is_core 属性
  1142. if (!isset($item['is_core'])) {
  1143. throw new \Exception('$item 对象缺少 is_core 属性');
  1144. }
  1145. // 当 is_core 为 2 时,则表示此网站不存在
  1146. if ($item['is_core'] == 2) {
  1147. return null;
  1148. } else if ($item['is_core'] == 1) {
  1149. // 当 is_core 为 1 时,则表示此网站是核心站
  1150. $c_show_time = $now;
  1151. } else {
  1152. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  1153. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  1154. if ($item['is_core'] == 0) {
  1155. $time += $waiting_interval;
  1156. }
  1157. }
  1158. return [
  1159. 'article_id' => $data['id'],
  1160. 'website_id' => $item['website_id'],
  1161. 'c_show_time' => $c_show_time,
  1162. ];
  1163. }
  1164. }, array_keys($webArray), $webArray)));
  1165. if (!empty($article_ignore) && !isset($data['ignore_ids'])) {
  1166. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  1167. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  1168. $websiteIds = $web->pluck('website_id')->toArray();
  1169. $del_article_ignore = ArticleIgnore::where('article_id', $data['id'])->whereNotIn('website_id', $websiteIds)->delete();
  1170. $article_ignores = ArticleIgnore::upsert(
  1171. $article_ignore,
  1172. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  1173. ['c_show_time'] // 需要更新的字段
  1174. );
  1175. if (!$article_ignores) {
  1176. throw new \Exception('c端展示时间插入失败');
  1177. }
  1178. }
  1179. if (!empty($data['ignore_ids'])) {
  1180. // return Result::success($article_ignore);
  1181. // 从数据库中删除 article_id 为 $data['id'] 且 website_id 在 $website_ids 中的记录
  1182. if (!empty($article_ignore)) {
  1183. $article_ignores = ArticleIgnore::upsert(
  1184. $article_ignore,
  1185. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  1186. ['is_ignore'] // 需要更新的字段
  1187. );
  1188. // if(!$article_ignores){
  1189. // throw new \Exception('屏蔽网站更新失败');
  1190. // }
  1191. }
  1192. }
  1193. }
  1194. // ------c_show_time********up_status*******
  1195. if ($result) {
  1196. return Result::success();
  1197. } else {
  1198. return Result::error("更新状态失败", 0);
  1199. }
  1200. }
  1201. /**
  1202. * 获取新闻详情
  1203. * @param array $data
  1204. * @return array
  1205. */
  1206. public function getArticleInfo(array $data): array
  1207. {
  1208. $where = [
  1209. 'article.id' => $data['id'],
  1210. // 'article.status' => 1,
  1211. ];
  1212. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  1213. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  1214. $info = $result;
  1215. // var_dump($info, 'info');
  1216. $info['survey_array'] = $articleSurvey;
  1217. if ($result) {
  1218. return Result::success($info);
  1219. } else {
  1220. return Result::error("查询失败", 0);
  1221. }
  1222. }
  1223. /**
  1224. * 获取头条新闻
  1225. * @param array $data
  1226. * @return array
  1227. */
  1228. public function getWebsiteArticlett(array $data): array
  1229. {
  1230. $website_id = $data['website_id'];
  1231. $website = Website::where('id', $data['website_id'])->first();
  1232. if (empty($website)) {
  1233. return Result::error("网站不存在", 0);
  1234. }
  1235. $categorys = $this->processArticlePro($website_id);
  1236. $catiall = $categorys['catiall'];
  1237. $categoryIds = $categorys['categoryIds'];
  1238. $where = [
  1239. 'status' => 1
  1240. ];
  1241. // $website_column = $website['column'];
  1242. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1243. $website_column = json_decode($website['website_column_arr_id'], true);
  1244. }
  1245. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1246. // return Result::success($diff_pid_categoryIds);
  1247. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1248. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1249. }
  1250. // $website_id = $data['website_id'];
  1251. $month = date("Y-m-d H:i:s", strtotime("-30 day"));
  1252. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  1253. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  1254. switch ($data['level']) {
  1255. case 1:
  1256. case 2:
  1257. case 3:
  1258. case 6: //1.头条资讯;2.轮播图;3.推荐图;6.今日热点
  1259. $query = Article::where($where)
  1260. ->where('level', 'like', '%' . $data['level'] . '%')
  1261. ->orderBy('updated_at', 'desc');
  1262. break;
  1263. case 4: //最新资讯
  1264. $query = Article::where($where)->orderBy('updated_at', 'desc');
  1265. break;
  1266. case 5: //资讯推荐
  1267. $query = Article::where($where)
  1268. ->where('updated_at', '>', $month);
  1269. break;
  1270. case 7: //资讯分类
  1271. if (isset($data['id']) && !empty($data['id'])) {
  1272. $keyword = Article::where('id', $data['id'])->value('keyword');
  1273. $keywordArray = explode(',', $keyword);
  1274. $whereL7 = [];
  1275. foreach ($keywordArray as $k => $v) {
  1276. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1277. }
  1278. $query = Article::where($where)->where($whereL7)->orderBy('updated_at', 'desc');;
  1279. break;
  1280. } else {
  1281. return Result::error("请输入资讯ID", 0);
  1282. break;
  1283. }
  1284. default:
  1285. break;
  1286. }
  1287. // $whereL7 = [];
  1288. // if(isset($data['id']) && !empty($data['id'])){
  1289. // $keyword = Article::where('id', $data['id'])->value('keyword');
  1290. // $keywordArray = explode(',', $keyword);
  1291. // foreach ($keywordArray as $k => $v) {
  1292. // $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1293. // }
  1294. // }
  1295. // $query = Article::where($where)
  1296. // ->when(isset($data['level']) && !empty($data['level']), function ($query) use ($data,$whereL7) {
  1297. // if($data['level'] == 1 || $data['level'] == 2 || $data['level'] == 3 || $data['level'] == 6){
  1298. // $query = $query->where('article.level','like','%'.$data['level'].'%')->orderBy('updated_at','desc');
  1299. // }
  1300. // if($data['level'] == 7){
  1301. // $query = $query->where($whereL7)->orderBy('updated_at','desc');
  1302. // }
  1303. // if($data['level'] == 4){
  1304. // $query = $query->inRandomOrder()
  1305. // ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  1306. // }
  1307. // if($data['level'] == 5){
  1308. // $query = $query->orderBy('updated_at','desc');
  1309. // }
  1310. // });
  1311. if ($data['textnum'] > 0) {
  1312. $query = clone $query;
  1313. $result['text'] = $query
  1314. ->whereIn('catid', $categoryIds)
  1315. ->leftJoinSub(function ($query) use ($website_id) {
  1316. $query->from('article_ignore')
  1317. ->where('website_id', $website_id);
  1318. }, 'article_ignore', function ($join) {
  1319. $join->on('article_ignore.article_id', '=', 'article.id');
  1320. })
  1321. ->where(function ($query) {
  1322. $query->whereNull('article_ignore.article_id')
  1323. ->orWhere(function ($subQuery) {
  1324. $subQuery->whereNotNull('article_ignore.article_id')
  1325. ->where('article_ignore.is_ignore', 0)
  1326. ->where(function ($subSubQuery) {
  1327. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1328. ->orWhereNull('article_ignore.c_show_time');
  1329. });
  1330. });
  1331. })
  1332. // ->where(function ($query) use ($website_id) {
  1333. // $query->whereNull('article_ignore.article_id')
  1334. // ->orWhere('article_ignore.website_id', '!=', $website_id);
  1335. // })
  1336. ->select(
  1337. 'article.id',
  1338. 'article.title',
  1339. 'article.author',
  1340. 'article.updated_at',
  1341. 'article.introduce',
  1342. 'article.islink',
  1343. 'article.linkurl',
  1344. 'article.copyfrom',
  1345. 'article.cat_arr_id',
  1346. 'article.catid',
  1347. 'article.level',
  1348. // 'article_ignore.is_ignore',
  1349. // 'article_ignore.c_show_time',
  1350. )
  1351. ->offset($data['placeid'])
  1352. ->limit($data['textnum'])
  1353. ->get()->all();
  1354. foreach ($result['text'] as $k => $v) {
  1355. $result['text'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1356. $result['text'][$k]->alias = $catiall[$v->catid]['alias'];
  1357. }
  1358. }
  1359. if ($data['imgnum'] > 0) {
  1360. $query = clone $query;
  1361. if ($data['textnum'] == 0) {
  1362. $query = $query->leftJoinSub(function ($query) use ($website_id) {
  1363. $query->from('article_ignore')
  1364. ->where('website_id', $website_id);
  1365. }, 'article_ignore', function ($join) {
  1366. $join->on('article_ignore.article_id', '=', 'article.id');
  1367. })
  1368. ->where(function ($query) {
  1369. $query->whereNull('article_ignore.article_id')
  1370. ->orWhere(function ($subQuery) {
  1371. $subQuery->whereNotNull('article_ignore.article_id')
  1372. ->where('article_ignore.is_ignore', 0)
  1373. ->where(function ($subSubQuery) {
  1374. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1375. ->orWhereNull('article_ignore.c_show_time');
  1376. });
  1377. });
  1378. });
  1379. }
  1380. $result['img'] = $query
  1381. ->whereIn('catid', $categoryIds)
  1382. ->where('article.imgurl', '!=', '')
  1383. ->select(
  1384. 'article.id',
  1385. 'article.title',
  1386. 'article.imgurl',
  1387. 'article.author',
  1388. 'article.updated_at',
  1389. 'article.introduce',
  1390. 'article.islink',
  1391. 'article.linkurl',
  1392. 'article.copyfrom',
  1393. 'article.cat_arr_id',
  1394. 'article.catid',
  1395. 'article.level',
  1396. // 'article_ignore.is_ignore',
  1397. // 'article_ignore.c_show_time',
  1398. )
  1399. ->offset($data['placeid'])
  1400. ->limit($data['imgnum'])
  1401. ->get()->all();
  1402. foreach ($result['img'] as $k => $v) {
  1403. $result['img'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1404. $result['img'][$k]->alias = $catiall[$v->catid]['alias'];
  1405. }
  1406. }
  1407. if (empty($result)) {
  1408. return Result::error("暂无相关资讯", 0);
  1409. }
  1410. return Result::success($result);
  1411. }
  1412. /**
  1413. * 获取模块新闻
  1414. * @param array $data
  1415. * @return array
  1416. */
  1417. public function getWebsiteModelArticles(array $data): array
  1418. {
  1419. $catid = $data['catid'];
  1420. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  1421. $category = $category->toArray();
  1422. if (!empty($category)) {
  1423. $where = [
  1424. 'status' => 1,
  1425. 'catid' => $catid,
  1426. ];
  1427. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  1428. // 1:文字新闻;2:轮播图;3:图文;
  1429. // 级别:0:未分类
  1430. // 3:推荐图片
  1431. if ($data['level'] == 1) {
  1432. $data['level'] = 0;
  1433. }
  1434. $result = Article::where($where)
  1435. ->where(function ($query) use ($data) {
  1436. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  1437. ->orWhereNull("level")
  1438. ->orWhereRaw("level = '[]'");
  1439. })
  1440. ->leftJoinSub(function ($query) use ($data) {
  1441. $query->from('article_ignore')
  1442. ->where('website_id', $data['website_id']);
  1443. }, 'article_ignore', function ($join) {
  1444. $join->on('article_ignore.article_id', '=', 'article.id');
  1445. })
  1446. ->where(function ($query) {
  1447. $query->whereNull('article_ignore.article_id')
  1448. ->orWhere(function ($subQuery) {
  1449. $subQuery->whereNotNull('article_ignore.article_id')
  1450. ->where('article_ignore.is_ignore', 0)
  1451. ->where(function ($subSubQuery) {
  1452. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1453. ->orWhereNull('article_ignore.c_show_time');
  1454. });
  1455. });
  1456. })
  1457. // ->where(function ($query) use ($data) {
  1458. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1459. // ->orWhereNull("ignore_ids");
  1460. // })
  1461. ->orderBy("updated_at", "desc")
  1462. ->offset($placeid)
  1463. ->limit($data['pagesize'])
  1464. ->get();
  1465. if (empty($result)) {
  1466. return Result::error("此栏目暂无相关新闻", 0);
  1467. }
  1468. } else {
  1469. return Result::error("此网站暂无此栏目", 0);
  1470. }
  1471. return Result::success($result);
  1472. }
  1473. /**
  1474. *获取新闻列表
  1475. * @param array $data
  1476. * @return array
  1477. */
  1478. public function getWebsiteArticleList(array $data): array
  1479. {
  1480. // return Result::success($data);
  1481. $where[] = ['status', '=', 1];
  1482. $website_id = $data['website_id'];
  1483. $website = Website::where('id', $data['website_id'])->first();
  1484. if (empty($website)) {
  1485. return Result::error("网站不存在", 0);
  1486. }
  1487. // $website_column = $website['column'];
  1488. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1489. $website_column = json_decode($website['website_column_arr_id'], true);
  1490. }
  1491. $categorys = $this->processArticlePro($website_id);
  1492. $cat_1st_arr = $categorys['cat_1st_arr'];
  1493. $catiall = $categorys['catiall'];
  1494. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1495. // return Result::success($diff_pid_categoryIds);
  1496. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1497. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1498. }
  1499. if (isset($data['catid']) && !empty($data['catid'])) {
  1500. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  1501. if (empty($category)) {
  1502. return Result::error("此网站暂无此栏目", 0);
  1503. }
  1504. array_push($where, ['catid', '=', $data['catid']]);
  1505. }
  1506. // return Result::success($where);
  1507. $query = Article::where($where)
  1508. ->leftJoinSub(function ($query) use ($website_id) {
  1509. $query->from('article_ignore')
  1510. ->where('website_id', $website_id);
  1511. }, 'article_ignore', function ($join) {
  1512. $join->on('article_ignore.article_id', '=', 'article.id');
  1513. })
  1514. ->where(function ($query) {
  1515. $query->whereNull('article_ignore.article_id')
  1516. ->orWhere(function ($subQuery) {
  1517. $subQuery->whereNotNull('article_ignore.article_id')
  1518. ->where('article_ignore.is_ignore', 0)
  1519. ->where(function ($subSubQuery) {
  1520. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1521. ->orWhereNull('article_ignore.c_show_time');
  1522. });
  1523. });
  1524. })
  1525. ->select(
  1526. 'article.id',
  1527. 'article.title',
  1528. 'article.imgurl',
  1529. 'article.author',
  1530. 'article.updated_at',
  1531. 'article.introduce',
  1532. 'article.islink',
  1533. 'article.linkurl',
  1534. 'article.copyfrom',
  1535. 'article.cat_arr_id',
  1536. 'article.catid'
  1537. );
  1538. $count = $query->count();
  1539. $rep = $query->orderBy("updated_at", "desc")
  1540. ->offset(($data['page'] - 1) * $data['pageSize'])
  1541. ->limit($data['pageSize'])
  1542. ->get()->all();
  1543. $categorys = $this->processArticlePro($website_id);
  1544. $cat_1st_arr = $categorys['cat_1st_arr'];
  1545. $catiall = $categorys['catiall'];
  1546. // $web['website_id'] = $data['website_id'];
  1547. foreach ($rep as $k => $v) {
  1548. $rep[$k]->category_name = $catiall[$v->catid]['alias'];
  1549. $rep[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1550. }
  1551. // $rep = $this->processArticles($rep,$web);
  1552. $data = [
  1553. 'rows' => $rep,
  1554. 'count' => $count,
  1555. ];
  1556. if (empty($rep)) {
  1557. return Result::error("没有信息数据");
  1558. }
  1559. return Result::success($data);
  1560. }
  1561. /**
  1562. * 前端-获取新闻详情
  1563. * @param array $data
  1564. * @return array
  1565. */
  1566. public function selectWebsiteArticleInfo(array $data): array
  1567. {
  1568. $where = [
  1569. 'article.id' => $data['id'],
  1570. 'article.status' => 1,
  1571. ];
  1572. $result = Article::where($where)
  1573. ->leftJoin("article_data", "article.id", "article_data.article_id")
  1574. ->leftJoin("article_extend", "article_extend.article_id", "article.id")
  1575. // ->where(function ($query) use ($data) {
  1576. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1577. // ->orWhereNull("ignore_ids");
  1578. // })
  1579. ->leftJoinSub(function ($query) use ($data) {
  1580. $query->from('article_ignore')
  1581. ->where('website_id', $data['website_id']);
  1582. }, 'article_ignore', function ($join) {
  1583. $join->on('article_ignore.article_id', '=', 'article.id');
  1584. })
  1585. ->where(function ($query) {
  1586. $query->whereNull('article_ignore.article_id')
  1587. ->orWhere(function ($subQuery) {
  1588. $subQuery->whereNotNull('article_ignore.article_id')
  1589. ->where('article_ignore.is_ignore', 0)
  1590. ->where(function ($subSubQuery) {
  1591. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1592. ->orWhereNull('article_ignore.c_show_time');
  1593. });
  1594. });
  1595. })
  1596. ->select(
  1597. 'article.*',
  1598. 'article_data.content',
  1599. 'article_data.article_id',
  1600. 'article_extend.website_url',
  1601. 'article_extend.email',
  1602. 'article_extend.contacts',
  1603. 'article_extend.contacts_mobile',
  1604. 'article_extend.contacts_address',
  1605. 'article_extend.zip_code',
  1606. 'article_extend.enterprise_name'
  1607. )
  1608. ->first();
  1609. if (empty($result)) {
  1610. return Result::error("暂无此新闻!", 0);
  1611. }
  1612. if (!empty($result['publiced_at'])) {
  1613. $result['updated_at'] = $result['publiced_at'];
  1614. }
  1615. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  1616. ->select('website_category.*', 'website.website_name', 'website.suffix')
  1617. ->where('website_category.website_id', $data['website_id'])
  1618. ->where(['website_category.category_id' => $result['catid']])
  1619. ->first();
  1620. if (empty($category)) {
  1621. return Result::error("查询失败", 0);
  1622. }
  1623. //手动推荐文章
  1624. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  1625. if (empty($commend_ids)) {
  1626. $commendArticle = [];
  1627. } else {
  1628. //去除不存在的文章ID
  1629. $commendArticle = Article::whereIn('article.id', $commend_ids)
  1630. ->leftjoin('website_category', 'website_category.category_id', '=', 'article.catid')
  1631. ->leftJoinSub(function ($query) use ($data) {
  1632. $query->from('article_ignore')
  1633. ->where('website_id', $data['website_id']);
  1634. }, 'article_ignore', function ($join) {
  1635. $join->on('article_ignore.article_id', '=', 'article.id');
  1636. })
  1637. ->where(function ($query) {
  1638. $query->whereNull('article_ignore.article_id')
  1639. ->orWhere(function ($subQuery) {
  1640. $subQuery->whereNotNull('article_ignore.article_id')
  1641. ->where('article_ignore.is_ignore', 0)
  1642. ->where(function ($subSubQuery) {
  1643. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1644. ->orWhereNull('article_ignore.c_show_time');
  1645. });
  1646. });
  1647. })
  1648. ->where('article.status', 1)
  1649. ->where('website_category.website_id', $data['website_id'])
  1650. ->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')
  1651. ->orderByRaw("FIELD(article.id, " . implode(',', $commend_ids) . ")")
  1652. // ->orderBy('article.updated_at', 'desc')
  1653. ->limit(5)
  1654. ->get();
  1655. //循环数组,取出cat_arr_id中的不重复值,再从website_category取出alias_pinyin,再将cat_arr_id的json转成路径/隔开
  1656. foreach ($commendArticle as $k => $v) {
  1657. $cat_arr_id = json_decode($v->cat_arr_id, true);
  1658. if (!empty($cat_arr_id) && is_array($cat_arr_id)) {
  1659. $cat_arr_id = array_unique($cat_arr_id);
  1660. // 从website_category取出alias_pinyin
  1661. $cat_arr = WebsiteCategory::where('website_id', $data['website_id'])
  1662. ->whereIn('category_id', $cat_arr_id)
  1663. ->pluck('alias_pinyin', 'category_id')
  1664. ->toArray();
  1665. // 将cat_arr_id的json转成路径/隔开
  1666. $path_parts = [];
  1667. foreach ($cat_arr_id as $cat_id) {
  1668. if (isset($cat_arr[$cat_id])) {
  1669. $path_parts[] = $cat_arr[$cat_id];
  1670. }
  1671. }
  1672. $v->alias_pinyin = implode('/', $path_parts);
  1673. } else {
  1674. $v->alias_pinyin = '';
  1675. }
  1676. }
  1677. }
  1678. $result['category_id'] = $category['category_id'];
  1679. $result['cat_name'] = $category['alias'];
  1680. $result['website_name'] = $category['website_name'] ?? "";
  1681. $result['suffix'] = $category['suffix'] ?? "";
  1682. $result['commendArticle'] = $commendArticle;
  1683. $result['commend_ids'] = $commend_ids;
  1684. return Result::success($result);
  1685. }
  1686. /**
  1687. * 前端-获取网站调查问卷
  1688. * @param array $data
  1689. * @return array
  1690. */
  1691. public function getWebsiteSurvey(array $data): array
  1692. {
  1693. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1694. $website = Website::where('id', $data['website_id'])->first();
  1695. if (empty($website)) {
  1696. return Result::error("暂无此网站", 0);
  1697. }
  1698. }
  1699. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1700. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1701. if (empty($article)) {
  1702. return Result::error("暂无此文章", 0);
  1703. }
  1704. // return Result::error($data,0);
  1705. $where['art_id'] = $data['art_id'];
  1706. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1707. } else {
  1708. $survey = Article::where(function ($query) {
  1709. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1710. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1711. })
  1712. ->where('status', 1)
  1713. ->where('is_survey', 1)
  1714. ->select('survey_id')
  1715. ->orderBy('updated_at', 'desc')
  1716. ->first();
  1717. if (empty($survey)) {
  1718. return Result::error("暂无调查问卷", 0);
  1719. }
  1720. $where['sur_id'] = $survey['survey_id'];
  1721. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1722. }
  1723. // return Result::success($where);
  1724. $result = ArticleSurvey::where($where)
  1725. ->where(function ($query) {
  1726. $query->where('is_other', 0)
  1727. ->orWhere(function ($subQuery) {
  1728. $subQuery->where('is_other', 1)
  1729. ->where('other_id', 0);
  1730. });
  1731. })
  1732. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1733. ->select('article_survey.*', 'article.survey_type')
  1734. ->get()->all();
  1735. if (empty($result)) {
  1736. return Result::error("此文章暂无调查问卷", 0);
  1737. }
  1738. return Result::success($result);
  1739. }
  1740. /**
  1741. * 前端-添加网站调查问卷选项
  1742. * @param array $data
  1743. * @return array
  1744. */
  1745. public function addWebsiteSurveyOption(array $data): array
  1746. {
  1747. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1748. $website = Website::where('id', $data['website_id'])->first();
  1749. if (empty($website)) {
  1750. return Result::error("暂无此网站", 0);
  1751. }
  1752. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1753. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1754. if (empty($survey)) {
  1755. return Result::error("此调查问卷不可添加选项", 0);
  1756. }
  1757. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1758. $choice = [
  1759. 'art_id' => $survey['art_id'],
  1760. 'website_id' => $data['website_id'],
  1761. 'survey_name' => $survey['survey_name'],
  1762. 'choice_name' => $data['choice_name'],
  1763. 'sur_id' => $survey['sur_id'],
  1764. 'is_other' => 1,
  1765. 'other_id' => $survey['id'],
  1766. ];
  1767. $result = ArticleSurvey::insertGetId($choice);
  1768. if (empty($result)) {
  1769. return Result::error("添加失败", 0);
  1770. }
  1771. return Result::success($result);
  1772. }
  1773. }
  1774. return Result::error("添加失败", 0);
  1775. }
  1776. return Result::error("添加失败", 0);
  1777. }
  1778. /**
  1779. * 前端-调查问卷投票
  1780. * @param array $data
  1781. * @return array
  1782. */
  1783. public function addWebsiteSurveyVote(array $data): array
  1784. {
  1785. // return Result::success($data);
  1786. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1787. $website = Website::where('id', $data['website_id'])->first();
  1788. if (empty($website)) {
  1789. return Result::error("暂无此网站", 0);
  1790. }
  1791. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1792. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1793. // return Result::success($survey);
  1794. if (empty($is_survey)) {
  1795. return Result::error("此调查问卷不存在", 0);
  1796. }
  1797. // return Result::success($survey);
  1798. // 调查问卷类型
  1799. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1800. //多选 若是json型则转化成数组类型
  1801. if (strpos($data['choice_id'], '[') === 0) {
  1802. $data['choice_id'] = json_decode($data['choice_id'], true);
  1803. } else {
  1804. // 单选 也转换成数组
  1805. $data['choice_id'] = [$data['choice_id']];
  1806. }
  1807. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1808. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1809. // ->where('website_id',$data['website_id'])
  1810. ->where('is_other', 1)
  1811. ->where('other_id', 0)
  1812. ->first();
  1813. if (!empty($other)) {
  1814. return Result::error("请选择已有的选项!", 0);
  1815. }
  1816. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1817. // ->where('website_id',$data['website_id'])
  1818. ->where('is_other', 1)
  1819. ->where('other_id', '!=', 0)
  1820. ->first();
  1821. // return Result::success($choice['other']);
  1822. $choice_id = $data['choice_id'];
  1823. if (!empty($choice['other'])) {
  1824. // array_push($data['choice_id'],$choice['other']['other_id']);
  1825. if (!empty($choice_id)) {
  1826. $key = array_search($choice['other']['id'], $choice_id);
  1827. if ($key !== false) {
  1828. unset($choice_id[$key]);
  1829. $choice_id = array_values($choice_id);
  1830. }
  1831. array_push($choice_id, $choice['other']['other_id']);
  1832. } else {
  1833. $choice_id[0] = $choice['other']['other_id'];
  1834. }
  1835. array_push($data['choice_id'], $choice['other']['other_id']);
  1836. }
  1837. // return Result::success($data);
  1838. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1839. // ->where('website_id',$data['website_id'])
  1840. ->increment('results', 1);
  1841. if (empty($choice)) {
  1842. return Result::error("请选择已有的选项!", 0);
  1843. }
  1844. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1845. // ->where('website_id',$data['website_id'])
  1846. ->where('other_id', 0)
  1847. ->get();
  1848. $survey['choice'] = $choice_id;
  1849. return Result::success($survey);
  1850. }
  1851. return Result::error("参数必填!");
  1852. }
  1853. return Result::error("此调查问卷不存在", 0);
  1854. }
  1855. return Result::error("参数必填!");
  1856. }
  1857. /**
  1858. * 后端-获取网站调查问卷列表
  1859. * @param array $data
  1860. * @return array
  1861. */
  1862. public function getSurveyList(array $data): array
  1863. {
  1864. $where = [];
  1865. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1866. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1867. }
  1868. $survey_type = isset($data['survey_type']) && $data['survey_type'] !== '' ? $data['survey_type'] : null;
  1869. if (!empty($where)) {
  1870. // 修复:先关联 article 再按 survey_type 过滤,避免查不到数据
  1871. $query = ArticleSurvey::select(
  1872. 'art_id as id',
  1873. Db::raw('MAX(id) as surid'),
  1874. Db::raw('MAX(survey_name) as survey_name'),
  1875. Db::raw('MAX(sur_id) as survey_id')
  1876. )
  1877. ->groupBy('art_id')
  1878. ->where($where)
  1879. ->when(!is_null($survey_type), function ($q) use ($survey_type) {
  1880. $q->whereIn('art_id', function ($sub) use ($survey_type) {
  1881. $sub->select('id')
  1882. ->from('article')
  1883. ->where('survey_type', $survey_type);
  1884. });
  1885. })
  1886. ->with(['article' => function ($query) {
  1887. $query->select('id', 'survey_type', 'created_at', 'updated_at', 'created_at');
  1888. }]);;
  1889. } else {
  1890. $query = ArticleSurvey::select(
  1891. 'art_id as id',
  1892. Db::raw('MAX(id) as surid'),
  1893. Db::raw('MAX(survey_name) as survey_name'),
  1894. Db::raw('MAX(sur_id) as survey_id'),
  1895. )
  1896. ->groupBy('art_id')
  1897. ->when(!is_null($survey_type), function ($q) use ($survey_type) {
  1898. $q->whereIn('art_id', function ($sub) use ($survey_type) {
  1899. $sub->select('id')
  1900. ->from('article')
  1901. ->where('survey_type', $survey_type);
  1902. });
  1903. })
  1904. ->with(['article' => function ($query) {
  1905. $query->select('id', 'survey_type', 'created_at', 'updated_at', 'created_at');
  1906. }]);
  1907. }
  1908. $count = $query->get()->count();
  1909. // 简单写法:直接统计分组后的 art_id 数量
  1910. $survey = $query->orderBy('id', 'desc')
  1911. ->limit($data['pageSize'])
  1912. ->offset(($data['page'] - 1) * $data['pageSize'])
  1913. ->get();
  1914. if (empty($survey->toArray())) {
  1915. return Result::error("暂无调查问卷!", 0);
  1916. }
  1917. $survey = array_map(function ($item) {
  1918. if (isset($item['article'])) {
  1919. $item['survey_type'] = $item['article']['survey_type'];
  1920. $item['created_at'] = $item['article']['created_at'];
  1921. $item['updated_at'] = $item['article']['updated_at'];
  1922. } else {
  1923. // 处理article为null的情况,设置默认值
  1924. $item['survey_type'] = null;
  1925. $item['created_at'] = null;
  1926. $item['updated_at'] = null;
  1927. }
  1928. unset($item['article']);
  1929. return $item;
  1930. }, $survey->toArray());
  1931. $result = [
  1932. 'rows' => $survey,
  1933. 'count' => $count,
  1934. ];
  1935. return Result::success($result);
  1936. }
  1937. /**
  1938. * 后端-获取网站调查问卷详情
  1939. * @param array $data
  1940. * @return array
  1941. */
  1942. public function getSurveyInfo(array $data): array
  1943. {
  1944. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1945. $where = ['sur_id' => $data['sur_id']];
  1946. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1947. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1948. ->select('article_survey.*', 'article.survey_type')
  1949. ->get()->all();
  1950. if (empty($choose)) {
  1951. return Result::error("此调查问卷不存在", 0);
  1952. }
  1953. $resultsArray = array_column($choose, 'results');
  1954. $total = array_sum($resultsArray);
  1955. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1956. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1957. // $total = 0;
  1958. if (!empty($other)) {
  1959. $total = $total + $other['results'];
  1960. $other['choice_name'] = '(其他)';
  1961. if (!empty($others)) {
  1962. $other['hasChildren'] = true;
  1963. // array_push($other,['hasChildren','=',true]);
  1964. $other['children'] = $others;
  1965. $other_choices = [$other->toArray()];
  1966. $mer_choice = array_merge($choose, $other_choices);
  1967. $value_choice = array_values($mer_choice);
  1968. } else {
  1969. // return Result::error('1111');
  1970. $other_choices = [$other->toArray()];
  1971. $other_choices = array_merge($choose, $other_choices);
  1972. $value_choice = array_values($other_choices);
  1973. // return Result::success($result);
  1974. }
  1975. } else {
  1976. $value_choice = $choose;
  1977. }
  1978. $result = [
  1979. 'choose' => $value_choice,
  1980. 'total' => $total,
  1981. ];
  1982. }
  1983. return Result::success($result);
  1984. }
  1985. /**
  1986. * 前端-搜索新闻列表
  1987. * @param array $data
  1988. * @return array
  1989. */
  1990. public function selectWebsiteArticle(array $data): array
  1991. {
  1992. $website = Website::where('id', $data['website_id'])->first();
  1993. if (empty($website)) {
  1994. return Result::error("网站不存在", 0);
  1995. }
  1996. // $website_column = $website['column'];
  1997. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1998. $website_column = json_decode($website['website_column_arr_id'], true);
  1999. }
  2000. $website_id = $data['website_id'];
  2001. $categorys = $this->processArticlePro($website_id);
  2002. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  2003. // return Result::success($diff_pid_categoryIds);
  2004. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2005. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2006. }
  2007. // return Result::success(reset($diff_pid_categoryIds) == 0);
  2008. // $cat_1st_arr = $categorys['cat_1st_arr'];
  2009. $catiall = $categorys['catiall'];
  2010. $categoryIds = $categorys['categoryIds'];
  2011. // return Result::success($categoryIds);
  2012. $query = Article::where('status', 1)
  2013. ->whereIn('catid', $categoryIds)
  2014. ->leftJoinSub(function ($query) use ($website_id) {
  2015. $query->from('article_ignore')
  2016. ->where('website_id', $website_id);
  2017. }, 'article_ignore', function ($join) {
  2018. $join->on('article_ignore.article_id', '=', 'article.id');
  2019. })
  2020. ->where(function ($query) {
  2021. $query->whereNull('article_ignore.article_id')
  2022. ->orWhere(function ($subQuery) {
  2023. $subQuery->whereNotNull('article_ignore.article_id')
  2024. ->where('article_ignore.is_ignore', 0)
  2025. ->where(function ($subSubQuery) {
  2026. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2027. ->orWhereNull('article_ignore.c_show_time');
  2028. });
  2029. });
  2030. });
  2031. // ->get()->all();
  2032. // return Result::success($query);
  2033. if (isset($data['cityid']) && !empty($data['cityid'])) {
  2034. $query->whereRaw("JSON_CONTAINS(article.city_arr_id, '" . intval($data['cityid']) . "')");
  2035. }
  2036. if (isset($data['department_id']) && !empty($data['department_id'])) {
  2037. $query->whereRaw("JSON_CONTAINS(article.department_arr_id, '" . intval($data['department_id']) . "')");
  2038. }
  2039. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2040. $query->where('article.title', 'like', '%' . $data['keyword'] . '%');
  2041. }
  2042. // 计算总数
  2043. $count = $query->count();
  2044. // return Result::success($count);
  2045. // 分页查询
  2046. $articles = $query
  2047. ->select(
  2048. 'article.id',
  2049. 'article.title',
  2050. 'article.imgurl',
  2051. 'article.author',
  2052. 'article.updated_at',
  2053. 'article.introduce',
  2054. 'article.islink',
  2055. 'article.linkurl',
  2056. 'article.copyfrom',
  2057. 'article.cat_arr_id',
  2058. 'article.catid',
  2059. 'article.department_arr_id',
  2060. 'article.city_arr_id',
  2061. // 'article_ignore.c_show_time',
  2062. // 'article_ignore.is_ignore'
  2063. )
  2064. ->orderBy("updated_at", "desc")
  2065. ->offset(($data['page'] - 1) * $data['pageSize'])
  2066. ->limit($data['pageSize'])
  2067. ->get();
  2068. // return Result::success($articles);
  2069. foreach ($articles as $k => $v) {
  2070. $articles[$k]->category_name = $catiall[$v->catid]['alias'];
  2071. $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2072. }
  2073. if (empty($articles)) {
  2074. return Result::error("没有符合条件的资讯数据");
  2075. }
  2076. $result = [
  2077. 'rows' => $articles,
  2078. 'count' => $count,
  2079. ];
  2080. return Result::success($result);
  2081. }
  2082. /**
  2083. * 模块新闻加强版
  2084. * @param array $data
  2085. * @return array
  2086. */
  2087. public function getWebsiteCatidArticle(array $data): array
  2088. {
  2089. $where = [
  2090. 'website_category.category_id' => $data['catid'],
  2091. 'website_category.website_id' => $data['website_id'],
  2092. ];
  2093. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  2094. $child_catnum = $data['child_catnum'] ?? 1;
  2095. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  2096. $childCategoryIds = array_column($category['child'], 'category_id');
  2097. if (empty($childCategoryIds)) {
  2098. return Result::error("暂无子栏目", 0);
  2099. }
  2100. $imgArticles = [];
  2101. $textArticles = [];
  2102. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  2103. // 初始化子分类图片新闻和文字新闻数组
  2104. // 查询所有子级栏目的图文新闻
  2105. $imgArticles = Article::where('catid', $childCategoryIds[0])
  2106. ->where(function ($query) use ($data) {
  2107. $query->where(function ($subQuery) use ($data) {
  2108. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  2109. })->orWhereNull("ignore_ids");
  2110. })
  2111. ->where('status', 1)
  2112. ->where('imgurl', '!=', '')
  2113. ->select('*')
  2114. ->orderBy('updated_at', 'desc')
  2115. ->limit($data['child_imgnum'])
  2116. ->get();
  2117. }
  2118. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  2119. // 查询所有子级栏目的文字新闻
  2120. $textArticles = Article::where('catid', $childCategoryIds[0])
  2121. ->where('status', 1)
  2122. ->where(function ($query) use ($data) {
  2123. $query->where(function ($subQuery) use ($data) {
  2124. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  2125. })->orWhereNull("ignore_ids");
  2126. })
  2127. ->select('*')
  2128. ->orderBy('updated_at', 'desc')
  2129. ->limit($data['child_textnum'])
  2130. ->get();
  2131. }
  2132. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  2133. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  2134. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  2135. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  2136. return $child;
  2137. }, $category['child']);
  2138. }
  2139. // }
  2140. if (isset($data['img_num']) && !empty($data['img_num'])) {
  2141. $category['img'] = WebsiteCategory::where($where)
  2142. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  2143. ->where('article.status', 1)
  2144. ->where('article.imgurl', '!=', '')
  2145. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  2146. ->orderBy('article.updated_at', 'desc')
  2147. ->limit($data['img_num'])
  2148. ->get();
  2149. }
  2150. if (isset($data['text_num']) && !empty($data['text_num'])) {
  2151. $category['text'] = WebsiteCategory::where($where)
  2152. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  2153. ->where('article.status', 1)
  2154. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  2155. ->orderBy('article.updated_at', 'desc')
  2156. ->limit($data['text_num'])
  2157. ->get();
  2158. }
  2159. // $category = $category->get();
  2160. if (empty($category)) {
  2161. return Result::error("查询失败", 0);
  2162. }
  2163. return Result::success($category);
  2164. }
  2165. /**
  2166. * 模块新闻加强plus版
  2167. * @param array $data
  2168. * @return array
  2169. */
  2170. public function getWebsiteAllArticle(array $data): array
  2171. {
  2172. // return Result::success($data);
  2173. $time1 = microtime(true);
  2174. $wetbsite_id = $data['website_id'] ?? 2;
  2175. $data = json_decode($data['id'], true);
  2176. $website = Website::where('id', $wetbsite_id)->first();
  2177. if (empty($website)) {
  2178. return Result::error("网站不存在", 0);
  2179. }
  2180. // return Result::success($website);
  2181. $website_column = $website['website_column_arr_id'] ?? '[]';
  2182. $website_column = json_decode($website_column, true);
  2183. $categorys = $this->processArticlePro($wetbsite_id);
  2184. $cat_1st_arr = $categorys['cat_1st_arr'];
  2185. $catiall = $categorys['catiall'];
  2186. // return Result::success($catiall);
  2187. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  2188. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2189. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2190. }
  2191. $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
  2192. // return Result::success($categorys);
  2193. $parent_category = array_column($data, 'parent');
  2194. $parent_cat = [];
  2195. $child_category = array_column($data, 'child');
  2196. if (!empty($parent_category)) {
  2197. foreach ($parent_category as $key => $value) {
  2198. $arr = array_map('intval', explode(',', $value));
  2199. $parent_cat[$key] = $arr[0] ?? 0;
  2200. $parent_category = $arr[0] ?? 0;
  2201. $article_imgnum = $arr[1] ?? 0;
  2202. $article_textnum = $arr[2] ?? 0;
  2203. if ($parent_category != 0) {
  2204. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2205. // return Result::success($category_arr);
  2206. if ($article_imgnum != 0) {
  2207. $img_article = Article::whereIn('catid', $category_arr)
  2208. ->where('status', 1)
  2209. ->where('imgurl', '!=', '')
  2210. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2211. $query->from('article_ignore')
  2212. ->where('website_id', $wetbsite_id);
  2213. }, 'article_ignore', function ($join) {
  2214. $join->on('article_ignore.article_id', '=', 'article.id');
  2215. })
  2216. ->where(function ($query) {
  2217. $query->whereNull('article_ignore.article_id')
  2218. ->orWhere(function ($subQuery) {
  2219. $subQuery->whereNotNull('article_ignore.article_id')
  2220. ->where('article_ignore.is_ignore', 0)
  2221. ->where(function ($subSubQuery) {
  2222. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2223. ->orWhereNull('article_ignore.c_show_time');
  2224. });
  2225. });
  2226. })
  2227. ->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')
  2228. ->orderBy('updated_at', 'desc')
  2229. ->limit($article_imgnum)
  2230. ->get()->all();
  2231. foreach ($img_article as $k => $v) {
  2232. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2233. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2234. }
  2235. } else {
  2236. $img_article = [];
  2237. }
  2238. if ($article_textnum != 0) {
  2239. $text_article = Article::whereIn('catid', $category_arr)
  2240. ->where('status', 1)
  2241. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2242. $query->from('article_ignore')
  2243. ->where('website_id', $wetbsite_id);
  2244. }, 'article_ignore', function ($join) {
  2245. $join->on('article_ignore.article_id', '=', 'article.id');
  2246. })
  2247. ->where(function ($query) {
  2248. $query->whereNull('article_ignore.article_id')
  2249. ->orWhere(function ($subQuery) {
  2250. $subQuery->whereNotNull('article_ignore.article_id')
  2251. ->where('article_ignore.is_ignore', 0)
  2252. ->where(function ($subSubQuery) {
  2253. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2254. ->orWhereNull('article_ignore.c_show_time');
  2255. });
  2256. });
  2257. })
  2258. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2259. ->orderBy('updated_at', 'desc')
  2260. ->limit($article_textnum)
  2261. ->get()->all();
  2262. foreach ($text_article as $k => $v) {
  2263. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2264. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2265. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2266. }
  2267. } else {
  2268. $text_article = [];
  2269. }
  2270. $catiall[$parent_category]['imgnum'] = $img_article;
  2271. $catiall[$parent_category]['textnum'] = $text_article;
  2272. $parent[$key] = $catiall[$parent_category];
  2273. } else {
  2274. $parent[$key] = '';
  2275. }
  2276. }
  2277. }
  2278. if (!empty($child_category)) {
  2279. foreach ($child_category as $key => $value) {
  2280. $arr = array_map('intval', explode(',', $value));
  2281. $parent_category = $parent_cat[$key];
  2282. $child_category = $arr[0] ?? 0;
  2283. $article_imgnum = $arr[1] ?? 0;
  2284. $article_textnum = $arr[2] ?? 0;
  2285. if ($child_category != 0) {
  2286. $all_childcat = $cat_1st_arr[$parent_category];
  2287. $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
  2288. // 从 $websiteInfoIndexed 中获取对应的数据
  2289. $info = $websiteInfoIndexed[$v];
  2290. // 返回一个包含所需信息的数组
  2291. return [
  2292. 'alias' => $info->alias,
  2293. 'category_id' => $info->category_id,
  2294. 'aLIas_pinyin' => $info->aLIas_pinyin,
  2295. 'pid' => $info->pid,
  2296. 'type' => $info->type,
  2297. 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
  2298. 'pinyin' => $info->pinyin,
  2299. ];
  2300. }, $all_childcat);
  2301. if ($article_imgnum != 0) {
  2302. $img_article = Article::where('catid', $child_category)
  2303. ->where('status', 1)
  2304. ->where('imgurl', '!=', '')
  2305. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2306. $query->from('article_ignore')
  2307. ->where('website_id', $wetbsite_id);
  2308. }, 'article_ignore', function ($join) {
  2309. $join->on('article_ignore.article_id', '=', 'article.id');
  2310. })
  2311. ->where(function ($query) {
  2312. $query->whereNull('article_ignore.article_id')
  2313. ->orWhere(function ($subQuery) {
  2314. $subQuery->whereNotNull('article_ignore.article_id')
  2315. ->where('article_ignore.is_ignore', 0)
  2316. ->where(function ($subSubQuery) {
  2317. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2318. ->orWhereNull('article_ignore.c_show_time');
  2319. });
  2320. });
  2321. })
  2322. ->select('id', 'title', 'imgurl', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2323. ->orderBy('updated_at', 'desc')
  2324. ->limit($article_imgnum)
  2325. ->get()->all();
  2326. foreach ($img_article as $k => $v) {
  2327. // var_dump($v);
  2328. // var_dump($k);
  2329. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2330. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2331. }
  2332. } else {
  2333. $img_article = [];
  2334. }
  2335. if ($article_textnum != 0) {
  2336. $text_article = Article::where('catid', $child_category)
  2337. ->where('status', 1)
  2338. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2339. $query->from('article_ignore')
  2340. ->where('website_id', $wetbsite_id);
  2341. }, 'article_ignore', function ($join) {
  2342. $join->on('article_ignore.article_id', '=', 'article.id');
  2343. })
  2344. ->where(function ($query) {
  2345. $query->whereNull('article_ignore.article_id')
  2346. ->orWhere(function ($subQuery) {
  2347. $subQuery->whereNotNull('article_ignore.article_id')
  2348. ->where('article_ignore.is_ignore', 0)
  2349. ->where(function ($subSubQuery) {
  2350. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2351. ->orWhereNull('article_ignore.c_show_time');
  2352. });
  2353. });
  2354. })
  2355. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2356. ->orderBy('updated_at', 'desc')
  2357. ->limit($article_textnum)
  2358. ->get()->all();
  2359. foreach ($text_article as $k => $v) {
  2360. // var_dump($v);
  2361. // var_dump($k);
  2362. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2363. // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2364. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2365. }
  2366. } else {
  2367. $text_article = [];
  2368. }
  2369. $catiall[$child_category]['all_childcat'] = $processedChildCat;
  2370. $catiall[$child_category]['imgnum'] = $img_article;
  2371. $catiall[$child_category]['textnum'] = $text_article;
  2372. $child[$key] = $catiall[$child_category];
  2373. // var_dump($pids);
  2374. } else {
  2375. $child[$key] = '';
  2376. }
  2377. }
  2378. }
  2379. foreach ($parent as $key => $value) {
  2380. $result[$key] = $value;
  2381. if (!empty($child[$key])) {
  2382. // var_dump($child[$key]);
  2383. $result[$key]['child'] = $child[$key];
  2384. // $value[$key]['child'] = $child[$key];
  2385. } else {
  2386. $result[$key]['child'] = [
  2387. "alias" => null,
  2388. "category_id" => null,
  2389. "type" => null,
  2390. "pinyin" => null,
  2391. "all_childcat" => [],
  2392. "imgnum" => [],
  2393. "textnum" => []
  2394. ];
  2395. }
  2396. }
  2397. return Result::success($result);
  2398. }
  2399. /**
  2400. * 辅助方法:获取文章列表
  2401. */
  2402. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  2403. {
  2404. sleep(1);
  2405. $query = Article::where('article.status', 1)
  2406. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  2407. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  2408. ->where(function ($query) use ($website) {
  2409. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  2410. })
  2411. ->leftJoin('website_category', function ($join) use ($website) {
  2412. $join->on('article.catid', '=', 'website_category.category_id')
  2413. ->where('website_category.website_id', '=', $website['website_id']);
  2414. })
  2415. ->select(
  2416. 'article.id',
  2417. 'article.title',
  2418. 'article.imgurl',
  2419. 'article.author',
  2420. 'article.updated_at',
  2421. 'article.introduce',
  2422. 'article.islink',
  2423. 'article.linkurl',
  2424. 'article.copyfrom',
  2425. 'article.cat_arr_id',
  2426. 'article.catid',
  2427. 'website_category.alias as category_name'
  2428. )
  2429. ->orderBy('updated_at', 'desc')
  2430. ->limit($limit);
  2431. // 如果是图片文章,添加图片URL条件
  2432. if ($isImageArticle) {
  2433. $query->where('imgurl', '!=', '');
  2434. } else {
  2435. // 文字文章不需要imgurl字段
  2436. $query->addSelect('article.introduce');
  2437. }
  2438. $articles = $query->get();
  2439. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  2440. }
  2441. /**
  2442. * 乡村网-获取特殊新闻模块
  2443. * @param array $data
  2444. * @return array
  2445. */
  2446. public function getWebsiteArticles(array $data): array
  2447. {
  2448. $website_id = $data['website_id'];
  2449. $website = Website::where('id', $website_id)->first();
  2450. if (empty($website)) {
  2451. return Result::error("网站不存在", 0);
  2452. }
  2453. // return Result::success($website);
  2454. $website_column = $website['website_column_arr_id'] ?? '[]';
  2455. $website_column = json_decode($website_column, true);
  2456. $catids = json_decode($data['id'], true);
  2457. $parent_category = array_column($catids, 'parent');
  2458. if (!empty($parent_category) && is_array($parent_category)) {
  2459. $categorys = $this->processArticlePro($website_id);
  2460. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  2461. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2462. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2463. }
  2464. $catiall = $categorys['catiall'];
  2465. $cat_1st_arr = $categorys['cat_1st_arr'];
  2466. // return Result::success($categorys);
  2467. foreach ($parent_category as $key => $value) {
  2468. $arr = array_map('intval', explode(',', $value));
  2469. $parent_category = $arr[0] ?? 0;
  2470. $article_imgnum = $arr[1] ?? 0;
  2471. $article_textnum = $arr[2] ?? 0;
  2472. if ($parent_category != 0) {
  2473. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2474. // return Result::success($category_arr);
  2475. if ($article_imgnum != 0) {
  2476. $img_article = Article::whereIn('article.catid', $category_arr)
  2477. ->where('article.status', 1)
  2478. ->where('article.imgurl', '!=', '')
  2479. ->leftJoinSub(function ($query) use ($website_id) {
  2480. $query->from('article_ignore')
  2481. ->where('website_id', $website_id);
  2482. }, 'article_ignore', function ($join) {
  2483. $join->on('article_ignore.article_id', '=', 'article.id');
  2484. })
  2485. ->where(function ($query) {
  2486. $query->whereNull('article_ignore.article_id')
  2487. ->orWhere(function ($subQuery) {
  2488. $subQuery->whereNotNull('article_ignore.article_id')
  2489. ->where('article_ignore.is_ignore', 0)
  2490. ->where(function ($subSubQuery) {
  2491. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2492. ->orWhereNull('article_ignore.c_show_time');
  2493. });
  2494. });
  2495. })
  2496. ->select(
  2497. 'article.id',
  2498. 'article.title',
  2499. 'article.imgurl',
  2500. 'article.author',
  2501. 'article.updated_at',
  2502. 'article.introduce',
  2503. 'article.islink',
  2504. 'article.linkurl',
  2505. 'article.copyfrom',
  2506. 'article.cat_arr_id',
  2507. 'article.catid as category_id'
  2508. )
  2509. ->orderBy('updated_at', 'desc')
  2510. ->limit($article_imgnum)
  2511. ->get()->all();
  2512. foreach ($img_article as $k => $v) {
  2513. $img_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2514. // return Result::success($v);
  2515. $img_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2516. }
  2517. } else {
  2518. $img_article = [];
  2519. }
  2520. if ($article_textnum != 0) {
  2521. $text_article = Article::whereIn('article.catid', $category_arr)
  2522. ->where('article.status', 1)
  2523. ->leftJoinSub(function ($query) use ($website_id) {
  2524. $query->from('article_ignore')
  2525. ->where('website_id', $website_id);
  2526. }, 'article_ignore', function ($join) {
  2527. $join->on('article_ignore.article_id', '=', 'article.id');
  2528. })
  2529. ->where(function ($query) {
  2530. $query->whereNull('article_ignore.article_id')
  2531. ->orWhere(function ($subQuery) {
  2532. $subQuery->whereNotNull('article_ignore.article_id')
  2533. ->where('article_ignore.is_ignore', 0)
  2534. ->where(function ($subSubQuery) {
  2535. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2536. ->orWhereNull('article_ignore.c_show_time');
  2537. });
  2538. });
  2539. })
  2540. ->select(
  2541. 'article.id',
  2542. 'article.title',
  2543. 'article.author',
  2544. 'article.updated_at',
  2545. 'article.introduce',
  2546. 'article.islink',
  2547. 'article.linkurl',
  2548. 'article.copyfrom',
  2549. 'article.cat_arr_id',
  2550. 'article.catid as category_id'
  2551. )
  2552. ->orderBy('updated_at', 'desc')
  2553. ->limit($article_textnum)
  2554. ->get()->all();
  2555. foreach ($text_article as $k => $v) {
  2556. $text_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2557. $text_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2558. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2559. }
  2560. } else {
  2561. $text_article = [];
  2562. }
  2563. $catiall[$parent_category]['imgnum'] = $img_article ?? [];
  2564. $catiall[$parent_category]['textnum'] = $text_article ?? [];
  2565. $parent[$key] = $catiall[$parent_category];
  2566. } else {
  2567. $parent[$key] = [];
  2568. }
  2569. }
  2570. }
  2571. return Result::success($parent);
  2572. }
  2573. // 封装处理商品的路由问题
  2574. function processGoods($goods, $data)
  2575. {
  2576. return $goods->map(function ($good) use ($data) {
  2577. $catid = $good->catid ?? 0;
  2578. // $pinyin = '';
  2579. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2580. if (!empty($category->pid) && $category->pid != 0) {
  2581. $level = json_decode($category->category_arr_id, true);
  2582. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  2583. ->whereIn('category_id', $level)
  2584. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2585. ->get(['aLIas_pinyin'])
  2586. ->pluck('aLIas_pinyin')
  2587. ->implode('/');
  2588. } else {
  2589. $pinyin = $category->aLIas_pinyin ?? '';
  2590. }
  2591. if (isset($good->city_id) && !empty($good->city_id)) {
  2592. $city = District::where('id', $good->city_id)->first(['name']);
  2593. $good->city_name = $city->name ?? '';
  2594. }
  2595. // 解析imgurl JSON并取第一条数据
  2596. $imgUrls = json_decode($good->imgurl, true);
  2597. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  2598. $good->pinyin = $pinyin;
  2599. return $good;
  2600. });
  2601. }
  2602. /**
  2603. * 获取商城首页-根据栏目id
  2604. * @param array $data
  2605. * @return array
  2606. * */
  2607. function getWebsiteCatidshop(array $data): array
  2608. {
  2609. $input['catid'] = $data['catid'];
  2610. $input['website_id'] = $data['website_id'];
  2611. $data = json_decode($input['catid'] ?? '', true) ?? [];
  2612. $result = array_map(function ($item) use ($input) {
  2613. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  2614. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  2615. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  2616. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  2617. if (empty($category) || $category->type != 2) {
  2618. return Result::error("暂无此栏目", 0);
  2619. } else {
  2620. $website['website_id'] = $input['website_id'];
  2621. $goods = Good::where('good.status', 2)
  2622. ->where('good.website_id', $website['website_id'])
  2623. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  2624. ->select(
  2625. 'good.id',
  2626. 'good.name',
  2627. 'good.imgurl',
  2628. 'good.description',
  2629. 'good.updated_at',
  2630. 'good.catid',
  2631. 'good.type_id',
  2632. 'good.price',
  2633. 'good.com',
  2634. 'good.level',
  2635. 'good.unit'
  2636. )
  2637. ->orderBy('updated_at', 'desc')
  2638. ->offset($goodStart)
  2639. ->limit($goodNum);
  2640. $all_goods = $goods->get();
  2641. $all_goods = $this->processGoods($all_goods, $website);
  2642. }
  2643. return $all_goods ?? [];
  2644. }
  2645. }, $data);
  2646. return Result::success($result);
  2647. }
  2648. /**
  2649. * 获取商品模块
  2650. * @param array $data
  2651. * @return array
  2652. * */
  2653. public function getWebsiteshop(array $data): array
  2654. {
  2655. $input['id'] = $data['id'];
  2656. $input['website_id'] = $data['website_id'];
  2657. $catid = $data['catid'];
  2658. $data = json_decode($input['id'] ?? '', true) ?? [];
  2659. $result['goods'] = array_map(function ($item) use ($input) {
  2660. // 检查parent元素是否存在且不是undefined
  2661. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  2662. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  2663. $website = $input['website_id'];
  2664. $query = Good::where('good.status', 2)
  2665. ->where('good.website_id', $website);
  2666. switch ($Levelid) {
  2667. case 1:
  2668. case 2:
  2669. case 3:
  2670. $goods = $query->where(function ($q) use ($Levelid) {
  2671. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  2672. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  2673. });
  2674. break;
  2675. case 4:
  2676. $goods = $query;
  2677. break;
  2678. case 5:
  2679. $goods = $query->where('type_id', 1);
  2680. break;
  2681. case 6:
  2682. $goods = $query->where('type_id', 2);
  2683. break;
  2684. default:
  2685. return [];
  2686. }
  2687. $all_goods = $goods
  2688. ->select(
  2689. 'good.id',
  2690. 'good.name',
  2691. 'good.imgurl',
  2692. 'good.description',
  2693. 'good.updated_at',
  2694. 'good.catid',
  2695. 'good.type_id',
  2696. 'good.price',
  2697. 'good.level',
  2698. 'good.website_id'
  2699. )
  2700. ->orderBy('updated_at', 'desc')
  2701. ->offset($goodStart)
  2702. ->limit($goodNum)
  2703. ->get();
  2704. $web['website_id'] = $website;
  2705. $all_goods = $this->processGoods($all_goods, $web);
  2706. }
  2707. return $all_goods;
  2708. }, $data);
  2709. $website = $input['website_id'];
  2710. $result['article'] = Article::where(function ($query) use ($website) {
  2711. $query->where(function ($subQuery) use ($website) {
  2712. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  2713. })->orWhereNull("ignore_ids");
  2714. })
  2715. ->where('catid', $catid)
  2716. ->where('article.status', 1)
  2717. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  2718. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  2719. ->orderBy('article.updated_at', 'desc')
  2720. ->first();
  2721. return Result::success($result);
  2722. }
  2723. /**
  2724. * 获取商品分类
  2725. * @param array $data
  2726. * @return array
  2727. * */
  2728. public function getWebsiteshopCat(array $data): array
  2729. {
  2730. $website = $data['website_id'];
  2731. $category = WebsiteCategory::where('website_id', $website)
  2732. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  2733. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  2734. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  2735. ->orderBy('sort')
  2736. ->get();
  2737. $cat = $category->map(function ($item) use ($website) {
  2738. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  2739. $pid = $item->pid ?? 0;
  2740. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  2741. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  2742. ->where('website_id', $website)
  2743. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  2744. ->get(['aLIas_pinyin'])
  2745. ->pluck('aLIas_pinyin')
  2746. ->implode('/');
  2747. } else {
  2748. $pinyin = $item->aLIas_pinyin ?? '';
  2749. }
  2750. $item->pinyin = $pinyin;
  2751. });
  2752. if (empty($category)) {
  2753. return Result::error("栏目查询失败", 0);
  2754. }
  2755. $cat_tree = Result::buildMenuTree($category);
  2756. $web['website_id'] = $website;
  2757. $goods = Good::where('website_id', $website)
  2758. ->where('status', 2)
  2759. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  2760. ->latest('updated_at')
  2761. ->offset(($data['page'] - 1) * $data['pageSize'])
  2762. ->limit($data['pageSize'])
  2763. ->get();
  2764. if (!empty($goods)) {
  2765. if ($goods->count() > 1 && !empty($goods)) {
  2766. $goods = $this->processGoods($goods, $web);
  2767. }
  2768. } else {
  2769. $goods = [];
  2770. }
  2771. $result = [
  2772. 'category' => $cat_tree,
  2773. 'goods' => $goods,
  2774. ];
  2775. // $resul['goods'] = $goods;
  2776. if (empty($result)) {
  2777. return Result::error("查询失败", 0);
  2778. }
  2779. return Result::success($result);
  2780. }
  2781. /*
  2782. * 获取商品列表
  2783. * @param array $data
  2784. * @return array
  2785. * */
  2786. public function getWebsiteshopList(array $data): array
  2787. {
  2788. // return Result::success($data);
  2789. $where = [
  2790. 'status' => 2,
  2791. 'website_id' => $data['website_id'],
  2792. ];
  2793. // if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  2794. // return Result::error("查询失败", 0);
  2795. // }
  2796. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  2797. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  2798. $data['catid'] = $category->category_id ?? 0;
  2799. }
  2800. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2801. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  2802. }
  2803. if (isset($data['type_id']) && !empty($data['type_id'])) {
  2804. array_push($where, ['type_id', $data['type_id']]);
  2805. }
  2806. $query = Good::where($where)
  2807. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2808. $query->where(function ($q) use ($data) {
  2809. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  2810. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  2811. });
  2812. })
  2813. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2814. $query->where(function ($q) use ($data) {
  2815. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  2816. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  2817. });
  2818. })
  2819. ->select(
  2820. 'good.id',
  2821. 'good.name',
  2822. 'good.imgurl',
  2823. 'good.description',
  2824. 'good.updated_at',
  2825. 'good.com',
  2826. 'good.catid',
  2827. 'good.type_id',
  2828. 'good.website_id',
  2829. 'good.cat_arr_id',
  2830. 'good.created_at',
  2831. 'good.city_id'
  2832. )
  2833. ->latest('updated_at');
  2834. if (isset($data['ismix']) && $data['ismix'] == 1) {
  2835. $result['count'] = $query->clone()->count();
  2836. $result['goods'] = $this->processGoods(
  2837. $query->clone()
  2838. ->offset(($data['page'] - 1) * $data['pageSize'])
  2839. ->limit($data['pageSize'])
  2840. ->get(),
  2841. $data
  2842. );
  2843. } else {
  2844. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  2845. // 获取 type_id 为 1 的数据
  2846. $result['type1'] = $this->processGoods(
  2847. $query->clone()
  2848. ->where('type_id', 1)
  2849. ->offset(($data['page'] - 1) * $data['pageSize'])
  2850. ->limit($data['pageSize'])
  2851. ->get(),
  2852. $data
  2853. );
  2854. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2855. // 获取 type_id 为 2 的数据
  2856. $result['type2'] = $this->processGoods(
  2857. $query->clone()
  2858. ->where('type_id', 2)
  2859. ->offset(($data['page'] - 1) * $data['pageSize'])
  2860. ->limit($data['pageSize'])
  2861. ->get(),
  2862. $data
  2863. );
  2864. }
  2865. if (empty($result)) {
  2866. return Result::error("查询失败", 0);
  2867. }
  2868. return Result::success($result);
  2869. }
  2870. /**
  2871. * 获取商品详情
  2872. * @param array $data
  2873. * @return array
  2874. * */
  2875. public function getWebsiteshopInfo(array $data): array
  2876. {
  2877. $where = [
  2878. 'good.status' => 2,
  2879. 'good.website_id' => $data['website_id'],
  2880. 'good.id' => $data['id'],
  2881. ];
  2882. $goods = Good::where($where)
  2883. ->where('good.id', $data['id'])
  2884. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2885. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2886. ->first();
  2887. if (empty($goods)) {
  2888. return Result::error("查询失败", 0);
  2889. }
  2890. $goods->imgurl = json_decode($goods->imgurl, true);
  2891. return Result::success($goods);
  2892. }
  2893. /**
  2894. * plus pro 处理文章路由问题
  2895. */
  2896. function processArticlePro($website_id)
  2897. {
  2898. // $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2899. // // $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2900. // // 取出category_id 对应的aLIas_pinyin
  2901. // $categoryIds = array_column($categorys, 'category_id');
  2902. // $categoryPIds = array_column($categorys, 'pid');
  2903. // $aliasPinyins = array_column($categorys, 'path');
  2904. // $alias = array_column($categorys, 'alias');
  2905. // $cat_arr = array_combine($categoryIds, $aliasPinyins);
  2906. // $cat_alias_arr = array_combine($categoryIds, $categoryPIds);
  2907. // // return Result::success($cat_arr);
  2908. // // $catiall = [];
  2909. // //一级所有子级的记录
  2910. // $cat_alias_arr = array_combine($categoryIds, $alias);
  2911. // return [
  2912. // 'cat_1st_arr' => $cat_alias_arr,
  2913. // 'catiall' => $cat_arr,
  2914. // // 'websiteInfoIndexed' => $websiteInfoIndexed,
  2915. // 'categoryIds' => $categoryIds,
  2916. // ];
  2917. $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2918. $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2919. // 取出category_id 对应的aLIas_pinyin
  2920. $categoryIds = array_column($categorys, 'category_id');
  2921. $categoryPIds = array_values(array_unique(array_filter(array_column($categorys, 'pid'), function ($pid) {
  2922. return $pid != 0;
  2923. })));
  2924. $category_path = array_column($categorys, 'path');
  2925. $cat_arr = array_combine($categoryIds, $category_path);
  2926. // return Result::success(array_diff($categoryIds, $categoryPIds));
  2927. $catiall = [];
  2928. //一级所有子级的记录
  2929. $cat_1st_arr = [];
  2930. foreach ($categorys as $key => $value) {
  2931. // $category_arr_id = json_decode($value->category_arr_id);
  2932. // $pinyin_str = '';
  2933. // // 算出一级 并且算出子级
  2934. if ($value->pid != 0 && in_array($value->pid, $categoryIds)) {
  2935. $cat_1st_arr[$value->pid][] = $value->category_id;
  2936. }
  2937. // foreach ($category_arr_id as $k => $v) {
  2938. // $pinyin_str .= $cat_arr[$v] . '/';
  2939. // }
  2940. // $pinyin_str = rtrim($pinyin_str, '/');
  2941. $catiall[$value->category_id]['alias'] = $value->alias;
  2942. $catiall[$value->category_id]['category_id'] = $value->category_id;
  2943. $catiall[$value->category_id]['type'] = $value->type;
  2944. $catiall[$value->category_id]['pinyin'] = $cat_arr[$value->category_id];
  2945. $websiteInfoIndexed[$value->category_id]->pinyin = $cat_arr[$value->category_id];
  2946. }
  2947. return [
  2948. 'cat_1st_arr' => $cat_1st_arr,
  2949. 'catiall' => $catiall,
  2950. 'websiteInfoIndexed' => $websiteInfoIndexed,
  2951. 'categoryIds' => $categoryIds,
  2952. 'diff_pid_categoryIds' => array_diff($categoryPIds, $categoryIds),
  2953. 'categoryPIds' => $categoryPIds,
  2954. ];
  2955. }
  2956. /**
  2957. * 封装处理文章的路由问题
  2958. * */
  2959. function processArticles($articles, $data)
  2960. {
  2961. // 检查 $articles 是否为数组或可迭代对象
  2962. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  2963. return $articles->map(function ($article) use ($data) {
  2964. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  2965. $catid = $article->cat_arr_id ?? '';
  2966. }
  2967. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  2968. $catid = $article->category_arr_id ?? '';
  2969. }
  2970. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  2971. $level = json_decode($catid, true);
  2972. if (!is_array($level)) {
  2973. return $article;
  2974. } else {
  2975. $level = array_map('intval', $level);
  2976. }
  2977. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2978. ->where($data)
  2979. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2980. ->pluck('aLIas_pinyin')
  2981. ->implode('/');
  2982. $article->pinyin = $pinyin ?? '';
  2983. return $article;
  2984. });
  2985. } else {
  2986. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2987. $catid = $articles->cat_arr_id ?? '';
  2988. $level = json_decode($catid, true);
  2989. if (!is_array($level)) {
  2990. return $articles;
  2991. } else {
  2992. $level = array_map('intval', $level);
  2993. }
  2994. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2995. ->where($data)
  2996. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2997. ->pluck('aLIas_pinyin')
  2998. ->implode('/');
  2999. $articles->pinyin = $pinyin ?? '';
  3000. return $articles;
  3001. }
  3002. }
  3003. // 封装处理由问题
  3004. function processJob($job, $data)
  3005. {
  3006. return $job->map(function ($job) use ($data) {
  3007. $category = $job->cat_arr_id ?? '';
  3008. $cityid = $job->city_arr_id ?? '';
  3009. $city = json_decode($cityid, true);
  3010. $pinyin = '';
  3011. $level = json_decode($category, true);
  3012. // 路由
  3013. if (!empty($level) && is_array($level)) {
  3014. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  3015. ->where('website_id', $data['website_id']) // 添加网站ID条件
  3016. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  3017. ->get(['aLIas_pinyin'])
  3018. ->pluck('aLIas_pinyin')
  3019. ->implode('/');
  3020. if (empty($pinyin)) {
  3021. $pinyin = $pinyin->aLIas_pinyin ?? '';
  3022. }
  3023. $job->pinyin = $pinyin;
  3024. }
  3025. // 取职位-城市 市??省
  3026. if (!empty($city) && is_array($city)) {
  3027. if (isset($city[1]) && !empty($city[1])) {
  3028. $city = District::where('id', $city[1])->first(['name']);
  3029. $job->city_name = $city->name ?? '';
  3030. } else if (isset($city[0]) && !empty($city[0])) {
  3031. $city = District::where('id', $city[0])->first(['name']);
  3032. $job->city_name = $city->name ?? '';
  3033. } else {
  3034. $job->city_name = '全国';
  3035. }
  3036. }
  3037. // 获取简历最后一级地区
  3038. if (isset($job->city_id) && !empty($job->city_id)) {
  3039. $city = District::where('id', $job->city_id)->first(['name']);
  3040. $job->hunt_cityname = $city->name ?? '';
  3041. }
  3042. // 组合详细地址
  3043. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  3044. $address_id = json_decode($job->address_arr_id, true) ?? [];
  3045. if (is_array($address_id) && !empty($address_id)) {
  3046. $address = District::whereIn('id', $address_id)
  3047. ->orderBy('level', 'asc')
  3048. ->get(['name'])
  3049. ->pluck('name')
  3050. ->implode('');
  3051. // $job->address_name = $address ?? '';
  3052. $job->address_name = ($address ?? '') . ($job->address ?? '');
  3053. }
  3054. }
  3055. // 取行业
  3056. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  3057. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  3058. if (!empty($job->industry)) {
  3059. $query->where('hyid', $job->industry);
  3060. } else if (!empty($job->hy_id)) {
  3061. $query->where('hyid', $job->hy_id);
  3062. } else if (!empty($job->company_hy_id)) {
  3063. $query->where('hyid', $job->company_hy_id);
  3064. } else {
  3065. $query->where('hyid', $job->job_industry);
  3066. }
  3067. })->first(['hyname']);
  3068. $job->hy_name = $hy_name->hyname ?? '';
  3069. }
  3070. // 取职位类别
  3071. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  3072. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  3073. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  3074. $job->zw_name = $zw_name->zwname ?? '';
  3075. }
  3076. // 取具体职位
  3077. 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))) {
  3078. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  3079. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  3080. $job->jtzw_name = $jtzw_name->zwname ?? '';
  3081. }
  3082. // 取工作经验
  3083. if (isset($job->experience) && !empty($job->experience)) {
  3084. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  3085. $job->experience_name = $experience->ename ?? '';
  3086. }
  3087. // 取学历
  3088. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  3089. $education = $job->educational ?? $job->school_education;
  3090. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  3091. $job->education_name = $education->ename ?? '';
  3092. }
  3093. // 语言
  3094. if (isset($job->language) && !empty($job->language)) {
  3095. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  3096. $job->language_name = $language->ename ?? '';
  3097. }
  3098. // 薪资
  3099. if (isset($job->salary) && !empty($job->salary)) {
  3100. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  3101. $job->salary_name = $salary->ename ?? '';
  3102. }
  3103. // 职位性质
  3104. if (isset($job->nature_id) && !empty($job->nature_id)) {
  3105. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  3106. $job->job_nature_name = $job_nature->ename ?? '';
  3107. }
  3108. // 公司规模
  3109. if (isset($job->company_size) && !empty($job->company_size)) {
  3110. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  3111. $job->company_size_name = $company_size->ename ?? '';
  3112. }
  3113. // 公司性质
  3114. if (isset($job->company_nature) && !empty($job->company_nature)) {
  3115. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  3116. $job->company_nature_name = $company_nature->nature_name ?? '';
  3117. }
  3118. // $job->pinyin = $pinyin;
  3119. return $job;
  3120. });
  3121. }
  3122. /**
  3123. * 获取书籍模块
  3124. * @param array $data
  3125. * @return array
  3126. * */
  3127. public function getWebsiteBook(array $data): array
  3128. {
  3129. $input['id'] = $data['id'];
  3130. $input['website_id'] = $data['website_id'];
  3131. // 将 JSON 字符串转换为 PHP 数组
  3132. $data = json_decode($input['id'], true);
  3133. // 使用 array_map 处理每个元素
  3134. $result = array_map(function ($item) use ($input) {
  3135. // 检查parent元素是否存在且不是undefined
  3136. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  3137. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  3138. $website = [
  3139. 'website_id' => $input['website_id'],
  3140. ];
  3141. // 查询栏目名称
  3142. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  3143. if (empty($category)) {
  3144. $parent_alias = '';
  3145. $parent_pinyin = null;
  3146. $imgBooks = [];
  3147. $textBooks = [];
  3148. } else {
  3149. $parent_alias = $category->alias ?? '';
  3150. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  3151. // 查找子分类ID数组
  3152. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  3153. array_push($childCategoryIds, $parentCatId);
  3154. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  3155. if ($parentImgNum != 0) {
  3156. // 查询图片新闻
  3157. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  3158. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  3159. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  3160. })
  3161. ->where('book.status', 2)
  3162. ->where('book.img_url', '!=', '')
  3163. ->where('book.website_id', $website['website_id'])
  3164. ->leftJoin('website_category', function ($join) use ($website) {
  3165. $join->on('book.cat_id', '=', 'website_category.category_id')
  3166. ->where('website_category.website_id', '=', $website['website_id']);
  3167. })
  3168. ->select(
  3169. 'book.id',
  3170. 'book.title',
  3171. 'book.img_url',
  3172. 'book.price',
  3173. 'book.market_price',
  3174. 'book.description',
  3175. 'book.cat_id',
  3176. 'book.description',
  3177. 'book.updated_at',
  3178. 'website_category.alias as category_name',
  3179. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3180. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3181. )
  3182. ->orderBy('updated_at', 'desc')
  3183. ->limit($parentImgNum)
  3184. ->get()->all();
  3185. // 查询文字新闻
  3186. }
  3187. if ($parentTextNum != 0) {
  3188. $textBooks = [];
  3189. $textBooks = Book::where(function ($query) use ($parentCatId) {
  3190. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  3191. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  3192. })
  3193. ->where('book.status', 2)
  3194. ->where('book.website_id', $website['website_id'])
  3195. ->leftJoin('website_category', function ($join) use ($website) {
  3196. $join->on('book.cat_id', '=', 'website_category.category_id')
  3197. ->where('website_category.website_id', '=', $website['website_id']);
  3198. })
  3199. ->select(
  3200. 'book.id',
  3201. 'book.title',
  3202. 'book.img_url',
  3203. 'book.price',
  3204. 'book.market_price',
  3205. 'book.description',
  3206. 'book.cat_id',
  3207. 'book.description',
  3208. 'book.updated_at',
  3209. 'website_category.alias as category_name',
  3210. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3211. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3212. )
  3213. ->orderBy('updated_at', 'desc')
  3214. ->limit($parentTextNum)
  3215. ->get()->all();
  3216. }
  3217. }
  3218. }
  3219. $resultItem = [
  3220. 'alias' => $parent_alias ?? '',
  3221. 'category_id' => $parentCatId ?? 0,
  3222. 'pinyin' => $parent_pinyin ?? null,
  3223. 'imgnum' => $imgBooks ?? [],
  3224. 'textnum' => $textBooks ?? [],
  3225. ];
  3226. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  3227. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  3228. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  3229. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3230. ->get()->all();
  3231. if (!empty($childCategory)) {
  3232. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  3233. // 查询子栏目名称
  3234. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  3235. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3236. ->first();
  3237. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  3238. $childImgArticles = [];
  3239. $childTextArticles = [];
  3240. $resultItem['child'] = [];
  3241. } else {
  3242. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  3243. // 查询子栏目图片新闻
  3244. $childImgArticles = Book::where('cat_id', $childCatId)
  3245. ->where('status', 2)
  3246. ->where('img_url', '!=', '')
  3247. ->where('book.website_id', $website['website_id'])
  3248. ->leftJoin('website_category', function ($join) use ($website) {
  3249. $join->on('book.cat_id', '=', 'website_category.category_id')
  3250. ->where('website_category.website_id', '=', $website['website_id']);
  3251. })
  3252. ->select(
  3253. 'book.id',
  3254. 'book.title',
  3255. 'book.img_url',
  3256. 'book.price',
  3257. 'book.market_price',
  3258. 'book.description',
  3259. 'book.cat_id',
  3260. 'book.description',
  3261. 'book.updated_at',
  3262. DB::raw("'$child_pinyin' as pinyin")
  3263. )
  3264. ->orderBy('updated_at', 'desc')
  3265. ->limit($childImgNum)
  3266. ->get()->all();
  3267. // 查询子栏目文字新闻
  3268. $childTextArticles = Book::where('cat_id', $childCatId)
  3269. ->where('status', 2)
  3270. ->where('book.website_id', $website['website_id'])
  3271. ->leftJoin('website_category', function ($join) use ($website) {
  3272. $join->on('book.cat_id', '=', 'website_category.category_id')
  3273. ->where('website_category.website_id', '=', $website['website_id']);
  3274. })
  3275. ->select(
  3276. 'book.id',
  3277. 'book.title',
  3278. 'book.img_url',
  3279. 'book.price',
  3280. 'book.market_price',
  3281. 'book.description',
  3282. 'book.cat_id',
  3283. 'book.description',
  3284. 'book.updated_at',
  3285. DB::raw("'$child_pinyin' as pinyin")
  3286. )
  3287. ->orderBy('updated_at', 'desc')
  3288. ->limit($childTextNum)
  3289. ->get()->all();
  3290. $resultItem['child'] = [
  3291. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  3292. 'category_id' => $childCatId,
  3293. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  3294. 'all_childcat' => $childCategory,
  3295. 'imgnum' => $childImgArticles,
  3296. 'textnum' => $childTextArticles,
  3297. ];
  3298. }
  3299. }
  3300. } else {
  3301. $resultItem['child'] = [];
  3302. }
  3303. return $resultItem;
  3304. }, $data);
  3305. return Result::success($result);
  3306. }
  3307. /**
  3308. * 获取书刊列表
  3309. * @param array $data
  3310. * @return array
  3311. * */
  3312. public function getWebsiteBookList(array $data): array
  3313. {
  3314. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3315. if (empty($web)) {
  3316. return Result::error("查询失败", 0);
  3317. }
  3318. $catid = $data['id'];
  3319. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  3320. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  3321. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  3322. $category_pinyin = $category ? $category->aLias_pinyin : '';
  3323. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  3324. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  3325. ->where('pid', $category['pid'])
  3326. ->select(
  3327. 'category_id',
  3328. 'alias',
  3329. 'aLIas_pinyin',
  3330. 'pid',
  3331. 'sort',
  3332. 'is_url',
  3333. 'web_url',
  3334. 'seo_title',
  3335. 'seo_keywords',
  3336. 'seo_description',
  3337. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  3338. )
  3339. ->orderBy('sort')
  3340. ->get()->all();
  3341. if (empty($category)) {
  3342. return Result::error("查询失败", 0);
  3343. }
  3344. $query = Book::where('book.status', 2)
  3345. ->where('book.website_id', $data['website_id'])
  3346. ->where('book.cat_id', $catid)
  3347. ->select(
  3348. 'book.id',
  3349. 'book.title',
  3350. 'book.img_url',
  3351. 'book.description',
  3352. 'book.updated_at',
  3353. 'book.cat_id',
  3354. DB::raw("'$pinyin' as pinyin")
  3355. )
  3356. ->orderBy('book.updated_at', 'desc');
  3357. $count = $query->count();
  3358. $query = clone $query;
  3359. $Book = $query
  3360. ->limit($data['pageSize'])
  3361. ->offset(($data['page'] - 1) * $data['pageSize'])
  3362. ->get()->all();
  3363. $result = [
  3364. 'category' => $categorys,
  3365. 'books' => $Book,
  3366. 'count' => $count,
  3367. ];
  3368. // if(empty($result)){
  3369. // return Result::error("查询失败", 0);
  3370. // }
  3371. return Result::success($result);
  3372. }
  3373. /**
  3374. * 获取书刊详情
  3375. * @param array $data
  3376. * @return array
  3377. * */
  3378. public function getWebsiteBookInfo(array $data): array
  3379. {
  3380. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3381. if (empty($web)) {
  3382. return Result::error("查询失败", 0);
  3383. }
  3384. $book = Book::where('status', 2)
  3385. ->where('website_id', $data['website_id'])
  3386. ->where('id', $data['id'])
  3387. ->select(
  3388. 'book.*',
  3389. )
  3390. ->orderBy('updated_at', 'desc')
  3391. ->first();
  3392. if (empty($book)) {
  3393. return Result::error("查询失败", 0);
  3394. }
  3395. // 先查询当前分类的 pid
  3396. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  3397. ->where('category_id', $book['cat_id'])
  3398. ->first(['pid', 'category_id']);
  3399. $query = WebsiteCategory::where('website_id', $data['website_id']);
  3400. if (!empty($carpid)) {
  3401. if ($carpid->pid != 0) {
  3402. $pid = $carpid['pid'];
  3403. // $parent_pinyin = '';
  3404. } else {
  3405. $pid = $carpid['category_id'];
  3406. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  3407. }
  3408. }
  3409. $categorys = $query->where('pid', $pid)
  3410. ->select(
  3411. 'category_id',
  3412. 'alias',
  3413. 'aLIas_pinyin',
  3414. 'pid',
  3415. 'sort',
  3416. 'is_url',
  3417. 'web_url',
  3418. 'category_arr_id as cat_arr_id',
  3419. )
  3420. ->orderBy('sort')
  3421. ->get();
  3422. $category = $this->processArticle($categorys, $data);
  3423. $result = [
  3424. 'category' => $category,
  3425. 'books' => $book,
  3426. ];
  3427. return Result::success($result);
  3428. }
  3429. /**
  3430. * 尝试
  3431. * @param array $data
  3432. * @return array
  3433. * */
  3434. public function test(array $data): array
  3435. {
  3436. $input['id'] = $data['id'];
  3437. $input['website_id'] = $data['website_id'];
  3438. // 将 JSON 字符串转换为 PHP 数组
  3439. $data = json_decode($input['id'], true);
  3440. $result = [];
  3441. $article = $data;
  3442. $result = array_map(function ($item) use ($input) {
  3443. $website = [
  3444. 'website_id' => $input['website_id'],
  3445. ];
  3446. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  3447. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  3448. $parent = [
  3449. 0 => $category['category_id'] ?? [],
  3450. 1 => $parentImgNum ?? [],
  3451. 2 => $parentTextNum ?? [],
  3452. ];
  3453. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  3454. $child = [];
  3455. $resultItem = [
  3456. // 'alias' => $parent_alias ?? '',
  3457. 'category_id' => $parentCatId ?? 0,
  3458. 'pinyin' => $parentImgNum ?? null,
  3459. 'imgnum' => $parentTextNum ?? [],
  3460. // 'textnum' => $textArticles ?? [],
  3461. ];
  3462. return $parent;
  3463. }, $data);
  3464. return Result::success($result);
  3465. // });
  3466. }
  3467. /**
  3468. * 封装处理文章的路由问题
  3469. * */
  3470. function processArticle($article, $data)
  3471. {
  3472. return $article->map(function ($article) use ($data) {
  3473. $catid = $article->cat_arr_id ?? '';
  3474. $level = json_decode($catid, true);
  3475. $pinyin = '';
  3476. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  3477. if (!empty($level) && is_array($level)) {
  3478. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  3479. ->where('website_id', $data['website_id'])
  3480. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  3481. ->get(['aLIas_pinyin'])
  3482. ->pluck('aLIas_pinyin')
  3483. ->implode('/');
  3484. } else {
  3485. $pinyin = '';
  3486. }
  3487. $article->pinyin = $pinyin;
  3488. return $article;
  3489. });
  3490. }
  3491. /**
  3492. * c端-获取招工招聘下拉选框
  3493. * @param array $data
  3494. * @return array
  3495. * */
  3496. public function getWebsiteJobSelect(array $data): array
  3497. {
  3498. $web = Website::where('id', $data['website_id'])->first();
  3499. if (empty($web)) {
  3500. return Result::error("该网站不存在", 0);
  3501. }
  3502. $hy = JobIndustry::get()->all();
  3503. $zw = JobPosition::where('zwpid', 0)->get()->all();
  3504. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  3505. $result = [
  3506. 'hy' => $hy,
  3507. 'zw' => $zw,
  3508. 'jtzw' => $jtzw,
  3509. ];
  3510. if (empty($result)) {
  3511. return Result::error("查询失败", 0);
  3512. }
  3513. return Result::success($result);
  3514. }
  3515. /**
  3516. * c端-获取招工招聘
  3517. * @param array $data
  3518. * @return array
  3519. * */
  3520. public function getWebsiteJob(array $data): array
  3521. {
  3522. $web = Website::where('id', $data['website_id'])->first();
  3523. if (empty($web)) {
  3524. return Result::error("该网站不存在", 0);
  3525. }
  3526. $job_hunting = JobHunting::where('job_hunting.status', 2)
  3527. ->where('job_hunting.website_id', $data['website_id'])
  3528. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3529. $query->where(function ($q) use ($data) {
  3530. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3531. });
  3532. })
  3533. ->select(
  3534. 'job_hunting.id',
  3535. 'job_hunting.catid',
  3536. 'job_hunting.cat_arr_id',
  3537. 'job_hunting.job_name_get',
  3538. 'job_hunting.industry',
  3539. 'job_hunting.name',
  3540. 'job_hunting.sexy',
  3541. 'job_hunting.origin',
  3542. 'job_hunting.city_arr_id',
  3543. 'job_hunting.experience',
  3544. 'job_hunting.updated_at',
  3545. 'job_hunting.salary',
  3546. 'job_hunting.skillList',
  3547. 'job_hunting.slelf_evaluation',
  3548. )
  3549. ->orderBy('updated_at', 'desc')
  3550. ->limit($data['job1_num'])
  3551. ->get();
  3552. $web['website_id'] = $data['website_id'];
  3553. if (empty($job_hunting)) {
  3554. $job_huntings = "未查询到相关简历信息";
  3555. } else {
  3556. $job_huntings = $this->processJob($job_hunting, $web);
  3557. }
  3558. // 0:待审核 1:已通过 2:已拒绝
  3559. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3560. ->where('job_recruiting.website_id', $data['website_id'])
  3561. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3562. $query->where(function ($q) use ($data) {
  3563. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3564. });
  3565. })
  3566. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3567. ->select(
  3568. 'job_recruiting.id',
  3569. 'job_recruiting.catid',
  3570. 'job_recruiting.cat_arr_id',
  3571. 'job_recruiting.title',
  3572. 'job_recruiting.jtzw_id',
  3573. 'job_recruiting.hy_id',
  3574. 'job_recruiting.city_arr_id',
  3575. 'job_recruiting.due_data',
  3576. 'job_recruiting.updated_at',
  3577. 'job_recruiting.experience',
  3578. 'job_recruiting.educational',
  3579. 'job_recruiting.salary',
  3580. 'job_recruiting.zw_id',
  3581. 'job_company.business_name',
  3582. 'job_recruiting.keyword',
  3583. 'job_recruiting.description',
  3584. )
  3585. ->orderBy('updated_at', 'desc')
  3586. ->limit($data['job2_num'])
  3587. ->get();
  3588. if (empty($job_recruiting->toArray())) {
  3589. $job_recruitings = "未查询到相关职位信息";
  3590. } else {
  3591. $job_recruitings = $this->processJob($job_recruiting, $web);
  3592. }
  3593. $result = [
  3594. 'job_hunting' => $job_huntings,
  3595. 'job_recuiting' => $job_recruitings,
  3596. ];
  3597. return Result::success($result);
  3598. }
  3599. /**
  3600. * c端-获取招工招聘列表
  3601. * @param array $data
  3602. * @return array
  3603. * */
  3604. public function getWebsiteJobList(array $data): array
  3605. {
  3606. $recruit_where = [];
  3607. $hunt_where = [];
  3608. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3609. if (empty($web)) {
  3610. return Result::error("此网站不存在", 0);
  3611. }
  3612. $website_id['website_id'] = $data['website_id'];
  3613. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  3614. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3615. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  3616. }
  3617. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3618. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  3619. }
  3620. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3621. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  3622. }
  3623. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3624. array_push($recruit_where, ['title', 'like', '%' . $data['keyword'] . '%']);
  3625. }
  3626. $query = JobRecruiting::where('job_recruiting.status', 1)
  3627. ->where('job_recruiting.website_id', $data['website_id'])
  3628. ->where($recruit_where)
  3629. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3630. $query->where(function ($q) use ($data) {
  3631. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3632. });
  3633. })
  3634. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  3635. $query->where(function ($q) use ($data) {
  3636. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  3637. });
  3638. })
  3639. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3640. ->select(
  3641. 'job_recruiting.id',
  3642. 'job_recruiting.catid',
  3643. 'job_recruiting.hy_id',
  3644. 'job_recruiting.title',
  3645. 'job_recruiting.zw_id',
  3646. 'job_recruiting.educational',
  3647. 'job_recruiting.jtzw_id',
  3648. 'job_recruiting.city_arr_id',
  3649. 'job_recruiting.due_data',
  3650. 'job_recruiting.experience',
  3651. 'job_recruiting.cat_arr_id',
  3652. 'job_recruiting.updated_at',
  3653. 'job_company.business_name',
  3654. 'job_recruiting.keyword',
  3655. 'job_recruiting.description',
  3656. )
  3657. ->orderBy('job_recruiting.updated_at', 'desc');
  3658. $recruit_count = $query->count();
  3659. $query = clone $query;
  3660. $JobRecruiting = $query
  3661. ->offset(($data['page'] - 1) * $data['pageSize'])
  3662. ->limit($data['pageSize'])
  3663. ->get();
  3664. if (empty($JobRecruiting)) {
  3665. $JobRecruiting = "暂无相关职位信息";
  3666. } else {
  3667. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  3668. }
  3669. }
  3670. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  3671. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3672. array_push($hunt_where, ['job_hunting.job', $data['zw_id']]);
  3673. }
  3674. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3675. array_push($hunt_where, ['job_hunting.job_name_get', $data['jtzw_id']]);
  3676. }
  3677. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3678. array_push($hunt_where, ['job_hunting.industry', $data['hy_id']]);
  3679. }
  3680. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3681. array_push($hunt_where, ['job_position.zwname', 'like', '%' . $data['keyword'] . '%']);
  3682. }
  3683. $query = JobHunting::where('job_hunting.status', 2)
  3684. ->where('job_hunting.website_id', $data['website_id'])
  3685. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3686. ->where($hunt_where)
  3687. // ->when(isset($data['keyword']) &&!empty($data['keyword']), function ($query) use ($data) {
  3688. // $query->where('job_position.zwname','like','%'.$data['keyword'].'%');
  3689. // })
  3690. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3691. $query->where(function ($q) use ($data) {
  3692. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3693. });
  3694. })
  3695. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  3696. $query->where(function ($q) use ($data) {
  3697. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  3698. });
  3699. })
  3700. ->select(
  3701. 'job_hunting.id',
  3702. 'job_hunting.catid',
  3703. 'job_hunting.sexy',
  3704. 'job_hunting.experience',
  3705. 'job_hunting.origin',
  3706. 'job_hunting.industry',
  3707. 'job_hunting.name',
  3708. 'job_hunting.job',
  3709. 'job_hunting.job_name_get',
  3710. 'job_hunting.city_arr_id',
  3711. 'job_hunting.cat_arr_id',
  3712. 'job_hunting.created_at',
  3713. 'job_hunting.updated_at',
  3714. 'job_position.zwname as job_name',
  3715. 'job_hunting.skillList',
  3716. 'job_hunting.slelf_evaluation',
  3717. )
  3718. ->orderBy('job_hunting.updated_at', 'desc');
  3719. $hunt_count = $query->count();
  3720. $query = clone $query;
  3721. $JobHunting = $query
  3722. ->offset(($data['page'] - 1) * $data['pageSize'])
  3723. ->limit($data['pageSize'])
  3724. ->get();
  3725. if (empty($JobHunting)) {
  3726. $JobRecruiting = "暂无相关简历信息";
  3727. } else {
  3728. $JobHunting = $this->processJob($JobHunting, $website_id);
  3729. }
  3730. }
  3731. $result = [
  3732. 'JobRecruiting' => $JobRecruiting ?? [],
  3733. 'recruit_count' => $recruit_count ?? 0,
  3734. 'JobHunting' => $JobHunting ?? [],
  3735. 'hunt_count' => $hunt_count ?? 0,
  3736. ];
  3737. return Result::success($result);
  3738. }
  3739. /**
  3740. * c端-获取招工招聘详情
  3741. * @param array $data
  3742. * @return array
  3743. * */
  3744. public function getWebsiteJobInfo(array $data): array
  3745. {
  3746. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3747. if (empty($web)) {
  3748. return Result::error("该网站不存在", 0);
  3749. }
  3750. $webid = [
  3751. 'website_id' => $data['website_id'],
  3752. ];
  3753. // 职位相关信息
  3754. if ($data['type'] == 1) {
  3755. $query = JobRecruiting::where('status', 1)
  3756. ->where('website_id', $data['website_id'])
  3757. ->select('*');
  3758. $job = $query->where('job_recruiting.id', $data['id'])->get();
  3759. $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();
  3760. if (!empty($company)) {
  3761. $result['company'] = $this->processJob($company, $webid);
  3762. }
  3763. $other_job = JobRecruiting::where('status', 1)
  3764. ->where('website_id', $data['website_id'])
  3765. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  3766. ->where('id', '!=', $data['id'])
  3767. ->where('user_id', '=', $job[0]['user_id'])
  3768. ->limit($data['pageSize'])
  3769. ->get();
  3770. if (!empty($other_job)) {
  3771. $result['other_job'] = $this->processJob($other_job, $webid);
  3772. }
  3773. } else {
  3774. // 简历相关信息
  3775. $job = JobHunting::where('job_hunting.status', 2)
  3776. ->where('job_hunting.website_id', $data['website_id'])
  3777. ->where('job_hunting.id', $data['id'])
  3778. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3779. ->select('job_hunting.*', 'user_name')
  3780. ->get();
  3781. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  3782. if (!empty($resume->toArray())) {
  3783. $result['resume'] = 1;
  3784. } else {
  3785. $result['resume'] = 0;
  3786. }
  3787. }
  3788. if (empty($job->toArray())) {
  3789. return Result::error("id参数错误", 0);
  3790. }
  3791. if (!empty($job[0]['job_experience'])) {
  3792. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  3793. if (!empty($job_experience)) {
  3794. // $hy = [];
  3795. foreach ($job_experience as $key => $value) {
  3796. // $id = $value['id'];
  3797. $hy[$key] = $value['job_industry'];
  3798. $zw_id[$key] = $value['job_typename'];
  3799. $jtzw_id[$key] = $value['job_name'];
  3800. }
  3801. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  3802. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  3803. // 先将关联表转换为索引数组,提高查找效率
  3804. $hyLookup = [];
  3805. foreach ($hy_table as $item) {
  3806. $hyLookup[$item['hyid']] = $item['hyname'];
  3807. }
  3808. $zwLookup = [];
  3809. foreach ($zw_table as $item) {
  3810. $zwLookup[$item['zwid']] = $item['zwname'];
  3811. }
  3812. foreach ($job_experience as $key => &$value) {
  3813. // 处理行业名称
  3814. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  3815. $value['hy_name'] = $hyLookup[$hy[$key]];
  3816. }
  3817. // 处理职位名称
  3818. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  3819. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  3820. }
  3821. // 处理具体职位名称
  3822. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  3823. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  3824. }
  3825. }
  3826. // 释放引用,防止意外修改后续代码
  3827. unset($value);
  3828. }
  3829. $result['job_experience'] = $job_experience ?? [];
  3830. }
  3831. if (!empty($job[0]['education_experience'])) {
  3832. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  3833. if (!empty($education_experience)) {
  3834. foreach ($education_experience as $key => $value) {
  3835. // $id = $value['id'];
  3836. $education[$key] = $value['school_education'];
  3837. }
  3838. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  3839. // // 先将关联表转换为索引数组,提高查找效率
  3840. $educationLookup = [];
  3841. foreach ($education_table as $item) {
  3842. $educationLookup[$item['evalue']] = $item['ename'];
  3843. }
  3844. foreach ($education_experience as $key => &$value) {
  3845. // 处理学历名称
  3846. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  3847. $value['education_name'] = $educationLookup[$education[$key]];
  3848. }
  3849. }
  3850. }
  3851. $result['education_experience'] = $job_experience ?? [];
  3852. }
  3853. $result['job'] = $this->processJob($job, $webid);
  3854. // // 返现对应的栏目
  3855. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  3856. $category = WebsiteCategory::where('website_id', $data['website_id'])
  3857. ->whereIn('category_id', $catid)
  3858. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  3859. ->orderBy('pid')->get()->all();
  3860. if (!empty($category)) {
  3861. $result['category'] = $category;
  3862. }
  3863. $result['job'] = $job;
  3864. $result['job_experience'] = $job_experience ?? [];
  3865. $result['education_experience'] = $education_experience ?? [];
  3866. if (empty($result)) {
  3867. return Result::error("参数错误", 0);
  3868. }
  3869. return Result::success($result);
  3870. }
  3871. /**
  3872. * c端-申请职位
  3873. * @param array $data
  3874. * @return array
  3875. * */
  3876. public function getWebsiteJobApply(array $data): array
  3877. {
  3878. // 首先验证网站是否存在
  3879. // return Result::success($data);
  3880. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3881. if (empty($web)) {
  3882. return Result::error("该网站不存在", 0);
  3883. }
  3884. // 验证用户是否存在且为个人会员/管理员
  3885. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3886. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3887. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  3888. return Result::error("用户不存在", 0);
  3889. }
  3890. // 去除重复元素和空元素,并保持原始顺序
  3891. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  3892. return !empty($value);
  3893. }));
  3894. // 验证职位是否存在 1:审核通过
  3895. $recruiting = JobRecruiting::where('status', 1)
  3896. ->where('website_id', $data['website_id'])
  3897. ->whereIn('id', $data['recruit_id'])
  3898. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  3899. if (empty($recruiting)) {
  3900. return Result::error("该职位不存在", 0);
  3901. }
  3902. // 简历是否存在
  3903. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  3904. if (empty($hunt_id)) {
  3905. return Result::error("该简历不存在", 0);
  3906. }
  3907. $data['hunt_id'] = $hunt_id['hunt_id'];
  3908. // // 验证是否已投递过该职位
  3909. $apply = JobApply::where('user_id', $data['user_id'])
  3910. ->where('hunt_id', $data['hunt_id'])
  3911. ->where('website_id', $data['website_id'])
  3912. ->whereIn('recruit_id', $data['recruit_id'])
  3913. ->get(['recruit_id']);
  3914. if (!empty($apply->toArray())) {
  3915. return Result::error("您已投递过该职位!");
  3916. }
  3917. $insertData = array_map(function ($recruiting) use ($data) {
  3918. return [
  3919. 'user_id' => $data['user_id'],
  3920. 'hunt_id' => $data['hunt_id'],
  3921. 'website_id' => $data['website_id'],
  3922. 'recruit_id' => $recruiting['recruit_id'],
  3923. 'receiver_id' => $recruiting['receiver_id'],
  3924. 'status' => 1,
  3925. ];
  3926. }, $recruiting);
  3927. // 批量插入数据
  3928. $result = JobApply::insert($insertData);
  3929. if (empty($result)) {
  3930. return Result::error("投递失败", 0);
  3931. }
  3932. return Result::success($result);
  3933. }
  3934. /**
  3935. * 招工招聘-沟通简历
  3936. * @param array $data
  3937. * @return array
  3938. * */
  3939. public function getWebsiteJobResume(array $data): array
  3940. {
  3941. // 首先验证网站是否存在
  3942. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3943. if (empty($web)) {
  3944. return Result::error("该网站不存在", 0);
  3945. }
  3946. // return Result::success($data);
  3947. // 验证用户是否存在且为企业会员/管理员
  3948. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3949. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3950. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3951. return Result::error("用户不存在", 0);
  3952. }
  3953. // 去除重复元素和空元素,并保持原始顺序
  3954. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  3955. return !empty($value);
  3956. }));
  3957. // 验证简历是否存在
  3958. $hunting = JobHunting::where('status', 2)
  3959. ->where('website_id', $data['website_id'])
  3960. ->whereIn('id', $data['hunt_id'])
  3961. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  3962. if (empty($hunting)) {
  3963. return Result::error("该简历不存在", 0);
  3964. }
  3965. // 验证是否已沟通过该简历
  3966. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3967. ->where('recruit_id', $data['recruit_id'])
  3968. ->where('website_id', $data['website_id'])
  3969. ->whereIn('hunt_id', $data['hunt_id'])
  3970. ->get(['hunt_id']);
  3971. if (!empty($remuse->toArray())) {
  3972. return Result::error("您已沟通过该简历!");
  3973. }
  3974. // 准备要插入的数据数组
  3975. $insertData = array_map(function ($hunting) use ($data) {
  3976. return [
  3977. 'user_id' => $data['user_id'],
  3978. 'recruit_id' => $data['recruit_id'],
  3979. 'website_id' => $data['website_id'],
  3980. 'hunt_id' => $hunting['hunt_id'],
  3981. 'receiver_id' => $hunting['receiver_id'],
  3982. 'status' => 1,
  3983. ];
  3984. }, $hunting);
  3985. // 批量插入数据
  3986. $result = JobRemuse::insert($insertData);
  3987. if (empty($result)) {
  3988. return Result::error("沟通失败", 0);
  3989. }
  3990. return Result::success($result);
  3991. }
  3992. /**
  3993. * 招工招聘 -我的职位(企业会员)
  3994. * @param array $data
  3995. * @return array
  3996. */
  3997. public function getWebsiteJobRecruiting(array $data): array
  3998. {
  3999. $web = Website::where('id', $data['website_id'])->first('id');
  4000. if (empty($web)) {
  4001. return Result::error("该网站不存在", 0);
  4002. }
  4003. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  4004. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  4005. return Result::error("用户暂无权限!", 0);
  4006. }
  4007. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  4008. $result = JobRecruiting::where('website_id', $data['website_id'])
  4009. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  4010. $query->where('user_id', $user['id']);
  4011. })
  4012. ->where('status', 1)
  4013. ->select('id', 'title', 'website_id', 'user_id', 'updated_at', 'keyword', 'catid', 'description')
  4014. ->orderBy('updated_at', 'desc')
  4015. ->limit($data['pageSize'])
  4016. ->get();
  4017. if (empty($result)) {
  4018. return Result::error("暂无相关职位信息", 0);
  4019. }
  4020. return Result::success($result);
  4021. }
  4022. /**
  4023. * c端 - 验证路由
  4024. * @param array $data
  4025. * @return array
  4026. */
  4027. /**
  4028. * c端 - 验证路由
  4029. * @param array $data
  4030. * @return array
  4031. */
  4032. public function checkWebsiteRoute(array $data): array
  4033. {
  4034. // 测试001111111222
  4035. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name', 'status']);
  4036. if (empty($web)) {
  4037. return Result::error("该网站不存在", 0);
  4038. } elseif ($web['status'] != 1) {
  4039. return Result::error("网站已经关闭", 0);
  4040. }
  4041. if (isset($data['other_route']) && !empty($data['other_route'])) {
  4042. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  4043. // 验证路由是否存在
  4044. if (empty($whiteRouterInfo)) {
  4045. $whiteRouterInfo = WhiteRouter::where("router_type", 1)->where('router_url', $data['other_route'])->first();
  4046. }
  4047. if (!empty($whiteRouterInfo)) {
  4048. return Result::success($whiteRouterInfo->toArray());
  4049. }
  4050. }
  4051. // 验证栏目路由
  4052. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  4053. ->where('path', $data['all_route'])
  4054. ->get()->all();
  4055. if (count($last_category) == 0) {
  4056. return Result::error("该栏目不存在", 0);
  4057. }
  4058. if (count($last_category) > 1) {
  4059. return Result::error("该栏目路由存在多个,路由验证失败!", 0);
  4060. }
  4061. if (count($last_category) == 1) {
  4062. $last_category = $last_category[0];
  4063. }
  4064. // return Result::success($last_category);
  4065. if (isset($data['id']) && !empty($data['id'])) {
  4066. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  4067. switch ($last_category['type']) {
  4068. case 1:
  4069. // 文章
  4070. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  4071. $article = Article::where('status', 1)
  4072. ->where('id', $data['id'])
  4073. ->where(function ($query) use ($data) {
  4074. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  4075. ->orWhereNull("ignore_ids");
  4076. })
  4077. ->first(['catid']);
  4078. if (empty($article)) {
  4079. return Result::error("该文章不存在", 0);
  4080. }
  4081. // return Result::success($article);
  4082. break;
  4083. case 2:
  4084. // 商品
  4085. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  4086. $article = Good::where('website_id', $data['website_id'])
  4087. ->where('status', 2)
  4088. ->where('id', $data['id'])
  4089. ->first(['cat_arr_id']);
  4090. if (empty($article)) {
  4091. return Result::error("该商品不存在", 0);
  4092. }
  4093. break;
  4094. case 3:
  4095. // 书刊信息
  4096. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  4097. $article = Book::where('website_id', $data['website_id'])
  4098. ->where('status', 2)
  4099. ->where('id', $data['id'])
  4100. ->first(['id', 'cat_arr_id']);
  4101. if (empty($article)) {
  4102. return Result::error("该书刊不存在", 0);
  4103. }
  4104. break;
  4105. case 4:
  4106. // 招聘
  4107. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核通过;(只有企业会员需要审核)',
  4108. $article = JobRecruiting::where('website_id', $data['website_id'])
  4109. ->where('status', 1)
  4110. ->where('id', $data['id'])
  4111. ->first(['cat_arr_id']);
  4112. if (empty($article)) {
  4113. return Result::error("该招聘不存在", 0);
  4114. }
  4115. break;
  4116. case 5:
  4117. // 求职
  4118. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  4119. $article = JobHunting::where('website_id', $data['website_id'])
  4120. ->where('status', 2)
  4121. ->where('id', $data['id'])
  4122. ->first(['cat_arr_id']);
  4123. if (empty($article)) {
  4124. return Result::error("该求职不存在", 0);
  4125. }
  4126. break;
  4127. case 6:
  4128. // 企业
  4129. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  4130. $article = Company::
  4131. // where('website_id', $data['website_id'])
  4132. // ->
  4133. where('status', 1)
  4134. ->where('id', $data['id'])
  4135. ->first(['cat_arr_id']);
  4136. if (empty($article)) {
  4137. return Result::error("该企业不存在", 0);
  4138. }
  4139. break;
  4140. case 7:
  4141. // 项目
  4142. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  4143. $article = Project::where('website_id', $data['website_id'])
  4144. ->where('status', 1)
  4145. ->where('id', $data['id'])
  4146. ->first(['cat_arr_id']);
  4147. if (empty($article)) {
  4148. return Result::error("该项目不存在", 0);
  4149. }
  4150. break;
  4151. default:
  4152. return Result::error("该数据不存在", 0);
  4153. break;
  4154. }
  4155. // return Result::success($article);
  4156. // $catid =0 ;
  4157. if (!isset($article['cat_arr_id'])) {
  4158. $catid = isset($article['catid']) ? $article['catid'] : (isset($article['category_id']) ? $article['category_id'] : null);
  4159. } else {
  4160. $catidArray = json_decode($article['cat_arr_id'], true);
  4161. $catid = !empty($catidArray) ? end($catidArray) : null;
  4162. }
  4163. // return Result::success($catid);
  4164. // // return Result::success($article['cat_arr_id']);
  4165. if (empty($catid)) {
  4166. return Result::error("该栏目路径不存在", 0);
  4167. }
  4168. $path = WebsiteCategory::where('website_id', $data['website_id'])
  4169. ->where('category_id', $catid)
  4170. ->first('path');
  4171. }
  4172. // else{
  4173. // // if ($last_category['pid'] != 0) {
  4174. // $cat_arr = json_decode($last_category['category_arr_id'], true);
  4175. // $catid = !empty($cat_arr) && is_array($cat_arr) ? end($cat_arr) : null;
  4176. // $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  4177. // ->where('category_id',$catid)
  4178. // ->where('path',$data['all_route'])
  4179. // ->first('path');
  4180. // // } else {
  4181. // // $pinyin[0] = $last_category['aLIas_pinyin'];
  4182. // // }
  4183. // }
  4184. // return Result::success($path);
  4185. if (!empty($path) && $path['path'] != $data['all_route']) {
  4186. return Result::error('非法路径!');
  4187. } else {
  4188. return Result::success($last_category['path']);
  4189. }
  4190. }
  4191. /**
  4192. * 招工招聘 - 获取推荐职位
  4193. * @param array $data
  4194. * @return array
  4195. */
  4196. public function getWebsiteLevelJob(array $data): array
  4197. {
  4198. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  4199. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  4200. ->where('job_recruiting.status', 1)
  4201. ->where('job_level', $data['job_level'])
  4202. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4203. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  4204. ->orderBy('job_recruiting.updated_at', 'desc')
  4205. ->limit($data['pageSize'])
  4206. ->get();
  4207. $web = ['website_id' => $data['website_id']];
  4208. if (!empty($job)) {
  4209. $result = $this->processJob($job, $web);
  4210. }
  4211. if (empty($result)) {
  4212. return Result::error("暂无相关职位信息", 0);
  4213. }
  4214. return Result::success($result);
  4215. }
  4216. /**
  4217. * 验证导航名称是否重复
  4218. * @return void
  4219. */
  4220. //20250226 产品列表
  4221. public function getGoodList(array $data): array
  4222. {
  4223. var_dump($data, '---------1-2--');
  4224. $type_id = isset($data['user_type_id']) ? $data['user_type_id'] : '';
  4225. unset($data['user_type_id']);
  4226. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4227. $where = [];
  4228. if ($type_id != '10000') {
  4229. $where = [
  4230. 'good.user_id' => $user_id,
  4231. ];
  4232. }
  4233. //类型
  4234. if (isset($data['type_id']) && $data['type_id']) {
  4235. $where['good.type_id'] = $data['type_id'];
  4236. }
  4237. //名称
  4238. if (isset($data['name']) && $data['name']) {
  4239. $where[] = ['good.name', 'like', '%' . $data['name'] . '%'];
  4240. }
  4241. //status
  4242. if (isset($data['status']) && $data['status'] != '') {
  4243. $where['good.status'] = $data['status'];
  4244. }
  4245. //status1
  4246. // if (isset($data['status1']) && $data['status1'] == 1) {
  4247. // $status1 = 1;
  4248. // }
  4249. $where1 = [];
  4250. //website_id
  4251. // if (isset($data['website_id']) && $data['website_id']) {
  4252. // $where1 = [
  4253. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  4254. // ];
  4255. // }
  4256. // website_name
  4257. if (isset($data['website_name']) && $data['website_name']) {
  4258. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  4259. }
  4260. // catid
  4261. if (isset($data['category_name']) && $data['category_name']) {
  4262. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  4263. }
  4264. // $result = Good::where($where)
  4265. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  4266. var_dump($where, '---------1---');
  4267. $result = Good::where($where)
  4268. ->when(!empty($where1), function ($query) use ($where1) {
  4269. return $query->where($where1);
  4270. })
  4271. //status 1待审核2已审核3已拒绝
  4272. ->when(isset($data['status1']), function ($query) {
  4273. return $query->whereIn('good.status', [1, 3]);
  4274. })
  4275. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4276. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4277. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4278. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4279. ->orderBy("updated_at", "desc")
  4280. ->limit($data['page_size'])
  4281. ->offset(($data['page'] - 1) * $data['page_size'])
  4282. ->get();
  4283. $count = Good::where($where)
  4284. ->when(!empty($where1), function ($query) use ($where1) {
  4285. return $query->where($where1);
  4286. })
  4287. //status 1待审核2已审核3已拒绝
  4288. ->when(isset($data['status1']), function ($query) {
  4289. return $query->whereIn('good.status', [1, 3]);
  4290. })
  4291. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4292. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4293. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4294. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4295. ->orderBy("updated_at", "desc")->count();
  4296. $data = [
  4297. 'rows' => $result->toArray(),
  4298. 'count' => $count,
  4299. ];
  4300. if (empty($result)) {
  4301. return Result::error("此栏目暂无相关产品", 0);
  4302. }
  4303. return Result::success($data);
  4304. }
  4305. public function getGoodInfo(array $data): array
  4306. {
  4307. $result = Good::where('id', $data['id'])->first();
  4308. if (empty($result)) {
  4309. return Result::error("此产品不存在", 0);
  4310. }
  4311. return Result::success($result);
  4312. }
  4313. public function addGood(array $data): array
  4314. {
  4315. // unset($data['city_arr_id']);
  4316. // unset($data['cat_arr_id']);
  4317. $data['city_id'] = end($data['city_arr_id']);
  4318. $data['catid'] = end($data['cat_arr_id']);
  4319. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4320. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4321. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4322. unset($data['imgUrl']); //大小写
  4323. if (isset($data['price']) && $data['price'] == '') {
  4324. $data['price'] = 0;
  4325. }
  4326. if ($data['imgurl'] == '') {
  4327. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4328. preg_match_all($reg, $data['detail'], $matches);
  4329. if (isset($matches[1][0])) {
  4330. //截取varchar240
  4331. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4332. }
  4333. }
  4334. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4335. //提取标题+内容中的关键词
  4336. $data['keyword'] = $data['name'];
  4337. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4338. Jieba::init(); // 初始化 jieba-php
  4339. Finalseg::init();
  4340. $segList = Jieba::cut($data['keyword']);
  4341. $segList1 = array_slice($segList, 0, 8);
  4342. $data['keyword'] = implode(',', $segList1);
  4343. }
  4344. if ($data['description'] == '') {
  4345. //提取内容中的描述
  4346. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4347. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4348. // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  4349. }
  4350. if ($data['status'] == 1) {
  4351. $this->sendMessage([
  4352. 'talk_type' => 200,
  4353. 'title' => $data['name'],
  4354. 'content' => '提交了审核',
  4355. 'messageType' => 3,
  4356. ]);
  4357. }
  4358. $result = Good::insert($data);
  4359. if (empty($result)) {
  4360. return Result::error("添加失败", 0);
  4361. }
  4362. return Result::success($result);
  4363. }
  4364. public function updateGood(array $data): array
  4365. {
  4366. $data['city_id'] = end($data['city_arr_id']);
  4367. $data['catid'] = end($data['cat_arr_id']);
  4368. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4369. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4370. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4371. //设置东八区
  4372. date_default_timezone_set('Asia/Shanghai');
  4373. $data['updated_at'] = date('Y-m-d H:i:s');
  4374. if (isset($data['price']) && $data['price'] == '') {
  4375. $data['price'] = 0;
  4376. }
  4377. if ($data['imgurl'] == '') {
  4378. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4379. preg_match_all($reg, $data['detail'], $matches);
  4380. if (isset($matches[1][0])) {
  4381. //截取varchar240
  4382. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4383. }
  4384. }
  4385. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4386. //提取标题+内容中的关键词
  4387. $data['keyword'] = $data['name'];
  4388. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4389. Jieba::init(); // 初始化 jieba-php
  4390. Finalseg::init();
  4391. $segList = Jieba::cut($data['keyword']);
  4392. $segList1 = array_slice($segList, 0, 8);
  4393. $data['keyword'] = implode(',', $segList1);
  4394. }
  4395. if ($data['description'] == '') {
  4396. //提取内容中的描述
  4397. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4398. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4399. }
  4400. if ($data['status'] == 1) {
  4401. $this->sendMessage([
  4402. 'talk_type' => 200,
  4403. 'title' => $data['name'],
  4404. 'content' => '提交了审核',
  4405. 'messageType' => 3,
  4406. ]);
  4407. }
  4408. $result = Good::where('id', $data['id'])->update($data);
  4409. if (empty($result)) {
  4410. return Result::error("更新失败", 0);
  4411. }
  4412. return Result::success($result);
  4413. }
  4414. public function delGood(array $data): array
  4415. {
  4416. $result = Good::where('id', $data['id'])->delete();
  4417. if (empty($result)) {
  4418. return Result::error("删除失败", 0);
  4419. }
  4420. return Result::success($result);
  4421. }
  4422. //20250226 产品列表
  4423. //20250306 求职信息
  4424. public function getJobHuntingList(array $data): array
  4425. {
  4426. $where = [];
  4427. if (isset($data['username']) && !empty($data['username'])) {
  4428. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4429. }
  4430. //status 1待审核2已审核3已拒绝
  4431. if (isset($data['status']) && $data['status'] != '') {
  4432. $where = [
  4433. 'job_hunting.status' => $data['status'],
  4434. ];
  4435. }
  4436. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4437. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4438. unset($data['type_id']);
  4439. if ($type_id != '10000') {
  4440. $where[] = ['job_hunting.user_id', '=', $user_id];
  4441. }
  4442. $result = JobHunting::where($where)
  4443. ->when(!empty($data['status1']), function ($query) use ($data) {
  4444. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4445. })
  4446. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4447. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4448. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  4449. ->orderBy("updated_at", "desc")
  4450. ->limit($data['page_size'])
  4451. ->offset(($data['page'] - 1) * $data['page_size'])
  4452. ->get();
  4453. if (empty($result)) {
  4454. return Result::error("查询失败", 0);
  4455. }
  4456. $count = JobHunting::where($where)
  4457. ->when(!empty($data['status1']), function ($query) use ($data) {
  4458. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4459. })
  4460. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4461. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4462. ->count();
  4463. $data = [
  4464. 'rows' => $result->toArray(),
  4465. 'count' => $count,
  4466. ];
  4467. return Result::success($data);
  4468. }
  4469. public function getJobHuntingApply(array $data): array
  4470. {
  4471. var_dump($data, '-----------------test--------1-');
  4472. $where = [];
  4473. if (isset($data['username']) && !empty($data['username'])) {
  4474. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4475. }
  4476. if (isset($data['salary']) && !empty($data['salary'])) {
  4477. $where[] = [
  4478. 'job_hunting.salary',
  4479. '=',
  4480. $data['salary'],
  4481. ];
  4482. }
  4483. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4484. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4485. unset($data['type_id']);
  4486. if ($type_id != '10000') {
  4487. $where[] = ['job_apply.receiver_id', '=', $user_id];
  4488. }
  4489. var_dump($where, '-----------------test---------');
  4490. $result = jobApply::where($where)
  4491. // ->when(!empty($data['status1']), function ($query) use ($data) {
  4492. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4493. // })
  4494. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  4495. ->where('job_enum.egroup', '=', 'income')
  4496. ->where('job_hunting.status', 2) //已审核
  4497. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4498. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4499. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4500. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4501. //职位----是申请职位
  4502. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4503. ->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')
  4504. ->orderBy("job_hunting.updated_at", "desc")
  4505. ->limit($data['page_size'])
  4506. ->offset(($data['page'] - 1) * $data['page_size'])
  4507. ->get();
  4508. if (empty($result)) {
  4509. return Result::error("查询失败", 0);
  4510. }
  4511. $count = jobApply::where($where)
  4512. ->where('job_enum.egroup', '=', 'income')
  4513. ->where('job_hunting.status', 2) //已审核
  4514. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4515. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4516. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4517. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4518. //职位----是申请职位
  4519. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4520. ->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')
  4521. ->count();
  4522. $data = [
  4523. 'rows' => $result->toArray(),
  4524. 'count' => $count,
  4525. ];
  4526. return Result::success($data);
  4527. }
  4528. public function addJobHunting(array $data): array
  4529. {
  4530. date_default_timezone_set('Asia/Shanghai');
  4531. unset($data['company_name']);
  4532. unset($data['job_industry']);
  4533. unset($data['job_name']);
  4534. unset($data['department']);
  4535. unset($data['job_timeList']);
  4536. unset($data['job_content']);
  4537. unset($data['job_typename']); //不知道这是啥,
  4538. $data['created_at'] = date('Y-m-d H:i:s');
  4539. $data['updated_at'] = date('Y-m-d H:i:s');
  4540. //根据用户 user_id 只能添加一次
  4541. $result = JobHunting::where('user_id', $data['user_id'])->first();
  4542. if (!empty($result)) {
  4543. return Result::error("您已添加过求职信息", 0);
  4544. }
  4545. var_dump($result, '-----------------test---------');
  4546. if (isset($data['city_arr_id']) && !empty($data['city_arr_id'])) {
  4547. if (is_string($data['city_arr_id'])) {
  4548. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4549. $cityArr = json_decode($data['city_arr_id'], true);
  4550. // 确保 $cityArr 是数组
  4551. if (is_array($cityArr)) {
  4552. $data['city_id'] = end($cityArr);
  4553. }
  4554. } else {
  4555. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4556. if (is_array($data['city_arr_id'])) {
  4557. $data['city_id'] = end($data['city_arr_id']);
  4558. }
  4559. }
  4560. }
  4561. // 处理求职所绑定栏目
  4562. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id'])) {
  4563. if (is_string($data['cat_arr_id'])) {
  4564. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4565. // 先清理可能存在的无效 JSON 字符
  4566. $cleanedCatArrStr = trim($data['cat_arr_id']);
  4567. $catArr = json_decode($cleanedCatArrStr, true);
  4568. // 检查 JSON 解码是否成功且结果是数组
  4569. if (json_last_error() === JSON_ERROR_NONE && is_array($catArr)) {
  4570. $data['catid'] = end($catArr);
  4571. }
  4572. } else {
  4573. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4574. if (is_array($data['cat_arr_id'])) {
  4575. $data['catid'] = end($data['cat_arr_id']);
  4576. }
  4577. }
  4578. }
  4579. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4580. $this->sendMessage([
  4581. 'talk_type' => 600,
  4582. 'title' => $data['name'],
  4583. 'content' => '提交了审核',
  4584. 'messageType' => 11,
  4585. ]);
  4586. }
  4587. $result = JobHunting::create($data);
  4588. if (empty($result)) {
  4589. return Result::error("添加失败", 0);
  4590. }
  4591. return Result::success($result);
  4592. }
  4593. public function delJobHunting(array $data): array
  4594. {
  4595. $result = JobHunting::where('id', $data['id'])->delete();
  4596. if (empty($result)) {
  4597. return Result::error("删除失败", 0);
  4598. }
  4599. return Result::success($result);
  4600. }
  4601. public function updateJobHunting(array $data): array
  4602. {
  4603. //设置东八区
  4604. date_default_timezone_set('Asia/Shanghai');
  4605. unset($data['company_name']);
  4606. unset($data['job_industry']);
  4607. unset($data['job_name']);
  4608. unset($data['department']);
  4609. unset($data['job_timeList']);
  4610. unset($data['job_content']);
  4611. unset($data['job_typename']); //不知道这是啥,
  4612. $data['created_at'] = date('Y-m-d H:i:s');
  4613. $data['updated_at'] = date('Y-m-d H:i:s');
  4614. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  4615. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4616. $cityArr = json_decode($data['city_arr_id'], true);
  4617. $data['city_id'] = end($cityArr);
  4618. } else {
  4619. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4620. $data['city_id'] = end($data['city_arr_id']);
  4621. }
  4622. // 处理求职所绑定栏目
  4623. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_string($data['cat_arr_id'])) {
  4624. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4625. $catArr = json_decode($data['cat_arr_id'], true);
  4626. $data['catid'] = end($catArr);
  4627. } else {
  4628. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4629. $data['catid'] = end($data['cat_arr_id']);
  4630. }
  4631. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4632. $this->sendMessage([
  4633. 'talk_type' => 600,
  4634. 'title' => $data['name'],
  4635. 'content' => '提交了审核',
  4636. 'messageType' => 11,
  4637. ]);
  4638. }
  4639. $result = JobHunting::where('id', $data['id'])->update($data);
  4640. if (empty($result)) {
  4641. return Result::error("更新失败", 0);
  4642. }
  4643. return Result::success($result);
  4644. }
  4645. public function getJobHuntingInfo(array $data): array
  4646. {
  4647. $result = JobHunting::where('id', $data['id'])->first();
  4648. if (empty($result)) {
  4649. return Result::error("查询失败", 0);
  4650. }
  4651. return Result::success($result);
  4652. }
  4653. public function getJobHuntingData(array $data): array
  4654. {
  4655. $jobEnum = JobEnum::get();
  4656. $jobIndustry = JobIndustry::get();
  4657. $jobNature = JobNature::get();
  4658. $jobPosition = JobPosition::get();
  4659. $data = [
  4660. 'jobEnum' => $jobEnum,
  4661. 'jobIndustry' => $jobIndustry,
  4662. 'jobNature' => $jobNature,
  4663. 'jobPosition' => $jobPosition,
  4664. ];
  4665. return Result::success($data);
  4666. }
  4667. public function delJobHuntingInfo(array $data): array
  4668. {
  4669. $result = JobHunting::where('id', $data['id'])->delete();
  4670. return Result::success();
  4671. }
  4672. //20250324 通知,公告,消息
  4673. public function delNotice(array $data): array
  4674. {
  4675. $result = Notice::where('id', $data['id'])->delete();
  4676. if ($result) {
  4677. return Result::success();
  4678. } else {
  4679. return Result::error("删除失败", 0);
  4680. }
  4681. }
  4682. public function getNoticeInfo(array $data): array
  4683. {
  4684. $result = Notice::where('id', $data['id'])->first();
  4685. // var_dump($result['re_user_ids'], '--------------------');
  4686. if (empty($result)) {
  4687. return Result::error("查询失败", 0);
  4688. }
  4689. return Result::success($result);
  4690. }
  4691. public function readNotice(array $data): array
  4692. {
  4693. $result = Notice::where('id', $data['id'])->first();
  4694. // var_dump($result['re_user_ids'], '--------------------');
  4695. if (empty($result)) {
  4696. return Result::error("查询失败", 0);
  4697. }
  4698. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4699. $re_user_ids = json_decode($result['re_user_ids'], true);
  4700. var_dump($re_user_ids, '--------------1---test---------');
  4701. var_dump($data, '--------------1---test---------');
  4702. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4703. //如果已经存在,就不再添加
  4704. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4705. $read_id = json_decode($result['read_id'], true);
  4706. if (!is_array($read_id)) {
  4707. $read_id = [];
  4708. }
  4709. if (!in_array($data['user_id'], $read_id)) {
  4710. $read_id[] = $data['user_id'];
  4711. $result['read_id'] = json_encode($read_id);
  4712. Notice::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4713. }
  4714. } else {
  4715. //如果不存在,就添加
  4716. $result['read_id'] = json_encode([$data['user_id']]);
  4717. Notice::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4718. }
  4719. }
  4720. return Result::success($result);
  4721. }
  4722. public function addNotice(array $data): array
  4723. {
  4724. date_default_timezone_set('Asia/Shanghai');
  4725. $data['created_at'] = date('Y-m-d H:i:s');
  4726. $data['updated_at'] = date('Y-m-d H:i:s');
  4727. // $data['level'] = "1,2,3,4,5";
  4728. $level = json_decode($data['level'], true);
  4729. $user_id = UserInfo::
  4730. //city_id不是null
  4731. whereNotNull('city_id')
  4732. ->whereNotNull('department_id')
  4733. ->where(function ($query) use ($data) {
  4734. $query->where(function ($subQuery) use ($data) {
  4735. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4736. });
  4737. })
  4738. ->where(function ($query) use ($data) {
  4739. $query->where(function ($subQuery) use ($data) {
  4740. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4741. });
  4742. })
  4743. ->when(isset($level) && is_array($level), function ($query) use ($level) {
  4744. $query->whereIn('level', $level);
  4745. })
  4746. ->pluck('user_id')->toArray();
  4747. $user_id = array_unique($user_id);
  4748. $chat_ids = $user_id;
  4749. $user_id = json_encode($user_id);
  4750. $data['re_user_ids'] = $user_id;
  4751. $this->sendMessage([
  4752. 'talk_type' => 700,
  4753. 'title' => $data['title'],
  4754. 'content' => '提交了审核',
  4755. 'messageType' => 5,
  4756. ]);
  4757. $result = Notice::insertGetId($data);
  4758. if (empty($result)) {
  4759. return Result::error("添加失败", 0);
  4760. }
  4761. return Result::success($result);
  4762. }
  4763. public function updateNotice(array $data): array
  4764. {
  4765. date_default_timezone_set('Asia/Shanghai');
  4766. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  4767. $user_id = UserInfo::
  4768. //city_id不是null
  4769. whereNotNull('city_id')
  4770. ->whereNotNull('department_id')
  4771. ->where(function ($query) use ($data) {
  4772. $query->where(function ($subQuery) use ($data) {
  4773. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4774. });
  4775. })
  4776. ->where(function ($query) use ($data) {
  4777. $query->where(function ($subQuery) use ($data) {
  4778. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4779. });
  4780. })
  4781. ->pluck('user_id')->toArray();
  4782. $user_id = array_unique($user_id);
  4783. $user_id = json_encode($user_id);
  4784. $data['re_user_ids'] = $user_id;
  4785. $data['updated_at'] = date('Y-m-d H:i:s');
  4786. $this->sendMessage([
  4787. 'talk_type' => 700,
  4788. 'title' => $data['title'],
  4789. 'content' => '提交了审核',
  4790. 'messageType' => 5,
  4791. ]);
  4792. $result = Notice::where('id', $data['id'])->update($data);
  4793. return Result::success($result);
  4794. }
  4795. public function getNoticeList(array $data): array
  4796. {
  4797. $where = [];
  4798. //title
  4799. if (isset($data['title']) && !empty($data['title'])) {
  4800. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4801. }
  4802. //level
  4803. if (isset($data['level']) && !empty($data['level'])) {
  4804. $where[] = ['notice.level', '=', $data['level']];
  4805. }
  4806. //status
  4807. if (isset($data['status']) && !empty($data['status'])) {
  4808. $where[] = ['notice.status', '=', $data['status']];
  4809. }
  4810. //type
  4811. if (isset($data['type']) && !empty($data['type'])) {
  4812. $where[] = ['notice.type', '=', $data['type']];
  4813. }
  4814. var_dump($data, '------------11111-2----test---------');
  4815. if ($data['type_id'] == 10000) {
  4816. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4817. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4818. })
  4819. ->where($where)
  4820. ->orderBy('updated_at', 'desc')
  4821. ->limit($data['page_size'])
  4822. ->offset(($data['page'] - 1) * $data['page_size'])
  4823. ->get();
  4824. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4825. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4826. })
  4827. ->where($where)
  4828. ->orderBy('updated_at', 'desc')
  4829. ->count();
  4830. } else {
  4831. $result = Notice::where($where)
  4832. // ->where('user_id', $data['user_id'])
  4833. ->Where(function ($query) use ($data) {
  4834. $query->Where(function ($q) use ($data) {
  4835. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4836. ->orWhere('notice.user_id', $data['user_id']);
  4837. });
  4838. })
  4839. ->when(!empty($data['status1']), function ($query) use ($data) {
  4840. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4841. })
  4842. ->orderBy('updated_at', 'desc')
  4843. ->limit($data['page_size'])
  4844. ->offset(($data['page'] - 1) * $data['page_size'])
  4845. ->get();
  4846. $total = Notice::where($where)
  4847. ->when(!empty($data['status1']), function ($query) use ($data) {
  4848. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4849. })
  4850. // ->where('user_id', $data['user_id'])
  4851. ->Where(function ($query) use ($data) {
  4852. $query->Where(function ($q) use ($data) {
  4853. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4854. ->orWhere('notice.user_id', $data['user_id']);
  4855. });
  4856. })
  4857. ->count();
  4858. }
  4859. if (empty($result)) {
  4860. return Result::error("查询失败", 0);
  4861. }
  4862. $data = [
  4863. 'rows' => $result,
  4864. 'count' => $total,
  4865. ];
  4866. return Result::success($data);
  4867. }
  4868. public function noticeList(array $data): array
  4869. {
  4870. $where = [];
  4871. //title
  4872. if (isset($data['title']) && !empty($data['title'])) {
  4873. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4874. }
  4875. //level
  4876. if (isset($data['level']) && !empty($data['level'])) {
  4877. $where[] = ['notice.level', '=', $data['level']];
  4878. }
  4879. //status
  4880. if (isset($data['status']) && !empty($data['status'])) {
  4881. $where[] = ['notice.status', '=', $data['status']];
  4882. }
  4883. //type
  4884. if (isset($data['type']) && !empty($data['type'])) {
  4885. $where[] = ['notice.type', '=', $data['type']];
  4886. }
  4887. var_dump($data, '------------11111-2----test---------');
  4888. if ($data['type_id'] == 10000) {
  4889. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4890. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4891. })
  4892. ->where($where)
  4893. ->orderBy('updated_at', 'desc')
  4894. ->limit($data['page_size'])
  4895. ->offset(($data['page'] - 1) * $data['page_size'])
  4896. ->get();
  4897. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4898. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4899. })
  4900. ->where($where)
  4901. ->orderBy('updated_at', 'desc')
  4902. ->count();
  4903. } else {
  4904. $result = Notice::where($where)
  4905. // ->where('user_id', $data['user_id'])
  4906. ->Where(function ($query) use ($data) {
  4907. $query->Where(function ($q) use ($data) {
  4908. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4909. ->orWhere('notice.user_id', $data['user_id']);
  4910. });
  4911. })
  4912. ->when(!empty($data['status1']), function ($query) use ($data) {
  4913. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4914. })
  4915. ->orderBy('updated_at', 'desc')
  4916. ->limit($data['page_size'])
  4917. ->offset(($data['page'] - 1) * $data['page_size'])
  4918. ->get();
  4919. $total = Notice::where($where)
  4920. ->when(!empty($data['status1']), function ($query) use ($data) {
  4921. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4922. })
  4923. // ->where('user_id', $data['user_id'])
  4924. ->Where(function ($query) use ($data) {
  4925. $query->Where(function ($q) use ($data) {
  4926. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4927. ->orWhere('notice.user_id', $data['user_id']);
  4928. });
  4929. })
  4930. ->count();
  4931. }
  4932. if (empty($result)) {
  4933. return Result::error("查询失败", 0);
  4934. }
  4935. $data = [
  4936. 'rows' => $result,
  4937. 'count' => $total,
  4938. ];
  4939. return Result::success($data);
  4940. }
  4941. public function getNoticeDetail(array $data): array
  4942. {
  4943. $result = Notice::where('id', $data['id'])->first();
  4944. if (empty($result)) {
  4945. return Result::error("查询失败", 0);
  4946. }
  4947. return Result::success($result);
  4948. }
  4949. public function deleteNotice(array $data): array
  4950. {
  4951. $notice = Notice::where('id', $data['id'])->first();
  4952. if (empty($notice)) {
  4953. return Result::error("删除失败", 0);
  4954. }
  4955. $chat_group_id = $notice->group_id;
  4956. if ($chat_group_id) {
  4957. //删除群聊
  4958. ChatGroups::where('id', $chat_group_id)->delete();
  4959. //删除群成员
  4960. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  4961. //删除群聊记录
  4962. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  4963. }
  4964. $result = Notice::where('id', $data['id'])->delete();
  4965. return Result::success($result);
  4966. }
  4967. public function complaintList(array $data): array
  4968. {
  4969. var_dump($data, '---------1---------');
  4970. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4971. unset($data['type_id']);
  4972. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4973. $where = [];
  4974. if ($type_id != 10000 && empty($data['deal_user'])) {
  4975. // $where['complaint.user_id'] = $user_id;
  4976. }
  4977. if (!empty($data['title'])) {
  4978. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4979. }
  4980. if (!empty($data['department_id'])) {
  4981. $where['complaint.department_id'] = $data['department_id'];
  4982. }
  4983. if (!empty($data['deal'])) {
  4984. $where['complaint.deal'] = $data['deal'];
  4985. }
  4986. if (!empty($data['status'])) {
  4987. $where['complaint.status'] = $data['status'];
  4988. }
  4989. var_dump(!empty($data['deal_user']), '----------1');
  4990. var_dump($where, '----------2');
  4991. $result = Complaint::where($where)
  4992. ->when(!empty($data['status1']), function ($query) use ($data) {
  4993. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4994. })
  4995. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4996. //json re_user_ids data[user_id]是不是在里面
  4997. $query->Where(function ($q) use ($data) {
  4998. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4999. ->where('complaint.status', 2);
  5000. });
  5001. })
  5002. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  5003. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  5004. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  5005. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  5006. ->orderBy('updated_at', 'desc')
  5007. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  5008. //sql输出
  5009. if (empty($result)) {
  5010. return Result::error("暂无投诉信息", 0);
  5011. }
  5012. // 取出数据
  5013. $rows = $result->items();
  5014. $count = $result->total();
  5015. $responseData = [
  5016. 'rows' => $rows,
  5017. 'count' => $count,
  5018. ];
  5019. return Result::success($responseData);
  5020. }
  5021. public function getComplaintList(array $data): array
  5022. {
  5023. var_dump($data, '00000001000000000000');
  5024. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  5025. unset($data['type_id']);
  5026. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  5027. $where = [];
  5028. if ($type_id != 10000 && empty($data['deal_user'])) {
  5029. $where['complaint.user_id'] = $user_id;
  5030. }
  5031. if (!empty($data['title'])) {
  5032. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  5033. }
  5034. if (!empty($data['department_id'])) {
  5035. $where['complaint.department_id'] = $data['department_id'];
  5036. }
  5037. if (!empty($data['deal'])) {
  5038. $where['complaint.deal'] = $data['deal'];
  5039. }
  5040. if (!empty($data['status'])) {
  5041. $where['complaint.status'] = $data['status'];
  5042. }
  5043. var_dump(!empty($data['deal_user']), '----------1');
  5044. var_dump($where, '----------2');
  5045. $result = Complaint::where($where)
  5046. ->when(!empty($data['status1']), function ($query) use ($data) {
  5047. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  5048. })
  5049. // ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  5050. // //json re_user_ids data[user_id]是不是在里面
  5051. // $query->Where(function ($q) use ($data) {
  5052. // $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  5053. // ->where('complaint.status', 2);
  5054. // });
  5055. // })
  5056. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  5057. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  5058. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  5059. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  5060. ->orderBy('updated_at', 'desc')
  5061. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  5062. //sql输出
  5063. if (empty($result)) {
  5064. return Result::error("暂无投诉信息", 0);
  5065. }
  5066. // 取出数据
  5067. $rows = $result->items();
  5068. $count = $result->total();
  5069. $responseData = [
  5070. 'rows' => $rows,
  5071. 'count' => $count,
  5072. ];
  5073. return Result::success($responseData);
  5074. }
  5075. public function getComplaintInfo(array $data): array
  5076. {
  5077. $result = Complaint::where('id', $data['id'])->first();
  5078. if (empty($result)) {
  5079. return Result::error("查询失败", 0);
  5080. }
  5081. return Result::success($result);
  5082. }
  5083. public function readComplaint(array $data): array
  5084. {
  5085. $result = Complaint::where('id', $data['id'])->first();
  5086. if (empty($result)) {
  5087. return Result::error("查询失败", 0);
  5088. }
  5089. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  5090. $re_user_ids = json_decode($result['re_user_ids'], true);
  5091. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  5092. //如果已经存在,就不再添加
  5093. if (isset($result['read_id']) && !empty($result['read_id'])) {
  5094. $read_id = json_decode($result['read_id'], true);
  5095. if (!is_array($read_id)) {
  5096. $read_id = [];
  5097. }
  5098. if (!in_array($data['user_id'], $read_id)) {
  5099. $read_id[] = $data['user_id'];
  5100. $result['read_id'] = json_encode($read_id);
  5101. Complaint::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  5102. }
  5103. } else {
  5104. //如果不存在,就添加
  5105. $result['read_id'] = json_encode([$data['user_id']]);
  5106. Complaint::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  5107. }
  5108. }
  5109. return Result::success($result);
  5110. }
  5111. public function addComplaint(array $data): array
  5112. {
  5113. date_default_timezone_set('Asia/Shanghai');
  5114. $data['created_at'] = date('Y-m-d H:i:s');
  5115. $data['updated_at'] = date('Y-m-d H:i:s');
  5116. $this->sendMessage([
  5117. 'talk_type' => 800,
  5118. 'title' => $data['title'],
  5119. 'content' => '提交了审核',
  5120. 'messageType' => 6,
  5121. ]);
  5122. $result = Complaint::create($data);
  5123. return Result::success($result);
  5124. }
  5125. public function updateComplaint(array $data): array
  5126. {
  5127. date_default_timezone_set('Asia/Shanghai');
  5128. $data['updated_at'] = date('Y-m-d H:i:s');
  5129. $user_id = $data['user_id'] ?? 0;
  5130. $type_id = $data['type_id'] ?? 0;
  5131. unset($data['user_id']);
  5132. unset($data['type_id']);
  5133. $this->sendMessage([
  5134. 'talk_type' => 800,
  5135. 'title' => $data['title'],
  5136. 'content' => '提交了审核',
  5137. 'messageType' => 6,
  5138. ]);
  5139. $result = Complaint::where('id', $data['id'])->update($data);
  5140. return Result::success($result);
  5141. }
  5142. public function deleteComplaint(array $data): array
  5143. {
  5144. $result = Complaint::where('id', $data['id'])->delete();
  5145. return Result::success($result);
  5146. }
  5147. public function getComplainInfo(array $data): array
  5148. {
  5149. $result = Complaint::where('id', $data['id'])->first();
  5150. if (empty($result)) {
  5151. return Result::error("查询失败", 0);
  5152. }
  5153. return Result::success($result);
  5154. }
  5155. public function updateComplaintStatus(array $data): array
  5156. {
  5157. date_default_timezone_set('Asia/Shanghai');
  5158. $data['updated_at'] = date('Y-m-d H:i:s');
  5159. $user_id = $data['user_id'] ?? 0;
  5160. $type_id = $data['type_id'] ?? 0;
  5161. unset($data['user_id']);
  5162. unset($data['type_id']);
  5163. //处理, 写入处理人
  5164. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  5165. $data['real_deal_user'] = $user_id;
  5166. }
  5167. //如果是deal 23,则判断是不是处理人
  5168. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  5169. $complaintInof = Complaint::where('id', $data['id'])
  5170. ->where('real_deal_user', $user_id)
  5171. ->first();
  5172. if (empty($complaintInof)) {
  5173. return Result::error("处理人错误", 0);
  5174. }
  5175. }
  5176. $complaintInfo = Complaint::where('id', $data['id'])->first();
  5177. if ($data['status'] == 1) {
  5178. $this->sendMessage([
  5179. 'talk_type' => 800,
  5180. 'title' => $complaintInfo['title'],
  5181. 'content' => '提交了审核',
  5182. 'messageType' => 6,
  5183. ]);
  5184. }
  5185. if ($data['status'] == 2 && !isset($data['deal'])) {
  5186. $this->sendMessage([
  5187. 'talk_type' => 801,
  5188. 'title' => $complaintInfo['title'],
  5189. 'content' => '审核通过',
  5190. 'messageType' => 6,
  5191. 'user_id' => $complaintInfo['user_id'],
  5192. ]);
  5193. $this->sendMessage([
  5194. 'talk_type' => 802,
  5195. 'title' => $complaintInfo['title'],
  5196. 'content' => '待处理',
  5197. 'messageType' => 6,
  5198. 'user_id' => $complaintInfo['re_user_ids'],
  5199. ]);
  5200. }
  5201. if ($data['status'] == 3 && !isset($data['deal'])) {
  5202. $this->sendMessage([
  5203. 'talk_type' => 801,
  5204. 'title' => $complaintInfo['title'],
  5205. 'content' => '审核拒绝',
  5206. 'messageType' => 6,
  5207. 'user_id' => $complaintInfo['user_id'],
  5208. ]);
  5209. }
  5210. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 2) {
  5211. $this->sendMessage([
  5212. 'talk_type' => 802,
  5213. 'title' => $complaintInfo['title'],
  5214. 'content' => '处理中',
  5215. 'messageType' => 6,
  5216. 'user_id' => $complaintInfo['re_user_ids'],
  5217. ]);
  5218. }
  5219. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 4) {
  5220. $this->sendMessage([
  5221. 'talk_type' => 802,
  5222. 'title' => $complaintInfo['title'],
  5223. 'content' => '不予处理',
  5224. 'messageType' => 6,
  5225. 'user_id' => $complaintInfo['re_user_ids'],
  5226. ]);
  5227. }
  5228. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 3) {
  5229. $this->sendMessage([
  5230. 'talk_type' => 802,
  5231. 'title' => $complaintInfo['title'],
  5232. 'content' => '已完结',
  5233. 'messageType' => 6,
  5234. 'user_id' => $complaintInfo['re_user_ids'],
  5235. ]);
  5236. }
  5237. $result = complaint::where('id', $data['id'])->update($data);
  5238. return Result::success($result);
  5239. }
  5240. public function updateGoodStatus(array $data): array
  5241. {
  5242. $user_id = $data['user_id'] ?? 0;
  5243. $type_id = $data['type_id'] ?? 0;
  5244. unset($data['user_id']);
  5245. unset($data['type_id']);
  5246. $goodInfo = Good::where('id', $data['id'])->first();
  5247. if ($data['status'] == 2) {
  5248. $this->sendMessage([
  5249. 'talk_type' => 201,
  5250. 'title' => $goodInfo['name'],
  5251. 'content' => '审核通过',
  5252. 'messageType' => 3,
  5253. 'user_id' => $goodInfo['user_id'],
  5254. ]);
  5255. }
  5256. if ($data['status'] == 3) {
  5257. $this->sendMessage([
  5258. 'talk_type' => 201,
  5259. 'title' => $goodInfo['name'],
  5260. 'content' => '审核拒绝',
  5261. 'messageType' => 3,
  5262. 'user_id' => $goodInfo['user_id'],
  5263. ]);
  5264. }
  5265. if ($data['status'] == 1) {
  5266. $this->sendMessage([
  5267. 'talk_type' => 200,
  5268. 'title' => $goodInfo['name'],
  5269. 'content' => '提交了审核',
  5270. 'messageType' => 3,
  5271. ]);
  5272. }
  5273. $result = Good::where('id', $data['id'])->update($data);
  5274. return Result::success($result);
  5275. }
  5276. public function updateJobHuntingStatus(array $data): array
  5277. {
  5278. $user_id = $data['user_id'] ?? 0;
  5279. $type_id = $data['type_id'] ?? 0;
  5280. unset($data['user_id']);
  5281. unset($data['type_id']);
  5282. $jogHuntingInfo = JobHunting::where('id', $data['id'])->first();
  5283. if ($data['status'] == 2) {
  5284. $this->sendMessage([
  5285. 'talk_type' => 601,
  5286. 'title' => $jogHuntingInfo['name'],
  5287. 'content' => '审核通过',
  5288. 'messageType' => 11,
  5289. 'user_id' => $jogHuntingInfo['user_id'],
  5290. ]);
  5291. }
  5292. if ($data['status'] == 3) {
  5293. $this->sendMessage([
  5294. 'talk_type' => 601,
  5295. 'title' => $jogHuntingInfo['name'],
  5296. 'content' => '审核拒绝',
  5297. 'messageType' => 11,
  5298. 'user_id' => $jogHuntingInfo['user_id'],
  5299. ]);
  5300. }
  5301. if ($data['status'] == 1) {
  5302. $this->sendMessage([
  5303. 'talk_type' => 600,
  5304. 'title' => $jogHuntingInfo['name'],
  5305. 'content' => '提交了审核',
  5306. 'messageType' => 11,
  5307. ]);
  5308. }
  5309. $result = JobHunting::where('id', $data['id'])->update($data);
  5310. return Result::success($result);
  5311. }
  5312. public function updateNoticeStatus(array $data): array
  5313. {
  5314. $user_id = $data['user_id'] ?? 0;
  5315. $type_id = $data['type_id'] ?? 0;
  5316. unset($data['user_id']);
  5317. unset($data['type_id']);
  5318. //查询公告
  5319. $notice = Notice::where('id', $data['id'])->first();
  5320. if (empty($notice)) {
  5321. return Result::error("公告不存在", 0);
  5322. }
  5323. //$chat_ids 去除掉$data['user_id']
  5324. $chat_ids = json_decode($notice['re_user_ids'], true);
  5325. $chat_ids = array_diff($chat_ids, [$notice['user_id']]);
  5326. //如果公告的状态是2,且是群聊公告,且状态是1,则创建群聊,第一次审核通过的时候处理成群聊
  5327. if ($data['status'] == 2 && $notice['is_group'] == 1 && ($notice['status'] == 1 || $notice['status'] == 3) && empty($notice['group_id'])) {
  5328. //chat_group
  5329. $group_id = PublicData::uuid();
  5330. $groupData = [
  5331. 'id' => $group_id,
  5332. 'creator_id' => $notice['user_id'],
  5333. 'group_name' => $notice['group_name'] ?? '',
  5334. 'profile' => $notice['profile'] ?? 0,
  5335. ];
  5336. var_dump($groupData, '-----------------groupData-------');
  5337. $groupResult = ChatGroups::insertGetId($groupData);
  5338. var_dump($groupResult, '-----------------groupid-------');
  5339. $groupMemberData = [
  5340. 'id' => PublicData::uuid(),
  5341. 'user_id' => $notice['user_id'],
  5342. 'group_id' => $group_id,
  5343. 'leader' => 2,
  5344. ];
  5345. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  5346. //插入群成员表
  5347. $groupMemberDataUser = [];
  5348. $chatData = [];
  5349. foreach ($chat_ids as $key => $value) {
  5350. $groupMemberDataUser[] = [
  5351. 'id' => PublicData::uuid(),
  5352. 'user_id' => $value,
  5353. 'group_id' => $group_id,
  5354. 'leader' => 1,
  5355. ];
  5356. $chatData[] = [
  5357. 'user_id' => $value,
  5358. 'msg_type' => 1,
  5359. 'receiver_id' => $group_id,
  5360. 'content' => '通过通知创建群聊',
  5361. 'group_receiver_id' => $notice['user_id'],
  5362. 'action' => 'recieved',
  5363. 'created_at' => date('Y-m-d H:i:s'),
  5364. ];
  5365. }
  5366. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  5367. ChatGroupsMember::insert($groupMemberDataUser);
  5368. //插入一条管理员聊天记录
  5369. $chatData[] = [
  5370. 'user_id' => $notice['user_id'],
  5371. 'msg_type' => 1,
  5372. 'receiver_id' => $group_id,
  5373. 'content' => '通过通知创建群聊',
  5374. 'group_receiver_id' => $notice['user_id'],
  5375. 'action' => 'said',
  5376. 'created_at' => date('Y-m-d H:i:s'),
  5377. ];
  5378. var_dump($chatData, '-----------------chatData-------');
  5379. $chatResult = ChatRecords::insert($chatData);
  5380. //处理imp
  5381. $group = [
  5382. 'type' => 1,
  5383. 'name' => $notice['group_name'] ?? '',
  5384. 'profile' => '',
  5385. 'avatar' => '',
  5386. 'creator_id' => $notice['user_id'],
  5387. ];
  5388. $groupResult = GroupImp::insertGetId($group);
  5389. var_dump($groupResult, '获取imp group_id');
  5390. $groupMember = [
  5391. 'user_id' => $notice['user_id'],
  5392. 'group_id' => $groupResult,
  5393. 'leader' => 1,
  5394. 'join_time' => Date('Y-m-d H:i:s')
  5395. ];
  5396. $groupMemberResult = GroupMemberImp::insertGetId($groupMember);
  5397. $talk_session = [
  5398. 'user_id' => $notice['user_id'],
  5399. 'to_from_id' => $groupResult,
  5400. 'talk_mode' => 2,
  5401. 'created_at' => Date('Y-m-d H:i:s'),
  5402. 'updated_at' => Date('Y-m-d H:i:s'),
  5403. ];
  5404. $talk_session_result = GroupTalkImp::insertGetId($talk_session);
  5405. //被通知人员处理
  5406. foreach ($chat_ids as $key => $value) {
  5407. $groupMemberdata[] = [
  5408. 'user_id' => $value,
  5409. 'group_id' => $groupResult,
  5410. 'leader' => 3,
  5411. 'join_time' => Date('Y-m-d H:i:s')
  5412. ];
  5413. $talk_sessionData[] = [
  5414. 'user_id' => $value,
  5415. 'to_from_id' => $groupResult,
  5416. 'talk_mode' => 2,
  5417. 'created_at' => Date('Y-m-d H:i:s'),
  5418. 'updated_at' => Date('Y-m-d H:i:s'),
  5419. ];
  5420. }
  5421. $groupResult1 = GroupMemberImp::insert($groupMemberdata);
  5422. $talk_sessionResult = GroupTalkImp::insert($talk_sessionData);
  5423. $group_id = $groupResult;
  5424. //更新result的 group_id
  5425. $data['group_id'] = $group_id;
  5426. Notice::where(['id' => $data['id']])->update($data);
  5427. }
  5428. if (($data['status'] == 1 || $data['status'] == 3) && $notice['is_group'] == 1 && $notice['status'] == 2 && !empty($notice['group_id'])) {
  5429. //删除掉信息
  5430. GroupImp::where('id', $notice['group_id'])->delete();
  5431. GroupMemberImp::where('group_id', $notice['group_id'])->delete();
  5432. GroupTalkImp::where('to_from_id', $notice['group_id'])->delete();
  5433. foreach ($chat_ids as $key => $value) {
  5434. }
  5435. //聊天记录删除
  5436. //如果是群聊公告,且已经有群聊id,则更新公告的group_id
  5437. $data['group_id'] = null;
  5438. Notice::where(['id' => $data['id']])->update($data);
  5439. }
  5440. $result = Notice::where('id', $data['id'])->update($data);
  5441. $noticeInfo = Notice::where('id', $data['id'])->first();
  5442. if ($data['status'] == 2) {
  5443. $this->sendMessage([
  5444. 'talk_type' => 701,
  5445. 'title' => $noticeInfo['title'],
  5446. 'content' => '审核通过',
  5447. 'messageType' => 3,
  5448. 'user_id' => $noticeInfo['user_id'],
  5449. ]);
  5450. }
  5451. if ($data['status'] == 3) {
  5452. $this->sendMessage([
  5453. 'talk_type' => 701,
  5454. 'title' => $noticeInfo['title'],
  5455. 'content' => '审核拒绝',
  5456. 'messageType' => 3,
  5457. 'user_id' => $noticeInfo['user_id'],
  5458. ]);
  5459. }
  5460. if ($data['status'] == 1) {
  5461. $this->sendMessage([
  5462. 'talk_type' => 700,
  5463. 'title' => $noticeInfo['title'],
  5464. 'content' => '提交了审核',
  5465. 'messageType' => 3,
  5466. ]);
  5467. }
  5468. return Result::success($result);
  5469. }
  5470. public function getDUser(array $data): array
  5471. {
  5472. if (!empty($data['ids'])) {
  5473. $user = User::whereIn('id', $data['ids'])->getall();
  5474. if (empty($user)) {
  5475. return Result::error('无数据', 0);
  5476. }
  5477. return Result::success($user);
  5478. }
  5479. $where = [];
  5480. if (!empty($data['department_id'])) {
  5481. $where['department_id'] = $data['department_id'];
  5482. }
  5483. if (!empty($data['city_id'])) {
  5484. $where['city_id'] = $data['city_id'];
  5485. }
  5486. $result = User::where('type_id', 2)
  5487. ->where('status', 1)
  5488. ->where($where)
  5489. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  5490. ->get();
  5491. if (empty($result)) {
  5492. return Result::error("查询失败", 0);
  5493. }
  5494. return Result::success($result);
  5495. }
  5496. /**
  5497. * 验证导航名称是否重复
  5498. * @return void
  5499. */
  5500. public function checkCategoryName(array $data): array
  5501. {
  5502. $result = Category::when($data, function ($query) use ($data) {
  5503. if (isset($data['name']) && $data['name']) {
  5504. $query->where("name", $data['name']);
  5505. }
  5506. if (isset($data['id']) && $data['id']) {
  5507. $query->where("id", "!=", $data['id']);
  5508. }
  5509. })->first();
  5510. if ($result) {
  5511. return Result::error("已存在");
  5512. } else {
  5513. return Result::success();
  5514. }
  5515. }
  5516. //20250226 产品列表
  5517. // 20250306 -------招聘--------fr
  5518. /*
  5519. * 招聘列表
  5520. * */
  5521. public function getJobRecruitingList(array $data): array
  5522. {
  5523. $where = [];
  5524. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  5525. if ($data['checkout'] == 0) {
  5526. $job_status = [0, 2];
  5527. } else {
  5528. $job_status = [1];
  5529. }
  5530. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5531. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  5532. }
  5533. $user = User::where('id', $data['user_id'])->first();
  5534. if (empty($user)) {
  5535. return Result::error("用户不存在", 0);
  5536. }
  5537. // 3:企业会员
  5538. if ($user['type_id'] == 3) {
  5539. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  5540. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  5541. }
  5542. // 如果 $where 为空,则不添加 where 条件
  5543. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5544. return $query->where($where);
  5545. })
  5546. ->whereIn('job_recruiting.status', $job_status)
  5547. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5548. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  5549. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  5550. ->orderBy("updated_at", "desc")
  5551. ->offset(($data['page'] - 1) * $data['page_size'])
  5552. ->limit($data['page_size'])
  5553. ->get()
  5554. ->all();
  5555. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5556. return $query->where($where);
  5557. })
  5558. ->whereIn('job_recruiting.status', $job_status)
  5559. ->count();
  5560. if (empty($result)) {
  5561. return Result::error("暂无招聘信息", 0);
  5562. }
  5563. return Result::success($result);
  5564. }
  5565. /*
  5566. * 招聘信息添加
  5567. * */
  5568. public function addJobRecruiting(array $data): array
  5569. {
  5570. // var_dump('添加招聘进入news------data',$data);
  5571. // return Result::success($data);
  5572. $user = User::where('user.id', $data['user_id'])
  5573. ->where('user.status', 1)
  5574. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5575. ->select(
  5576. 'user.type_id',
  5577. 'user.mobile',
  5578. 'user.email',
  5579. 'user_info.business_name',
  5580. 'user_info.company_hy_id',
  5581. 'user_info.company_nature',
  5582. 'user_info.company_size',
  5583. 'user_info.introduction',
  5584. 'user_info.real_name',
  5585. 'user_info.company_url',
  5586. 'user_info.address_arr_id',
  5587. 'user_info.address'
  5588. )
  5589. ->first();
  5590. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5591. return Result::error("用户不存在", 0);
  5592. }
  5593. $web = Website::where('id', $data['website_id'])->first();
  5594. if (empty($web)) {
  5595. return Result::error("网站不存在", 0);
  5596. }
  5597. // var_dump('添加招聘进入news---user---user',$user);
  5598. // 处理招聘关键词
  5599. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5600. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5601. } else {
  5602. Jieba::init(); // 初始化 jieba-php
  5603. Finalseg::init();
  5604. $segList = Jieba::cut($data['title']);
  5605. $segList1 = array_slice($segList, 0, 8);
  5606. $data['keyword'] = implode(',', $segList1);
  5607. }
  5608. if (!isset($data['seo_description']) || empty($data['seo_description'])) {
  5609. $content = $data['description'];
  5610. // 去除 <style> 和 <script> 标签及其内容
  5611. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5612. // 去除所有 HTML 标签
  5613. $content = strip_tags($content);
  5614. // 去除 HTML 实体
  5615. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5616. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5617. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5618. // 去除多余空白
  5619. $content = preg_replace('/\s+/u', '', $content);
  5620. // 截取 100 个字符
  5621. $data['seo_description'] = mb_substr($content, 0, 100);
  5622. }
  5623. // return Result::success($user);
  5624. $data['action_id'] = $data['user_id'] ?? null;
  5625. $data['user_type'] = $user['type_id'] ?? null;
  5626. $data['cat_arr_id'] = isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) ? array_values(array_unique($data['cat_arr_id'])) : [];
  5627. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5628. $data['catid'] = end($data['cat_arr_id']);
  5629. } else {
  5630. $data['catid'] = 0;
  5631. }
  5632. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? array_values(array_unique($data['city_arr_id'])) : [];
  5633. $data['cat_arr_id'] = isset($data['cat_arr_id']) && $data['cat_arr_id'] != [] ? json_encode(array_map('intval', $data['cat_arr_id'])) : '[]';
  5634. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '[]';
  5635. // 公司地址 管理员必填
  5636. $data['address_arr_id'] = isset($data['address_arr_id']) && !empty($data['address_arr_id']) ? array_values(array_unique($data['address_arr_id'])) : [];
  5637. $data['address_arr_id'] = isset($data['address_arr_id']) && $data['address_arr_id'] != [] ? json_encode(array_map('intval', $data['address_arr_id'])) : '[]';
  5638. // 管理员-企业相关信息
  5639. $company = [
  5640. // 'user_id' => $data['user_id']?? null,
  5641. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5642. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5643. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5644. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5645. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5646. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5647. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5648. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5649. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5650. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5651. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5652. ];
  5653. //去掉相关企业信息
  5654. $job = array_diff_key($data, array_flip(array_keys($company)));
  5655. // var_dump('添加招聘进入news---job---user',$job);
  5656. Db::beginTransaction();
  5657. try {
  5658. // // 先添加职位相关信息
  5659. if ($user['type_id'] == 10000) {
  5660. $job['status'] = 1;
  5661. }
  5662. $job['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5663. $job['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5664. $job['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5665. $job['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5666. $job['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5667. $job['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5668. $job['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5669. // return Result::success($job);
  5670. $jobId = JobRecruiting::insertGetId($job);
  5671. if (empty($jobId)) {
  5672. Db::rollBack();
  5673. return Result::error("添加失败");
  5674. }
  5675. // 添加公司信息
  5676. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5677. $company['job_id'] = $jobId;
  5678. $company['user_type'] = isset($user['type_id']) && $user['type_id'] !== '' ? $user['type_id'] : null;
  5679. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5680. if ($user['type_id'] == 10000) {
  5681. // 管理员添加企业信息
  5682. $companyId = JobCompany::insertGetId($company);
  5683. if (empty($companyId)) {
  5684. Db::rollBack();
  5685. return Result::error("添加失败");
  5686. }
  5687. } else {
  5688. // 企业会员添加企业信息
  5689. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5690. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5691. $company['user_type'] = isset($data['user_type']) && $data['user_type'] !== '' ? $data['user_type'] : null;
  5692. $company['job_id'] = $jobId;
  5693. $companyId = JobCompany::insertGetId($company);
  5694. if (empty($companyId)) {
  5695. Db::rollBack();
  5696. return Result::error("添加失败");
  5697. }
  5698. }
  5699. Db::commit();
  5700. $result = [
  5701. 'job_id' => $jobId,
  5702. 'company_id' => $companyId,
  5703. ];
  5704. return Result::success($result);
  5705. } catch (\Exception $e) {
  5706. Db::rollBack();
  5707. return Result::error($e->getMessage(), 0);
  5708. }
  5709. // return Result::success($result);
  5710. }
  5711. /*
  5712. * 获取招聘信息详情
  5713. * */
  5714. public function getJobRecruitingInfo(array $data): array
  5715. {
  5716. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  5717. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5718. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5719. ->select(
  5720. 'job_recruiting.*',
  5721. 'website.website_name as website_name',
  5722. 'job_company.business_name',
  5723. 'job_company.company_hy_id',
  5724. 'job_company.company_size',
  5725. 'job_company.company_nature',
  5726. 'job_company.introduction',
  5727. 'job_company.real_name',
  5728. 'job_company.mobile',
  5729. 'job_company.company_url',
  5730. 'job_company.address_arr_id',
  5731. 'job_company.address',
  5732. 'job_company.email'
  5733. )
  5734. ->first();
  5735. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  5736. if (!empty($cityId)) {
  5737. if (isset($cityId[1]) && $cityId[1] != null) {
  5738. $city = District::where('id', $cityId[1])->first(['name']);
  5739. } else {
  5740. $city = District::where('id', $cityId[0])->first(['name']);
  5741. }
  5742. $result['city'] = $city['name'] ?? '';
  5743. }
  5744. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  5745. if (is_array($addressId) && !empty($addressId)) {
  5746. $address = District::whereIn('id', $addressId)
  5747. ->orderBy('level', 'asc')
  5748. ->get(['name'])
  5749. ->pluck('name')
  5750. ->implode('');
  5751. // $job->address_name = $address ?? '';
  5752. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  5753. }
  5754. if (empty($result)) {
  5755. return Result::error("招聘信息不存在", 0);
  5756. }
  5757. // return Result::success($job);
  5758. return Result::success($result);
  5759. }
  5760. /*
  5761. * 修改招聘信息
  5762. * */
  5763. public function upJobRecruiting(array $data): array
  5764. {
  5765. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  5766. // return Result::success($job);
  5767. if (empty($job)) {
  5768. return Result::error("招聘信息不存在", 0);
  5769. }
  5770. $user = User::where('id', $data['user_id'])->first();
  5771. // return Result::success($user);
  5772. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5773. return Result::error("用户不存在", 0);
  5774. }
  5775. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5776. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5777. }
  5778. // 处理招聘关键词
  5779. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5780. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5781. } else {
  5782. Jieba::init(); // 初始化 jieba-php
  5783. Finalseg::init();
  5784. $segList = Jieba::cut($data['title']);
  5785. $segList1 = array_slice($segList, 0, 8);
  5786. $data['keyword'] = implode(',', $segList1);
  5787. }
  5788. if (!isset($data['seo_description']) || empty($data['seo_description'])) {
  5789. $content = $data['description'];
  5790. // 去除 <style> 和 <script> 标签及其内容
  5791. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5792. // 去除所有 HTML 标签
  5793. $content = strip_tags($content);
  5794. // 去除 HTML 实体
  5795. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5796. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5797. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5798. // 去除多余空白
  5799. $content = preg_replace('/\s+/u', '', $content);
  5800. // 截取 100 个字符
  5801. $data['seo_description'] = mb_substr($content, 0, 100);
  5802. }
  5803. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  5804. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5805. $data['catid'] = end($data['cat_arr_id']);
  5806. } else {
  5807. }
  5808. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  5809. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  5810. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  5811. // 公司地址 管理员必填
  5812. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  5813. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5814. // 管理员-企业相关信息
  5815. $company = [
  5816. // 'user_id' => $data['user_id']?? null,
  5817. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5818. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5819. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5820. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5821. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5822. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5823. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5824. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5825. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5826. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5827. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5828. ];
  5829. //去掉相关企业信息
  5830. $data = array_diff_key($data, array_flip(array_keys($company)));
  5831. $jobId = $data['id'];
  5832. $web = $data['website_id'];
  5833. $data['action_id'] = $data['user_id'];
  5834. unset($data['user_id']);
  5835. unset($data['user_type']);
  5836. unset($data['id']);
  5837. unset($data['website_id']);
  5838. // return Result::success($data);
  5839. Db::beginTransaction();
  5840. try {
  5841. // 管理员修改招聘信息
  5842. if ($user['type_id'] == 10000) {
  5843. $data['website_id'] = $web;
  5844. $company['website_id'] = $data['website_id'];
  5845. $data['status'] = 1;
  5846. } else {
  5847. $data['status'] = 0;
  5848. }
  5849. $data['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5850. $data['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5851. $data['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5852. $data['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5853. $data['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5854. $data['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5855. $data['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5856. // return Result::success($job);
  5857. // Db::rollBack();
  5858. // return Result::success($company);
  5859. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  5860. $this->sendMessage([
  5861. 'talk_type' => 500,
  5862. 'title' => $data['title'],
  5863. 'content' => '提交了审核',
  5864. 'messageType' => 10,
  5865. ]);
  5866. }
  5867. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  5868. if (empty($result['job'])) {
  5869. Db::rollBack();
  5870. return Result::error("修改招聘信息失败");
  5871. }
  5872. // 管理员修改企业相关信息
  5873. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  5874. if (empty($result['company'])) {
  5875. Db::rollBack();
  5876. return Result::error("修改企业相关信息失败");
  5877. }
  5878. Db::commit();
  5879. // return Result::success($result);
  5880. } catch (\Exception $e) {
  5881. Db::rollBack();
  5882. return Result::error($e->getMessage(), 0);
  5883. }
  5884. return Result::success($result);
  5885. }
  5886. /*
  5887. * 招聘信息删除
  5888. * */
  5889. public function delJobRecruiting(array $data): array
  5890. {
  5891. $user = User::where('id', $data['user_id'])->first();
  5892. if (empty($user)) {
  5893. return Result::error("用户不存在", 0);
  5894. }
  5895. $job = JobRecruiting::where('id', $data['id'])->first();
  5896. if (empty($job)) {
  5897. return Result::error("招聘信息不存在", 0);
  5898. }
  5899. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5900. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5901. }
  5902. Db::beginTransaction();
  5903. try {
  5904. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  5905. if (empty($result['job'])) {
  5906. Db::rollBack();
  5907. return Result::error("删除招聘信息失败");
  5908. }
  5909. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  5910. if (empty($result['company'])) {
  5911. Db::rollBack();
  5912. return Result::error("删除企业相关信息失败");
  5913. }
  5914. Db::commit();
  5915. } catch (\Exception $e) {
  5916. Db::rollBack();
  5917. return Result::error($e->getMessage(), 0);
  5918. }
  5919. return Result::success($result);
  5920. }
  5921. /*
  5922. * 获取公司信息
  5923. * */
  5924. public function getJobCompany(array $data): array
  5925. {
  5926. $user = User::where('user.id', $data['user_id'])
  5927. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5928. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  5929. ->first();
  5930. // return Result::success($user);
  5931. if (empty($user)) {
  5932. return Result::error("用户不存在", 0);
  5933. }
  5934. if ($user['type_id'] == 3) {
  5935. $result = [
  5936. // 'id' => 0,
  5937. 'user_id' => $data['user_id'],
  5938. 'website_id' => $data['website_id'],
  5939. 'business_name' => $user['business_name'], // 企业名称
  5940. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  5941. 'company_nature' => $user['company_nature'], // 公司性质
  5942. 'company_size' => $user['company_size'], // 公司规模
  5943. 'introduction' => $user['introduction'], // 公司简介
  5944. 'real_name' => $user['real_name'], // 企业联系人
  5945. 'mobile' => $user['mobile'], // 企业联系电话
  5946. 'company_url' => $user['company_url'], // 企业网址
  5947. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  5948. 'address' => $user['address'], // 企业地址
  5949. 'email' => $user['email'], // 企业邮箱
  5950. ];
  5951. } else {
  5952. return Result::error("用户类型错误", 0);
  5953. }
  5954. if (empty($result)) {
  5955. return Result::error("公司信息不存在", 0);
  5956. }
  5957. return Result::success($result);
  5958. }
  5959. /*
  5960. * 修改公司信息
  5961. * */
  5962. public function upJobCompany(array $data): array
  5963. {
  5964. // return Result::success($data);
  5965. $user = User::where('user.id', $data['user_id'])
  5966. ->where('user.status', 1)
  5967. ->select('user.user_name', 'user.type_id')
  5968. ->first();
  5969. if (empty($user)) {
  5970. return Result::error("用户不存在", 0);
  5971. }
  5972. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5973. $job_company = JobCompany::where('user_id', $data['user_id'])->first();
  5974. $company = [
  5975. 'business_name' => $data['business_name'], // 企业名称
  5976. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5977. 'company_nature' => $data['company_nature'], // 公司性质
  5978. 'company_size' => $data['company_size'], // 公司规模
  5979. 'introduction' => $data['introduction'], // 公司简介
  5980. // 'real_name' => $data['real_name'], // 企业联系人
  5981. 'company_url' => $data['company_url'], // 企业网址
  5982. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5983. 'address' => $data['address'], // 企业详细地址
  5984. // 'email' => $data['email'], // 企业邮箱
  5985. ];
  5986. if ($user['type_id'] == 3) {
  5987. Db::beginTransaction();
  5988. try {
  5989. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  5990. 'business_name' => $data['business_name'], // 企业名称
  5991. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5992. 'company_nature' => $data['company_nature'], // 公司性质
  5993. 'company_size' => $data['company_size'], // 公司规模
  5994. 'introduction' => $data['introduction'], // 公司简介
  5995. // 'real_name' => $data['real_name'], // 企业联系人
  5996. 'company_url' => $data['company_url'], // 企业网址
  5997. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5998. 'address' => $data['address'], // 企业详细地址
  5999. ]);
  6000. if (empty($result['userinfo'])) {
  6001. Db::rollBack();
  6002. return Result::error('修改企业会员信息失败!');
  6003. }
  6004. $result['user'] = User::where('id', $data['user_id'])->update([
  6005. 'email' => $data['email'], // 企业邮箱
  6006. ]);
  6007. if (empty($result['user'])) {
  6008. Db::rollBack();
  6009. return Result::error('修改个人中心信息失败!');
  6010. }
  6011. // 该企业会员若是未发布招聘信息则暂无该企业会员的企业信息
  6012. if (!empty($job_company)) {
  6013. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  6014. if (empty($result['job_company'])) {
  6015. Db::rollBack();
  6016. return Result::error('修改企业会员信息失败!');
  6017. }
  6018. }
  6019. Db::commit();
  6020. return Result::success($result);
  6021. } catch (\Exception $e) {
  6022. Db::rollBack();
  6023. return Result::error($e->getMessage(), 0);
  6024. }
  6025. } else {
  6026. return Result::error("用户类型错误", 0);
  6027. }
  6028. }
  6029. /*
  6030. * 获取省-市
  6031. * */
  6032. public function getJobRecruitingArea(array $data): array
  6033. {
  6034. if (isset($data['pid']) && $data['pid'] != null) {
  6035. $result = District::where('pid', $data['pid'])->get()->all();
  6036. } else {
  6037. $result = District::where('level', 1)->get()->all();
  6038. }
  6039. if (empty($result)) {
  6040. return Result::error("暂无此省市", 0);
  6041. }
  6042. return Result::success($result);
  6043. }
  6044. /*
  6045. * 获取行业分类
  6046. * */
  6047. public function getIndustry(array $data): array
  6048. {
  6049. $result = JobIndustry::get()->all();
  6050. if (empty($result)) {
  6051. return Result::error("暂无行业分类", 0);
  6052. }
  6053. return Result::success($result);
  6054. }
  6055. /*
  6056. * 获取职位
  6057. * */
  6058. public function getPositionList(array $data): array
  6059. {
  6060. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  6061. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  6062. } else {
  6063. $result = JobPosition::where('zwpid', 0)->get()->all();
  6064. }
  6065. if (empty($result)) {
  6066. return Result::error("暂无此职位", 0);
  6067. }
  6068. return Result::success($result);
  6069. }
  6070. /*
  6071. * 获取工作性质-菜单
  6072. * */
  6073. public function getJobNature(array $data): array
  6074. {
  6075. $result = JobEnum::where('egroup', 'nature')->get()->all();
  6076. if (empty($result)) {
  6077. return Result::error("暂无工作性质", 0);
  6078. }
  6079. return Result::success($result);
  6080. }
  6081. /*
  6082. * 获取工作经验-菜单
  6083. * */
  6084. public function getExperience(array $data): array
  6085. {
  6086. $result = JobEnum::where('egroup', 'years')->get()->all();
  6087. if (empty($result)) {
  6088. return Result::error("暂无工作经验", 0);
  6089. }
  6090. return Result::success($result);
  6091. }
  6092. /*
  6093. * 获取学历-菜单
  6094. * */
  6095. public function getEducation(array $data): array
  6096. {
  6097. $result = JobEnum::where('egroup', 'education')->get()->all();
  6098. if (empty($result)) {
  6099. return Result::error("暂无学历", 0);
  6100. }
  6101. return Result::success($result);
  6102. }
  6103. /*
  6104. * 获取薪资-菜单
  6105. * */
  6106. public function getSalary(array $data): array
  6107. {
  6108. $result = JobEnum::where('egroup', 'income')->get()->all();
  6109. if (empty($result)) {
  6110. return Result::error("暂无薪资", 0);
  6111. }
  6112. return Result::success($result);
  6113. }
  6114. /*
  6115. * 获取语言-菜单
  6116. * */
  6117. public function getLanguage(array $data): array
  6118. {
  6119. $result = JobEnum::where('egroup', 'language')->get()->all();
  6120. if (empty($result)) {
  6121. return Result::error("暂无语言", 0);
  6122. }
  6123. return Result::success($result);
  6124. }
  6125. /*
  6126. * 获取掌握程度-菜单
  6127. * */
  6128. public function getLevel(array $data): array
  6129. {
  6130. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  6131. if (empty($result)) {
  6132. return Result::error("暂无工作性质", 0);
  6133. }
  6134. return Result::success($result);
  6135. }
  6136. // 公司信息
  6137. /*
  6138. * 获取公司性质-菜单
  6139. * */
  6140. public function getCompanyNature(array $data): array
  6141. {
  6142. $result = JobNature::get()->all();
  6143. if (empty($result)) {
  6144. return Result::error("暂无公司性质", 0);
  6145. }
  6146. return Result::success($result);
  6147. }
  6148. /*
  6149. * 获取公司规模-菜单
  6150. * */
  6151. public function getCompanySize(array $data): array
  6152. {
  6153. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  6154. if (empty($result)) {
  6155. return Result::error("暂无公司规模", 0);
  6156. }
  6157. return Result::success($result);
  6158. }
  6159. /*
  6160. * 招聘信息审核
  6161. * */
  6162. public function checkJobRecruiting(array $data): array
  6163. {
  6164. $user = User::where('id', $data['user_id'])->first();
  6165. if (empty($user)) {
  6166. return Result::error("用户不存在", 0);
  6167. }
  6168. $job = JobRecruiting::where('id', $data['id'])->first();
  6169. if (empty($job)) {
  6170. return Result::error("招聘信息不存在", 0);
  6171. }
  6172. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  6173. if ($user['type_id'] != 10000) {
  6174. return Result::error("用户暂无权限审核此招聘信息!", 0);
  6175. }
  6176. // 驳回原因
  6177. if ($data['status'] == 2) {
  6178. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  6179. }
  6180. $data['action_id'] = $data['user_id'];
  6181. unset($data['user_id']);
  6182. if ($data['status'] == 1) {
  6183. $this->sendMessage([
  6184. 'talk_type' => 501,
  6185. 'title' => $job['title'],
  6186. 'content' => '审核通过',
  6187. 'messageType' => 10,
  6188. 'user_id' => $job['user_id'],
  6189. ]);
  6190. }
  6191. if ($data['status'] == 2) {
  6192. $this->sendMessage([
  6193. 'talk_type' => 501,
  6194. 'title' => $job['title'],
  6195. 'content' => '审核拒绝',
  6196. 'messageType' => 10,
  6197. 'user_id' => $job['user_id'],
  6198. ]);
  6199. }
  6200. if ($data['status'] == 0) {
  6201. $this->sendMessage([
  6202. 'talk_type' => 500,
  6203. 'title' => $job['title'],
  6204. 'content' => '提交了审核',
  6205. 'messageType' => 10,
  6206. ]);
  6207. }
  6208. $result = JobRecruiting::where('id', $data['id'])->update($data);
  6209. if (empty($result)) {
  6210. return Result::error("审核失败", 0);
  6211. }
  6212. return Result::success($result);
  6213. }
  6214. public function myApplyList(array $data): array
  6215. {
  6216. var_dump($data, '------参数');
  6217. $user = User::where('id', $data['user_id'])->first();
  6218. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6219. return Result::error("用户不存在", 0);
  6220. }
  6221. // 1:个人会员 职场机会
  6222. if ($user['type_id'] == 1) {
  6223. $where['user_id'] = $user['id'];
  6224. }
  6225. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  6226. $query->where('user_id', $user['id']);
  6227. })
  6228. ->pluck('recruit_id');
  6229. $where = [];
  6230. if (isset($data['salary']) && $data['salary'] != null) {
  6231. $where['job_recruiting.salary'] = $data['salary'];
  6232. }
  6233. if (isset($data['experience']) && $data['experience'] != null) {
  6234. $where['job_recruiting.experience'] = $data['experience'];
  6235. }
  6236. if (isset($data['business_name']) && $data['business_name'] != null) {
  6237. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6238. }
  6239. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6240. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6241. ->where($where);
  6242. // ->count();
  6243. $count = $query->count();
  6244. $query = clone $query;
  6245. $job = $query
  6246. ->leftJoin('job_enum as income_enum', function ($join) {
  6247. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6248. ->where('income_enum.egroup', 'income');
  6249. })
  6250. ->leftJoin('job_enum as years_enum', function ($join) {
  6251. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6252. ->where('years_enum.egroup', 'years');
  6253. })
  6254. // ->where($where)
  6255. ->orderBy('job_recruiting.updated_at', 'desc')
  6256. ->select(
  6257. 'job_recruiting.id',
  6258. 'job_recruiting.title',
  6259. 'job_company.business_name',
  6260. 'income_enum.evalue as salary_evalue',
  6261. 'income_enum.ename as salary_ename',
  6262. 'years_enum.evalue as experience_evalue',
  6263. 'years_enum.ename as experience_ename',
  6264. 'job_recruiting.updated_at'
  6265. )
  6266. ->offset(($data['page'] - 1) * $data['pageSize'])
  6267. ->limit($data['pageSize'])
  6268. ->get()
  6269. ->all();
  6270. if (empty($job)) {
  6271. return Result::error("暂无招聘信息", 0);
  6272. }
  6273. $result = [
  6274. 'row' => $job,
  6275. 'count' => $count,
  6276. ];
  6277. return Result::success($result);
  6278. }
  6279. public function readJobApply(array $data): array
  6280. {
  6281. $result = JobApply::where('id', $data['id'])->first();
  6282. if (empty($result)) {
  6283. return Result::error("查询失败", 0);
  6284. }
  6285. $result = JobApply::where('id', $data['id'])->update([
  6286. 'status' => 2,
  6287. ]);
  6288. return Result::success($result);
  6289. }
  6290. /*
  6291. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  6292. * */
  6293. public function getRecruitingList(array $data): array
  6294. {
  6295. $user = User::where('id', $data['user_id'])->first();
  6296. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6297. return Result::error("用户不存在", 0);
  6298. }
  6299. // 1:个人会员 职场机会
  6300. if ($user['type_id'] == 1) {
  6301. $where['user_id'] = $user['id'];
  6302. }
  6303. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  6304. $query->where('receiver_id', $user['id']);
  6305. })
  6306. ->pluck('recruit_id');
  6307. // return Result::success($recruitingId);
  6308. $where = [];
  6309. if (isset($data['salary']) && $data['salary'] != null) {
  6310. $where['job_recruiting.salary'] = $data['salary'];
  6311. }
  6312. if (isset($data['experience']) && $data['experience'] != null) {
  6313. $where['job_recruiting.experience'] = $data['experience'];
  6314. }
  6315. if (isset($data['business_name']) && $data['business_name'] != null) {
  6316. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6317. }
  6318. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6319. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6320. ->where($where);
  6321. // ->count();
  6322. $count = $query->count();
  6323. $query = clone $query;
  6324. $job = $query
  6325. ->leftJoin('job_enum as income_enum', function ($join) {
  6326. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6327. ->where('income_enum.egroup', 'income');
  6328. })
  6329. ->leftJoin('job_enum as years_enum', function ($join) {
  6330. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6331. ->where('years_enum.egroup', 'years');
  6332. })
  6333. // ->where($where)
  6334. ->orderBy('job_recruiting.updated_at', 'desc')
  6335. ->select(
  6336. 'job_recruiting.id',
  6337. 'job_recruiting.title',
  6338. 'job_company.business_name',
  6339. 'income_enum.evalue as salary_evalue',
  6340. 'income_enum.ename as salary_ename',
  6341. 'years_enum.evalue as experience_evalue',
  6342. 'years_enum.ename as experience_ename',
  6343. 'job_recruiting.updated_at'
  6344. )
  6345. ->offset(($data['page'] - 1) * $data['pageSize'])
  6346. ->limit($data['pageSize'])
  6347. ->get()
  6348. ->all();
  6349. if (empty($job)) {
  6350. return Result::error("暂无招聘信息", 0);
  6351. }
  6352. $result = [
  6353. 'row' => $job,
  6354. 'count' => $count,
  6355. ];
  6356. return Result::success($result);
  6357. }
  6358. /*
  6359. * 获取企业会员-招聘信息列表
  6360. * */
  6361. public function getRecruitingInfo(array $data): array
  6362. {
  6363. $user = User::where('id', $data['user_id'])->first();
  6364. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6365. return Result::error("用户不存在", 0);
  6366. }
  6367. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  6368. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6369. ->select(
  6370. 'job_recruiting.*',
  6371. 'job_company.business_name',
  6372. 'job_company.company_hy_id',
  6373. 'job_company.company_size',
  6374. 'job_company.company_nature',
  6375. 'job_company.introduction',
  6376. 'job_company.real_name',
  6377. 'job_company.mobile',
  6378. 'job_company.company_url',
  6379. 'job_company.address_arr_id',
  6380. 'job_company.address',
  6381. 'job_company.email'
  6382. )
  6383. ->get();
  6384. if (empty($recruiting)) {
  6385. return Result::error("暂无招聘信息", 0);
  6386. }
  6387. return Result::success($recruiting);
  6388. }
  6389. /*
  6390. * 获取企业会员-我的沟通
  6391. * */
  6392. public function getJobResumeList(array $data): array
  6393. {
  6394. $user = User::where('id', $data['user_id'])->first();
  6395. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  6396. return Result::error("用户不存在", 0);
  6397. }
  6398. $where = [];
  6399. if (isset($data['salary']) && $data['salary'] != null) {
  6400. $where['job_hunting.salary'] = $data['salary'];
  6401. }
  6402. if (isset($data['user_name']) && $data['user_name'] != null) {
  6403. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  6404. }
  6405. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  6406. $query->where('job_resume.user_id', $user['id']);
  6407. })
  6408. ->when(!empty($where), function ($query) use ($where) {
  6409. $query->where($where);
  6410. })
  6411. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  6412. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  6413. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  6414. ->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');
  6415. $count = $job->count();
  6416. if ($count == 0) {
  6417. return Result::error("暂无沟通记录", 0);
  6418. }
  6419. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  6420. ->offset(($data['page'] - 1) * $data['pageSize'])
  6421. ->limit($data['pageSize'])
  6422. ->get();
  6423. if (empty($jobs)) {
  6424. return Result::error("暂无沟通记录", 0);
  6425. }
  6426. $result['row'] = $this->processJob($jobs, '');
  6427. $result['count'] = $count;
  6428. return Result::success($result);
  6429. }
  6430. public function readJobResume(array $data): array
  6431. {
  6432. $result = JobResume::where('id', $data['id'])->first();
  6433. if (empty($result)) {
  6434. return Result::error("查询失败", 0);
  6435. }
  6436. $result = JobResume::where('id', $data['id'])->update([
  6437. 'status' => 2,
  6438. ]);
  6439. return Result::success($result);
  6440. }
  6441. // 20250306 招聘
  6442. //20250422 书刊音像
  6443. public function addBook(array $data): array
  6444. {
  6445. $user_id = $data['user_id'] ?? 0;
  6446. $type_id = $data['type_id'] ?? 0;
  6447. // $website_id = $data['website_id'] ?? 0;
  6448. // unset($data['user_id']);
  6449. unset($data['type_id']);
  6450. // unset($data['website_id']);
  6451. //处理数组
  6452. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6453. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6454. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6455. if ($data['img_url'] == '') {
  6456. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6457. preg_match_all($reg, $data['detail'], $matches);
  6458. if (isset($matches[1][0])) {
  6459. //截取varchar240
  6460. $data['img_url'] = substr($matches[1][0], 0, 240);
  6461. }
  6462. }
  6463. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  6464. //提取标题+内容中的关键词
  6465. $data['keyword'] = $data['title'];
  6466. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6467. Jieba::init(); // 初始化 jieba-php
  6468. Finalseg::init();
  6469. $segList = Jieba::cut($data['keyword']);
  6470. $segList1 = array_slice($segList, 0, 8);
  6471. $data['keyword'] = implode(',', $segList1);
  6472. }
  6473. if ($data['description'] == '') {
  6474. //提取内容中的描述
  6475. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6476. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6477. }
  6478. var_dump($data, '--');
  6479. if ($data['status'] == 1) {
  6480. $this->sendMessage([
  6481. 'talk_type' => 400,
  6482. 'title' => $data['title'],
  6483. 'content' => '提交了审核',
  6484. 'messageType' => 7,
  6485. ]);
  6486. }
  6487. $result = Book::insertGetId($data);
  6488. if (empty($result)) {
  6489. return Result::error("添加失败", 0);
  6490. }
  6491. return Result::success($result);
  6492. }
  6493. public function getBookList(array $data): array
  6494. {
  6495. $where = [];
  6496. if (!empty($data["title"])) {
  6497. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  6498. }
  6499. if (!empty($data['website_name'])) {
  6500. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  6501. }
  6502. if (!empty($data['status'])) {
  6503. $where[] = ['book.status', '=', $data['status']];
  6504. }
  6505. $user_id = $data['user_id'];
  6506. $type_id = $data['type_id'];
  6507. // $type_id = 4;
  6508. var_dump($type_id, '------1--------');
  6509. if ($type_id != 10000) {
  6510. $where[] = ['book.user_id', '=', $user_id];
  6511. }
  6512. var_dump(!empty($data['status1']), '=-===1');
  6513. $result = Book::where($where)
  6514. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  6515. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  6516. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  6517. ->when(isset($data['status1']), function ($query) use ($data) {
  6518. $query->whereIn('book.status', [1, 3]);
  6519. })
  6520. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  6521. ->orderBy("updated_at", "desc")
  6522. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  6523. if (empty($result)) {
  6524. return Result::error("暂无数据", 0);
  6525. }
  6526. // 取出数据
  6527. $rows = $result->items();
  6528. $count = $result->total();
  6529. $responseData = [
  6530. 'rows' => $rows,
  6531. 'count' => $count,
  6532. ];
  6533. return Result::success($responseData);
  6534. }
  6535. public function deleteBook(array $data): array
  6536. {
  6537. $result = Book::where('id', $data['id'])->delete();
  6538. if (empty($result)) {
  6539. return Result::error("删除失败", 0);
  6540. }
  6541. return Result::success($result);
  6542. }
  6543. public function updateBook(array $data): array
  6544. {
  6545. // $user_id = $data['user_id'] ?? 0;
  6546. $type_id = $data['type_id'] ?? 0;
  6547. // $website_id = $data['website_id'] ?? 0;
  6548. unset($data['user_id']);
  6549. unset($data['type_id']);
  6550. // unset($data['website_id']);
  6551. //处理数组
  6552. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6553. if ($data['img_url'] == '') {
  6554. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6555. preg_match_all($reg, $data['detail'], $matches);
  6556. if (isset($matches[1][0])) {
  6557. //截取varchar240
  6558. $data['img_url'] = substr($matches[1][0], 0, 240);
  6559. }
  6560. }
  6561. if ($data['keyword'] == '') {
  6562. //提取标题+内容中的关键词
  6563. $data['keyword'] = $data['title'];
  6564. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6565. Jieba::init(); // 初始化 jieba-php
  6566. Finalseg::init();
  6567. $segList = Jieba::cut($data['keyword']);
  6568. $segList1 = array_slice($segList, 0, 8);
  6569. $data['keyword'] = implode(',', $segList1);
  6570. }
  6571. if ($data['description'] == '') {
  6572. //提取内容中的描述
  6573. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6574. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6575. }
  6576. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6577. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6578. if ($data['status'] == 1) {
  6579. $this->sendMessage([
  6580. 'talk_type' => 400,
  6581. 'title' => $data['title'],
  6582. 'content' => '提交了审核',
  6583. 'messageType' => 7,
  6584. ]);
  6585. }
  6586. $result = Book::where("id", $data["id"])->update($data);
  6587. if (empty($result)) {
  6588. return Result::error("更新失败", 0);
  6589. }
  6590. return Result::success($result);
  6591. }
  6592. public function getBookInfo(array $data): array
  6593. {
  6594. $result = Book::where("id", $data["id"])->first();
  6595. if (empty($result)) {
  6596. return Result::error("获取失败", 0);
  6597. }
  6598. return Result::success($result);
  6599. }
  6600. public function updateBookStatus(array $data): array
  6601. {
  6602. //审核
  6603. unset($data['user_id']);
  6604. $bookInfo = Book::where("id", $data["id"])->first();
  6605. var_dump($bookInfo, '----');
  6606. if ($data['status'] == 2) {
  6607. $this->sendMessage([
  6608. 'talk_type' => 401,
  6609. 'title' => $bookInfo['title'],
  6610. 'content' => '审核通过',
  6611. 'messageType' => 7,
  6612. 'user_id' => $bookInfo['user_id'],
  6613. ]);
  6614. }
  6615. if ($data['status'] == 3) {
  6616. $this->sendMessage([
  6617. 'talk_type' => 401,
  6618. 'title' => $bookInfo['title'],
  6619. 'content' => '审核拒绝',
  6620. 'messageType' => 7,
  6621. 'user_id' => $bookInfo['user_id'],
  6622. ]);
  6623. }
  6624. if ($data['status'] == 1) {
  6625. $this->sendMessage([
  6626. 'talk_type' => 400,
  6627. 'title' => $bookInfo['title'],
  6628. 'content' => '提交了审核',
  6629. 'messageType' => 7,
  6630. // 'user_id'=>$bookInfo['user_id'],
  6631. ]);
  6632. }
  6633. $result = Book::where("id", $data["id"])->update($data);
  6634. if (empty($result)) {
  6635. return Result::error("更新失败", 0);
  6636. }
  6637. return Result::success($result);
  6638. }
  6639. //20250422 书刊音像
  6640. /**
  6641. * 贴身宝贝
  6642. * @param array $data
  6643. * @return array
  6644. */
  6645. public function getWebsiteTsbb(array $data): array
  6646. {
  6647. $month = $data['month'] ?? date('m');
  6648. $day = $data['day'] ?? date('d');
  6649. // 使用缓存键
  6650. $cacheKey = "tsbb_data_{$month}_{$day}";
  6651. // 尝试从缓存获取数据
  6652. $container = \Hyperf\Context\ApplicationContext::getContainer();
  6653. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  6654. if ($cachedData = $cache->get($cacheKey)) {
  6655. return Result::success(unserialize($cachedData));
  6656. }
  6657. //查询老黄历
  6658. try {
  6659. $date = date('Y-m-d');
  6660. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  6661. // 使用 curl 替代 file_get_contents
  6662. $ch = curl_init();
  6663. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  6664. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  6665. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  6666. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  6667. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  6668. 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');
  6669. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  6670. 'Accept: application/json',
  6671. 'Content-Type: application/json',
  6672. 'Referer: https://www.36jxs.com/'
  6673. ]);
  6674. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  6675. curl_setopt($ch, CURLOPT_ENCODING, '');
  6676. $almanacResponse = curl_exec($ch);
  6677. var_dump("====:", $almanacResponse);
  6678. if (curl_errno($ch)) {
  6679. var_dump('Curl error:', curl_error($ch));
  6680. throw new \Exception('Curl error: ' . curl_error($ch));
  6681. }
  6682. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  6683. curl_close($ch);
  6684. if ($almanacResponse === false) {
  6685. throw new \Exception('Failed to fetch almanac data');
  6686. }
  6687. $almanacData = json_decode($almanacResponse, true);
  6688. if (json_last_error() !== JSON_ERROR_NONE) {
  6689. throw new \Exception('Failed to parse almanac data');
  6690. }
  6691. $almanacInfo = $almanacData['data'] ?? [];
  6692. } catch (\Exception $e) {
  6693. var_dump('Exception:', $e->getMessage());
  6694. $almanacInfo = [];
  6695. }
  6696. // 获取历史上的今天数据
  6697. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6698. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  6699. ->orderBy('year', 'asc')
  6700. ->select("title", "id", "year", DB::raw('1 as type'))
  6701. ->limit(16)
  6702. ->get();
  6703. // 获取节日数据 - 从今天开始获取未来4条
  6704. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  6705. ->orderBy('showtime', 'asc')
  6706. ->select("title", "id", "showtime", DB::raw('2 as type'))
  6707. ->limit(16)
  6708. ->get();
  6709. //说文解字
  6710. $chartacterList = Character::orderBy('updated_at', 'desc')
  6711. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  6712. ->limit(6)
  6713. ->get();
  6714. //谜语沙龙
  6715. $riddletList = Riddle::orderBy('updated_at', 'desc')
  6716. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  6717. ->limit(4)
  6718. ->get();
  6719. //成语欣赏
  6720. $idiomList = Idiom::orderBy('updated_at', 'desc')
  6721. ->select("id", "title", "duyin", DB::raw('5 as type'))
  6722. ->limit(32)
  6723. ->get();
  6724. //名联赏析
  6725. $coupletList = Couplet::orderBy('updated_at', 'desc')
  6726. ->select("id", "first", "second", DB::raw('6 as type'))
  6727. ->limit(6)
  6728. ->get();
  6729. // 获取分类文章数据
  6730. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  6731. ->pluck('category_id')
  6732. ->toArray();
  6733. $articlesList = [];
  6734. foreach ($categoryIds as $catid) {
  6735. // 先查有图片的
  6736. $withImg = DB::table('article')
  6737. ->where('status', 1)
  6738. ->where('catid', $catid)
  6739. ->whereNotNull('imgurl')
  6740. ->where('imgurl', '!=', '')
  6741. ->orderBy('updated_at', 'desc')
  6742. ->limit(6)
  6743. ->get();
  6744. $count = $withImg->count();
  6745. if ($count < 6) {
  6746. // 不足6条再查无图片的补足
  6747. $withoutImg = DB::table('article')
  6748. ->where('status', 1)
  6749. ->where('catid', $catid)
  6750. ->where(function ($q) {
  6751. $q->whereNull('imgurl')->orWhere('imgurl', '');
  6752. })
  6753. ->orderBy('updated_at', 'desc')
  6754. ->limit(6 - $count)
  6755. ->get();
  6756. $articles = $withImg->concat($withoutImg);
  6757. } else {
  6758. $articles = $withImg;
  6759. }
  6760. // 组装
  6761. $category = \App\Model\Category::find($catid);
  6762. $websiteCategory = WebsiteCategory::where('category_id', $catid)->first();
  6763. $articlesList[] = [
  6764. 'category_name' => $category ? $category->name : '',
  6765. 'catid' => $catid,
  6766. 'pinyin' => $websiteCategory ? $websiteCategory->aLIas_pinyin : '',
  6767. 'type' => 100,
  6768. 'list' => $articles->map(function ($item) {
  6769. return [
  6770. 'id' => $item->id,
  6771. 'title' => $item->title,
  6772. 'imgurl' => $item->imgurl,
  6773. 'created_at' => $item->created_at
  6774. ];
  6775. })->values()
  6776. ];
  6777. }
  6778. $result = [
  6779. 'almanac' => $almanacInfo,
  6780. 'historyTodayList' => [
  6781. 'category_name' => '历史上的今天',
  6782. 'list' => $historyTodayList,
  6783. 'type' => 1
  6784. ],
  6785. 'festivalList' => [
  6786. 'category_name' => '节日预告',
  6787. 'list' => $festivalList,
  6788. 'type' => 2
  6789. ],
  6790. 'chartacterList' => [
  6791. 'category_name' => '说文解字',
  6792. 'list' => $chartacterList,
  6793. 'type' => 3
  6794. ],
  6795. 'coupletList' => [
  6796. 'category_name' => '名联赏析',
  6797. 'list' => $coupletList,
  6798. 'type' => 6
  6799. ],
  6800. 'riddletList' => [
  6801. 'category_name' => '谜语沙龙',
  6802. 'list' => $riddletList,
  6803. 'type' => 4
  6804. ],
  6805. 'idiomList' => [
  6806. 'category_name' => '成语欣赏',
  6807. 'list' => $idiomList,
  6808. 'type' => 5
  6809. ],
  6810. 'articlesList' => $articlesList
  6811. ];
  6812. // 缓存结果,设置1小时过期
  6813. $cache->set($cacheKey, serialize($result), 3600);
  6814. return Result::success($result);
  6815. }
  6816. /**
  6817. * 获取资讯列表
  6818. */
  6819. public function getWebsiteTsbbList(array $data): array
  6820. {
  6821. $page = $data['page'] ?? 1;
  6822. $pageSize = $data['pageSize'] ?? 10;
  6823. // 如果没有传入月份和日期,则使用今天的日期
  6824. $month = $data['month'] ?? date('m');
  6825. $day = $data['day'] ?? date('d');
  6826. $total = 0;
  6827. $result = [];
  6828. $data['type'] = intval($data['type']);
  6829. var_dump("接收参数:", $data);
  6830. switch ($data['type']) {
  6831. case 1:
  6832. $query = HistoryToday::where(function ($q) use ($month, $day) {
  6833. // 当前月份之后的数据
  6834. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  6835. // 或者当前月份且日期大于等于当前日期的数据
  6836. ->orWhere(function ($q) use ($month, $day) {
  6837. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6838. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  6839. });
  6840. })
  6841. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  6842. $total = $query->count();
  6843. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  6844. ->offset(($page - 1) * $pageSize)
  6845. ->limit($pageSize)
  6846. ->get();
  6847. break;
  6848. case 2:
  6849. $query = Festival::where(function ($q) use ($month, $day) {
  6850. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  6851. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  6852. ->orWhere(function ($q) use ($month, $day) {
  6853. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  6854. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  6855. });
  6856. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  6857. $total = $query->count();
  6858. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  6859. ->offset(($page - 1) * $pageSize)
  6860. ->limit($pageSize)
  6861. ->get();
  6862. break;
  6863. case 3:
  6864. $query = Character::orderBy("updated_at", "desc");
  6865. $total = $query->count();
  6866. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  6867. ->offset(($page - 1) * $pageSize)
  6868. ->limit($pageSize)
  6869. ->get();
  6870. break;
  6871. case 4:
  6872. $query = Riddle::orderBy("updated_at", "desc");
  6873. $total = $query->count();
  6874. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  6875. ->offset(($page - 1) * $pageSize)
  6876. ->limit($pageSize)
  6877. ->get();
  6878. break;
  6879. case 5:
  6880. $query = Idiom::orderBy("updated_at", "desc");
  6881. $total = $query->count();
  6882. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  6883. ->offset(($page - 1) * $pageSize)
  6884. ->limit($pageSize)
  6885. ->get();
  6886. break;
  6887. case 6:
  6888. $query = Couplet::orderBy("updated_at", "desc");
  6889. $total = $query->count();
  6890. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  6891. ->offset(($page - 1) * $pageSize)
  6892. ->limit($pageSize)
  6893. ->get();
  6894. break;
  6895. default:
  6896. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  6897. $total = $query->count();
  6898. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  6899. ->offset(($page - 1) * $pageSize)
  6900. ->limit($pageSize)
  6901. ->get();
  6902. }
  6903. return Result::success([
  6904. 'list' => $result,
  6905. 'total' => $total,
  6906. 'page' => (int)$page,
  6907. 'pageSize' => (int)$pageSize,
  6908. 'month' => $month,
  6909. 'day' => $day
  6910. ]);
  6911. }
  6912. /**
  6913. * 1:历史上的今天
  6914. * 2:节日
  6915. * 3:文章
  6916. *
  6917. * 资讯详情信息
  6918. */
  6919. public function getWebsiteTsbbDetail(array $data): array
  6920. {
  6921. $data['type'] = intval($data['type']);
  6922. switch ($data['type']) {
  6923. case 1:
  6924. $result = HistoryToday::where("id", $data['id'])->first();
  6925. break;
  6926. case 2:
  6927. $result = Festival::where("id", $data['id'])->first();
  6928. break;
  6929. case 3:
  6930. $result = Character::where("id", $data['id'])->first();
  6931. break;
  6932. case 4:
  6933. $result = Riddle::where("id", $data['id'])->first();
  6934. break;
  6935. case 5:
  6936. $result = Idiom::where("id", $data['id'])->first();
  6937. break;
  6938. case 6:
  6939. $result = Couplet::where("id", $data['id'])->first();
  6940. break;
  6941. default:
  6942. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  6943. break;
  6944. }
  6945. return Result::success($result);
  6946. }
  6947. /**
  6948. * 农网导航首页数据
  6949. */
  6950. public function getWebsiteNwHomeList(array $data): array
  6951. {
  6952. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  6953. ->pluck('category_id')
  6954. ->toArray();
  6955. // 使用子查询优化
  6956. $articlesList = DB::table('article')
  6957. ->select([
  6958. 'article.id',
  6959. 'article.title',
  6960. 'article.imgurl',
  6961. 'article.created_at',
  6962. 'category.name as category_name',
  6963. 'category.id as category_id',
  6964. 'website_category.aLIas_pinyin as pinyin',
  6965. 'parent_wc.aLIas_pinyin as parent_pinyin',
  6966. DB::raw('100 as type')
  6967. ])
  6968. ->join('category', 'article.catid', '=', 'category.id')
  6969. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  6970. ->leftJoin('website_category as parent_wc', function ($join) {
  6971. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  6972. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  6973. })
  6974. ->where('website_category.website_id', $data['website_id'])
  6975. ->where('article.status', 1)
  6976. ->whereIn('category.id', $categoryIds)
  6977. ->orderBy('article.created_at', 'desc')
  6978. ->get()
  6979. ->groupBy('category_id')
  6980. ->map(function ($group) {
  6981. // 确保第一条数据有图片
  6982. $firstWithImage = $group->first(function ($item) {
  6983. return !empty($item->imgurl);
  6984. });
  6985. if ($firstWithImage) {
  6986. // 如果有带图片的文章,将其放在第一位
  6987. $group = $group->filter(function ($item) use ($firstWithImage) {
  6988. return $item->id !== $firstWithImage->id;
  6989. })->prepend($firstWithImage);
  6990. }
  6991. return [
  6992. 'category_name' => $group->first()->category_name,
  6993. 'catid' => $group->first()->category_id,
  6994. 'pinyin' => $group->first()->pinyin,
  6995. 'parent_pinyin' => $group->first()->parent_pinyin,
  6996. 'list' => $group->take(4)->map(function ($item) {
  6997. return [
  6998. 'id' => $item->id,
  6999. 'title' => $item->title,
  7000. ];
  7001. })->values()
  7002. ];
  7003. })
  7004. ->values()
  7005. ->toArray();
  7006. return Result::success($articlesList);
  7007. }
  7008. /**
  7009. * 企业管理
  7010. * @param array $data
  7011. * @return array
  7012. */
  7013. public function getCompanyList(array $data): array
  7014. {
  7015. // return Result::success($data);
  7016. $where = [];
  7017. $user = User::where('id', $data['user_id'])->first();
  7018. if (empty($user)) {
  7019. return Result::error('用户不存在!');
  7020. }
  7021. if ($user['type_id'] != 10000) {
  7022. $where['user_id'] = $data['user_id'];
  7023. }
  7024. if (isset($data['title']) && !empty($data['title'])) {
  7025. array_push($where, ['company.title', 'like', '%' . $data['title'] . '%']);
  7026. }
  7027. if (isset($data['website_id']) && !empty($data['website_id'])) {
  7028. array_push($where, ['website.id', $data['website_id']]);
  7029. }
  7030. if (isset($data['ischeck']) && !empty($data['ischeck'])) {
  7031. if ($data['ischeck'] == 1) {
  7032. if (isset($data['status']) && $data['status'] != '') {
  7033. array_push($where, ['company.status', $data['status']]);
  7034. $query = Company::where($where);
  7035. } else {
  7036. $query = Company::whereIn('company.status', [0, 2]);
  7037. }
  7038. } else {
  7039. $query = Company::where('company.status', 1);
  7040. }
  7041. }
  7042. $result = $query->where($where)
  7043. ->leftJoin('website_category', function ($query) {
  7044. $query->on('website_category.category_id', '=', 'company.category_id')
  7045. ->on('website_category.website_id', '=', 'company.website_id');
  7046. })
  7047. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  7048. ->select(
  7049. 'company.id',
  7050. 'company.title',
  7051. 'company.website_id',
  7052. 'company.category_id',
  7053. 'website.website_name',
  7054. 'website_category.alias as category_name',
  7055. 'company.status',
  7056. 'company.updated_at',
  7057. 'company.user_id'
  7058. )
  7059. ->orderBy('company.updated_at', 'desc')
  7060. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  7061. if ($result->isEmpty()) {
  7062. return Result::error("暂无企业", 0);
  7063. }
  7064. return Result::success($result);
  7065. }
  7066. /**
  7067. * 添加企业
  7068. * @param array $data
  7069. * @return array
  7070. */
  7071. public function addCompany(array $data): array
  7072. {
  7073. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  7074. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  7075. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  7076. $data['cat_arr_id'] = json_encode($car_arr_id);
  7077. } else {
  7078. $data['cat_arr_id'] = '';
  7079. }
  7080. if ($data['imgurl'] == '') {
  7081. //content中提取图片第一个图,正则提取
  7082. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  7083. preg_match_all($reg, $data['content'], $matches);
  7084. if (isset($matches[1][0])) {
  7085. //截取varchar240
  7086. $data['imgurl'] = substr($matches[1][0], 0, 240);
  7087. }
  7088. }
  7089. if ($data['keyword'] == '') {
  7090. //提取标题+内容中的关键词
  7091. $data['keyword'] = $data['title'];
  7092. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7093. Jieba::init(); // 初始化 jieba-php
  7094. Finalseg::init();
  7095. $segList = Jieba::cut($data['keyword']);
  7096. $segList1 = array_slice($segList, 0, 8);
  7097. $data['keyword'] = implode(',', $segList1);
  7098. }
  7099. if ($data['introduce'] == '' || empty($data['introduce'])) {
  7100. //提取内容中的描述
  7101. $content = $data['content'];
  7102. // 去除 <style> 和 <script> 标签及其内容
  7103. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7104. // 去除所有 HTML 标签
  7105. $content = strip_tags($content);
  7106. // 去除 HTML 实体
  7107. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7108. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7109. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7110. // 去除多余空白
  7111. $content = preg_replace('/\s+/u', '', $content);
  7112. // 截取 100 个字符
  7113. $data['introduce'] = mb_substr($content, 0, 100);
  7114. }
  7115. $user = User::where('id', $data['user_id'])->first();
  7116. if (empty($user)) {
  7117. return Result::error('用户不存在!');
  7118. }
  7119. if ($user['type_id'] == 10000) {
  7120. $data['status'] = 1;
  7121. }
  7122. if (isset($data['level']) && $data['level'] != null) {
  7123. $data['level'] = intval($data['level']);
  7124. } else {
  7125. $data['level'] = null;
  7126. }
  7127. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  7128. $this->sendMessage([
  7129. 'talk_type' => 900,
  7130. 'title' => $data['title'],
  7131. 'content' => '提交了审核',
  7132. 'messageType' => 8,
  7133. ]);
  7134. }
  7135. $result = Company::insertGetId($data);
  7136. if ($result) {
  7137. return Result::success($result);
  7138. } else {
  7139. return Result::error('添加失败');
  7140. }
  7141. }
  7142. /**
  7143. * 更新企业
  7144. * @param array $data
  7145. * @return array
  7146. */
  7147. public function upCompany(array $data): array
  7148. {
  7149. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  7150. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  7151. $data['cat_arr_id'] = json_encode($car_arr_id);
  7152. $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
  7153. } else {
  7154. $data['cat_arr_id'] = '';
  7155. }
  7156. if ($data['imgurl'] == '') {
  7157. //content中提取图片第一个图,正则提取
  7158. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  7159. preg_match_all($reg, $data['content'], $matches);
  7160. if (isset($matches[1][0])) {
  7161. //截取varchar
  7162. $data['imgurl'] = substr($matches[1][0], 0, 240);
  7163. }
  7164. }
  7165. if ($data['keyword'] == '') {
  7166. //提取标题+内容中的关键词
  7167. $data['keyword'] = $data['title'];
  7168. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7169. Jieba::init(); // 初始化 jieba-php
  7170. Finalseg::init();
  7171. $segList = Jieba::cut($data['keyword']);
  7172. $segList1 = array_slice($segList, 0, 8);
  7173. $data['keyword'] = implode(',', $segList1);
  7174. }
  7175. if ($data['introduce'] == '') {
  7176. //提取内容中的描述
  7177. $content = $data['content'];
  7178. // 去除 <style> 和 <script> 标签及其内容
  7179. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7180. // 去除所有 HTML 标签
  7181. $content = strip_tags($content);
  7182. // 去除 HTML 实体
  7183. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7184. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7185. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7186. // 去除多余空白
  7187. $content = preg_replace('/\s+/u', '', $content);
  7188. // 截取 100 个字符
  7189. $data['introduce'] = mb_substr($content, 0, 100);
  7190. }
  7191. if (isset($data['level']) && $data['level'] != null) {
  7192. $data['level'] = intval($data['level']);
  7193. } else {
  7194. $data['level'] = null;
  7195. }
  7196. $user = User::where('id', $data['user_id'])->first();
  7197. if (empty($user)) {
  7198. return Result::error('用户不存在!');
  7199. }
  7200. if ($user['type_id'] == 10000) {
  7201. $data['status'] = 1;
  7202. } else {
  7203. $data['status'] = 0;
  7204. }
  7205. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  7206. $this->sendMessage([
  7207. 'talk_type' => 900,
  7208. 'title' => $data['title'],
  7209. 'content' => '提交了审核',
  7210. 'messageType' => 8,
  7211. ]);
  7212. }
  7213. $result = Company::where('id', $data['id'])->update($data);
  7214. if ($result) {
  7215. return Result::success($result);
  7216. } else {
  7217. return Result::error('修改失败');
  7218. }
  7219. }
  7220. /**
  7221. * 删除企业
  7222. * @param array $data
  7223. * @return array
  7224. */
  7225. public function delCompany(array $data): array
  7226. {
  7227. $result = Company::where('id', $data['id'])->delete();
  7228. if ($result) {
  7229. return Result::success($result);
  7230. } else {
  7231. return Result::error('删除失败');
  7232. }
  7233. }
  7234. /**
  7235. * 审核企业
  7236. * @param array $data
  7237. * @return array
  7238. */
  7239. public function checkCompany(array $data): array
  7240. {
  7241. $user = User::where('id', $data['user_id'])->first();
  7242. if (empty($user)) {
  7243. return Result::error('用户不存在!');
  7244. }
  7245. $company = Company::where('id', $data['id'])->first();
  7246. if (empty($company)) {
  7247. return Result::error('企业不存在!');
  7248. }
  7249. // 状态:0:未审核 1:已审核 2:已拒绝
  7250. if ($data['status'] == 2 || $data['status'] == '2') {
  7251. $this->sendMessage([
  7252. 'talk_type' => 901,
  7253. 'title' => $company['title'],
  7254. 'content' => '审核拒绝',
  7255. 'messageType' => 8,
  7256. 'user_id' => $company['user_id'],
  7257. ]);
  7258. $result = Company::where('id', $data['id'])->update(['status' => $data['status'], 'reject_reason' => $data['reason']]);
  7259. } else {
  7260. if ($data['status'] == 1) {
  7261. $this->sendMessage([
  7262. 'talk_type' => 901,
  7263. 'title' => $company['title'],
  7264. 'content' => '审核通过',
  7265. 'messageType' => 8,
  7266. 'user_id' => $company['user_id'],
  7267. ]);
  7268. } else if ($data['status'] == 0) {
  7269. $this->sendMessage([
  7270. 'talk_type' => 900,
  7271. 'title' => $company['title'],
  7272. 'content' => '提交了审核',
  7273. 'messageType' => 8,
  7274. ]);
  7275. }
  7276. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  7277. }
  7278. if (empty($result)) {
  7279. return Result::error('审核失败!');
  7280. } else {
  7281. return Result::success($result);
  7282. }
  7283. }
  7284. /**
  7285. * 获取企业信息
  7286. * @param array $data
  7287. * @return array
  7288. */
  7289. public function getCompanyInfo(array $data): array
  7290. {
  7291. $result = Company::where('id', $data['id'])->first();
  7292. $city_arr = json_decode($result['city_arr_id']);
  7293. $result['city_name'] = District::whereIn('id', $city_arr)
  7294. ->pluck('name')
  7295. ->implode('-');
  7296. if (empty($result)) {
  7297. return Result::error('企业不存在!');
  7298. } else {
  7299. return Result::success($result);
  7300. }
  7301. }
  7302. /**
  7303. * @param array $data
  7304. * @return array
  7305. */
  7306. public function getWebsiteCompany(array $data): array
  7307. {
  7308. $categorys = json_decode($data['id'], true);
  7309. $category_arr = $this->processArticlePro($data['website_id']);
  7310. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7311. $catiall = $category_arr['catiall'];
  7312. $categoryIds = $category_arr['categoryIds'];
  7313. // return Result::success($category_arr);
  7314. foreach ($categorys as $key => $value) {
  7315. if (array_key_exists('level', $value)) {
  7316. $parts = explode(',', $value['level']);
  7317. $level = $parts[0] ?? null;
  7318. $imgnum = $parts[1] ?? null;
  7319. $textnum = $parts[2] ?? null;
  7320. if (!empty($textnum) && $textnum > 0) {
  7321. $text_num = Company::where('level', $level)
  7322. ->whereIn('category_id', $categoryIds)
  7323. ->where('status', 1)
  7324. ->select(
  7325. 'company.id',
  7326. 'company.title',
  7327. 'company.description',
  7328. 'company.updated_at',
  7329. 'company.category_id',
  7330. 'company.cat_arr_id'
  7331. )
  7332. ->orderBy('updated_at', 'desc')
  7333. ->limit($textnum)
  7334. ->get()->all();
  7335. }
  7336. if (!empty($imgnum) && $imgnum > 0) {
  7337. $img_num = Company::where('level', $level)
  7338. ->whereIn('category_id', $categoryIds)
  7339. ->where('status', 1)
  7340. ->where('imgurl', '!=', '')
  7341. ->whereNotNull('imgurl')
  7342. ->select(
  7343. 'company.id',
  7344. 'company.title',
  7345. 'company.description',
  7346. 'company.updated_at',
  7347. 'company.imgurl as imgs',
  7348. 'company.category_id',
  7349. 'company.cat_arr_id'
  7350. )
  7351. ->orderBy('updated_at', 'desc')
  7352. ->limit($imgnum)
  7353. ->get()->all();
  7354. }
  7355. }
  7356. if (array_key_exists('id', $value)) {
  7357. $parts = explode(',', $value['id']);
  7358. $category_id = $parts[0] ?? null;
  7359. $imgnum = $parts[1] ?? null;
  7360. $textnum = $parts[2] ?? null;
  7361. $category_arr = array_merge([$category_id], $cat_1st_arr[$category_id] ?? [0]);
  7362. if (!empty($textnum) && $textnum > 0) {
  7363. $text_num = Company::whereIn('category_id', $category_arr)
  7364. // ->where('website_id', $data['website_id'])
  7365. ->where('status', 1)
  7366. ->select(
  7367. 'company.id',
  7368. 'company.title',
  7369. 'company.description',
  7370. 'company.updated_at',
  7371. 'company.category_id',
  7372. 'company.cat_arr_id'
  7373. )
  7374. ->orderBy('updated_at', 'desc')
  7375. ->limit($textnum)
  7376. ->get()->all();
  7377. }
  7378. if (!empty($imgnum) && $imgnum > 0) {
  7379. $img_num = Company::whereIn('category_id', $category_arr)
  7380. // ->where('website_id', $data['website_id'])
  7381. ->where('status', 1)
  7382. ->where('imgurl', '!=', '')
  7383. ->whereNotNull('imgurl')
  7384. ->select(
  7385. 'company.id',
  7386. 'company.title',
  7387. 'company.description',
  7388. 'company.updated_at',
  7389. 'company.imgurl as imgs',
  7390. 'company.category_id',
  7391. 'company.cat_arr_id'
  7392. )
  7393. ->orderBy('updated_at', 'desc')
  7394. ->limit($imgnum)
  7395. ->get()->all();
  7396. }
  7397. }
  7398. if (!empty($text_num)) {
  7399. foreach ($text_num as $k => $v) {
  7400. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7401. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7402. }
  7403. }
  7404. if (!empty($img_num)) {
  7405. foreach ($img_num as $k => $v) {
  7406. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7407. $imgurl = json_decode($v['imgs'], true);
  7408. if (!empty($imgurl)) {
  7409. $img_num[$k]->imgurl = $imgurl[0];
  7410. }
  7411. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7412. }
  7413. }
  7414. $company[$key]['img_num'] = $img_num ?? [];
  7415. $company[$key]['text_num'] = $text_num ?? [];
  7416. }
  7417. if (empty($company)) {
  7418. return Result::error("暂无相关企业信息", 0);
  7419. }
  7420. return Result::success($company);
  7421. }
  7422. /**
  7423. * @param array $data
  7424. * @return array
  7425. */
  7426. public function getWebsiteCompanyList(array $data): array
  7427. {
  7428. $where['website_id'] = $data['website_id'];
  7429. $where['status'] = 1;
  7430. $categoryIds = [];
  7431. if (isset($data['category_id']) && !empty($data['category_id'])) {
  7432. $category_id = $data['category_id'];
  7433. }
  7434. $category_arr = $this->processArticlePro($data['website_id']);
  7435. $categoryIds = $category_arr['categoryIds'];
  7436. // return Result::success($cat_1st_arr);
  7437. $company = Company::when(isset($data['keyword']) && !empty($data['keyword']), function ($query) use ($data) {
  7438. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  7439. })
  7440. ->when(!isset($category_id) || empty($category_id), function ($query) use ($categoryIds) {
  7441. $query->whereIn('category_id', $categoryIds);
  7442. })
  7443. ->when(isset($data['category_id']) && !empty($data['category_id']), function ($query) use ($category_id) {
  7444. $query->where('category_id', $category_id);
  7445. })
  7446. ->where('status', 1)
  7447. ->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id', 'updated_at')
  7448. ->orderBy('updated_at', 'desc')
  7449. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  7450. if (empty($company)) {
  7451. return Result::error("暂无相关公司信息", 0);
  7452. }
  7453. $result = [
  7454. 'count' => $company->total(),
  7455. 'data' => $company->items(), // 使用 items() 方法替代不存在的 data() 方法
  7456. ];
  7457. return Result::success($result);
  7458. }
  7459. /**
  7460. * 获取项目列表
  7461. * @param array $data
  7462. * @return array
  7463. */
  7464. public function getProjectList(array $data): array
  7465. {
  7466. $where = [];
  7467. $user = User::where('id', $data['user_id'])->first();
  7468. if (empty($user)) {
  7469. return Result::error('用户不存在!');
  7470. }
  7471. if ($user->type_id != 10000) {
  7472. array_push($where, ['project.user_id', $data['user_id']]);
  7473. }
  7474. $query = Project::query();
  7475. if (isset($data['website_id']) && !empty($data['website_id'])) {
  7476. array_push($where, ['project.website_id', $data['website_id']]);
  7477. }
  7478. if (isset($data['title']) && !empty($data['title'])) {
  7479. array_push($where, ['project.title', 'like', '%' . $data['title'] . '%']);
  7480. }
  7481. if ($data['status'] != 3) {
  7482. array_push($where, ['project.status', $data['status']]);
  7483. }
  7484. $query = Project::where($where)
  7485. ->when($data['status'] == 3, function ($query) {
  7486. $query->whereIn('project.status', [0, 2]);
  7487. });
  7488. $count = $query->clone()
  7489. ->count();
  7490. $rows = $query->clone()
  7491. ->leftJoin('website', 'project.website_id', 'website.id')
  7492. ->leftJoin('website_category', function ($join) {
  7493. $join->on('project.website_id', '=', 'website_category.website_id')
  7494. ->on('project.category_id', '=', 'website_category.category_id');
  7495. })
  7496. ->select(
  7497. 'project.id',
  7498. 'project.title',
  7499. 'project.updated_at',
  7500. 'project.status',
  7501. 'website.website_name',
  7502. 'website_category.alias as category_name',
  7503. 'project.website_id',
  7504. 'project.user_id'
  7505. )
  7506. ->orderBy('project.updated_at', 'desc')
  7507. ->offset(($data['page'] - 1) * $data['pageSize'])
  7508. ->limit($data['pageSize'])
  7509. ->get();
  7510. if ($rows->isEmpty()) {
  7511. return Result::error("暂无相关项目信息", 0);
  7512. }
  7513. $result = [
  7514. 'count' => $count,
  7515. 'rows' => $rows,
  7516. ];
  7517. return Result::success($result);
  7518. }
  7519. /**
  7520. * 添加项目
  7521. * @param array $data
  7522. * @return array
  7523. */
  7524. public function addProject(array $data): array
  7525. {
  7526. $user = User::where('id', $data['user_id'])->first();
  7527. if (empty($user)) {
  7528. return Result::error("暂无相关用户信息", 0);
  7529. }
  7530. if ($user->type_id == 10000) {
  7531. $data['status'] = 1;
  7532. } else {
  7533. $data['status'] = 0;
  7534. }
  7535. if ($data['keyword'] == '') {
  7536. //提取标题+内容中的关键词
  7537. $data['keyword'] = $data['title'];
  7538. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7539. Jieba::init(); // 初始化 jieba-php
  7540. Finalseg::init();
  7541. $segList = Jieba::cut($data['keyword']);
  7542. $segList1 = array_slice($segList, 0, 8);
  7543. $data['keyword'] = implode(',', $segList1);
  7544. }
  7545. if ($data['description'] == '') {
  7546. //提取内容中的描述
  7547. // var_dump(11111);
  7548. //提取内容中的描述
  7549. $content = $data['introduce'];
  7550. // 去除 <style> 和 <script> 标签及其内容
  7551. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7552. // 去除所有 HTML 标签
  7553. $content = strip_tags($content);
  7554. // 去除 HTML 实体
  7555. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7556. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7557. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7558. // 去除多余空白
  7559. $content = preg_replace('/\s+/u', '', $content);
  7560. // 截取 100 个字符
  7561. $data['description'] = mb_substr($content, 0, 100);
  7562. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7563. }
  7564. if ($data['status'] == 0) {
  7565. $this->sendMessage([
  7566. 'talk_type' => 1000,
  7567. 'title' => $data['title'],
  7568. 'content' => '提交了审核',
  7569. 'messageType' => 9,
  7570. ]);
  7571. }
  7572. $project = Project::insertGetId($data);
  7573. if (empty($project)) {
  7574. return Result::error("暂无相关项目信息", 0);
  7575. }
  7576. return Result::success($project);
  7577. }
  7578. /**
  7579. * 更新项目
  7580. * @param array $data
  7581. * @return array
  7582. */
  7583. public function upProject(array $data): array
  7584. {
  7585. $project = Project::where('id', $data['id'])->first();
  7586. if (empty($project)) {
  7587. return Result::error("暂无相关项目信息", 0);
  7588. }
  7589. $id = $data['id'];
  7590. unset($data['id']);
  7591. $user = User::where('id', $data['user_id'])->first();
  7592. if (empty($user)) {
  7593. return Result::error("暂无相关用户信息", 0);
  7594. }
  7595. if ($user->type_id == 10000) {
  7596. $data['status'] = 1;
  7597. } else {
  7598. $data['status'] = 0;
  7599. }
  7600. unset($data['user_id']);
  7601. if ($data['keyword'] == '') {
  7602. //提取标题+内容中的关键词
  7603. $data['keyword'] = $data['title'];
  7604. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7605. Jieba::init(); // 初始化 jieba-php
  7606. Finalseg::init();
  7607. $segList = Jieba::cut($data['keyword']);
  7608. $segList1 = array_slice($segList, 0, 8);
  7609. $data['keyword'] = implode(',', $segList1);
  7610. }
  7611. if ($data['description'] == '') {
  7612. //提取内容中的描述
  7613. // var_dump(11111);
  7614. //提取内容中的描述
  7615. $content = $data['introduce'];
  7616. // 去除 <style> 和 <script> 标签及其内容
  7617. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7618. // 去除所有 HTML 标签
  7619. $content = strip_tags($content);
  7620. // 去除 HTML 实体
  7621. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7622. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7623. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7624. // 去除多余空白
  7625. $content = preg_replace('/\s+/u', '', $content);
  7626. // 截取 100 个字符
  7627. $data['description'] = mb_substr($content, 0, 100);
  7628. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7629. }
  7630. if ($data['status'] == 0) {
  7631. $this->sendMessage([
  7632. 'talk_type' => 1000,
  7633. 'title' => $data['title'],
  7634. 'content' => '提交了审核',
  7635. 'messageType' => 9,
  7636. ]);
  7637. }
  7638. $result = Project::where('id', $id)->update($data);
  7639. if (empty($result)) {
  7640. return Result::error("更新失败", 0);
  7641. }
  7642. return Result::success($result);
  7643. }
  7644. /**
  7645. * 删除项目
  7646. * @param array $data
  7647. * @return array
  7648. */
  7649. public function delProject(array $data): array
  7650. {
  7651. $user = User::where('id', $data['user_id'])->first();
  7652. if (empty($user)) {
  7653. return Result::error("暂无相关用户信息", 0);
  7654. }
  7655. $project = Project::where('id', $data['id'])->first();
  7656. if (empty($project)) {
  7657. return Result::error("暂无相关项目信息", 0);
  7658. }
  7659. $result = Project::where('id', $data['id'])->delete();
  7660. if (empty($result)) {
  7661. return Result::error("删除失败", 0);
  7662. }
  7663. return Result::success($result);
  7664. }
  7665. /**
  7666. * 审核项目
  7667. * @param array $data
  7668. * @return array
  7669. */
  7670. public function checkProject(array $data): array
  7671. {
  7672. $user = User::where('id', $data['user_id'])->first();
  7673. if (empty($user)) {
  7674. return Result::error("暂无相关用户信息", 0);
  7675. }
  7676. // 0:未审核; 1:已审核; 2:已拒绝;
  7677. if ($user->type_id != 10000) {
  7678. if ($data['status'] == 1 || $data['status'] == 2) {
  7679. return Result::error("此用户权限不足", 0);
  7680. }
  7681. }
  7682. $project = Project::where('id', $data['id'])->first();
  7683. if (empty($project)) {
  7684. return Result::error("暂无相关项目信息", 0);
  7685. }
  7686. if ($data['status'] == 2) {
  7687. $this->sendMessage([
  7688. 'talk_type' => 1001,
  7689. 'title' => $project['title'],
  7690. 'content' => '审核拒绝',
  7691. 'messageType' => 9,
  7692. 'user_id' => $project['user_id'],
  7693. ]);
  7694. $result = Project::where('id', $data['id'])->update(['status' => $data['status'], 'refuse_reason' => $data['refuse_reason']]);
  7695. } else {
  7696. if ($data['status'] == 1) {
  7697. $this->sendMessage([
  7698. 'talk_type' => 1001,
  7699. 'title' => $project['title'],
  7700. 'content' => '审核通过',
  7701. 'messageType' => 9,
  7702. 'user_id' => $project['user_id'],
  7703. ]);
  7704. } else if ($data['status'] == 0) {
  7705. $this->sendMessage([
  7706. 'talk_type' => 1000,
  7707. 'title' => $project['title'],
  7708. 'content' => '提交了审核',
  7709. 'messageType' => 9,
  7710. ]);
  7711. }
  7712. $result = Project::where('id', $data['id'])->update(['status' => $data['status']]);
  7713. }
  7714. if (empty($result)) {
  7715. return Result::error("审核失败", 0);
  7716. }
  7717. return Result::success($result);
  7718. }
  7719. /**
  7720. * 获取项目详情
  7721. * @param array $data
  7722. * @return array
  7723. */
  7724. public function getProjectInfo(array $data): array
  7725. {
  7726. $project = Project::where('id', $data['id'])->first();
  7727. if (empty($project)) {
  7728. return Result::error("暂无相关项目信息", 0);
  7729. }
  7730. return Result::success($project);
  7731. }
  7732. public function getWebsiteCompanyInfo(array $data): array
  7733. {
  7734. $company = Company::where('id', $data['id'])
  7735. ->leftJoin('job_industry', 'job_industry.hyid', 'company.hy_id')
  7736. ->where('status', 1)
  7737. // ->where('website_id', $data['website_id'])
  7738. ->select('company.*', 'job_industry.hyname as hy_name')
  7739. ->first();
  7740. // 企业性质:0:市场监管;1:信访纪检;2:公检法司;3:高关注机构
  7741. $jobnature_id = $company['jobnature_id'] ?? null;
  7742. if ($jobnature_id !== null) {
  7743. switch ($jobnature_id) {
  7744. case 0:
  7745. $company->jobnature_name = '市场监督';
  7746. break;
  7747. case 1:
  7748. $company->jobnature_name = '信访纪检';
  7749. break;
  7750. case 2:
  7751. $company->jobnature_name = '公检法司';
  7752. break;
  7753. case 3:
  7754. $company->jobnature_name = '高关注机构';
  7755. break;
  7756. default:
  7757. $company->jobnature_name = '';
  7758. break;
  7759. }
  7760. } else {
  7761. $company->jobnature_name = '';
  7762. }
  7763. $city_arr = $company->city_arr_id;
  7764. if (!empty($city_arr)) {
  7765. $city_arr = json_decode($city_arr, true);
  7766. $cityNames = District::whereIn('id', $city_arr)
  7767. ->pluck('name')
  7768. ->implode('-');
  7769. $company->city_name = $cityNames;
  7770. } else {
  7771. $company->city_name = '';
  7772. }
  7773. if (empty($company)) {
  7774. return Result::error("暂无相关公司信息", 0);
  7775. }
  7776. return Result::success($company);
  7777. }
  7778. public function getMSG(array $data): array
  7779. {
  7780. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  7781. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  7782. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  7783. $result = [];
  7784. if ($type_id == 1 or $type_id == 2 or $type_id == 3 or $type_id == 4) {
  7785. //最近的5篇已审的文章
  7786. $apply_articale = Article::where('status', 1)
  7787. ->where('admin_user_id', $user_id)
  7788. ->orderBy('updated_at', 'desc')
  7789. // ->limit(5)
  7790. ->get();
  7791. //获取5条用户的已审核商品
  7792. $good = Good::where('status', 2)
  7793. ->where('user_id', $user_id)
  7794. ->orderBy('updated_at', 'desc')
  7795. // ->limit(5)
  7796. ->get();
  7797. //获取5条用户待审核的公告
  7798. $notice = Notice::where('status', 2)
  7799. ->where('user_id', $user_id)
  7800. ->orderBy('updated_at', 'desc')
  7801. ->limit(5)->get();
  7802. //获取5条用户的待审核投诉
  7803. $complaint = Complaint::where('status', 2)
  7804. ->where('user_id', $user_id)
  7805. ->orderBy('updated_at', 'desc')
  7806. // ->limit(5)
  7807. ->get();
  7808. //获取5条用户的book
  7809. $book = Book::where('status', 2)
  7810. ->where('user_id', $user_id)
  7811. ->orderBy('updated_at', 'desc')
  7812. // ->limit(5)
  7813. ->get();
  7814. //获取5条用户的求职
  7815. //获取5条用户的求职 1
  7816. $job_hunting = JobHunting::where('job_hunting.status', 2)
  7817. ->where('job_hunting.user_id', $user_id)
  7818. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7819. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7820. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7821. ->orderBy('updated_at', 'desc')
  7822. // ->limit(5)
  7823. ->get();
  7824. //获取5条用户的求职 2
  7825. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  7826. ->where('job_recruiting.user_id', $user_id)
  7827. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7828. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7829. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7830. ->orderBy('updated_at', 'desc')
  7831. // ->limit(5)
  7832. ->get();
  7833. //人才库 1
  7834. $job_apply = JobApply::where('job_apply.status', 1)
  7835. ->where('job_apply.receiver_id', $user_id)
  7836. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7837. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7838. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7839. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7840. ->select('job_recruiting', 'job_recruiting.', '', '')
  7841. ->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')
  7842. ->orderBy('updated_at', 'desc')
  7843. // ->limit(5)
  7844. ->get();
  7845. // 职场机会 2
  7846. $job_resume = JobResume::where('job_resume.status', 1)
  7847. ->where('job_resume.receiver_id', $user_id)
  7848. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7849. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7850. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7851. ->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')
  7852. ->orderBy('updated_at', 'desc')
  7853. // ->limit(5)
  7854. ->get();
  7855. //获取5条用户待处理的投诉
  7856. $complaint_deal = Complaint::where('status', 2)
  7857. ->where('deal', 1)
  7858. ->whereJsonContains('re_user_ids', $user_id)
  7859. ->orderBy('updated_at', 'desc')
  7860. // ->limit(5)
  7861. ->get();
  7862. //获取 被通知者未读信息
  7863. $notice_unread = Notice::where('status', 2)
  7864. ->whereJsonContains('re_user_ids', $user_id)
  7865. //未读消息
  7866. ->where(function ($query) use ($user_id) {
  7867. $query->whereJsonDoesntContain('read_id', $user_id)
  7868. ->orWhereNull('read_id');
  7869. })
  7870. ->orderBy('updated_at', 'desc')
  7871. ->get();
  7872. $complaint_unread = Complaint::where('status', 2)
  7873. ->whereJsonContains('re_user_ids', $user_id)
  7874. //未读消息
  7875. ->where(function ($query) use ($user_id) {
  7876. $query->whereJsonDoesntContain('read_id', $user_id)
  7877. ->orWhereNull('read_id');
  7878. })
  7879. ->orderBy('updated_at', 'desc')
  7880. ->get();
  7881. //获取5条用户的yijing审核公司 :0:未审核;1:已审核;2:已拒绝
  7882. $complany = Company::where('status', 1)
  7883. ->where('user_id', $user_id)
  7884. ->orderBy('updated_at', 'desc')
  7885. // ->limit(5)
  7886. ->get();
  7887. //获取5条单聊未读聊天消息
  7888. // $chat = ChatRecords::where('is_read', 0)
  7889. // ->where('user_id', $user_id)
  7890. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7891. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7892. // ->where('action', 'recieved')
  7893. // ->where('talk_type', 1)
  7894. // ->orderBy('created_at', 'desc')
  7895. // // ->limit(5)
  7896. // ->get();
  7897. //获取5条未读群聊信息
  7898. // $chat_group = ChatRecords::where('is_read', 0)
  7899. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7900. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7901. // ->where('user_id', $user_id)
  7902. // ->where('talk_type', 2)
  7903. // ->orderBy('created_at', 'desc')
  7904. // // ->limit(5)
  7905. // ->get();
  7906. //获取5条用户的待审核项目
  7907. $project = Project::where('status', 1)
  7908. ->where('user_id', $user_id)
  7909. ->orderBy('updated_at', 'desc')
  7910. // ->limit(5)
  7911. ->get();
  7912. // count($chat) + count($chat_group) +
  7913. $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)
  7914. + count($complany)
  7915. + count($project)
  7916. + count($notice_unread)
  7917. + count($complaint_unread)
  7918. // + count($chat) + count($chat_group)
  7919. ;
  7920. $result = [
  7921. 'apply_articale' => $apply_articale,
  7922. // 'chat' => $chat,
  7923. // 'chat_group' => $chat_group,
  7924. 'good' => $good,
  7925. 'notice' => $notice,
  7926. 'complaint' => $complaint,
  7927. 'book' => $book,
  7928. 'job_hunting' => $job_hunting,
  7929. 'job_recruiting' => $job_recruiting,
  7930. 'job_apply' => $job_apply,
  7931. 'job_resume' => $job_resume,
  7932. 'complaint_deal' => $complaint_deal,
  7933. 'complany' => $complany,
  7934. 'project' => $project,
  7935. 'notice_unread' => $notice_unread,
  7936. 'complaint_unread' => $complaint_unread,
  7937. 'count' => $count,
  7938. ];
  7939. } elseif ($type_id == 12) {
  7940. //最近的5篇已审的文章
  7941. $apply_articale = Article::where('status', 1)
  7942. ->where('admin_user_id', $user_id)
  7943. ->limit(5)->get();
  7944. //获取5条单聊未读聊天消息
  7945. $chat = ChatRecords::where('is_read', 0)
  7946. ->where('user_id', $user_id)
  7947. ->where('talk_type', 1)
  7948. ->orderBy('created_at', 'desc')
  7949. ->limit(5)->get();
  7950. //获取5条未读群聊信息
  7951. $chat_group = ChatRecords::where('is_read', 0)
  7952. ->where('user_id', $user_id)
  7953. ->where('talk_type', 2)
  7954. ->orderBy('created_at', 'desc')
  7955. ->limit(5)->get();
  7956. //获取5条用户的已审核商品
  7957. $good = Good::where('status', 2)
  7958. ->where('user_id', $user_id)
  7959. ->orderBy('updated_at', 'desc')
  7960. ->limit(5)->get();
  7961. //获取5条用户的book
  7962. $book = Book::where('status', 2)
  7963. ->where('user_id', $user_id)
  7964. ->orderBy('updated_at', 'desc')
  7965. ->limit(5)->get();
  7966. //获取5条用户的求职
  7967. //获取5条用户的求职 1
  7968. //count($chat) + count($chat_group)
  7969. $count = count($apply_articale) + count($good);
  7970. $result = [
  7971. 'apply_articale' => $apply_articale,
  7972. 'chat' => $chat,
  7973. 'chat_group' => $chat_group,
  7974. 'good' => $good,
  7975. 'book' => $book,
  7976. 'count' => $count,
  7977. ];
  7978. } elseif ($type_id == 13) {
  7979. //最近的5篇已审的文章
  7980. $apply_articale = Article::where('status', 1)
  7981. ->where('admin_user_id', $user_id)
  7982. ->limit(5)->get();
  7983. //获取5条单聊未读聊天消息
  7984. $chat = ChatRecords::where('is_read', 0)
  7985. ->where('user_id', $user_id)
  7986. ->where('talk_type', 1)
  7987. ->orderBy('created_at', 'desc')
  7988. ->limit(5)->get();
  7989. //获取5条未读群聊信息
  7990. $chat_group = ChatRecords::where('is_read', 0)
  7991. ->where('user_id', $user_id)
  7992. ->where('talk_type', 2)
  7993. ->orderBy('created_at', 'desc')
  7994. ->limit(5)->get();
  7995. //获取5条用户的已审核商品
  7996. $good = Good::where('status', 2)
  7997. ->where('user_id', $user_id)
  7998. ->orderBy('updated_at', 'desc')
  7999. ->limit(5)->get();
  8000. //count($chat) + count($chat_group) +
  8001. $count = count($apply_articale) + count($good);
  8002. $result = [
  8003. 'apply_articale' => $apply_articale,
  8004. 'chat' => $chat,
  8005. 'chat_group' => $chat_group,
  8006. 'good' => $good,
  8007. 'count' => $count,
  8008. ];
  8009. } elseif ($type_id == 14) {
  8010. //最近的5篇已审的文章
  8011. $apply_articale = Article::where('status', 1)
  8012. ->where('admin_user_id', $user_id)
  8013. // ->limit(5)
  8014. ->get();
  8015. //获取5条用户的已审核商品
  8016. $good = Good::where('status', 2)
  8017. ->where('user_id', $user_id)
  8018. ->orderBy('updated_at', 'desc')
  8019. // ->limit(5)
  8020. ->get();
  8021. $count = count($apply_articale) + count($good);
  8022. $result = [
  8023. 'apply_articale' => $apply_articale,
  8024. 'chat' => '',
  8025. 'chat_group' => '',
  8026. 'good' => $good,
  8027. 'count' => $count,
  8028. ];
  8029. } elseif ($type_id == 10000) {
  8030. //获取未审核的5篇文章
  8031. $apply_articale = Article::where('status', 0)
  8032. ->orderBy('updated_at', 'desc')
  8033. // ->limit(5)
  8034. ->get();
  8035. //获取5条单聊未读聊天消息
  8036. //获取5条单聊未读聊天消息
  8037. // $chat = ChatRecords::where('is_read', 0)
  8038. // ->where('user_id', $user_id)
  8039. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  8040. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  8041. // ->where('action', 'recieved')
  8042. // ->where('talk_type', 1)
  8043. // ->orderBy('created_at', 'desc')
  8044. // // ->limit(5)
  8045. // ->get();
  8046. // //获取5条未读群聊信息
  8047. // $chat_group = ChatRecords::where('is_read', 0)
  8048. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  8049. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  8050. // ->where('user_id', $user_id)
  8051. // ->where('talk_type', 2)
  8052. // ->orderBy('created_at', 'desc')
  8053. // // ->limit(5)
  8054. // ->get();
  8055. //获取5条用户的已审核商品
  8056. $good = Good::where('status', 1)
  8057. // ->where('user_id', $user_id)
  8058. ->orderBy('updated_at', 'desc')
  8059. // ->limit(5)
  8060. ->get();
  8061. //获取5条用户待审核的公告
  8062. $notice = Notice::where('status', 1)
  8063. ->orderBy('updated_at', 'desc')
  8064. // ->limit(5)
  8065. ->get();
  8066. //获取5条用户的待审核投诉
  8067. $complaint = Complaint::where('status', 1)
  8068. ->orderBy('updated_at', 'desc')
  8069. // ->limit(5)
  8070. ->get();
  8071. //获取5条用户的book
  8072. $book = Book::where('status', 1)
  8073. ->orderBy('updated_at', 'desc')
  8074. // ->limit(5)
  8075. ->get();
  8076. //获取5条用户的求职 1
  8077. $job_hunting = JobHunting::where('job_hunting.status', 1)
  8078. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  8079. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  8080. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  8081. ->orderBy('updated_at', 'desc')
  8082. // ->limit(5)
  8083. ->get();
  8084. //获取5条用户的求职 2
  8085. $job_recruiting = JobRecruiting::where('job_recruiting.status', 0)
  8086. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  8087. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  8088. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  8089. ->orderBy('updated_at', 'desc')
  8090. // ->limit(5)
  8091. ->get();
  8092. //人才库 1
  8093. $job_apply = JobApply::where('job_apply.status', 1)
  8094. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  8095. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  8096. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  8097. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  8098. ->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')
  8099. ->orderBy('updated_at', 'desc')
  8100. // ->limit(5)
  8101. ->get();
  8102. // 职场机会 2
  8103. $job_resume = JobResume::where('job_resume.status', 1)
  8104. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  8105. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  8106. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  8107. ->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')
  8108. ->orderBy('updated_at', 'desc')
  8109. // ->limit(5)
  8110. ->get();
  8111. //待审核数据com pro
  8112. $complany = Company::where('status', 0)
  8113. ->orderBy('updated_at', 'desc')
  8114. // ->limit(5)
  8115. ->get();
  8116. $project = Project::where('status', 0)
  8117. ->orderBy('updated_at', 'desc')
  8118. // ->limit(5)
  8119. ->get();
  8120. $count =
  8121. // count($chat) +
  8122. // count($chat_group) +
  8123. count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting)
  8124. // + count($job_apply)
  8125. // + count($job_resume)
  8126. + count($complany)
  8127. + count($project);
  8128. $result = [
  8129. 'apply_articale' => $apply_articale,
  8130. // 'chat' => $chat,
  8131. // 'chat_group' => $chat_group,
  8132. 'good' => $good,
  8133. 'notice' => $notice,
  8134. 'complaint' => $complaint,
  8135. 'book' => $book,
  8136. 'job_hunting' => $job_hunting,
  8137. 'job_recruiting' => $job_recruiting,
  8138. // 'job_apply' => $job_apply,
  8139. // 'job_resume' => $job_resume,
  8140. 'complany' => $complany,
  8141. 'project' => $project,
  8142. 'count' => $count,
  8143. ];
  8144. } elseif ($type_id == 20000) {
  8145. }
  8146. var_dump($type_id, '-----------------test---------');
  8147. return Result::success($result);
  8148. }
  8149. /**
  8150. * @param array $data
  8151. * @return array
  8152. */
  8153. public function getWebsiteProject(array $data): array
  8154. {
  8155. $categorys = json_decode($data['id'], true);
  8156. if (!empty($categorys)) {
  8157. $category_arr = $this->processArticlePro($data['website_id']);
  8158. $cat_1st_arr = $category_arr['cat_1st_arr'];
  8159. $catiall = $category_arr['catiall'];
  8160. // return Result::success($catiall);
  8161. foreach ($categorys as $key => $val) {
  8162. if (isset($val['level'][0]) && !empty($val['level'][0])) {
  8163. $level = explode(',', $val['level'])[0];
  8164. $imgnum = explode(',', $val['level'])[1] ?? null;
  8165. $textnum = explode(',', $val['level'])[2] ?? null;
  8166. if ($level == 1) {
  8167. if (!empty($textnum) && $textnum > 0) {
  8168. $text_num = Project::where('level', $level)
  8169. ->where('website_id', $data['website_id'])
  8170. ->where('status', 1)
  8171. ->select(
  8172. 'project.id',
  8173. 'project.title',
  8174. 'project.description',
  8175. 'project.updated_at',
  8176. 'project.category_id',
  8177. 'project.cat_arr_id'
  8178. )
  8179. ->orderBy('updated_at', 'desc')
  8180. ->limit($textnum)
  8181. ->get()->all();
  8182. }
  8183. if (!empty($imgnum) && $imgnum > 0) {
  8184. $img_num = Project::where('level', $level)
  8185. ->where('website_id', $data['website_id'])
  8186. ->where('status', 1)
  8187. ->where('imgurl', '!=', '')
  8188. ->whereNotNull('imgurl')
  8189. ->select(
  8190. 'project.id',
  8191. 'project.title',
  8192. 'project.description',
  8193. 'project.updated_at',
  8194. 'project.imgurl as imgs',
  8195. 'project.category_id',
  8196. 'project.cat_arr_id'
  8197. )
  8198. ->orderBy('updated_at', 'desc')
  8199. ->limit($imgnum)
  8200. ->get()->all();
  8201. }
  8202. } else {
  8203. if (!empty($textnum) && $textnum > 0) {
  8204. $text_num = Project::where('website_id', $data['website_id'])
  8205. ->where('status', 1)
  8206. ->select(
  8207. 'project.id',
  8208. 'project.title',
  8209. 'project.description',
  8210. 'project.updated_at',
  8211. 'project.category_id',
  8212. 'project.cat_arr_id',
  8213. 'project.website_id',
  8214. 'project.updated_at',
  8215. 'project.created_at'
  8216. )
  8217. ->orderBy('updated_at', 'desc')
  8218. ->limit($textnum)
  8219. ->get()->all();
  8220. }
  8221. if (!empty($imgnum) && $imgnum > 0) {
  8222. $img_num = Project::where('website_id', $data['website_id'])
  8223. ->where('status', 1)
  8224. ->where('imgurl', '!=', '')
  8225. ->whereNotNull('imgurl')
  8226. ->select(
  8227. 'project.id',
  8228. 'project.title',
  8229. 'project.description',
  8230. 'project.updated_at',
  8231. 'project.imgurl as imgs',
  8232. 'project.category_id',
  8233. 'project.cat_arr_id'
  8234. )
  8235. ->orderBy('updated_at', 'desc')
  8236. ->limit($imgnum)
  8237. ->get()->all();
  8238. }
  8239. }
  8240. }
  8241. if (isset($val['id'][0]) && !empty($val['id'][0])) {
  8242. $category_ids = explode(',', $val['id'])[0];
  8243. $cat_imgnum = explode(',', $val['id'])[1] ?? null;
  8244. $cat_textnum = explode(',', $val['id'])[2] ?? null;
  8245. $category_arr = array_merge([$category_ids], $cat_1st_arr[$category_ids] ?? [0]);
  8246. if (!empty($cat_textnum) && $cat_textnum > 0) {
  8247. $text_num = Project::whereIn('category_id', $category_arr)
  8248. ->where('website_id', $data['website_id'])
  8249. ->where('status', 1)
  8250. ->select(
  8251. 'project.id',
  8252. 'project.title',
  8253. 'project.description',
  8254. 'project.updated_at',
  8255. 'project.category_id',
  8256. 'project.cat_arr_id'
  8257. )
  8258. ->orderBy('updated_at', 'desc')
  8259. ->limit($cat_textnum)
  8260. ->get()->all();
  8261. }
  8262. if (!empty($cat_imgnum) && $cat_imgnum > 0) {
  8263. $img_num = Project::whereIn('category_id', $category_arr)
  8264. ->where('website_id', $data['website_id'])
  8265. ->where('status', 1)
  8266. ->where('imgurl', '!=', '')
  8267. ->whereNotNull('imgurl')
  8268. ->select(
  8269. 'project.id',
  8270. 'project.title',
  8271. 'project.description',
  8272. 'project.updated_at',
  8273. 'project.imgurl as imgs',
  8274. 'project.category_id',
  8275. 'project.cat_arr_id'
  8276. )
  8277. ->orderBy('updated_at', 'desc')
  8278. ->limit($cat_imgnum)
  8279. ->get()->all();
  8280. }
  8281. }
  8282. if (!empty($img_num)) {
  8283. foreach ($img_num as $k => $v) {
  8284. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8285. $imgurl = json_decode($v['imgs'], true);
  8286. if (!empty($imgurl)) {
  8287. $img_num[$k]->imgurl = $imgurl[0];
  8288. }
  8289. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8290. }
  8291. }
  8292. if (!empty($text_num)) {
  8293. foreach ($text_num as $k => $v) {
  8294. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8295. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8296. }
  8297. }
  8298. $project[$key]['img_num'] = $img_num ?? [];
  8299. $project[$key]['text_num'] = $text_num ?? [];
  8300. }
  8301. }
  8302. if (empty($project)) {
  8303. return Result::error("暂无相关项目信息", 0);
  8304. }
  8305. return Result::success($project);
  8306. }
  8307. /**
  8308. * @param array $data
  8309. * @return array
  8310. */
  8311. public function getWebsiteProjectInfo(array $data): array
  8312. {
  8313. $project = Project::where('id', $data['id'])
  8314. ->where('status', 1)
  8315. ->where('website_id', $data['website_id'])
  8316. ->select('project.*')
  8317. ->first();
  8318. if (empty($project)) {
  8319. return Result::error("暂无相关项目信息", 0);
  8320. }
  8321. return Result::success($project);
  8322. }
  8323. /**
  8324. * @param array $data
  8325. * @return array
  8326. */
  8327. public function getWebsiteProjectList(array $data): array
  8328. {
  8329. $where = [];
  8330. if (isset($data['category_id']) && !empty($data['category_id'])) {
  8331. $where['category_id'] = $data['category_id'];
  8332. }
  8333. if (isset($data['keyword']) && !empty($data['keyword'])) {
  8334. $where[] = ['title', 'like', '%' . $data['keyword'] . '%'];
  8335. }
  8336. $query = Project::where($where)
  8337. ->where('status', 1)
  8338. ->where('website_id', $data['website_id'])
  8339. ->select(
  8340. 'project.id',
  8341. 'project.title',
  8342. 'project.description',
  8343. 'project.imgurl as imgs',
  8344. 'project.category_id',
  8345. 'project.cat_arr_id'
  8346. )
  8347. ->orderBy('updated_at', 'desc');
  8348. $count = $query->count();
  8349. $project = $query->clone()
  8350. ->offset(($data['page'] - 1) * $data['pageSize'])
  8351. ->limit($data['pageSize'])
  8352. ->get()->all();
  8353. if (empty($project)) {
  8354. return Result::error("暂无相关项目信息", 0);
  8355. }
  8356. $categorys = $this->processArticlePro($data['website_id']);
  8357. $catiall = $categorys['catiall'];
  8358. foreach ($project as $key => $val) {
  8359. $project[$key]->category_name = $catiall[$val->category_id]['alias'];
  8360. if (!empty($val['imgs'])) {
  8361. $imgurl = json_decode($val['imgs'], true);
  8362. if (!empty($imgurl)) {
  8363. $project[$key]->imgurl = $imgurl[0];
  8364. }
  8365. } else {
  8366. $project[$key]->imgurl = '';
  8367. }
  8368. $project[$key]->pinyin = $catiall[$val->category_id]['pinyin'];
  8369. }
  8370. $result = [
  8371. 'rows' => $project,
  8372. 'count' => $count,
  8373. ];
  8374. return Result::success($result);
  8375. }
  8376. /**
  8377. * @param array $data
  8378. * @return array
  8379. */
  8380. public function getWebsiteCategoryJob(array $data): array
  8381. {
  8382. $categorys = json_decode($data['id'], true);
  8383. if (!empty($categorys)) {
  8384. $category_arr = $this->processArticlePro($data['website_id']);
  8385. $cat_1st_arr = $category_arr['cat_1st_arr'];
  8386. $catiall = $category_arr['catiall'];
  8387. foreach ($categorys as $key => $val) {
  8388. if (isset($val['id']) && !empty($val['id'])) {
  8389. $catid = explode(',', $val['id'])[0] ?? null;
  8390. $type = explode(',', $val['id'])[1] ?? null;
  8391. $textnum = explode(',', $val['id'])[2] ?? null;
  8392. }
  8393. // 4:招聘;5:求职;
  8394. if ($textnum > 0 && $type == 4 && !empty($catid)) {
  8395. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  8396. $job = JobRecruiting::WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($catid) . "') = 1")
  8397. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  8398. ->where('job_recruiting.status', 1)
  8399. ->where('job_recruiting.website_id', $data['website_id'])
  8400. ->select(
  8401. 'job_recruiting.id',
  8402. 'job_recruiting.title',
  8403. 'job_company.business_name',
  8404. 'job_recruiting.updated_at',
  8405. 'job_recruiting.cat_arr_id',
  8406. 'job_recruiting.keyword',
  8407. 'job_recruiting.description'
  8408. )
  8409. ->orderBy('job_recruiting.updated_at', 'desc')
  8410. ->limit($textnum)
  8411. ->get()->all();
  8412. } else if ($textnum > 0 && $type == 5 && !empty($catid)) {
  8413. // 状态 审核状态,1待审核2已审核3已拒绝
  8414. $job = JobHunting::WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($catid) . "') = 1")
  8415. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  8416. ->where('job_hunting.status', 2)
  8417. ->where('job_hunting.website_id', $data['website_id'])
  8418. ->select(
  8419. 'job_hunting.id',
  8420. 'job_hunting.name',
  8421. 'job_hunting.cat_arr_id',
  8422. 'job_position.zwname as job_name',
  8423. 'job_hunting.updated_at',
  8424. // 'job_hunting.keyword',
  8425. 'job_hunting.slelf_evaluation'
  8426. )
  8427. ->orderBy('updated_at', 'desc')
  8428. ->limit($textnum)
  8429. ->get()->all();
  8430. } else {
  8431. $job = [];
  8432. }
  8433. // var_dump($catid.'222uuuuuuu'.$key);
  8434. if (!empty($job)) {
  8435. foreach ($job as $k => $value) {
  8436. if (isset($value->cat_arr_id)) {
  8437. $catArr = json_decode($value->cat_arr_id, true);
  8438. $catId = end($catArr);
  8439. } else {
  8440. continue;
  8441. }
  8442. if (isset($catiall[$catId])) {
  8443. $job[$k]->pinyin = $catiall[$catId]['pinyin'];
  8444. }
  8445. }
  8446. }
  8447. // var_dump($catid.'xxxxx'.$key);
  8448. $result[$key] = $job ?? [];
  8449. }
  8450. }
  8451. if (empty($result)) {
  8452. return Result::error("暂无相关分类信息", 0);
  8453. }
  8454. return Result::success($result);
  8455. }
  8456. /**
  8457. * 发送消息
  8458. * @param array $messageData
  8459. * @return void
  8460. */
  8461. public function sendMessage($messageData)
  8462. {
  8463. $msg = [
  8464. 'talk_type' => $messageData['talk_type'],
  8465. 'title' => $messageData['title'],
  8466. 'content' => $messageData['content'],
  8467. 'messageType' => $messageData['messageType'],
  8468. 'user_id' => $messageData['user_id'] ?? '',
  8469. 'time' => microtime(),
  8470. ];
  8471. $message = new MqProducer($msg);
  8472. $producer = ContextApplicationContext::getContainer()->get(Producer::class);
  8473. $producer->produce($message);
  8474. }
  8475. /**
  8476. * 行业分类管理 ------1121
  8477. * @param array $data
  8478. * @return array
  8479. */
  8480. public function getJobIndustryList(array $data): array
  8481. {
  8482. $page = $data['page'] ?? 1;
  8483. $page_size = $data['page_size'] ?? 10;
  8484. if (isset($data['hyname']) && !empty($data['hyname'])) {
  8485. $where = ['hyname', 'like', '%' . $data['hyname'] . '%'];
  8486. } else {
  8487. $where = [];
  8488. }
  8489. $rs_query = JobIndustry::when(!empty($where), function ($query) use ($where) {
  8490. $query->where([$where]); // 修复:将条件包装成二维数组
  8491. })
  8492. ->orderBy('updated_at', 'desc');
  8493. $count = $rs_query->count();
  8494. $hy = $rs_query->offset(($page - 1) * $page_size)->limit($page_size)->get()->all();
  8495. $result = [
  8496. 'count' => $count,
  8497. 'list' => $hy,
  8498. ];
  8499. if (empty($hy)) {
  8500. return Result::success('暂无数据');
  8501. }
  8502. return Result::success($result);
  8503. }
  8504. /**
  8505. * 添加行业分类
  8506. * @param array $data
  8507. * @return array
  8508. */
  8509. public function addJobIndustry(array $data): array
  8510. {
  8511. $hy_name = JobIndustry::where('hyname', $data['hyname'])->first(['hyid']);
  8512. if (!empty($hy_name)) {
  8513. return Result::error('行业分类已存在');
  8514. }
  8515. $hy = JobIndustry::insertGetId($data);
  8516. if (empty($hy)) {
  8517. return Result::error('添加失败');
  8518. }
  8519. return Result::success($hy);
  8520. }
  8521. /**
  8522. * 更新行业分类
  8523. * @param array $data
  8524. * @return array
  8525. */
  8526. public function upJobIndustry(array $data): array
  8527. {
  8528. $hy_query = JobIndustry::get();
  8529. $hy_ids = $hy_query->pluck('hyid')->toArray();
  8530. $hy_names = $hy_query->pluck('hyname')->toArray();
  8531. if (!in_array($data['hyid'], $hy_ids)) {
  8532. return Result::error('行业分类不存在');
  8533. }
  8534. if (isset($data['hyname']) && !empty($data['hyname'])) {
  8535. $other_key_hy = array_search($data['hyid'], $hy_ids);
  8536. // return Result::success($other_key_hy);
  8537. unset($hy_names[$other_key_hy]);
  8538. if (in_array($data['hyname'], $hy_names)) {
  8539. return Result::error('行业分类名称已存在');
  8540. }
  8541. }
  8542. $hy = JobIndustry::where('hyid', $data['hyid'])->update($data);
  8543. if (empty($hy)) {
  8544. return Result::error('更新失败');
  8545. }
  8546. return Result::success($hy);
  8547. }
  8548. /**
  8549. * 删除行业分类
  8550. * @param array $data
  8551. * @return array
  8552. */
  8553. public function delJobIndustry(array $data): array
  8554. {
  8555. $hy_id = JobIndustry::where('hyid', $data['hyid'])->first(['hyid']);
  8556. if (empty($hy_id)) {
  8557. return Result::error('行业分类不存在');
  8558. }
  8559. $hy = JobIndustry::where('hyid', $data['hyid'])->delete();
  8560. if (empty($hy)) {
  8561. return Result::error('删除失败');
  8562. }
  8563. return Result::success($hy);
  8564. }
  8565. /**
  8566. * 职位分类-列表
  8567. * @param array $data
  8568. * @return array
  8569. */
  8570. public function getJobPositionList(array $data): array
  8571. {
  8572. $page = $data['page'] ?? 1;
  8573. $page_size = $data['page_size'] ?? 10;
  8574. $where = [];
  8575. if (isset($data['zwname']) && !empty($data['zwname'])) {
  8576. $zwids = JobPosition::where('zwpid', 0)
  8577. ->when(!empty($data['zwname']), function ($query) use ($data) {
  8578. $query->where('zwname', 'like', '%' . $data['zwname'] . '%');
  8579. })
  8580. ->orderBy('updated_at', 'desc')
  8581. ->pluck('zwid')
  8582. // ->get()
  8583. ->toArray();
  8584. }
  8585. if (isset($data['childname']) && !empty($data['childname'])) {
  8586. $child_zwids = JobPosition::where('zwpid', '!=', 0)
  8587. ->when(!empty($data['childname']), function ($query) use ($data) {
  8588. $query->where('zwname', 'like', '%' . $data['childname'] . '%');
  8589. })
  8590. ->orderBy('updated_at', 'desc')
  8591. ->pluck('zwpid')
  8592. // ->get()
  8593. ->toArray();
  8594. if (isset($zwids) && is_array($zwids) && is_array($child_zwids)) {
  8595. $child_zwids = array_intersect($zwids, $child_zwids);
  8596. }
  8597. $zwids = array_values(array_unique($child_zwids));
  8598. }
  8599. $zwids = $zwids ?? null;
  8600. $count = JobPosition::when(!empty($zwids), function ($query) use ($zwids) {
  8601. $query->whereIn('zwid', $zwids);
  8602. })
  8603. ->where('zwpid', 0)
  8604. ->count();
  8605. $position = JobPosition::when(!empty($zwids), function ($query) use ($zwids) {
  8606. $query->whereIn('zwid', $zwids);
  8607. })
  8608. ->where('zwpid', 0)
  8609. ->orderBy('updated_at', 'desc')
  8610. ->offset(($page - 1) * $page_size)
  8611. ->limit($page_size)->get()
  8612. ->map(function ($item) use ($data) {
  8613. $item->children = $item->where('zwpid', $item->zwid)
  8614. ->when(!empty($data['childname']), function ($query) use ($data) {
  8615. $query->where('zwname', 'like', '%' . $data['childname'] . '%');
  8616. })
  8617. ->orderBy('updated_at', 'desc')
  8618. ->get();
  8619. return $item;
  8620. })
  8621. ->all();
  8622. $result = [
  8623. 'count' => $count,
  8624. 'list' => $position,
  8625. ];
  8626. if (empty($result)) {
  8627. return Result::success('暂无数据');
  8628. }
  8629. return Result::success($result);
  8630. }
  8631. /**
  8632. * 职位分类-添加
  8633. * @param array $data
  8634. * @return array
  8635. */
  8636. public function addJobPosition(array $data): array
  8637. {
  8638. $zw_name = JobPosition::where('zwpid', $data['zwpid'])
  8639. ->where('zwname', $data['zwname'])->first(['zwid']);
  8640. if (!empty($zw_name)) {
  8641. return Result::error('职位分类已存在');
  8642. }
  8643. $zw = JobPosition::insertGetId($data);
  8644. if (empty($zw)) {
  8645. return Result::error('添加失败');
  8646. }
  8647. return Result::success($zw);
  8648. }
  8649. /**
  8650. * 更新职位分类
  8651. * @param array $data
  8652. * @return array
  8653. */
  8654. public function upJobPosition(array $data): array
  8655. {
  8656. $zw_position = JobPosition::get();
  8657. if (!in_array($data['zwid'], $zw_position->pluck('zwid')->toArray())) {
  8658. return Result::error('职位分类不存在');
  8659. }
  8660. $zw_name = $zw_position->where('zwid', '!=', $data['zwid'])
  8661. ->where('zwpid', $data['zwpid'])
  8662. ->where('zwname', $data['zwname'])->first();
  8663. if (!empty($zw_name)) {
  8664. return Result::error('职位分类已存在');
  8665. }
  8666. $result = JobPosition::where('zwid', $data['zwid'])->update($data);
  8667. if (empty($result)) {
  8668. return Result::error('更新失败');
  8669. }
  8670. return Result::success($result);
  8671. }
  8672. /**
  8673. * 删除职位分类
  8674. * @param array $data
  8675. * @return array
  8676. */
  8677. public function delJobPosition(array $data): array
  8678. {
  8679. $zw_jobposition = JobPosition::get();
  8680. $zw_id = $zw_jobposition->where('zwid', $data['zwid'])->first();
  8681. if (empty($zw_id)) {
  8682. return Result::error('职位分类不存在');
  8683. }
  8684. if ($zw_id->zwpid == 0) {
  8685. $zw_job = JobPosition::where('zwpid', $zw_id->zwid)->first();
  8686. if (!empty($zw_job)) {
  8687. return Result::error('请先删除子分类');
  8688. }
  8689. }
  8690. $result = JobPosition::where('zwid', $data['zwid'])->delete();
  8691. if (empty($result)) {
  8692. return Result::error('删除失败');
  8693. }
  8694. return Result::success($result);
  8695. }
  8696. /**
  8697. * 网民留言-添加
  8698. * @param array $data
  8699. * @return array
  8700. */
  8701. public function addMessage(array $data): array
  8702. {
  8703. $user = User::where('id', $data['user_id'])->first();
  8704. if (empty($user)) {
  8705. return Result::error('用户不存在');
  8706. }
  8707. if ($user['type_id'] == 10000) {
  8708. $data['status'] = 1;
  8709. } else {
  8710. $data['status'] = 0;
  8711. }
  8712. if ($data['keyword'] == '') {
  8713. //提取标题+内容中的关键词
  8714. $data['keyword'] = $data['title'];
  8715. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  8716. Jieba::init(); // 初始化 jieba-php
  8717. Finalseg::init();
  8718. $segList = Jieba::cut($data['keyword']);
  8719. $segList1 = array_slice($segList, 0, 8);
  8720. $data['keyword'] = implode(',', $segList1);
  8721. }
  8722. if ($data['description'] == '') {
  8723. //提取内容中的描述
  8724. $content = $data['content'];
  8725. // 去除 <style> 和 <script> 标签及其内容
  8726. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  8727. // 去除所有 HTML 标签
  8728. $content = strip_tags($content);
  8729. // 去除 HTML 实体
  8730. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  8731. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  8732. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  8733. // 去除多余空白
  8734. $content = preg_replace('/\s+/u', '', $content);
  8735. // 截取 100 个字符
  8736. $data['description'] = mb_substr($content, 0, 100);
  8737. }
  8738. if (!empty($data['reply'])) {
  8739. $data['reply_userid'] = $data['user_id'];
  8740. }
  8741. $result = Message::insertGetId($data);
  8742. if (empty($result)) {
  8743. return Result::error('添加失败');
  8744. }
  8745. return Result::success($result);
  8746. }
  8747. /**
  8748. * 网民留言-更新
  8749. * @param array $data
  8750. * @return array
  8751. */
  8752. public function upMessage(array $data): array
  8753. {
  8754. $user = User::where('id', $data['user_id'])->first();
  8755. if (empty($user)) {
  8756. return Result::error('用户不存在');
  8757. }
  8758. if ($user['type_id'] == 10000) {
  8759. $data['status'] = 1;
  8760. } else {
  8761. $data['status'] = 0;
  8762. }
  8763. $message = Message::where('id', $data['id'])->first();
  8764. if (empty($message)) {
  8765. return Result::error('留言不存在');
  8766. }
  8767. if ($data['user_id'] != $message['user_id'] && $user['type_id'] != 10000) {
  8768. return Result::error('非留言人不能更新');
  8769. }
  8770. if ($data['keyword'] == '') {
  8771. //提取标题+内容中的关键词
  8772. $data['keyword'] = $data['title'];
  8773. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  8774. Jieba::init(); // 初始化 jieba-php
  8775. Finalseg::init();
  8776. $segList = Jieba::cut($data['keyword']);
  8777. $segList1 = array_slice($segList, 0, 8);
  8778. $data['keyword'] = implode(',', $segList1);
  8779. }
  8780. if ($data['description'] == '') {
  8781. //提取内容中的描述
  8782. $content = $data['content'];
  8783. // 去除 <style> 和 <script> 标签及其内容
  8784. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  8785. // 去除所有 HTML 标签
  8786. $content = strip_tags($content);
  8787. // 去除 HTML 实体
  8788. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  8789. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  8790. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  8791. // 去除多余空白
  8792. $content = preg_replace('/\s+/u', '', $content);
  8793. // 截取 100 个字符
  8794. $data['description'] = mb_substr($content, 0, 100);
  8795. }
  8796. unset($data['id']);
  8797. if (!empty($data['reply'])) {
  8798. $data['reply_userid'] = $data['user_id'];
  8799. unset($data['user_id']);
  8800. }
  8801. $result = Message::where('id', $message['id'])->update($data);
  8802. if (empty($result)) {
  8803. return Result::error('更新失败');
  8804. }
  8805. return Result::success($result);
  8806. }
  8807. /**
  8808. * 网民留言-删除
  8809. * @param array $data
  8810. * @return array
  8811. */
  8812. public function delMessage(array $data): array
  8813. {
  8814. $result = Message::where('id', $data['id'])->delete();
  8815. if (empty($result)) {
  8816. return Result::error('删除失败');
  8817. }
  8818. return Result::success($result);
  8819. }
  8820. /**
  8821. * 网民留言-更新状态
  8822. * @param array $data
  8823. * @return array
  8824. */
  8825. public function upMessageStatus(array $data): array
  8826. {
  8827. $message = Message::where('id', $data['id'])->first();
  8828. if (empty($message)) {
  8829. return Result::error('留言不存在!');
  8830. }
  8831. unset($data['id']);
  8832. unset($data['user_id']);
  8833. if ($data['status'] != 2) {
  8834. $data['reason'] = null;
  8835. }
  8836. $result = Message::where('id', $message['id'])->update($data);
  8837. if (empty($result)) {
  8838. return Result::error('留言更新失败!');
  8839. }
  8840. return Result::success($result);
  8841. }
  8842. /**
  8843. * 网民留言-获取详情
  8844. * @param array $data
  8845. * @return array
  8846. */
  8847. public function getMessageInfo(array $data): array
  8848. {
  8849. $result = Message::where('message.id', $data['id'])
  8850. ->leftJoin('website_column', 'message.column_id', '=', 'website_column.id')
  8851. ->select('message.*', 'website_column.column_arr_id')
  8852. ->first();
  8853. if (empty($result)) {
  8854. return Result::error('留言不存在!');
  8855. }
  8856. $result['column_arr_id'] = json_decode($result['column_arr_id'] ?? [], true);
  8857. return Result::success($result);
  8858. }
  8859. /**
  8860. * 网民留言-获取列表
  8861. * @param array $data
  8862. * @return array
  8863. */
  8864. public function getMessageList(array $data): array
  8865. {
  8866. $where = [];
  8867. if ($data['is_master'] == 1) {
  8868. $where['message.status'] = 1;
  8869. } else if ($data['is_master'] == 2) {
  8870. $where['message.status'] = 2;
  8871. } else if ($data['is_master'] == 3) {
  8872. $where['message.status'] = 0;
  8873. }
  8874. $user = User::where('id', $data['user_id'])->first();
  8875. if (empty($user)) {
  8876. return Result::error('用户不存在');
  8877. }
  8878. $column_arr_id = [];
  8879. if ($user['type_id'] != 10000 && !empty($data['website_id'])) {
  8880. $where['message.user_id'] = $data['user_id'];
  8881. $web = Website::where('id', $data['website_id'])->first('website_column_arr_id');
  8882. if (empty($web)) {
  8883. return Result::error('此网站未关联任何网站属性!');
  8884. }
  8885. $column_arr_id = json_decode($web['website_column_arr_id'], true);
  8886. }
  8887. if (!empty($data['title'])) {
  8888. array_push($where, ['message.title', 'like', '%' . $data['title'] . '%']);
  8889. }
  8890. $result = Message::when($data['is_master'] == 0, function ($query) {
  8891. $query->whereIn('message.status', [0, 2]);
  8892. })
  8893. ->when(!empty($where), function ($query) use ($where) {
  8894. $query->where($where);
  8895. })
  8896. ->leftJoin('user', 'message.user_id', '=', 'user.id')
  8897. ->select('message.*', 'user.nickname')
  8898. ->orderBy('message.updated_at', 'desc')
  8899. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  8900. if (empty($result->items())) {
  8901. return Result::error('留言不存在!');
  8902. }
  8903. $result = [
  8904. 'data' => $result->items(),
  8905. 'count' => $result->total(),
  8906. ];
  8907. if (!empty($column_arr_id) && $user['type_id'] != 10000) {
  8908. foreach ($result['data'] as $key => $value) {
  8909. if (in_array($value['column_id'], $column_arr_id)) {
  8910. $result['data'][$key]['is_update'] = 1;
  8911. } else {
  8912. $result['data'][$key]['is_update'] = 0;
  8913. }
  8914. }
  8915. }
  8916. return Result::success($result);
  8917. }
  8918. /**
  8919. * 网民留言-检查是否可编辑
  8920. * @param array $data
  8921. * @return array
  8922. */
  8923. public function checkMessageEdit(array $data): array
  8924. {
  8925. $message = Message::where('id', $data['id'])->first();
  8926. if (empty($message)) {
  8927. return Result::error('留言不存在!');
  8928. }
  8929. $web = Website::where('id', $data['website_id'])->first();
  8930. if (empty($web)) {
  8931. return Result::error('网站不存在!');
  8932. }
  8933. $column_arr = json_decode($web['website_column_arr_id'] ?? [], true);
  8934. if (empty($column_arr)) {
  8935. return Result::error('该网站未关联任何属性!');
  8936. }
  8937. if (!in_array($message['column_id'], $column_arr)) {
  8938. return Result::error('不可编辑');
  8939. }
  8940. return Result::success('可编辑');
  8941. }
  8942. /**
  8943. * 调研选题-获取所有Researchers
  8944. * @param array $data
  8945. * @return array
  8946. */
  8947. public function getAllResearcher(array $data): array
  8948. {
  8949. $where['role_user.role_id'] = 21;
  8950. if (!empty($data['id'])) {
  8951. $where['user.id'] = $data['id'];
  8952. }
  8953. if (!empty($data['real_name'])) {
  8954. array_push($where, ['user_info.real_name', 'like', '%' . $data['real_name'] . '%']);
  8955. }
  8956. $users = User::leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  8957. ->leftJoin('role_user', 'user.id', '=', 'role_user.user_id')
  8958. ->where($where)
  8959. ->select('user.id', 'user_info.real_name', 'user_info.number')
  8960. ->get()->toArray();
  8961. if (empty($users)) {
  8962. return Result::error('此调研员不存在!');
  8963. }
  8964. $user_number = array_search($data['user_id'], array_column($users, 'id'));
  8965. if ($user_number == false) {
  8966. $result['number'] = null;
  8967. } else {
  8968. $result['number'] = $users[$user_number]['number'];
  8969. }
  8970. $result['users'] = $users;
  8971. $result['user_id'] = $data['user_id'];
  8972. return Result::success($result);
  8973. }
  8974. /**
  8975. * 调研选题-添加
  8976. * @param array $data
  8977. * @return array
  8978. */
  8979. public function addResearchTopic(array $data): array
  8980. {
  8981. $user = User::where('id', $data['user_id'])->first();
  8982. if (empty($user)) {
  8983. return Result::error('用户不存在');
  8984. }
  8985. if ($user['type_id'] == 10000) {
  8986. $data['status'] = 1;
  8987. } else {
  8988. $data['status'] = 0;
  8989. }
  8990. if ($data['keyword'] == '') {
  8991. //提取标题+内容中的关键词
  8992. $data['keyword'] = $data['title'];
  8993. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  8994. Jieba::init(); // 初始化 jieba-php
  8995. Finalseg::init();
  8996. $segList = Jieba::cut($data['keyword']);
  8997. $segList1 = array_slice($segList, 0, 8);
  8998. $data['keyword'] = implode(',', $segList1);
  8999. }
  9000. if ($data['description'] == '') {
  9001. //提取内容中的描述
  9002. $content = $data['content'];
  9003. // 去除 <style> 和 <script> 标签及其内容
  9004. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  9005. // 去除所有 HTML 标签
  9006. $content = strip_tags($content);
  9007. // 去除 HTML 实体
  9008. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  9009. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  9010. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  9011. // 去除多余空白
  9012. $content = preg_replace('/\s+/u', '', $content);
  9013. // 截取 100 个字符
  9014. $data['description'] = mb_substr($content, 0, 100);
  9015. }
  9016. $data['level'] = empty($data['level']) ? null : $data['level'];
  9017. $data['province_id'] = empty($data['province_id']) ? null : $data['province_id'];
  9018. $data['city_id'] = empty($data['city_id']) ? null : $data['city_id'];
  9019. $data['county_id'] = empty($data['county_id']) ? null : $data['county_id'];
  9020. $data['due_time'] = empty($data['due_time']) ? null : $data['due_time'];
  9021. $users_id = empty($data['users_id']) ? null : $data['users_id'];
  9022. unset($data['users_id']);
  9023. // return Result::success($data);
  9024. Db::beginTransaction();
  9025. try {
  9026. $result = ResearchTopic::insertGetId($data);
  9027. if (empty($result)) {
  9028. Db::rollBack();
  9029. return Result::error('添加失败');
  9030. }
  9031. if (!empty($users_id) && is_string($users_id)) {
  9032. $users = json_decode($users_id ?? '[]', true);
  9033. }
  9034. $users_type4 = User::where('type_id', 4)->pluck('id');
  9035. $type4_num = array_intersect($users, $users_type4->toArray());
  9036. if (count($users) != count($type4_num)) {
  9037. Db::rollBack();
  9038. return Result::error('请选择调研员!');
  9039. }
  9040. // return Result::success($users);
  9041. if (!empty($users) && is_array($users)) {
  9042. // 去重:确保同一 retopic_id + user_id 组合唯一
  9043. $users = array_values(array_unique($users));
  9044. // 组装关联数据
  9045. $users_topic = [];
  9046. foreach ($users as $key => $value) {
  9047. $users_topic[$key] = [
  9048. 'user_id' => $value,
  9049. 'retopic_id' => $result,
  9050. ];
  9051. }
  9052. // 使用 insertOrIgnore 忽略重复主键/唯一索引冲突
  9053. $retopic_user = RetopicUser::insert($users_topic);
  9054. if (empty($retopic_user)) {
  9055. Db::rollBack();
  9056. return Result::error('添加失败');
  9057. }
  9058. }
  9059. Db::commit();
  9060. return Result::success($result);
  9061. } catch (\Exception $e) {
  9062. Db::rollBack();
  9063. return Result::error($e->getMessage());
  9064. }
  9065. }
  9066. /**
  9067. * 调研选题-编辑
  9068. * @param array $data
  9069. * @return array
  9070. */
  9071. public function upResearchTopic(array $data): array
  9072. {
  9073. $user = User::where('id', $data['user_id'])->first();
  9074. if (empty($user)) {
  9075. return Result::error('用户不存在');
  9076. }
  9077. if ($user['type_id'] == 10000) {
  9078. $data['status'] = 1;
  9079. } else {
  9080. $data['status'] = 0;
  9081. }
  9082. $topic = ResearchTopic::where('id', $data['id'])->first();
  9083. if (empty($topic)) {
  9084. return Result::error('此调研选题不存在');
  9085. }
  9086. if ($data['keyword'] == '') {
  9087. //提取标题+内容中的关键词
  9088. $data['keyword'] = $data['title'];
  9089. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  9090. Jieba::init(); // 初始化 jieba-php
  9091. Finalseg::init();
  9092. $segList = Jieba::cut($data['keyword']);
  9093. $segList1 = array_slice($segList, 0, 8);
  9094. $data['keyword'] = implode(',', $segList1);
  9095. }
  9096. if ($data['description'] == '') {
  9097. //提取内容中的描述
  9098. $content = $data['content'];
  9099. // 去除 <style> 和 <script> 标签及其内容
  9100. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  9101. // 去除所有 HTML 标签
  9102. $content = strip_tags($content);
  9103. // 去除 HTML 实体
  9104. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  9105. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  9106. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  9107. // 去除多余空白
  9108. $content = preg_replace('/\s+/u', '', $content);
  9109. // 截取 100 个字符
  9110. $data['description'] = mb_substr($content, 0, 100);
  9111. }
  9112. $data['level'] = empty($data['level']) ? null : $data['level'];
  9113. $data['province_id'] = empty($data['province_id']) ? null : $data['province_id'];
  9114. $data['city_id'] = empty($data['city_id']) ? null : $data['city_id'];
  9115. $data['county_id'] = empty($data['county_id']) ? null : $data['county_id'];
  9116. $data['due_time'] = empty($data['due_time']) ? null : $data['due_time'];
  9117. $users_id = empty($data['users_id']) ? null : $data['users_id'];
  9118. $id = $data['id'];
  9119. unset($data['users_id']);
  9120. unset($data['id']);
  9121. // return Result::success($data);
  9122. Db::beginTransaction();
  9123. try {
  9124. $result = ResearchTopic::where('id', $id)->update($data);
  9125. if (empty($result)) {
  9126. Db::rollBack();
  9127. return Result::error('编辑调研选题失败!');
  9128. }
  9129. if (!empty($users_id) && is_string($users_id)) {
  9130. $users = json_decode($users_id ?? '[]', true);
  9131. }
  9132. // return Result::success($users);
  9133. $retopic_users = RetopicUser::where('retopic_id', $id)->pluck('user_id')->toArray();
  9134. if (!empty($retopic_users)) {
  9135. $del_users = RetopicUser::where('retopic_id', $id)->delete();
  9136. if (empty($del_users)) {
  9137. Db::rollBack();
  9138. return Result::error('编辑同行人员失败!');
  9139. }
  9140. }
  9141. if (!empty($users) && is_array($users)) {
  9142. // 去重:确保同一 retopic_id + user_id 组合唯一
  9143. $users = array_values(array_unique($users));
  9144. // 组装关联数据
  9145. $users_topic = [];
  9146. foreach ($users as $key => $value) {
  9147. $users_topic[$key] = [
  9148. 'user_id' => $value,
  9149. 'retopic_id' => $id,
  9150. ];
  9151. }
  9152. // 使用 insertOrIgnore 忽略重复主键/唯一索引冲突
  9153. $retopic_user = RetopicUser::insert($users_topic);
  9154. if (empty($retopic_user)) {
  9155. Db::rollBack();
  9156. return Result::error('编辑失败');
  9157. }
  9158. }
  9159. Db::commit();
  9160. return Result::success($result);
  9161. } catch (\Exception $e) {
  9162. Db::rollBack();
  9163. return Result::error($e->getMessage());
  9164. }
  9165. }
  9166. /**
  9167. * 调研选题-删除
  9168. * @param array $data
  9169. * @return array
  9170. */
  9171. public function delResearchTopic(array $data): array
  9172. {
  9173. $user = User::where('id', $data['user_id'])->first();
  9174. if (empty($user)) {
  9175. return Result::error('用户不存在');
  9176. }
  9177. $topic = ResearchTopic::where('id', $data['id'])->first();
  9178. if (empty($topic)) {
  9179. return Result::error('此调研选题不存在');
  9180. }
  9181. Db::beginTransaction();
  9182. try {
  9183. $result = ResearchTopic::where('id', $data['id'])->delete();
  9184. if (empty($result)) {
  9185. Db::rollBack();
  9186. return Result::error('删除调研选题失败!');
  9187. }
  9188. $topic_users = RetopicUser::where('retopic_id', $data['id'])->pluck('user_id')->toArray();
  9189. if (!empty($topic_users)) {
  9190. $del_topic_users = RetopicUser::where('retopic_id', $data['id'])->delete();
  9191. if (empty($del_topic_users)) {
  9192. Db::rollBack();
  9193. return Result::error('删除同行人员失败!');
  9194. }
  9195. }
  9196. Db::commit();
  9197. return Result::success($result);
  9198. } catch (\Exception $e) {
  9199. Db::rollBack();
  9200. return Result::error($e->getMessage());
  9201. }
  9202. }
  9203. /**
  9204. * 调研选题-列表
  9205. * @param array $data
  9206. * @return array
  9207. */
  9208. public function getResearchTopicList(array $data): array
  9209. {
  9210. $user = User::where('id', $data['user_id'])->first();
  9211. if (empty($user)) {
  9212. return Result::error('用户不存在!');
  9213. }
  9214. $where = [];
  9215. if ($user->type_id != 10000) {
  9216. $where['research_topic.user_id'] = $data['user_id'];
  9217. $website = Website::where('id', $data['website_id'])->first();
  9218. if (empty($website)) {
  9219. return Result::error('网站不存在!');
  9220. }
  9221. $web_column = json_decode($website->website_column_arr_id ?? '[]', true);
  9222. if (empty($web_column)) {
  9223. return Result::error('网站未配置栏目!');
  9224. }
  9225. }
  9226. if ($data['is_master'] != 0) {
  9227. if ($data['is_master'] == 3) {
  9228. $where['research_topic.status'] = 0;
  9229. } else {
  9230. $where['research_topic.status'] = $data['is_master'];
  9231. }
  9232. }
  9233. if (!empty($data['title'])) {
  9234. array_push($where, ['research_topic.title', 'like', '%' . $data['title'] . '%']);
  9235. }
  9236. $page = $data['page'] ?? 1;
  9237. $page_size = $data['page_size'] ?? 10;
  9238. $research_topic = ResearchTopic::when($data['is_master'] == 0, function ($query) use ($data) {
  9239. $query->whereIn('research_topic.status', [0, 2]);
  9240. })
  9241. ->when(!empty($where), function ($query) use ($where) {
  9242. $query->where($where);
  9243. })
  9244. ->with([
  9245. 'retopicUsers' => function ($query) {
  9246. $query->select('id', 'user_id', 'retopic_id');
  9247. }
  9248. ])
  9249. ->leftJoin('user', 'user.id', '=', 'research_topic.user_id')
  9250. ->leftJoin('user_info', 'user_info.user_id', '=', 'research_topic.user_id')
  9251. ->select(
  9252. 'research_topic.id',
  9253. 'research_topic.title',
  9254. 'research_topic.updated_at',
  9255. 'research_topic.status',
  9256. 'research_topic.due_time',
  9257. 'user_info.real_name',
  9258. 'research_topic.column_id',
  9259. 'research_topic.user_id',
  9260. 'user.user_name'
  9261. )
  9262. ->orderBy('research_topic.updated_at', 'desc')
  9263. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  9264. if (empty($research_topic->items())) {
  9265. return Result::error('暂无调研选题!');
  9266. }
  9267. $result = [
  9268. 'rows' => $research_topic->items(),
  9269. 'count' => $research_topic->total()
  9270. ];
  9271. foreach ($result['rows'] as $key => $value) {
  9272. if ($user->type_id != 10000) {
  9273. if (in_array($value['column_id'], $web_column)) {
  9274. $result['rows'][$key]['is_update'] = 1;
  9275. } else {
  9276. $result['rows'][$key]['is_update'] = 0;
  9277. }
  9278. } else {
  9279. if ($value['user_id'] == $data['user_id']) {
  9280. $result['rows'][$key]['is_update'] = 1;
  9281. } else {
  9282. $result['rows'][$key]['is_update'] = 0;
  9283. }
  9284. }
  9285. if (!isset($value['real_name']) || empty($value['real_name'])) {
  9286. $result['rows'][$key]['real_name'] = $value['user_name'];
  9287. }
  9288. if (!empty($value['retopicUsers'])) {
  9289. $retopic_users = $value['retopicUsers'];
  9290. $retopic_user = $retopic_users->pluck('user_id')->toArray();
  9291. $result['rows'][$key]['txry_users'] = implode(',', $retopic_user);
  9292. unset($result['rows'][$key]['retopicUsers']);
  9293. }
  9294. }
  9295. return Result::success($result);
  9296. }
  9297. /**
  9298. * 调研选题-修改状态
  9299. * @param array $data
  9300. * @return array
  9301. */
  9302. public function checkResearchTopic(array $data): array
  9303. {
  9304. $user = User::where('id', $data['user_id'])->first();
  9305. if (empty($user)) {
  9306. return Result::error('用户不存在!');
  9307. }
  9308. if ($user->type_id != 10000 && ($data['status'] == 1 || $data['status'] == 2)) {
  9309. return Result::error('此用户暂无权限!');
  9310. }
  9311. $topic = ResearchTopic::where('id', $data['id'])->first();
  9312. if (empty($topic)) {
  9313. return Result::error('此调研选题不存在');
  9314. }
  9315. $id = $data['id'];
  9316. unset($data['id']);
  9317. unset($data['user_id']);
  9318. $result = ResearchTopic::where('id', $id)->update($data);
  9319. if (empty($result)) {
  9320. return Result::error('修改调研选题状态失败!');
  9321. }
  9322. return Result::success($result);
  9323. }
  9324. /**
  9325. * 调研选题-详情
  9326. * @param array $data
  9327. * @return array
  9328. */
  9329. public function getResearchTopicInfo(array $data): array
  9330. {
  9331. $user = User::where('id', $data['user_id'])->first();
  9332. if (empty($user)) {
  9333. return Result::error('用户不存在!');
  9334. }
  9335. $research_topic = ResearchTopic::where('research_topic.id', $data['id'])
  9336. ->with([
  9337. 'retopicUsers' => function ($query) {
  9338. $query->select('user_id', 'retopic_id');
  9339. }
  9340. ])
  9341. ->leftJoin('user', 'user.id', '=', 'research_topic.user_id')
  9342. ->leftJoin('user_info', 'user_info.user_id', '=', 'research_topic.user_id')
  9343. ->select('research_topic.*', 'user_info.number')
  9344. ->first();
  9345. if (empty($research_topic)) {
  9346. return Result::error('获取调研选题详情失败!');
  9347. }
  9348. $retopic_user = $research_topic['retopicUsers'];
  9349. if (!empty($retopic_user)) {
  9350. $retopic_user = $retopic_user->pluck('user_id')->toArray();
  9351. foreach ($retopic_user as $key => $value) {
  9352. $real_name = UserInfo::where('user_id', $value)->value('real_name');
  9353. $research_topic['retopicUsers'][$key]['real_name'] = $real_name;
  9354. $research_topic['retopicUsers'][$key]['user_id'] = $value;
  9355. unset($research_topic['retopicUsers'][$key]['retopic_id']);
  9356. }
  9357. }
  9358. return Result::success($research_topic);
  9359. }
  9360. /**
  9361. * 添加网站导航
  9362. * @param array $data
  9363. */
  9364. public function addWebCateinfo(array $data): array
  9365. {
  9366. $user = User::where('id', $data['user_id'])->first();
  9367. if (empty($user)) {
  9368. return Result::error('用户不存在');
  9369. }
  9370. if ($user['type_id'] == 10000) {
  9371. $data['status'] = 1;
  9372. } else {
  9373. $data['status'] = 0;
  9374. }
  9375. if ($data['keyword'] == '') {
  9376. //提取标题+内容中的关键词
  9377. $data['keyword'] = $data['title'];
  9378. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  9379. Jieba::init(); // 初始化 jieba-php
  9380. Finalseg::init();
  9381. $segList = Jieba::cut($data['keyword']);
  9382. $segList1 = array_slice($segList, 0, 8);
  9383. $data['keyword'] = implode(',', $segList1);
  9384. }
  9385. if ($data['description'] == '') {
  9386. //提取内容中的描述
  9387. $content = $data['content'];
  9388. // 去除 <style> 和 <script> 标签及其内容
  9389. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  9390. // 去除所有 HTML 标签
  9391. $content = strip_tags($content);
  9392. // 去除 HTML 实体
  9393. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  9394. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  9395. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  9396. // 去除多余空白
  9397. $content = preg_replace('/\s+/u', '', $content);
  9398. // 截取 100 个字符
  9399. $data['description'] = mb_substr($content, 0, 100);
  9400. }
  9401. $data['cate_name'] = empty($data['cate_name']) ? '官网导航' : $data['cate_name'];
  9402. $data['province_id'] = empty($data['province_id']) ? null : $data['province_id'];
  9403. $data['city_id'] = empty($data['city_id']) ? null : $data['city_id'];
  9404. $data['county_id'] = empty($data['county_id']) ? null : $data['county_id'];
  9405. unset($data['users_id']);
  9406. $result = WebCateinfo::insertGetId($data);
  9407. if (empty($result)) {
  9408. return Result::error('添加失败');
  9409. }
  9410. return Result::success($result);
  9411. }
  9412. /**
  9413. * 更新网站导航
  9414. * @param array $data
  9415. */
  9416. public function upWebCateinfo(array $data): array
  9417. {
  9418. $webCateinfo = WebCateinfo::where('id', $data['id'])->first();
  9419. if (empty($webCateinfo)) {
  9420. return Result::error('导航不存在');
  9421. }
  9422. $user = User::where('id', $data['user_id'])->first();
  9423. if (empty($user)) {
  9424. return Result::error('用户不存在');
  9425. }
  9426. if ($user['type_id'] == 10000) {
  9427. $data['status'] = 1;
  9428. } else {
  9429. $data['status'] = 0;
  9430. }
  9431. if ($data['keyword'] == '') {
  9432. //提取标题+内容中的关键词
  9433. $data['keyword'] = $data['title'];
  9434. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  9435. Jieba::init(); // 初始化 jieba-php
  9436. Finalseg::init();
  9437. $segList = Jieba::cut($data['keyword']);
  9438. $segList1 = array_slice($segList, 0, 8);
  9439. $data['keyword'] = implode(',', $segList1);
  9440. }
  9441. if ($data['description'] == '') {
  9442. //提取内容中的描述
  9443. $content = $data['content'];
  9444. // 去除 <style> 和 <script> 标签及其内容
  9445. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  9446. // 去除所有 HTML 标签
  9447. $content = strip_tags($content);
  9448. // 去除 HTML 实体
  9449. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  9450. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  9451. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  9452. // 去除多余空白
  9453. $content = preg_replace('/\s+/u', '', $content);
  9454. // 截取 100 个字符
  9455. $data['description'] = mb_substr($content, 0, 100);
  9456. }
  9457. $data['cate_name'] = empty($data['cate_name']) ? '官网导航' : $data['cate_name'];
  9458. $data['province_id'] = empty($data['province_id']) ? null : $data['province_id'];
  9459. $data['city_id'] = empty($data['city_id']) ? null : $data['city_id'];
  9460. $data['county_id'] = empty($data['county_id']) ? null : $data['county_id'];
  9461. unset($data['users_id']);
  9462. $result = WebCateinfo::where('id', $data['id'])->update($data);
  9463. if (empty($result)) {
  9464. return Result::error('更新失败');
  9465. }
  9466. return Result::success($result);
  9467. }
  9468. /**
  9469. * 获取网站导航列表
  9470. * @param array $data
  9471. * @return array
  9472. */
  9473. public function getWebCateinfoList(array $data): array
  9474. {
  9475. $user = User::where('id', $data['user_id'])->first();
  9476. if (empty($user)) {
  9477. return Result::error('用户不存在');
  9478. }
  9479. $where = [];
  9480. if ($user['type_id'] != 10000) {
  9481. $where['web_cateinfo.user_id'] = $data['user_id'];
  9482. }
  9483. if (!empty($data['title'])) {
  9484. array_push($where, ['web_cateinfo.title', 'like', '%' . $data['title'] . '%']);
  9485. }
  9486. if ($data['is_master'] != 0) {
  9487. if ($data['is_master'] == 3) {
  9488. $where['web_cateinfo.status'] = 0;
  9489. } else {
  9490. $where['web_cateinfo.status'] = $data['is_master'];
  9491. }
  9492. }
  9493. $web_cateinfo = WebCateinfo::when(!empty($data['is_master'] == 0), function ($query) use ($where) {
  9494. $query->whereIn('web_cateinfo.status', [0, 2]);
  9495. })
  9496. ->when(!empty($where), function ($query) use ($where) {
  9497. $query->where($where);
  9498. })
  9499. ->leftJoin('user', 'web_cateinfo.user_id', '=', 'user.id')
  9500. ->select(['web_cateinfo.id', 'web_cateinfo.user_id', 'user.nickname', 'web_cateinfo.title', 'web_cateinfo.cate_name', 'web_cateinfo.status', 'web_cateinfo.updated_at'])
  9501. ->orderBy('updated_at', 'desc')
  9502. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  9503. if (empty($web_cateinfo->items())) {
  9504. return Result::error('官网导航不存在');
  9505. }
  9506. $result = [
  9507. 'rows' => $web_cateinfo->items(),
  9508. 'total' => $web_cateinfo->total(),
  9509. ];
  9510. foreach ($result['rows'] as $key => $value) {
  9511. if ($value['user_id'] == $data['user_id']) {
  9512. $result['rows'][$key]['is_update'] = 1;
  9513. } else {
  9514. $result['rows'][$key]['is_update'] = 0;
  9515. }
  9516. }
  9517. return Result::success($result);
  9518. }
  9519. /**
  9520. * 删除网站导航
  9521. * @param array $data
  9522. */
  9523. public function delWebCateinfo(array $data): array
  9524. {
  9525. $webCateinfo = WebCateinfo::where('id', $data['id'])->first();
  9526. if (empty($webCateinfo)) {
  9527. return Result::error('导航不存在');
  9528. }
  9529. $result = WebCateinfo::where('id', $data['id'])->delete();
  9530. if (empty($result)) {
  9531. return Result::error('删除失败');
  9532. }
  9533. return Result::success($result);
  9534. }
  9535. /**
  9536. * 审核网站导航
  9537. * @param array $data
  9538. */
  9539. public function checkWebCateinfo(array $data): array
  9540. {
  9541. $webCateinfo = WebCateinfo::where('id', $data['id'])->first();
  9542. if (empty($webCateinfo)) {
  9543. return Result::error('导航不存在');
  9544. }
  9545. $user = User::where('id', $data['user_id'])->first();
  9546. if (empty($user)) {
  9547. return Result::error('用户不存在');
  9548. }
  9549. if ($user['type_id'] != 10000 && $data['status'] == 1) {
  9550. return Result::error('非管理员不能审核');
  9551. }
  9552. $update_data['status'] = $data['status'];
  9553. if ($data['status'] == 2) {
  9554. $update_data['reason'] = $data['reason'];
  9555. }
  9556. $result = WebCateinfo::where('id', $data['id'])->update($update_data);
  9557. if (empty($result)) {
  9558. return Result::error('审核失败');
  9559. }
  9560. return Result::success($result);
  9561. }
  9562. /**
  9563. * 获取网站导航详情
  9564. * @param array $data
  9565. */
  9566. public function getWebCateinfoDetail(array $data): array
  9567. {
  9568. $webCateinfo = WebCateinfo::where('id', $data['id'])->first();
  9569. if (empty($webCateinfo)) {
  9570. return Result::error('导航不存在');
  9571. }
  9572. $result = $webCateinfo->toArray();
  9573. return Result::success($result);
  9574. }
  9575. /**
  9576. * 推荐单页管理
  9577. * @param array $data
  9578. */
  9579. public function getAdviceSinglePages(array $data): array
  9580. {
  9581. $user = User::where('id', $data['user_id'])->first();
  9582. if (empty($user)) {
  9583. return Result::error('用户不存在');
  9584. }
  9585. $where = [];
  9586. if (empty($data['website_id']) && $user['type_id'] == 10000) {
  9587. $category = [];
  9588. } else {
  9589. $where = [
  9590. 'website_id' => $data['website_id'] ?? $data['web_id'],
  9591. ];
  9592. $category = WebsiteCategory::where($where)->pluck('category_id')->toArray();
  9593. // var_dump($ids);
  9594. if (empty($category)) {
  9595. return Result::error("推荐单页不存在");
  9596. }
  9597. }
  9598. if (!empty($data['title'])) {
  9599. array_push($where, ['title', 'like', '%' . $data['title'] . '%']);
  9600. }
  9601. $result = SinglePage::when(!empty($category), function ($query) use ($category) {
  9602. $query->whereIn('catid', $category);
  9603. })
  9604. ->when(!empty($where), function ($query) use ($where) {
  9605. $query->where($where);
  9606. })
  9607. // ->when(!isset($data['catid']), function ($query) use ($data) {
  9608. // $query->where('catid', $data['catid']);
  9609. // })
  9610. ->where('status', 1)
  9611. ->select(['id', 'title', 'catid', 'status', 'website_id', 'updated_at'])
  9612. ->orderBy('updated_at', 'desc')
  9613. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  9614. if (empty($result->items())) {
  9615. return Result::error('推荐单页不存在!');
  9616. }
  9617. $result = [
  9618. 'rows' => $result->items(),
  9619. 'total' => $result->total(),
  9620. ];
  9621. return Result::success($result);
  9622. }
  9623. /**
  9624. * 添加单页
  9625. * @param array $data
  9626. */
  9627. public function addSinglePage(array $data): array
  9628. {
  9629. $user = User::where('id', $data['user_id'])->first();
  9630. if (empty($user)) {
  9631. return Result::error('用户不存在');
  9632. }
  9633. if ($user['type_id'] == 10000) {
  9634. $data['status'] = 1;
  9635. } else {
  9636. $data['status'] = 0;
  9637. }
  9638. if (is_array($data['cat_arr_id'])) {
  9639. $data['cat_arr_id'] = array_map(function ($item) {
  9640. return intval($item);
  9641. }, $data['cat_arr_id']);
  9642. $data['catid'] = end($data['cat_arr_id']);
  9643. $data['cat_arr_id'] = json_encode($data['cat_arr_id'], JSON_UNESCAPED_UNICODE);
  9644. } else {
  9645. return Result::error('请选择栏目;');
  9646. }
  9647. if (!empty($data['commend_id']) && is_array($data['commend_id'])) {
  9648. $data['commend_id'] = json_encode($data['commend_id'], JSON_UNESCAPED_UNICODE);
  9649. } else {
  9650. $data['commend_id'] = null;
  9651. }
  9652. if ($data['keyword'] == '') {
  9653. //提取标题+内容中的关键词
  9654. $articleData['keyword'] = $data['title'];
  9655. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  9656. Jieba::init(); // 初始化 jieba-php
  9657. Finalseg::init();
  9658. $segList = Jieba::cut($articleData['keyword']);
  9659. $segList1 = array_slice($segList, 0, 8);
  9660. $data['keyword'] = implode(',', $segList1);
  9661. }
  9662. if ($data['description'] == '') {
  9663. //提取内容中的描述
  9664. $content = $data['content'];
  9665. // 去除 <style> 和 <script> 标签及其内容
  9666. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  9667. // 去除所有 HTML 标签
  9668. $content = strip_tags($content);
  9669. // 去除 HTML 实体
  9670. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  9671. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  9672. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  9673. // 去除多余空白
  9674. $content = preg_replace('/\s+/u', '', $content);
  9675. // 截取 100 个字符
  9676. $data['description'] = mb_substr($content, 0, 100);
  9677. }
  9678. if (empty($data['publiced_at'])) {
  9679. $data['publiced_at'] = null;
  9680. }
  9681. $result = SinglePage::insertGetId($data);
  9682. if (empty($result)) {
  9683. return Result::error('添加失败');
  9684. }
  9685. return Result::success($result);
  9686. }
  9687. /**
  9688. * 更新单页
  9689. * @param array $data
  9690. */
  9691. public function upSinglePage(array $data): array
  9692. {
  9693. $singlePage = SinglePage::where('id', $data['id'])->where('user_id', $data['user_id'])->first();
  9694. if (empty($singlePage)) {
  9695. return Result::error('单页不存在');
  9696. }
  9697. $user = User::where('id', $data['user_id'])->first();
  9698. if (empty($user)) {
  9699. return Result::error('用户不存在');
  9700. }
  9701. $where['id'] = $data['id'];
  9702. unset($data['id']);
  9703. if ($user['type_id'] == 10000) {
  9704. $data['status'] = 1;
  9705. } else {
  9706. $data['status'] = 0;
  9707. }
  9708. if (is_array($data['cat_arr_id'])) {
  9709. $data['cat_arr_id'] = array_map(function ($item) {
  9710. return intval($item);
  9711. }, $data['cat_arr_id']);
  9712. $data['catid'] = end($data['cat_arr_id']);
  9713. $data['cat_arr_id'] = json_encode($data['cat_arr_id'], JSON_UNESCAPED_UNICODE);
  9714. } else {
  9715. return Result::error('请选择栏目;');
  9716. }
  9717. if (!empty($data['commend_id']) && is_array($data['commend_id'])) {
  9718. $data['commend_id'] = json_encode($data['commend_id'], JSON_UNESCAPED_UNICODE);
  9719. } else {
  9720. $data['commend_id'] = null;
  9721. }
  9722. if ($data['keyword'] == '') {
  9723. //提取标题+内容中的关键词
  9724. $articleData['keyword'] = $data['title'];
  9725. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  9726. Jieba::init(); // 初始化 jieba-php
  9727. Finalseg::init();
  9728. $segList = Jieba::cut($articleData['keyword']);
  9729. $segList1 = array_slice($segList, 0, 8);
  9730. $data['keyword'] = implode(',', $segList1);
  9731. }
  9732. if ($data['description'] == '') {
  9733. //提取内容中的描述
  9734. $content = $data['content'];
  9735. // 去除 <style> 和 <script> 标签及其内容
  9736. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  9737. // 去除所有 HTML 标签
  9738. $content = strip_tags($content);
  9739. // 去除 HTML 实体
  9740. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  9741. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  9742. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  9743. // 去除多余空白
  9744. $content = preg_replace('/\s+/u', '', $content);
  9745. // 截取 100 个字符
  9746. $data['description'] = mb_substr($content, 0, 100);
  9747. }
  9748. if (empty($data['publiced_at'])) {
  9749. $data['publiced_at'] = null;
  9750. }
  9751. $result = SinglePage::where($where)->update($data);
  9752. if (empty($result)) {
  9753. return Result::error('更新失败');
  9754. }
  9755. return Result::success($result);
  9756. }
  9757. /**
  9758. * 删除单页
  9759. * @param array $data
  9760. */
  9761. public function delSinglePage(array $data): array
  9762. {
  9763. $singlePage = SinglePage::where('id', $data['id'])->first();
  9764. if (empty($singlePage)) {
  9765. return Result::error('单页不存在');
  9766. }
  9767. $user = User::where('id', $data['user_id'])->first();
  9768. if (empty($user)) {
  9769. return Result::error('用户不存在');
  9770. }
  9771. $where['id'] = $data['id'];
  9772. $result = SinglePage::where($where)->delete();
  9773. if (empty($result)) {
  9774. return Result::error('删除失败');
  9775. }
  9776. return Result::success($result);
  9777. }
  9778. /**
  9779. * 审核单页
  9780. * @param array $data
  9781. */
  9782. public function checkSinglePage(array $data): array
  9783. {
  9784. $user = User::where('id', $data['user_id'])->first();
  9785. if (empty($user)) {
  9786. return Result::error('用户不存在');
  9787. }
  9788. if ($user['type_id'] != 10000 && in_array($data['status'], [1, 2])) {
  9789. return Result::error('非管理员不能审核单页');
  9790. }
  9791. if ($data['status'] == 2) {
  9792. $update_data['reason'] = $data['reason'] ?? '';
  9793. }
  9794. $update_data['status'] = $data['status'];
  9795. $result = SinglePage::where('id', $data['id'])->update($update_data);
  9796. if (empty($result)) {
  9797. return Result::error('更新失败');
  9798. }
  9799. return Result::success($result);
  9800. }
  9801. /**
  9802. * 更新单页状态
  9803. * @param array $data
  9804. */
  9805. public function getSinglePageList(array $data): array
  9806. {
  9807. $user = User::where('id', $data['user_id'])->first();
  9808. if (empty($user)) {
  9809. return Result::error('用户不存在');
  9810. }
  9811. $where = [];
  9812. if ($user['type_id'] != 10000) {
  9813. $where['single_page.user_id'] = $data['user_id'];
  9814. }
  9815. if ($data['is_master'] == 3) {
  9816. $where['single_page.status'] = 0;
  9817. } else if ($data['is_master'] != 0) {
  9818. $where['single_page.status'] = $data['is_master'];
  9819. }
  9820. if (!empty($data['title'])) {
  9821. array_push($where, ['single_page.title', 'like', '%' . $data['title'] . '%']);
  9822. }
  9823. $result = SinglePage::when($data['is_master'] == 0, function ($query) use ($data) {
  9824. $query->whereIn('single_page.status', [0, 2]);
  9825. })
  9826. ->when(!empty($where), function ($query) use ($where) {
  9827. $query->where($where);
  9828. })
  9829. ->with([
  9830. 'websiteCategory' => function ($query) {
  9831. $query->select('website_id', 'category_id', 'alias');
  9832. },
  9833. 'user' => function ($query) {
  9834. $query->select('id', 'nickname');
  9835. }
  9836. ])
  9837. ->select([
  9838. 'single_page.id',
  9839. 'single_page.title',
  9840. 'single_page.content',
  9841. 'single_page.updated_at',
  9842. 'single_page.status',
  9843. 'single_page.catid',
  9844. 'single_page.website_id',
  9845. 'single_page.user_id'
  9846. ])
  9847. ->orderBy('single_page.updated_at', 'desc')
  9848. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  9849. if (empty($result->items())) {
  9850. return Result::error('暂无数据');
  9851. }
  9852. $result = [
  9853. 'rows' => $result->items(),
  9854. 'total' => $result->total(),
  9855. ];
  9856. foreach ($result['rows'] as $key => $value) {
  9857. $result['rows'][$key]['category_alias'] = $value['websiteCategory']['alias'] ?? '';
  9858. $result['rows'][$key]['user_nickname'] = $value['user']['nickname'] ?? '';
  9859. $result['rows'][$key]['websiteCategory'] = $value['websiteCategory']['alias'] ?? '';
  9860. unset($result['rows'][$key]['user']);
  9861. unset($result['rows'][$key]['websiteCategory']);
  9862. if ($user['type_id'] == 10000) {
  9863. if ($value['user_id'] == $data['user_id']) {
  9864. $result['rows'][$key]['is_update'] = 1;
  9865. } else {
  9866. $result['rows'][$key]['is_update'] = 0;
  9867. }
  9868. } else {
  9869. if ($value['website_id'] == $data['website_id']) {
  9870. $result['rows'][$key]['is_update'] = 1;
  9871. } else {
  9872. $result['rows'][$key]['is_update'] = 0;
  9873. }
  9874. }
  9875. }
  9876. return Result::success($result);
  9877. }
  9878. /**
  9879. * 获取单页详情
  9880. * @param array $data
  9881. */
  9882. public function getSinglePageInfo(array $data): array
  9883. {
  9884. $singlePage = SinglePage::where('id', $data['id'])->first();
  9885. if (empty($singlePage)) {
  9886. return Result::error('单页不存在');
  9887. }
  9888. $user = User::where('id', $data['user_id'])->first();
  9889. if (empty($user)) {
  9890. return Result::error('用户不存在');
  9891. }
  9892. $where['id'] = $data['id'];
  9893. $result = SinglePage::where($where)->first();
  9894. if (empty($result)) {
  9895. return Result::error('获取失败');
  9896. }
  9897. $result['cat_arr_id'] = json_decode($result['cat_arr_id'] ?? '[]', true);
  9898. $result['commend_id'] = json_decode($result['commend_id'] ?? '[]', true);
  9899. return Result::success($result);
  9900. }
  9901. // 政讯--官网--在线留言
  9902. /**
  9903. * 政讯--官网--在线留言-添加
  9904. * @param array $data
  9905. * @return array
  9906. */
  9907. public function addOnline(array $data): array
  9908. {
  9909. $user = User::where('id', $data['user_id'])->first();
  9910. if (empty($user)) {
  9911. return Result::error('用户不存在');
  9912. }
  9913. if ($user['type_id'] == 10000) {
  9914. $data['status'] = 1;
  9915. } else {
  9916. $data['status'] = 0;
  9917. }
  9918. $result = Gonline::insertGetId($data);
  9919. if (empty($result)) {
  9920. return Result::error('添加失败');
  9921. }
  9922. return Result::success($result);
  9923. }
  9924. /**
  9925. * 网民留言-获取官网在线留言列表
  9926. * @param array $data
  9927. * @return array
  9928. */
  9929. public function getOnlineList(array $data): array
  9930. {
  9931. $page = $data['page'] ?? 1;
  9932. $page_size = $data['page_size'] ?? 10;
  9933. $where = [];
  9934. if (!empty($data['title'])) {
  9935. array_push($where, ['gonline.title', 'like', '%' . $data['title'] . '%']);
  9936. }
  9937. if (!empty($data['status'])) {
  9938. $where['gonline.status'] = $data['status'];
  9939. }
  9940. $user = User::where('id', $data['user_id'])->first();
  9941. if (empty($user)) {
  9942. return Result::error('用户不存在');
  9943. }
  9944. $column_arr_id = [];
  9945. if ($user['type_id'] != 10000 && !empty($data['website_id'])) {
  9946. $where['gonline.user_id'] = $data['user_id'];
  9947. $web = Website::where('id', $data['website_id'])->first('website_column_arr_id');
  9948. if (empty($web)) {
  9949. return Result::error('此网站未关联任何网站属性!');
  9950. }
  9951. $column_arr_id = json_decode($web['website_column_arr_id'], true);
  9952. }
  9953. if (!empty($data['title'])) {
  9954. array_push($where, ['gonline.title', 'like', '%' . $data['title'] . '%']);
  9955. }
  9956. $result = Gonline::when($data['is_master'] == 0, function ($query) {
  9957. $query->whereIn('gonline.status', [0, 2]);
  9958. })
  9959. ->when(!empty($where), function ($query) use ($where) {
  9960. $query->where($where);
  9961. })
  9962. ->leftJoin('user', 'gonline.user_id', '=', 'user.id')
  9963. ->select('gonline.*', 'user.nickname')
  9964. ->orderBy('gonline.updated_at', 'desc')
  9965. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  9966. if (empty($result->items())) {
  9967. return Result::error('留言不存在!');
  9968. }
  9969. $result = [
  9970. 'data' => $result->items(),
  9971. 'count' => $result->total(),
  9972. ];
  9973. if (!empty($column_arr_id) && $user['type_id'] != 10000) {
  9974. foreach ($result['data'] as $key => $value) {
  9975. if (in_array($value['column_id'], $column_arr_id)) {
  9976. $result['data'][$key]['is_update'] = 1;
  9977. } else {
  9978. $result['data'][$key]['is_update'] = 0;
  9979. }
  9980. }
  9981. }
  9982. return Result::success($result);
  9983. }
  9984. /**
  9985. * 网民留言-留言修改
  9986. * @param array $data
  9987. * @return array
  9988. */
  9989. public function upOnline(array $data): array
  9990. {
  9991. $user = User::where('id', $data['user_id'])->first();
  9992. if (empty($user)) {
  9993. return Result::error('用户不存在!');
  9994. }
  9995. $gonline = Gonline::where('id', $data['id'])->first();
  9996. if (empty($gonline)) {
  9997. return Result::error('此留言不存在');
  9998. }
  9999. }
  10000. /**
  10001. * 网民留言-检查是否可编辑
  10002. * @param array $data
  10003. * @return array
  10004. */
  10005. public function checkOnline(array $data): array
  10006. {
  10007. $gonline = Gonline::where('id', $data['id'])->first();
  10008. if (empty($gonline)) {
  10009. return Result::error('此留言不存在');
  10010. }
  10011. $web = Website::where('id', $data['website_id'])->first();
  10012. if (empty($web)) {
  10013. return Result::error('网站不存在!');
  10014. }
  10015. $column_arr = json_decode($web['website_column_arr_id'] ?? [], true);
  10016. if (empty($column_arr)) {
  10017. return Result::error('该网站未关联任何属性!');
  10018. }
  10019. if (!in_array($gonline['column_id'], $column_arr)) {
  10020. return Result::error('不可编辑');
  10021. }
  10022. return Result::success('可编辑');
  10023. }
  10024. /**
  10025. * 网民留言-修改留言状态
  10026. * @param array $data
  10027. * @return array
  10028. */
  10029. public function upOnlineStatus(array $data): array
  10030. {
  10031. $user = User::where('id', $data['user_id'])->first();
  10032. if (empty($user)) {
  10033. return Result::error('用户不存在!');
  10034. }
  10035. $gonline = Gonline::where('id', $data['id'])->first();
  10036. if (empty($gonline)) {
  10037. return Result::error('此留言不存在');
  10038. }
  10039. $id = $data['id'];
  10040. unset($data['id']);
  10041. unset($data['user_id']);
  10042. $result = Gonline::where('id', $id)->update($data);
  10043. if (empty($result)) {
  10044. return Result::error('修改留言状态失败!');
  10045. }
  10046. return Result::success($result);
  10047. }
  10048. /**
  10049. * 网民留言-删除留言
  10050. * @param array $data
  10051. * @return array
  10052. */
  10053. public function delOnline(array $data): array
  10054. {
  10055. $user = User::where('id', $data['user_id'])->first();
  10056. if (empty($user)) {
  10057. return Result::error('用户不存在!');
  10058. }
  10059. $gonline = Gonline::where('id', $data['id'])->first();
  10060. if (empty($gonline)) {
  10061. return Result::error('此留言不存在');
  10062. }
  10063. $result = Gonline::where('id', $data['id'])->delete();
  10064. if (empty($result)) {
  10065. return Result::error('删除留言失败!');
  10066. }
  10067. return Result::success($result);
  10068. }
  10069. /**
  10070. * 网民留言-获取详情
  10071. * @param array $data
  10072. * @return array
  10073. */
  10074. public function getOnlineInfo(array $data): array
  10075. {
  10076. $user = User::where('id', $data['user_id'])->first();
  10077. if (empty($user)) {
  10078. return Result::error('用户不存在!');
  10079. }
  10080. $gonline = Gonline::where('id', $data['id'])->first();
  10081. if (empty($gonline)) {
  10082. return Result::error('此留言不存在');
  10083. }
  10084. return Result::success($gonline);
  10085. }
  10086. /**
  10087. * 网民留言-修改状态
  10088. * @param array $data
  10089. * @return array
  10090. */
  10091. public function checkOnlineStatus(array $data): array
  10092. {
  10093. $user = User::where('id', $data['user_id'])->first();
  10094. if (empty($user)) {
  10095. return Result::error('用户不存在!');
  10096. }
  10097. $gonline = Gonline::where('id', $data['id'])->first();
  10098. if (empty($gonline)) {
  10099. return Result::error('此留言不存在');
  10100. }
  10101. $id = $data['id'];
  10102. unset($data['id']);
  10103. unset($data['user_id']);
  10104. $result = Gonline::where('id', $id)->update($data);
  10105. if (empty($result)) {
  10106. return Result::error('修改留言状态失败!');
  10107. }
  10108. return Result::success($result);
  10109. }
  10110. // 政讯--官网--法律咨询 Glaw
  10111. /**
  10112. * 法律咨询-获取官网法律咨询列表
  10113. * @param array $data
  10114. * @return array
  10115. */
  10116. public function getLawList(array $data): array
  10117. {
  10118. $page = $data['page'] ?? 1;
  10119. $page_size = $data['page_size'] ?? 10;
  10120. $where = [];
  10121. if (!empty($data['title'])) {
  10122. array_push($where, ['glaw.title', 'like', '%' . $data['title'] . '%']);
  10123. }
  10124. if (!empty($data['status'])) {
  10125. $where['glaw.status'] = $data['status'];
  10126. }
  10127. $result = Glaw::when($data['is_master'] == 0, function ($query) {
  10128. $query->whereIn('glaw.status', [0, 2]);
  10129. })
  10130. ->when(!empty($where), function ($query) use ($where) {
  10131. $query->where($where);
  10132. })
  10133. ->leftJoin('user', 'glaw.user_id', '=', 'user.id')
  10134. ->select('glaw.*', 'user.nickname')
  10135. ->orderBy('glaw.updated_at', 'desc')
  10136. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  10137. if (empty($result->items())) {
  10138. return Result::error('法律咨询不存在!');
  10139. }
  10140. $result = [
  10141. 'data' => $result->items(),
  10142. 'count' => $result->total(),
  10143. ];
  10144. return Result::success($result);
  10145. }
  10146. /**
  10147. * 法律咨询-修改法律咨询状态
  10148. * @param array $data
  10149. * @return array
  10150. */
  10151. public function upLawStatus(array $data): array
  10152. {
  10153. $user = User::where('id', $data['user_id'])->first();
  10154. if (empty($user)) {
  10155. return Result::error('用户不存在!');
  10156. }
  10157. $glaw = Glaw::where('id', $data['id'])->first();
  10158. if (empty($glaw)) {
  10159. return Result::error('此法律咨询不存在');
  10160. }
  10161. $id = $data['id'];
  10162. unset($data['id']);
  10163. unset($data['user_id']);
  10164. $result = Glaw::where('id', $id)->update($data);
  10165. if (empty($result)) {
  10166. return Result::error('修改法律咨询状态失败!');
  10167. }
  10168. return Result::success($result);
  10169. }
  10170. /**
  10171. * 法律咨询-删除法律咨询
  10172. * @param array $data
  10173. * @return array
  10174. */
  10175. public function delLaw(array $data): array
  10176. {
  10177. $user = User::where('id', $data['user_id'])->first();
  10178. if (empty($user)) {
  10179. return Result::error('用户不存在!');
  10180. }
  10181. $glaw = Glaw::where('id', $data['id'])->first();
  10182. if (empty($glaw)) {
  10183. return Result::error('此法律咨询不存在');
  10184. }
  10185. }
  10186. /**
  10187. * 法律咨询-获取详情
  10188. * @param array $data
  10189. * @return array
  10190. */
  10191. public function getLawInfo(array $data): array
  10192. {
  10193. $user = User::where('id', $data['user_id'])->first();
  10194. if (empty($user)) {
  10195. return Result::error('用户不存在!');
  10196. }
  10197. $glaw = Glaw::where('id', $data['id'])->first();
  10198. if (empty($glaw)) {
  10199. return Result::error('此法律咨询不存在');
  10200. }
  10201. return Result::success($glaw);
  10202. }
  10203. /**
  10204. * 法律咨询-添加
  10205. * @param array $data
  10206. * @return array
  10207. */
  10208. public function addLaw(array $data): array
  10209. {
  10210. $user = User::where('id', $data['user_id'])->first();
  10211. if (empty($user)) {
  10212. return Result::error('用户不存在!');
  10213. }
  10214. $result = Glaw::create($data);
  10215. if (empty($result)) {
  10216. return Result::error('添加法律咨询失败!');
  10217. }
  10218. return Result::success($result);
  10219. }
  10220. /**
  10221. * 法律咨询-编辑
  10222. */
  10223. public function upLaw(array $data): array
  10224. {
  10225. $user = User::where('id', $data['user_id'])->first();
  10226. if (empty($user)) {
  10227. return Result::error('用户不存在!');
  10228. }
  10229. $glaw = Glaw::where('id', $data['id'])->first();
  10230. if (empty($glaw)) {
  10231. return Result::error('此法律咨询不存在');
  10232. }
  10233. $id = $data['id'];
  10234. unset($data['id']);
  10235. unset($data['user_id']);
  10236. $result = Glaw::where('id', $id)->update($data);
  10237. if (empty($result)) {
  10238. return Result::error('编辑法律咨询失败!');
  10239. }
  10240. return Result::success($result);
  10241. }
  10242. /**
  10243. * 法律咨询-检查是否可编辑
  10244. */
  10245. public function checkLaw(array $data): array
  10246. {
  10247. $glaw = Glaw::where('id', $data['id'])->first();
  10248. if (empty($glaw)) {
  10249. return Result::error('此法律咨询不存在');
  10250. }
  10251. $web = Website::where('id', $data['website_id'])->first();
  10252. if (empty($web)) {
  10253. return Result::error('网站不存在!');
  10254. }
  10255. $column_arr = json_decode($web['website_column_arr_id'] ?? [], true);
  10256. if (empty($column_arr)) {
  10257. return Result::error('该网站未关联任何属性!');
  10258. }
  10259. if (!in_array($glaw['column_id'], $column_arr)) {
  10260. return Result::error('不可编辑');
  10261. }
  10262. return Result::success('可编辑');
  10263. }
  10264. }