NewsService.php 314 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555
  1. <?php
  2. namespace App\JsonRpc;
  3. use App\Model\Article;
  4. use App\Model\ArticleData;
  5. use App\Model\Category;
  6. use App\Model\HistoryToday;
  7. use App\Model\WebsiteCategory;
  8. use App\Model\ArticleSurvey;
  9. use App\Model\District;
  10. use App\Model\Good;
  11. use App\Model\JobCompany;
  12. use App\Model\Website;
  13. use App\Model\JobRecruiting;
  14. use App\Model\JobIndustry;
  15. use App\Model\Book;
  16. use App\Model\JobPosition;
  17. use App\Model\Notice;
  18. use App\Model\JobNature;
  19. use App\Model\JobEnum;
  20. use App\Model\User;
  21. use App\Model\UserRole;
  22. use App\Model\News;
  23. use App\Model\UserInfo;
  24. use App\Model\WebsiteGroup;;
  25. use App\Model\JobResume;
  26. use Hyperf\DbConnection\Db;
  27. use Hyperf\RpcServer\Annotation\RpcService;
  28. use App\Tools\Result;
  29. use Directory;
  30. use Ramsey\Uuid\Uuid;
  31. use Hyperf\Utils\Random;
  32. use Fukuball\Jieba\Jieba;
  33. use Fukuball\Jieba\Finalseg;
  34. use Hyperf\Utils\Collection;
  35. use function Hyperf\Support\retry;
  36. use App\Tools\PublicData;
  37. use App\Model\ChatGroups;
  38. use App\Model\ChatGroupsMember;
  39. use App\Model\ChatRecords;
  40. use App\Model\Complaint;
  41. use Hamcrest\Arrays\IsArray;
  42. use Hyperf\Codec\Json;
  43. use App\Tools\buildMenuTree;
  44. use App\Model\JobApply;
  45. use App\Model\JobHunting;
  46. use App\Model\JobRemuse;
  47. use Hyperf\Redis\Redis;
  48. use Hyperf\Di\Annotation\Inject;
  49. use App\Model\Festival;
  50. use App\Model\Character;
  51. use App\Model\Couplet;
  52. use App\Model\Riddle;
  53. use App\Model\Idiom;
  54. use App\Model\WhiteRouter;
  55. use Illuminate\Support\Facades\Cache;
  56. use App\Model\Company;
  57. use Hyperf\Paginator\Paginator;
  58. use App\Model\Project;
  59. use Hyperf\Context\Context;
  60. use Hyperf\Context\ApplicationContext as ContextApplicationContext;
  61. use Hyperf\Amqp\Producer;
  62. use App\Amqp\Producer\MqProducer;
  63. use App\Model\Web;
  64. use App\Model\GroupMemberImp;
  65. use App\Model\GroupImp;
  66. use App\Model\GroupTalkImp;
  67. use App\Model\GroupTalkMessagerImp;
  68. use App\Model\ArticleIgnore;
  69. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  70. class NewsService implements NewsServiceInterface
  71. {
  72. #[Inject]
  73. protected Redis $redis;
  74. /**
  75. * 获取导航池列表
  76. * @param array $data
  77. * @return array
  78. */
  79. public function getCategoryList(array $data): array
  80. {
  81. $search = $data['name'] ?? '';
  82. $page = (int)($data['page'] ?? 1);
  83. $perPage = (int)($data['pageSize'] ?? 10);
  84. // 1. 查出所有匹配的分类id
  85. if ($search) {
  86. $matchedIds = Category::where('name', 'like', "%{$search}%")->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  87. if (empty($matchedIds)) {
  88. return Result::success(['rows' => [], 'total' => 0]);
  89. }
  90. // 2. 递归查所有父级,直到一级分类
  91. $idsStr = implode(',', $matchedIds);
  92. $sql = "
  93. WITH RECURSIVE parents AS (
  94. SELECT * FROM category WHERE id IN ($idsStr)
  95. UNION ALL
  96. SELECT c.* FROM category c
  97. INNER JOIN parents p ON c.id = p.pid
  98. )
  99. SELECT * FROM parents
  100. ";
  101. $parents = Db::select($sql);
  102. $parentIds = [];
  103. foreach ($parents as $row) {
  104. if ($row->pid == 0) {
  105. $parentIds[] = $row->id;
  106. }
  107. }
  108. $parentIds = array_unique($parentIds);
  109. } else {
  110. // 没有搜索,一级分类就是根
  111. $parentIds = Category::where('pid', 0)->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  112. }
  113. // 3. 一级分类分页
  114. $total = count($parentIds);
  115. $parentIds = array_slice($parentIds, ($page - 1) * $perPage, $perPage);
  116. if (empty($parentIds)) {
  117. return Result::success(['rows' => [], 'total' => $total]);
  118. }
  119. // 4. 递归查所有子孙
  120. $idsStr = implode(',', $parentIds);
  121. $sql = "
  122. WITH RECURSIVE subcategories AS (
  123. SELECT * FROM category WHERE id IN ($idsStr)
  124. UNION ALL
  125. SELECT c.* FROM category c
  126. INNER JOIN subcategories s ON c.pid = s.id
  127. )
  128. SELECT * FROM subcategories ORDER BY updated_at DESC
  129. ";
  130. $allCategories = Db::select($sql);
  131. // 5. 组装树结构
  132. $categoryMap = [];
  133. foreach ($allCategories as $cat) {
  134. $cat = (array)$cat;
  135. $cat['children'] = [];
  136. $categoryMap[$cat['id']] = $cat;
  137. }
  138. foreach ($categoryMap as $id => &$cat) {
  139. if ($cat['pid'] && isset($categoryMap[$cat['pid']])) {
  140. $categoryMap[$cat['pid']]['children'][] = &$cat;
  141. }
  142. }
  143. unset($cat);
  144. $categoryTree = [];
  145. foreach ($parentIds as $id) {
  146. if (isset($categoryMap[$id])) {
  147. $categoryTree[] = $categoryMap[$id];
  148. }
  149. }
  150. return Result::success([
  151. 'rows' => $categoryTree,
  152. 'total' => $total,
  153. ]);
  154. }
  155. private function findMatchedCategories($search)
  156. {
  157. if ($search) {
  158. return Category::where('name', 'like', "%{$search}%")
  159. ->orderBy('updated_at', 'desc')
  160. ->get();
  161. }
  162. return Category::orderBy('updated_at', 'desc') // 按 updated_at 字段倒序排序
  163. ->get();
  164. }
  165. private function findAllParents($categories)
  166. {
  167. $allCategories = [];
  168. foreach ($categories as $category) {
  169. $parentId = $category->pid;
  170. while ($parentId > 0) {
  171. $parent = Category::find($parentId);
  172. if ($parent) {
  173. $allCategories[$parent->id] = $parent;
  174. $parentId = $parent->pid;
  175. } else {
  176. break;
  177. }
  178. }
  179. $allCategories[$category->id] = $category;
  180. }
  181. return array_values($allCategories);
  182. }
  183. private function buildCategoryTree($category, $allRequiredCategories)
  184. {
  185. $categoryData = $category->toArray();
  186. $children = [];
  187. foreach ($allRequiredCategories as $c) {
  188. if ($c->pid === $category->id) {
  189. $children[] = $this->buildCategoryTree($c, $allRequiredCategories);
  190. }
  191. }
  192. if (!empty($children)) {
  193. $categoryData['children'] = $children;
  194. }
  195. return $categoryData;
  196. }
  197. public function myCategoryList(array $data): array
  198. {
  199. $sszq = $data['sszq'] ?? '';
  200. unset($data['sszq']);
  201. //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
  202. $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
  203. $where[] = [
  204. 'pid',
  205. '=',
  206. $data['pid'],
  207. ];
  208. if (isset($data['name'])) {
  209. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  210. }
  211. var_dump($where);
  212. //根据分类id,从category表中取出分类信息
  213. $result = Category::where($where)
  214. ->whereIn('category.id', $catorytids)
  215. ->select('category.*', 'category.id as category_id')->get();
  216. if (empty($result)) {
  217. return Result::error("没有栏目数据");
  218. }
  219. return Result::success($result);
  220. }
  221. /**
  222. * @param array $data
  223. * @return array
  224. */
  225. public function categoryList(array $data): array
  226. {
  227. $where[] = [
  228. 'pid',
  229. '=',
  230. $data['pid']
  231. ];
  232. if (isset($data['name'])) {
  233. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  234. }
  235. var_dump($where);
  236. $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
  237. if (empty($result)) {
  238. return Result::error("没有栏目数据");
  239. }
  240. return Result::success($result);
  241. }
  242. /**
  243. * @param array $data
  244. * @return array
  245. */
  246. public function addCategory(array $data): array
  247. {
  248. if (isset($data['id'])) {
  249. unset($data['id']);
  250. }
  251. $id = Category::insertGetId($data);
  252. if (empty($id)) {
  253. return Result::error("添加失败");
  254. }
  255. return Result::success(['id' => $id]);
  256. }
  257. /**
  258. * @param array $data
  259. * @return array
  260. */
  261. public function delCategory(array $data): array
  262. {
  263. Db::beginTransaction();
  264. try {
  265. $categoryList = Category::where(['pid' => $data['id']])->get();
  266. if ($categoryList->toArray()) {
  267. Db::rollBack();
  268. return Result::error("分类下面有子分类不能删除");
  269. }
  270. $articleList = Article::where(['catid' => $data['id']])->get();
  271. if ($articleList->toArray()) {
  272. Db::rollBack();
  273. return Result::error("分类下面有资讯不能删除");
  274. }
  275. $result = Category::where($data)->delete();
  276. WebsiteCategory::where(['category_id' => $data['id']])->delete();
  277. if (!$result) {
  278. Db::rollBack();
  279. return Result::error("删除失败");
  280. }
  281. Db::commit();
  282. return Result::success($result);
  283. } catch (\Exception $e) {
  284. Db::rollBack();
  285. return Result::error("删除失败" . $e->getMessage());
  286. }
  287. }
  288. /**
  289. * @param array $data
  290. * @return array
  291. */
  292. public function updateCategory(array $data): array
  293. {
  294. $where = [
  295. 'id' => $data['id'],
  296. ];
  297. $result = Category::where($where)->update($data);
  298. if ($result) {
  299. return Result::success($result);
  300. } else {
  301. return Result::error("更新失败");
  302. }
  303. }
  304. /**
  305. * 获取导航池信息
  306. * @param array $data
  307. * @return array
  308. */
  309. public function getCategoryInfo(array $data): array
  310. {
  311. $where = [
  312. 'id' => $data['id'],
  313. ];
  314. $result = Category::where($where)->first();
  315. if ($result) {
  316. return Result::success($result);
  317. } else {
  318. return Result::error("更新失败");
  319. }
  320. }
  321. public function getArticleCommend(array $data): array
  322. {
  323. $where = [
  324. 'website_id' => $data['website_id'],
  325. ];
  326. $ids = WebsiteCategory::where($where)->pluck('category_id')->toArray();
  327. var_dump($ids);
  328. if (empty($ids)) {
  329. return Result::error("没有推荐数据");
  330. }
  331. //id
  332. $whereArticle = [];
  333. if (isset($data['id'])) {
  334. $whereArticle['id'] = $data['id'];
  335. }
  336. //title like
  337. if (isset($data['title'])) {
  338. array_push($whereArticle, ['title', 'like', "%{$data['title']}%"]);
  339. }
  340. $article = Article::whereIn('catid', values: $ids)->where('status', 1)
  341. ->where($whereArticle)
  342. ->orderBy('id', 'desc')
  343. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  344. if ($article) {
  345. $data = [
  346. 'rows' => $article->items(),
  347. 'count' => $article->total(),
  348. ];
  349. return Result::success($data);
  350. } else {
  351. return Result::error("获取失败失败");
  352. }
  353. }
  354. /**
  355. * @param array $data
  356. * @return array
  357. */
  358. public function getArticleList(array $data): array
  359. {
  360. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  361. $type_id = $data['type_id'];
  362. unset($data['type_id']);
  363. $user_id = $data['user_id'];
  364. unset($data['user_id']);
  365. $where = [];
  366. $status1 = [];
  367. if (isset($data['id']) && $data['id']) {
  368. array_push($where, ['article.id', '=', $data['id']]);
  369. }
  370. if (isset($data['title']) && $data['title']) {
  371. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  372. }
  373. if (isset($data['category_name']) && $data['category_name']) {
  374. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  375. }
  376. if (isset($data['catid']) && $data['catid']) {
  377. array_push($where, ['article.catid', '=', $data['catid']]);
  378. }
  379. if (isset($data['author']) && $data['author']) {
  380. array_push($where, ['article.author', '=', $data['author']]);
  381. }
  382. if (isset($data['islink']) && $data['islink'] !== "") {
  383. array_push($where, ['article.islink', '=', $data['islink']]);
  384. }
  385. if (isset($data['status']) && $data['status'] !== "") {
  386. array_push($where, ['article.status', '=', $data['status']]);
  387. }
  388. if (isset($data['status1'])) {
  389. $status1 = json_decode(($data['status1']));
  390. }
  391. //不是管理员展示个人数据;
  392. if ($type_id != 10000) {
  393. $where[] = ['article.admin_user_id', '=', $user_id];
  394. }
  395. // $rep = Article::where($where)
  396. // ->whereNotIn('article.status', [404])
  397. // ->when($status1, function ($query) use ($status1) {
  398. // if (isset($status1) && $status1) {
  399. // $query->whereIn('article.status', $status1);
  400. // }
  401. // })
  402. // ->leftJoin('category', 'article.catid', 'category.id')
  403. // ->leftJoin('website_category', function ($join) {
  404. // $join->on('article.web_site_id', '=', 'website_category.website_id')
  405. // ->on('article.catid', '=', 'website_category.category_id');
  406. // })
  407. // ->when($type_id != 10000 && !empty($data['website_id']), function ($query) use ($data) {
  408. // $query->leftJoin('article_ignore', function ($join) use ($data) {
  409. // $join->on('article.id', '=', 'article_ignore.article_id')
  410. // ->where('article_ignore.website_id', $data['website_id']);
  411. // });
  412. // })
  413. // ->select("article.*", "category.name as category_name", "website_category.alias",
  414. // Db::raw('IFNULL(article_ignore.c_show_time, "") as c_show_time'))
  415. // ->orderBy("article.updated_at", "desc")
  416. // ->limit($data['pageSize'])
  417. // ->offset(($data['page'] - 1) * $data['pageSize'])->get();
  418. //
  419. $query = Article::where($where)
  420. ->whereNotIn('article.status', [404])
  421. ->when($status1, function ($query) use ($status1) {
  422. if (isset($status1) && $status1) {
  423. $query->whereIn('article.status', $status1);
  424. }
  425. })
  426. ->leftJoin('category', 'article.catid', 'category.id')
  427. ->leftJoin('website_category', function ($join) {
  428. $join->on('article.web_site_id', '=', 'website_category.website_id')
  429. ->on('article.catid', '=', 'website_category.category_id');
  430. });
  431. if ($type_id != 10000 && !empty($data['website_id'])) {
  432. $query = $query
  433. ->leftJoin('article_ignore', function ($join) use ($data) {
  434. $join->on('article.id', '=', 'article_ignore.article_id')
  435. ->where('article_ignore.website_id', $data['website_id']);
  436. })
  437. ->select("article.*", "category.name as category_name", "website_category.alias",'article_ignore.c_show_time');
  438. } else {
  439. $query = $query
  440. ->select("article.*", "category.name as category_name", "website_category.alias");
  441. }
  442. $rep = $query
  443. ->orderBy("article.updated_at", "desc")
  444. ->limit($data['pageSize'])
  445. ->offset(($data['page'] - 1) * $data['pageSize'])
  446. ->get();
  447. $count = $query->count();
  448. $data = [
  449. 'rows' => $rep->toArray(),
  450. 'count' => $count,
  451. ];
  452. if (empty($rep)) {
  453. return Result::error("没有信息数据");
  454. }
  455. return Result::success($data);
  456. }
  457. /**
  458. * @param array $data
  459. * @return array
  460. */
  461. public function addArticle(array $data): array
  462. {
  463. var_dump($data, '----------12-----------1');
  464. // ------c_show_time********add***1****
  465. $is_collect = $data['is_collect'] ?? 0;
  466. $user_type = $data['user_type'];
  467. unset($data['is_collect']);
  468. unset($data['user_type']);
  469. // ------c_show_time********add***1****
  470. unset($data['nav_add_pool_id']);
  471. // unset($data['commend_id']);
  472. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  473. Db::beginTransaction();
  474. try {
  475. //处理投票
  476. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  477. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  478. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  479. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  480. unset($data['is_survey']);
  481. unset($data['survey_name']);
  482. unset($data['suvey_array']);
  483. unset($data['website_id']);
  484. unset($data['web_site_id']);
  485. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  486. if ($data['hits'] == '') {
  487. $data['hits'] = 0;
  488. }
  489. if ($data['is_original'] == '') {
  490. $data['is_original'] = 0;
  491. }
  492. if ($data['status'] == '') {
  493. $data['status'] = 0;
  494. }
  495. $articleData = $data;
  496. unset($articleData['content']);
  497. //自动处理缩略图、关键字、描述
  498. if ($articleData['imgurl'] == '') {
  499. //如果没有图,设置level=0
  500. $levelArr = json_decode($articleData['level'], true);
  501. var_dump($levelArr, '----------levelArr-----------1');
  502. //content中提取图片第一个图,正则提取
  503. // -------采集器相关优化-----
  504. // 优化正则表达式,仅匹配 src 属性值,避免匹配到多余内容
  505. if($is_collect == 1){
  506. $reg = '/<img.*?src=[\'"]?((?!.*\.gif)[^\'" >]+)[\'"]?.*?>/i';
  507. }else{
  508. $reg = '/<img.*?src=[\'"]?([^\'" >]+)[\'"]?.*?>/i';
  509. }
  510. // -------采集器相关优化-----
  511. preg_match_all($reg, $data['content'], $matches);
  512. if (isset($matches[1][0])) {
  513. //截取varchar240
  514. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  515. //如果有图,设置level=3
  516. if (!in_array(3, $levelArr)) {
  517. $levelArr[] = 3;
  518. }
  519. $articleData['level'] = json_encode($levelArr);
  520. } else {
  521. if (!in_array(0, $levelArr)) {
  522. $levelArr[] = 0;
  523. }
  524. $articleData['level'] = json_encode($levelArr);
  525. }
  526. }
  527. var_dump($articleData['level'], '----------$articleData[level]----------1');
  528. if ($articleData['keyword'] == '') {
  529. //提取标题+内容中的关键词
  530. $articleData['keyword'] = $data['title'];
  531. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  532. Jieba::init(); // 初始化 jieba-php
  533. Finalseg::init();
  534. $segList = Jieba::cut($articleData['keyword']);
  535. $segList1 = array_slice($segList, 0, 8);
  536. $articleData['keyword'] = implode(',', $segList1);
  537. }
  538. if ($articleData['introduce'] == '') {
  539. //提取内容中的描述
  540. $content = $data['content'];
  541. // 去除 <style> 和 <script> 标签及其内容
  542. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  543. // 去除所有 HTML 标签
  544. $content = strip_tags($content);
  545. // 去除 HTML 实体
  546. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  547. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  548. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  549. // 去除多余空白
  550. $content = preg_replace('/\s+/u', '', $content);
  551. // 截取 100 个字符
  552. $articleData['introduce'] = mb_substr($content, 0, 100);
  553. }
  554. if ($articleData['status'] == 0) {
  555. $this->sendMessage([
  556. 'talk_type' => 100,
  557. 'title' => $articleData['title'],
  558. 'content' => '提交了审核',
  559. 'messageType' => 2,
  560. ]);
  561. }
  562. $id = Article::insertGetId($articleData);
  563. if (!$id) {
  564. throw new \Exception('文章插入失败');
  565. }
  566. $articleDataContent = [
  567. 'article_id' => $id,
  568. 'content' => $data['content'],
  569. ];
  570. $contentInsertId = ArticleData::insertGetId($articleDataContent);
  571. if (!$contentInsertId) {
  572. throw new \Exception('文章内容插入失败');
  573. }
  574. // ------c_show_time********add***2****
  575. // 直接使用当前系统时间,不再强制添加8小时
  576. $now = date('Y-m-d H:i:s');
  577. if($user_type == 10000 || $is_collect == 1){
  578. // 管理员添加文章时,核心站c端显示时间就是创建时间;非核心站c端显示时间就是此创建时间往后推二十分钟;
  579. // 非管理员添加文章时,不做操作只有在审核通过时获取c端显示时间
  580. if (!isset($data['catid'])) {
  581. throw new \Exception('缺少必要字段:catid');
  582. }
  583. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  584. $web = WebsiteCategory::where('category_id', $data['catid'])
  585. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  586. ->select('website_id',
  587. 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'))
  588. ->get();
  589. // $id = 225; -----测试开启
  590. // 采集来的文章,错开时间在两小时之内发布
  591. if($user_type == 10000 && $is_collect == 1){
  592. $web_num = $web->where('is_core', '!=', 2)->count();
  593. $waiting_interval = 10;
  594. if($web_num > 12){
  595. // 若网站数量大于12个,则每个网站间隔时间取均值
  596. // 防止除数为 0,虽然这里 $web_num 是 count 结果不会为 0,但做健壮性检查
  597. $waiting_interval = 120 / max(1, $web_num);
  598. }
  599. $time = 0;
  600. }else{
  601. // 非核心站与核心站----显示时间-----间隔
  602. $time = 20;
  603. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  604. $waiting_interval = 5;
  605. }
  606. // 将 Hyperf\Database\Model\Collection 转换为数组
  607. $webArray = $web->toArray();
  608. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $id, $waiting_interval, $is_collect) {
  609. // 检查 $item 对象是否有 is_core 属性
  610. if (!isset($item['is_core'])) {
  611. throw new \Exception('$item 对象缺少 is_core 属性');
  612. }
  613. // 当 is_core 为 2 时,则表示此网站不存在
  614. if ($item['is_core'] == 2) {
  615. return null;
  616. }
  617. if($is_collect == 1){
  618. // 采集来的文章,错开时间在两小时之内发布
  619. // $time = 0;
  620. $c_show_time = date('Y-m-d H:i:s', strtotime($now)+$time*60);
  621. $time += $waiting_interval;
  622. }else if($item['is_core'] == 1){
  623. // 当 is_core 为 1 时,则表示此网站是核心站
  624. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  625. }else{
  626. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  627. $c_show_time = date('Y-m-d H:i:s', strtotime($now)+$time*60);
  628. if ($item['is_core'] == 0) {
  629. $time += $waiting_interval;
  630. }
  631. }
  632. return [
  633. 'article_id' => $id,
  634. 'website_id' => $item['website_id'],
  635. 'c_show_time' => $c_show_time,
  636. // 'is_core' => $item['is_core'],
  637. // 'time' => $time
  638. ];
  639. }, array_keys($webArray), $webArray)));
  640. // Db::commit();
  641. // return Result::success($article_ignore);
  642. if(!empty($article_ignore)){
  643. $article_ignores = ArticleIgnore::insert($article_ignore);
  644. if(!$article_ignores){
  645. throw new \Exception('c端展示时间插入失败');
  646. }
  647. }
  648. }
  649. // ------c_show_time********add***2****
  650. //处理投票
  651. if ($is_survey == 1) {
  652. //生成年月日时分秒+8位随机数
  653. $uuid = date('YmdHis') . rand(10000000, 99999999);
  654. var_dump($suvey_array, 'suvey_array________');
  655. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  656. var_dump($suveys_array, '---------------------1');
  657. var_dump($suvey_array, '---------------------2');
  658. $suvey_data = [];
  659. foreach ($suveys_array as $key => $value) {
  660. if ($value == '') {
  661. continue;
  662. }
  663. if (is_array($value)) {
  664. $suvey_data[] = [
  665. 'sur_id' => $uuid,
  666. 'art_id' => $id,
  667. 'website_id' => $website_id ?? 2,
  668. 'survey_name' => $survey_name,
  669. 'choice_name' => $value[1],
  670. 'is_other' => 1,
  671. 'other_id' => 0,
  672. 'results' => 0,
  673. ];
  674. } else {
  675. $suvey_data[] = [
  676. 'sur_id' => $uuid,
  677. 'art_id' => $id,
  678. 'website_id' => $website_id ?? 2,
  679. 'survey_name' => $survey_name,
  680. 'choice_name' => $value,
  681. 'is_other' => 0,
  682. 'other_id' => 0,
  683. 'results' => 0,
  684. ];
  685. }
  686. if (empty($suvey_data)) {
  687. throw new \Exception("投票数据为空");
  688. }
  689. }
  690. $result = ArticleSurvey::insert($suvey_data);
  691. if (!$result) {
  692. throw new \Exception("投票失败,ArticleSurvey插入失败");
  693. }
  694. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  695. if (!$result) {
  696. throw new \Exception("投票失败,更新主表失败");
  697. }
  698. }
  699. Db::commit();
  700. return Result::success(['id' => $id]);
  701. } catch (\Throwable $ex) {
  702. Db::rollBack();
  703. var_dump($ex->getMessage());
  704. return Result::error("创建失败", 0);
  705. }
  706. }
  707. /**
  708. * @param array $data
  709. * @return array
  710. */
  711. public function delArticle(array $data): array
  712. {
  713. // ------c_show_time********del*******
  714. Db::beginTransaction();
  715. try{
  716. $article = Article::where(['id' => $data['id']])->delete();
  717. // 若文章删除失败,抛出异常,后续 SQL 语句不会执行
  718. if (!$article) {
  719. throw new \Exception("删除失败,文章删除失败");
  720. }
  721. //survey投票删除
  722. ArticleSurvey::where(['art_id' => $data['id']])->delete(); // 修正类名大小写
  723. $articleIgnore = ArticleIgnore::where(['article_id' => $data['id']])->delete();
  724. $article_data = ArticleData::where(['article_id' => $data['id']])->delete();
  725. // 若文章详情删除失败,抛出异常
  726. if (!$article_data) {
  727. throw new \Exception("删除失败,文章详情删除失败");
  728. }
  729. Db::commit(); // 所有操作成功,提交事务
  730. }catch (\Throwable $ex) {
  731. Db::rollBack();
  732. var_dump($ex->getMessage());
  733. return Result::error("删除失败: " . $ex->getMessage(), 0);
  734. }
  735. // ------c_show_time********del*******
  736. if (!$article) {
  737. return Result::error("删除失败");
  738. }
  739. return Result::success($article);
  740. }
  741. /**
  742. * @param array $data
  743. * @return array
  744. */
  745. public function updateArticle(array $data): array
  746. {
  747. var_dump($data, '----------12-----------1');
  748. Db::beginTransaction();
  749. // ------c_show_time********up*******
  750. $user_type = isset($data['user_type']) ? $data['user_type'] : 0;
  751. // 无论是否改变了c端显示时间或者栏目,都需要将未屏蔽的网站显示时间删除记录
  752. // 若是存在交集,则进行修改,若无,则合并(此表中的记录应该包含被屏蔽网站及涉及所有网站的展示时间)
  753. $web = WebsiteCategory::where('category_id', $data['catid'])
  754. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  755. ->select('website_id',
  756. 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'))
  757. ->get();
  758. // 根据错误信息,问题在于 $web 可能是一个包含对象的集合,不能直接用于 whereNotIn 方法
  759. // 先从 $web 集合中提取 website_id 字段的值,再进行删除操作
  760. $websiteIds = $web->pluck('website_id')->toArray();
  761. $del_article_ignore = ArticleIgnore::where('article_id', $data['id'])->whereNotIn('website_id', $websiteIds)->delete();
  762. if($user_type == 0){
  763. throw new \Exception("用户类型不能为空");
  764. }
  765. if($user_type == 10000 ){
  766. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  767. $web = WebsiteCategory::where('category_id', $data['catid'])
  768. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  769. ->select('website_id',
  770. 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'))
  771. ->get();
  772. // 非核心站与核心站----显示时间-----间隔
  773. $time = 20;
  774. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  775. $waiting_interval = 5;
  776. $webArray = $web->toArray();
  777. if(empty($webArray)){
  778. throw new \Exception('网站分类不存在');
  779. }
  780. // 直接使用当前系统时间,不再强制添加8小时
  781. $now = date('Y-m-d H:i:s');
  782. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  783. // 检查 $item 对象是否有 is_core 属性
  784. if (!isset($item['is_core'])) {
  785. throw new \Exception('$item 对象缺少 is_core 属性');
  786. }
  787. // 当 is_core 为 2 时,则表示此网站不存在
  788. if ($item['is_core'] == 2) {
  789. return null;
  790. }else if($item['is_core'] == 1){
  791. // 当 is_core 为 1 时,则表示此网站是核心站
  792. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  793. }else{
  794. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  795. $c_show_time = date('Y-m-d H:i:s', strtotime($now)+$time*60);
  796. if ($item['is_core'] == 0) {
  797. $time += $waiting_interval;
  798. }
  799. }
  800. return [
  801. 'article_id' => $data['id'],
  802. 'website_id' => $item['website_id'],
  803. 'c_show_time' => $c_show_time,
  804. ];
  805. }, array_keys($webArray), $webArray)));
  806. if(!empty($article_ignore)){
  807. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  808. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  809. $article_ignores = ArticleIgnore::upsert(
  810. $article_ignore,
  811. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  812. ['c_show_time'] // 需要更新的字段
  813. );
  814. if(!$article_ignores){
  815. throw new \Exception('c端展示时间插入失败');
  816. }
  817. }
  818. // Db::commit();
  819. // return Result::success($article_ignore);
  820. }
  821. // ------c_show_time********up*******
  822. unset($data['user_type']);
  823. // unset($data['web_site_id']);
  824. unset($data['nav_add_pool_id']);
  825. try {
  826. //处理投票
  827. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  828. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  829. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  830. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  831. unset($data['is_survey']);
  832. unset($data['survey_name']);
  833. unset($data['suvey_array']);
  834. unset($data['website_id']);
  835. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  836. if ($data['hits'] == '') {
  837. $data['hits'] = 0;
  838. }
  839. if ($data['is_original'] == '') {
  840. $data['is_original'] = 0;
  841. }
  842. if ($data['status'] == '') {
  843. $data['status'] = 0;
  844. }
  845. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  846. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  847. $articleData = $data;
  848. unset($articleData['content']);
  849. unset($articleData['status_name']);
  850. unset($articleData['name']);
  851. unset($articleData['content']);
  852. unset($articleData['pid_arr']);
  853. unset($articleData['pid']);
  854. //自动处理缩略图、关键字、描述
  855. if ($articleData['imgurl'] == '') {
  856. //如果没有图,设置level=0
  857. $levelArr = json_decode($articleData['level'], true);
  858. var_dump($levelArr, '----------levelArr-----------1');
  859. //content中提取图片第一个图,正则提取
  860. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  861. preg_match_all($reg, $data['content'], $matches);
  862. if (isset($matches[1][0])) {
  863. //截取varchar240
  864. // 截取到第一个<
  865. $articleData['imgurl'] = $matches[1][0];
  866. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  867. $pos = strpos($articleData['imgurl'], '"');
  868. if ($pos !== false) {
  869. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  870. }
  871. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  872. //如果有图,设置level=3
  873. if (!in_array(3, $levelArr)) {
  874. $levelArr[] = 3;
  875. }
  876. $articleData['level'] = json_encode($levelArr);
  877. } else {
  878. if (!in_array(0, $levelArr)) {
  879. $levelArr[] = 0;
  880. }
  881. $articleData['level'] = json_encode($levelArr);
  882. }
  883. }
  884. var_dump($articleData['level'], '----------$articleData[level]----------1');
  885. if ($articleData['keyword'] == '') {
  886. //提取标题+内容中的关键词
  887. $articleData['keyword'] = $data['title'];
  888. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  889. Jieba::init(); // 初始化 jieba-php
  890. Finalseg::init();
  891. $segList = Jieba::cut($articleData['keyword']);
  892. $segList1 = array_slice($segList, 0, 8);
  893. $articleData['keyword'] = implode(',', $segList1);
  894. }
  895. if ($articleData['introduce'] == '') {
  896. //提取内容中的描述
  897. $content = $data['content'];
  898. // 去除 <style> 和 <script> 标签及其内容
  899. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  900. // 去除所有 HTML 标签
  901. $content = strip_tags($content);
  902. // 去除 HTML 实体
  903. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  904. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  905. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  906. // 去除多余空白
  907. $content = preg_replace('/\s+/u', '', $content);
  908. // 截取 100 个字符
  909. $articleData['introduce'] = mb_substr($content, 0, 100);
  910. }
  911. if ($articleData['status'] == 0) {
  912. $this->sendMessage([
  913. 'talk_type' => 100,
  914. 'title' => $articleData['title'],
  915. 'content' => '提交了审核',
  916. 'messageType' => 2,
  917. ]);
  918. }
  919. $id = Article::where(['id' => $data['id']])->update($articleData);
  920. $articleDataContent = [
  921. 'content' => $data['content'],
  922. ];
  923. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  924. //处理投票
  925. $id = $data['id'];
  926. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  927. var_dump($suvey_array, 'suvey_array________delete');
  928. //处理投票
  929. if ($is_survey == 1) {
  930. //生成年月日时分秒+8位随机数
  931. $uuid = date('YmdHis') . rand(10000000, 99999999);
  932. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  933. var_dump($suveys_array, '---------------------1');
  934. $suvey_data = [];
  935. if (is_array($suveys_array)) {
  936. foreach ($suveys_array as $key => $value) {
  937. if ($value == '') {
  938. continue;
  939. }
  940. if (is_array($value)) {
  941. $suvey_data[] = [
  942. 'sur_id' => $uuid,
  943. 'art_id' => $id,
  944. 'website_id' => $website_id ?? 2,
  945. 'survey_name' => $survey_name,
  946. 'choice_name' => $value[1],
  947. 'is_other' => 1,
  948. 'other_id' => 0,
  949. 'results' => 0,
  950. ];
  951. } else {
  952. $suvey_data[] = [
  953. 'sur_id' => $uuid,
  954. 'art_id' => $id,
  955. 'website_id' => $website_id ?? 2,
  956. 'survey_name' => $survey_name,
  957. 'choice_name' => $value,
  958. 'is_other' => 0,
  959. 'other_id' => 0,
  960. 'results' => 0,
  961. ];
  962. }
  963. if (empty($suvey_data)) {
  964. throw new \Exception("投票数据为空");
  965. }
  966. }
  967. }
  968. $result = ArticleSurvey::insert($suvey_data);
  969. if (!$result) {
  970. throw new \Exception("投票失败");
  971. }
  972. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  973. if (!$result) {
  974. throw new \Exception("投票失败");
  975. }
  976. } else {
  977. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  978. }
  979. Db::commit();
  980. return Result::success([]);
  981. } catch (\Throwable $ex) {
  982. Db::rollBack();
  983. var_dump($ex->getMessage());
  984. return Result::error("更新失败" . $ex->getMessage(), 0);
  985. }
  986. }
  987. /**
  988. * 更新资讯状态
  989. * @param array $data
  990. * @return array
  991. */
  992. public function upArticleStatus(array $data): array
  993. {
  994. $articleData = Article::where(['id' => $data['id']])->first();
  995. //发送10次
  996. // for ($i = 0; $i < 10; $i++) {
  997. // $this->sendMessage([
  998. // 'talk_type' => 100,
  999. // 'title' => $i . $articleData['title'],
  1000. // 'content' => '审核通过',
  1001. // 'messageType' => 2,
  1002. // 'user_id' => $articleData['admin_user_id'],
  1003. // ]);
  1004. // }
  1005. // var_dump($data['status'], 'status');
  1006. // return Result::success();
  1007. if ($data['status'] == 1) {
  1008. $this->sendMessage([
  1009. 'talk_type' => 101,
  1010. 'title' => $articleData['title'],
  1011. 'content' => '审核通过',
  1012. 'messageType' => 2,
  1013. 'user_id' => $articleData['admin_user_id'],
  1014. ]);
  1015. }
  1016. if ($data['status'] == 2) {
  1017. $this->sendMessage([
  1018. 'talk_type' => 101,
  1019. 'title' => $articleData['title'],
  1020. 'content' => '审核拒绝',
  1021. 'messageType' => 2,
  1022. 'user_id' => $articleData['admin_user_id'],
  1023. ]);
  1024. }
  1025. if ($data['status'] == 0) {
  1026. $this->sendMessage([
  1027. 'talk_type' => 100,
  1028. 'title' => $articleData['title'],
  1029. 'content' => '提交了审核',
  1030. 'messageType' => 2,
  1031. ]);
  1032. }
  1033. $result = Article::where(['id' => $data['id']])->update($data);
  1034. if (isset($data['ignore_ids']) && !empty($data['ignore_ids'])) {
  1035. //article_ignore 表插入数据 db操作
  1036. //转成数组
  1037. //删掉数据重新写入
  1038. // DB::table('article_ignore')->where('article_id', $data['id'])->delete();
  1039. $website_ids = is_array($data['ignore_ids']) ? $data['ignore_ids'] : json_decode($data['ignore_ids'], true);
  1040. // $insert_data = [];
  1041. // foreach ($website_ids as $key => $value) {
  1042. // $insert_data[] = [
  1043. // 'article_id' => $data['id'],
  1044. // 'website_id' => $value,
  1045. // 'is_ignore' => 1
  1046. // ];
  1047. // }
  1048. DB::table('article_ignore')->where('article_id', $data['id'])
  1049. ->when(!empty($website_ids), function ($query) use ($website_ids) {
  1050. $query->whereIn('website_id', $website_ids);
  1051. })
  1052. ->update(['is_ignore' => !empty($website_ids) ? 1 : 0]);
  1053. // ------c_show_time********up_status*******
  1054. // 若是审核通过 则更新c_show_time
  1055. if($data['status'] == 1){
  1056. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  1057. $web = Article::where('article.id',$data['id'])
  1058. ->leftJoin('website_category','article.catid','website_category.category_id')
  1059. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  1060. ->select('website_id',
  1061. 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'))
  1062. ->get();
  1063. // 非核心站与核心站----显示时间-----间隔
  1064. $time = 20;
  1065. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  1066. $waiting_interval = 5;
  1067. $webArray = $web->toArray();
  1068. if(empty($webArray)){
  1069. throw new \Exception('网站分类不存在');
  1070. }
  1071. // 直接使用当前系统时间,不再强制添加8小时
  1072. $now = date('Y-m-d H:i:s');
  1073. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  1074. // 检查 $item 对象是否有 is_core 属性
  1075. if (!isset($item['is_core'])) {
  1076. throw new \Exception('$item 对象缺少 is_core 属性');
  1077. }
  1078. // 当 is_core 为 2 时,则表示此网站不存在
  1079. if ($item['is_core'] == 2) {
  1080. return null;
  1081. }else if($item['is_core'] == 1){
  1082. // 当 is_core 为 1 时,则表示此网站是核心站
  1083. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  1084. }else{
  1085. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  1086. $c_show_time = date('Y-m-d H:i:s', strtotime($now)+$time*60);
  1087. if ($item['is_core'] == 0) {
  1088. $time += $waiting_interval;
  1089. }
  1090. }
  1091. return [
  1092. 'article_id' => $data['id'],
  1093. 'website_id' => $item['website_id'],
  1094. 'c_show_time' => $c_show_time,
  1095. ];
  1096. }, array_keys($webArray), $webArray)));
  1097. if(!empty($article_ignore)){
  1098. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  1099. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  1100. $article_ignores = ArticleIgnore::upsert(
  1101. $article_ignore,
  1102. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  1103. ['c_show_time'] // 需要更新的字段
  1104. );
  1105. if(!$article_ignores){
  1106. throw new \Exception('c端展示时间插入失败');
  1107. }
  1108. }
  1109. }
  1110. // ------c_show_time********up_status*******
  1111. }
  1112. if ($result) {
  1113. return Result::success();
  1114. } else {
  1115. return Result::error("更新状态失败", 0);
  1116. }
  1117. }
  1118. /**
  1119. * 获取新闻详情
  1120. * @param array $data
  1121. * @return array
  1122. */
  1123. public function getArticleInfo(array $data): array
  1124. {
  1125. $where = [
  1126. 'article.id' => $data['id'],
  1127. // 'article.status' => 1,
  1128. ];
  1129. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  1130. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  1131. $info = $result;
  1132. // var_dump($info, 'info');
  1133. $info['survey_array'] = $articleSurvey;
  1134. if ($result) {
  1135. return Result::success($info);
  1136. } else {
  1137. return Result::error("查询失败", 0);
  1138. }
  1139. }
  1140. /**
  1141. * 获取头条新闻
  1142. * @param array $data
  1143. * @return array
  1144. */
  1145. public function getWebsiteArticlett(array $data): array
  1146. {
  1147. $website_id = $data['website_id'];
  1148. $website = Website::where('id', $data['website_id'])->first();
  1149. if (empty($website)) {
  1150. return Result::error("网站不存在", 0);
  1151. }
  1152. $categorys = $this->processArticlePro($website_id);
  1153. $catiall = $categorys['catiall'];
  1154. $categoryIds = $categorys['categoryIds'];
  1155. $where = [
  1156. 'status' => 1
  1157. ];
  1158. // $website_column = $website['column'];
  1159. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1160. $website_column = json_decode($website['website_column_arr_id'], true);
  1161. }
  1162. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1163. // return Result::success($diff_pid_categoryIds);
  1164. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1165. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1166. }
  1167. // $website_id = $data['website_id'];
  1168. $month = date("Y-m-d H:i:s", strtotime("-30 day"));
  1169. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  1170. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  1171. switch ($data['level']) {
  1172. case 1:
  1173. case 2:
  1174. case 3:
  1175. case 6: //1.头条资讯;2.轮播图;3.推荐图;6.今日热点
  1176. $query = Article::where($where)
  1177. ->where('level', 'like', '%' . $data['level'] . '%')
  1178. ->orderBy('updated_at', 'desc');
  1179. break;
  1180. case 4: //最新资讯
  1181. $query = Article::where($where)->orderBy('updated_at', 'desc');
  1182. break;
  1183. case 5: //资讯推荐
  1184. $query = Article::where($where)
  1185. ->where('updated_at', '>', $month);
  1186. break;
  1187. case 7: //资讯分类
  1188. if (isset($data['id']) && !empty($data['id'])) {
  1189. $keyword = Article::where('id', $data['id'])->value('keyword');
  1190. $keywordArray = explode(',', $keyword);
  1191. $whereL7 = [];
  1192. foreach ($keywordArray as $k => $v) {
  1193. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1194. }
  1195. $query = Article::where($where)->where($whereL7)->orderBy('updated_at', 'desc');;
  1196. break;
  1197. } else {
  1198. return Result::error("请输入资讯ID", 0);
  1199. break;
  1200. }
  1201. default:
  1202. break;
  1203. }
  1204. // $whereL7 = [];
  1205. // if(isset($data['id']) && !empty($data['id'])){
  1206. // $keyword = Article::where('id', $data['id'])->value('keyword');
  1207. // $keywordArray = explode(',', $keyword);
  1208. // foreach ($keywordArray as $k => $v) {
  1209. // $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1210. // }
  1211. // }
  1212. // $query = Article::where($where)
  1213. // ->when(isset($data['level']) && !empty($data['level']), function ($query) use ($data,$whereL7) {
  1214. // if($data['level'] == 1 || $data['level'] == 2 || $data['level'] == 3 || $data['level'] == 6){
  1215. // $query = $query->where('article.level','like','%'.$data['level'].'%')->orderBy('updated_at','desc');
  1216. // }
  1217. // if($data['level'] == 7){
  1218. // $query = $query->where($whereL7)->orderBy('updated_at','desc');
  1219. // }
  1220. // if($data['level'] == 4){
  1221. // $query = $query->inRandomOrder()
  1222. // ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  1223. // }
  1224. // if($data['level'] == 5){
  1225. // $query = $query->orderBy('updated_at','desc');
  1226. // }
  1227. // });
  1228. if ($data['textnum'] > 0) {
  1229. $query = clone $query;
  1230. $result['text'] = $query
  1231. ->whereIn('catid', $categoryIds)
  1232. ->leftJoinSub(function ($query) use ($website_id) {
  1233. $query->from('article_ignore')
  1234. ->where('website_id', $website_id);
  1235. }, 'article_ignore', function ($join) {
  1236. $join->on('article_ignore.article_id', '=', 'article.id');
  1237. })
  1238. ->where(function ($query) {
  1239. $query->whereNull('article_ignore.article_id')
  1240. ->orWhere(function ($subQuery) {
  1241. $subQuery->whereNotNull('article_ignore.article_id')
  1242. ->where('article_ignore.is_ignore', 0)
  1243. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  1244. });
  1245. })
  1246. // ->where(function ($query) use ($website_id) {
  1247. // $query->whereNull('article_ignore.article_id')
  1248. // ->orWhere('article_ignore.website_id', '!=', $website_id);
  1249. // })
  1250. ->select(
  1251. 'article.id',
  1252. 'article.title',
  1253. 'article.author',
  1254. 'article.updated_at',
  1255. 'article.introduce',
  1256. 'article.islink',
  1257. 'article.linkurl',
  1258. 'article.copyfrom',
  1259. 'article.cat_arr_id',
  1260. 'article.catid',
  1261. 'article.level',
  1262. // 'article_ignore.is_ignore',
  1263. // 'article_ignore.c_show_time',
  1264. )
  1265. ->offset($data['placeid'])
  1266. ->limit($data['textnum'])
  1267. ->get()->all();
  1268. foreach ($result['text'] as $k => $v) {
  1269. $result['text'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1270. $result['text'][$k]->alias = $catiall[$v->catid]['alias'];
  1271. }
  1272. }
  1273. if ($data['imgnum'] > 0) {
  1274. $query = clone $query;
  1275. if($data['textnum'] == 0){
  1276. $query = $query->leftJoinSub(function ($query) use ($website_id) {
  1277. $query->from('article_ignore')
  1278. ->where('website_id', $website_id);
  1279. }, 'article_ignore', function ($join) {
  1280. $join->on('article_ignore.article_id', '=', 'article.id');
  1281. })
  1282. ->where(function ($query) {
  1283. $query->whereNull('article_ignore.article_id')
  1284. ->orWhere(function ($subQuery) {
  1285. $subQuery->whereNotNull('article_ignore.article_id')
  1286. ->where('article_ignore.is_ignore', 0)
  1287. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  1288. });
  1289. });
  1290. }
  1291. $result['img'] = $query
  1292. ->whereIn('catid', $categoryIds)
  1293. ->where('article.imgurl', '!=', '')
  1294. ->select(
  1295. 'article.id',
  1296. 'article.title',
  1297. 'article.imgurl',
  1298. 'article.author',
  1299. 'article.updated_at',
  1300. 'article.introduce',
  1301. 'article.islink',
  1302. 'article.linkurl',
  1303. 'article.copyfrom',
  1304. 'article.cat_arr_id',
  1305. 'article.catid',
  1306. 'article.level',
  1307. // 'article_ignore.is_ignore',
  1308. // 'article_ignore.c_show_time',
  1309. )
  1310. ->offset($data['placeid'])
  1311. ->limit($data['imgnum'])
  1312. ->get()->all();
  1313. foreach ($result['img'] as $k => $v) {
  1314. $result['img'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1315. $result['img'][$k]->alias = $catiall[$v->catid]['alias'];
  1316. }
  1317. }
  1318. if (empty($result)) {
  1319. return Result::error("暂无相关资讯", 0);
  1320. }
  1321. return Result::success($result);
  1322. }
  1323. /**
  1324. * 获取模块新闻
  1325. * @param array $data
  1326. * @return array
  1327. */
  1328. public function getWebsiteModelArticles(array $data): array
  1329. {
  1330. $catid = $data['catid'];
  1331. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  1332. $category = $category->toArray();
  1333. if (!empty($category)) {
  1334. $where = [
  1335. 'status' => 1,
  1336. 'catid' => $catid,
  1337. ];
  1338. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  1339. // 1:文字新闻;2:轮播图;3:图文;
  1340. // 级别:0:未分类
  1341. // 3:推荐图片
  1342. if ($data['level'] == 1) {
  1343. $data['level'] = 0;
  1344. }
  1345. $result = Article::where($where)
  1346. ->where(function ($query) use ($data) {
  1347. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  1348. ->orWhereNull("level")
  1349. ->orWhereRaw("level = '[]'");
  1350. })
  1351. ->leftJoinSub(function ($query) use ($data) {
  1352. $query->from('article_ignore')
  1353. ->where('website_id', $data['website_id']);
  1354. }, 'article_ignore', function ($join) {
  1355. $join->on('article_ignore.article_id', '=', 'article.id');
  1356. })
  1357. ->where(function ($query) {
  1358. $query->whereNull('article_ignore.article_id')
  1359. ->orWhere(function ($subQuery) {
  1360. $subQuery->whereNotNull('article_ignore.article_id')
  1361. ->where('article_ignore.is_ignore', 0)
  1362. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  1363. });
  1364. })
  1365. // ->where(function ($query) use ($data) {
  1366. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1367. // ->orWhereNull("ignore_ids");
  1368. // })
  1369. ->orderBy("updated_at", "desc")
  1370. ->offset($placeid)
  1371. ->limit($data['pagesize'])
  1372. ->get();
  1373. if (empty($result)) {
  1374. return Result::error("此栏目暂无相关新闻", 0);
  1375. }
  1376. } else {
  1377. return Result::error("此网站暂无此栏目", 0);
  1378. }
  1379. return Result::success($result);
  1380. }
  1381. /**
  1382. *获取新闻列表
  1383. * @param array $data
  1384. * @return array
  1385. */
  1386. public function getWebsiteArticleList(array $data): array
  1387. {
  1388. // return Result::success($data);
  1389. $where[] = ['status', '=', 1];
  1390. $website_id = $data['website_id'];
  1391. $website = Website::where('id', $data['website_id'])->first();
  1392. if (empty($website)) {
  1393. return Result::error("网站不存在", 0);
  1394. }
  1395. // $website_column = $website['column'];
  1396. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1397. $website_column = json_decode($website['website_column_arr_id'], true);
  1398. }
  1399. $categorys = $this->processArticlePro($website_id);
  1400. $cat_1st_arr = $categorys['cat_1st_arr'];
  1401. $catiall = $categorys['catiall'];
  1402. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1403. // return Result::success($diff_pid_categoryIds);
  1404. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1405. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1406. }
  1407. if (isset($data['catid']) && !empty($data['catid'])) {
  1408. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  1409. if (empty($category)) {
  1410. return Result::error("此网站暂无此栏目", 0);
  1411. }
  1412. array_push($where, ['catid', '=', $data['catid']]);
  1413. }
  1414. // return Result::success($where);
  1415. $query = Article::where($where)
  1416. ->leftJoinSub(function ($query) use ($website_id) {
  1417. $query->from('article_ignore')
  1418. ->where('website_id', $website_id);
  1419. }, 'article_ignore', function ($join) {
  1420. $join->on('article_ignore.article_id', '=', 'article.id');
  1421. })
  1422. ->where(function ($query) {
  1423. $query->whereNull('article_ignore.article_id')
  1424. ->orWhere(function ($subQuery) {
  1425. $subQuery->whereNotNull('article_ignore.article_id')
  1426. ->where('article_ignore.is_ignore', 0)
  1427. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  1428. });
  1429. })
  1430. ->select(
  1431. 'article.id',
  1432. 'article.title',
  1433. 'article.imgurl',
  1434. 'article.author',
  1435. 'article.updated_at',
  1436. 'article.introduce',
  1437. 'article.islink',
  1438. 'article.linkurl',
  1439. 'article.copyfrom',
  1440. 'article.cat_arr_id',
  1441. 'article.catid'
  1442. );
  1443. $count = $query->count();
  1444. $rep = $query->orderBy("updated_at", "desc")
  1445. ->offset(($data['page'] - 1) * $data['pageSize'])
  1446. ->limit($data['pageSize'])
  1447. ->get()->all();
  1448. $categorys = $this->processArticlePro($website_id);
  1449. $cat_1st_arr = $categorys['cat_1st_arr'];
  1450. $catiall = $categorys['catiall'];
  1451. // $web['website_id'] = $data['website_id'];
  1452. foreach ($rep as $k => $v) {
  1453. $rep[$k]->category_name = $catiall[$v->catid]['alias'];
  1454. $rep[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1455. }
  1456. // $rep = $this->processArticles($rep,$web);
  1457. $data = [
  1458. 'rows' => $rep,
  1459. 'count' => $count,
  1460. ];
  1461. if (empty($rep)) {
  1462. return Result::error("没有信息数据");
  1463. }
  1464. return Result::success($data);
  1465. }
  1466. /**
  1467. * 前端-获取新闻详情
  1468. * @param array $data
  1469. * @return array
  1470. */
  1471. public function selectWebsiteArticleInfo(array $data): array
  1472. {
  1473. $where = [
  1474. 'article.id' => $data['id'],
  1475. 'article.status' => 1,
  1476. ];
  1477. $result = Article::where($where)
  1478. ->leftJoin("article_data", "article.id", "article_data.article_id")
  1479. ->leftJoin("article_extend", "article_extend.article_id", "article.id")
  1480. // ->where(function ($query) use ($data) {
  1481. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1482. // ->orWhereNull("ignore_ids");
  1483. // })
  1484. ->leftJoinSub(function ($query) use ($data) {
  1485. $query->from('article_ignore')
  1486. ->where('website_id', $data['website_id']);
  1487. }, 'article_ignore', function ($join) {
  1488. $join->on('article_ignore.article_id', '=', 'article.id');
  1489. })
  1490. ->where(function ($query) {
  1491. $query->whereNull('article_ignore.article_id')
  1492. ->orWhere(function ($subQuery) {
  1493. $subQuery->whereNotNull('article_ignore.article_id')
  1494. ->where('article_ignore.is_ignore', 0)
  1495. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  1496. });
  1497. })
  1498. ->select(
  1499. 'article.*',
  1500. 'article_data.content',
  1501. 'article_data.article_id',
  1502. 'article_extend.website_url',
  1503. 'article_extend.email',
  1504. 'article_extend.contacts',
  1505. 'article_extend.contacts_mobile',
  1506. 'article_extend.contacts_address',
  1507. 'article_extend.zip_code',
  1508. 'article_extend.enterprise_name'
  1509. )
  1510. ->first();
  1511. if (empty($result)) {
  1512. return Result::error("暂无此新闻!", 0);
  1513. }
  1514. if (!empty($result['publiced_at'])) {
  1515. $result['updated_at'] = $result['publiced_at'];
  1516. }
  1517. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  1518. ->select('website_category.*', 'website.website_name', 'website.suffix')
  1519. ->where('website_category.website_id', $data['website_id'])
  1520. ->where(['website_category.category_id' => $result['catid']])
  1521. ->first();
  1522. if (empty($category)) {
  1523. return Result::error("查询失败", 0);
  1524. }
  1525. //手动推荐文章
  1526. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  1527. if (empty($commend_ids)) {
  1528. $commendArticle = [];
  1529. } else {
  1530. //去除不存在的文章ID
  1531. $commendArticle = Article::whereIn('article.id', $commend_ids)
  1532. ->leftjoin('website_category', 'website_category.category_id', '=', 'article.catid')
  1533. ->leftJoinSub(function ($query) use ($data) {
  1534. $query->from('article_ignore')
  1535. ->where('website_id', $data['website_id']);
  1536. }, 'article_ignore', function ($join) {
  1537. $join->on('article_ignore.article_id', '=', 'article.id');
  1538. })
  1539. ->where(function ($query) {
  1540. $query->whereNull('article_ignore.article_id')
  1541. ->orWhere(function ($subQuery) {
  1542. $subQuery->whereNotNull('article_ignore.article_id')
  1543. ->where('article_ignore.is_ignore', 0)
  1544. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  1545. });
  1546. })
  1547. ->where('article.status', 1)
  1548. ->where('website_category.website_id', $data['website_id'])
  1549. ->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')
  1550. ->orderByRaw("FIELD(article.id, " . implode(',', $commend_ids) . ")")
  1551. // ->orderBy('article.updated_at', 'desc')
  1552. ->limit(5)
  1553. ->get();
  1554. //循环数组,取出cat_arr_id中的不重复值,再从website_category取出alias_pinyin,再将cat_arr_id的json转成路径/隔开
  1555. foreach ($commendArticle as $k => $v) {
  1556. $cat_arr_id = json_decode($v->cat_arr_id, true);
  1557. if (!empty($cat_arr_id) && is_array($cat_arr_id)) {
  1558. $cat_arr_id = array_unique($cat_arr_id);
  1559. // 从website_category取出alias_pinyin
  1560. $cat_arr = WebsiteCategory::where('website_id', $data['website_id'])
  1561. ->whereIn('category_id', $cat_arr_id)
  1562. ->pluck('alias_pinyin', 'category_id')
  1563. ->toArray();
  1564. // 将cat_arr_id的json转成路径/隔开
  1565. $path_parts = [];
  1566. foreach ($cat_arr_id as $cat_id) {
  1567. if (isset($cat_arr[$cat_id])) {
  1568. $path_parts[] = $cat_arr[$cat_id];
  1569. }
  1570. }
  1571. $v->alias_pinyin = implode('/', $path_parts);
  1572. } else {
  1573. $v->alias_pinyin = '';
  1574. }
  1575. }
  1576. }
  1577. $result['category_id'] = $category['category_id'];
  1578. $result['cat_name'] = $category['alias'];
  1579. $result['website_name'] = $category['website_name'] ?? "";
  1580. $result['suffix'] = $category['suffix'] ?? "";
  1581. $result['commendArticle'] = $commendArticle;
  1582. $result['commend_ids'] = $commend_ids;
  1583. return Result::success($result);
  1584. }
  1585. /**
  1586. * 前端-获取网站调查问卷
  1587. * @param array $data
  1588. * @return array
  1589. */
  1590. public function getWebsiteSurvey(array $data): array
  1591. {
  1592. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1593. $website = Website::where('id', $data['website_id'])->first();
  1594. if (empty($website)) {
  1595. return Result::error("暂无此网站", 0);
  1596. }
  1597. }
  1598. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1599. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1600. if (empty($article)) {
  1601. return Result::error("暂无此文章", 0);
  1602. }
  1603. // return Result::error($data,0);
  1604. $where['art_id'] = $data['art_id'];
  1605. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1606. } else {
  1607. $survey = Article::where(function ($query) {
  1608. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1609. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1610. })
  1611. ->where('status', 1)
  1612. ->where('is_survey', 1)
  1613. ->select('survey_id')
  1614. ->orderBy('updated_at', 'desc')
  1615. ->first();
  1616. if (empty($survey)) {
  1617. return Result::error("暂无调查问卷", 0);
  1618. }
  1619. $where['sur_id'] = $survey['survey_id'];
  1620. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1621. }
  1622. // return Result::success($where);
  1623. $result = ArticleSurvey::where($where)
  1624. ->where(function ($query) {
  1625. $query->where('is_other', 0)
  1626. ->orWhere(function ($subQuery) {
  1627. $subQuery->where('is_other', 1)
  1628. ->where('other_id', 0);
  1629. });
  1630. })
  1631. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1632. ->select('article_survey.*', 'article.survey_type')
  1633. ->get()->all();
  1634. if (empty($result)) {
  1635. return Result::error("此文章暂无调查问卷", 0);
  1636. }
  1637. return Result::success($result);
  1638. }
  1639. /**
  1640. * 前端-添加网站调查问卷选项
  1641. * @param array $data
  1642. * @return array
  1643. */
  1644. public function addWebsiteSurveyOption(array $data): array
  1645. {
  1646. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1647. $website = Website::where('id', $data['website_id'])->first();
  1648. if (empty($website)) {
  1649. return Result::error("暂无此网站", 0);
  1650. }
  1651. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1652. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1653. if (empty($survey)) {
  1654. return Result::error("此调查问卷不可添加选项", 0);
  1655. }
  1656. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1657. $choice = [
  1658. 'art_id' => $survey['art_id'],
  1659. 'website_id' => $data['website_id'],
  1660. 'survey_name' => $survey['survey_name'],
  1661. 'choice_name' => $data['choice_name'],
  1662. 'sur_id' => $survey['sur_id'],
  1663. 'is_other' => 1,
  1664. 'other_id' => $survey['id'],
  1665. ];
  1666. $result = ArticleSurvey::insertGetId($choice);
  1667. if (empty($result)) {
  1668. return Result::error("添加失败", 0);
  1669. }
  1670. return Result::success($result);
  1671. }
  1672. }
  1673. return Result::error("添加失败", 0);
  1674. }
  1675. return Result::error("添加失败", 0);
  1676. }
  1677. /**
  1678. * 前端-调查问卷投票
  1679. * @param array $data
  1680. * @return array
  1681. */
  1682. public function addWebsiteSurveyVote(array $data): array
  1683. {
  1684. // return Result::success($data);
  1685. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1686. $website = Website::where('id', $data['website_id'])->first();
  1687. if (empty($website)) {
  1688. return Result::error("暂无此网站", 0);
  1689. }
  1690. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1691. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1692. // return Result::success($survey);
  1693. if (empty($is_survey)) {
  1694. return Result::error("此调查问卷不存在", 0);
  1695. }
  1696. // return Result::success($survey);
  1697. // 调查问卷类型
  1698. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1699. //多选 若是json型则转化成数组类型
  1700. if (strpos($data['choice_id'], '[') === 0) {
  1701. $data['choice_id'] = json_decode($data['choice_id'], true);
  1702. } else {
  1703. // 单选 也转换成数组
  1704. $data['choice_id'] = [$data['choice_id']];
  1705. }
  1706. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1707. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1708. // ->where('website_id',$data['website_id'])
  1709. ->where('is_other', 1)
  1710. ->where('other_id', 0)
  1711. ->first();
  1712. if (!empty($other)) {
  1713. return Result::error("请选择已有的选项!", 0);
  1714. }
  1715. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1716. // ->where('website_id',$data['website_id'])
  1717. ->where('is_other', 1)
  1718. ->where('other_id', '!=', 0)
  1719. ->first();
  1720. // return Result::success($choice['other']);
  1721. $choice_id = $data['choice_id'];
  1722. if (!empty($choice['other'])) {
  1723. // array_push($data['choice_id'],$choice['other']['other_id']);
  1724. if (!empty($choice_id)) {
  1725. $key = array_search($choice['other']['id'], $choice_id);
  1726. if ($key !== false) {
  1727. unset($choice_id[$key]);
  1728. $choice_id = array_values($choice_id);
  1729. }
  1730. array_push($choice_id, $choice['other']['other_id']);
  1731. } else {
  1732. $choice_id[0] = $choice['other']['other_id'];
  1733. }
  1734. array_push($data['choice_id'], $choice['other']['other_id']);
  1735. }
  1736. // return Result::success($data);
  1737. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1738. // ->where('website_id',$data['website_id'])
  1739. ->increment('results', 1);
  1740. if (empty($choice)) {
  1741. return Result::error("请选择已有的选项!", 0);
  1742. }
  1743. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1744. // ->where('website_id',$data['website_id'])
  1745. ->where('other_id', 0)
  1746. ->get();
  1747. $survey['choice'] = $choice_id;
  1748. return Result::success($survey);
  1749. }
  1750. return Result::error("参数必填!");
  1751. }
  1752. return Result::error("此调查问卷不存在", 0);
  1753. }
  1754. return Result::error("参数必填!");
  1755. }
  1756. /**
  1757. * 后端-获取网站调查问卷列表
  1758. * @param array $data
  1759. * @return array
  1760. */
  1761. public function getSurveyList(array $data): array
  1762. {
  1763. $where = [];
  1764. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1765. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1766. }
  1767. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  1768. array_push($where, ['survey_type', '=', $data['survey_type']]);
  1769. }
  1770. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  1771. array_push($where, ['is_survey', '=', $data['is_survey']]);
  1772. }
  1773. // return Result::success($where);
  1774. if (!empty($where)) {
  1775. $query = Article::where($where)->where(function ($q) {
  1776. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1777. });
  1778. } else {
  1779. $query = Article::where(function ($q) {
  1780. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1781. });
  1782. }
  1783. $count = $query->count();
  1784. $survey = $query->orderByDesc('id')
  1785. ->limit($data['pageSize'])
  1786. ->offset(($data['page'] - 1) * $data['pageSize'])
  1787. ->get();
  1788. if (empty($survey->toArray())) {
  1789. return Result::error("暂无调查问卷!", 0);
  1790. }
  1791. $result = [
  1792. 'rows' => $survey,
  1793. 'count' => $count,
  1794. ];
  1795. return Result::success($result);
  1796. }
  1797. /**
  1798. * 后端-获取网站调查问卷详情
  1799. * @param array $data
  1800. * @return array
  1801. */
  1802. public function getSurveyInfo(array $data): array
  1803. {
  1804. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1805. $where = ['sur_id' => $data['sur_id']];
  1806. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1807. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1808. ->select('article_survey.*', 'article.survey_type')
  1809. ->get()->all();
  1810. if (empty($choose)) {
  1811. return Result::error("此调查问卷不存在", 0);
  1812. }
  1813. $resultsArray = array_column($choose, 'results');
  1814. $total = array_sum($resultsArray);
  1815. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1816. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1817. // $total = 0;
  1818. if (!empty($other)) {
  1819. $total = $total + $other['results'];
  1820. $other['choice_name'] = '(其他)';
  1821. if (!empty($others)) {
  1822. $other['hasChildren'] = true;
  1823. // array_push($other,['hasChildren','=',true]);
  1824. $other['children'] = $others;
  1825. $other_choices = [$other->toArray()];
  1826. $mer_choice = array_merge($choose, $other_choices);
  1827. $value_choice = array_values($mer_choice);
  1828. } else {
  1829. // return Result::error('1111');
  1830. $other_choices = [$other->toArray()];
  1831. $other_choices = array_merge($choose, $other_choices);
  1832. $value_choice = array_values($other_choices);
  1833. // return Result::success($result);
  1834. }
  1835. } else {
  1836. $value_choice = $choose;
  1837. }
  1838. $result = [
  1839. 'choose' => $value_choice,
  1840. 'total' => $total,
  1841. ];
  1842. }
  1843. return Result::success($result);
  1844. }
  1845. /**
  1846. * 前端-搜索新闻列表
  1847. * @param array $data
  1848. * @return array
  1849. */
  1850. public function selectWebsiteArticle(array $data): array
  1851. {
  1852. $website = Website::where('id', $data['website_id'])->first();
  1853. if (empty($website)) {
  1854. return Result::error("网站不存在", 0);
  1855. }
  1856. // $website_column = $website['column'];
  1857. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1858. $website_column = json_decode($website['website_column_arr_id'], true);
  1859. }
  1860. $website_id = $data['website_id'];
  1861. $categorys = $this->processArticlePro($website_id);
  1862. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1863. // return Result::success($diff_pid_categoryIds);
  1864. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1865. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1866. }
  1867. // return Result::success(reset($diff_pid_categoryIds) == 0);
  1868. // $cat_1st_arr = $categorys['cat_1st_arr'];
  1869. $catiall = $categorys['catiall'];
  1870. $categoryIds = $categorys['categoryIds'];
  1871. // return Result::success($categoryIds);
  1872. $query = Article::where('status', 1)
  1873. ->whereIn('catid', $categoryIds)
  1874. ->leftJoinSub(function ($query) use ($website_id) {
  1875. $query->from('article_ignore')
  1876. ->where('website_id', $website_id);
  1877. }, 'article_ignore', function ($join) {
  1878. $join->on('article_ignore.article_id', '=', 'article.id');
  1879. })
  1880. ->where(function ($query) {
  1881. $query->whereNull('article_ignore.article_id')
  1882. ->orWhere(function ($subQuery) {
  1883. $subQuery->whereNotNull('article_ignore.article_id')
  1884. ->where('article_ignore.is_ignore', 0)
  1885. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  1886. });
  1887. });
  1888. // ->get()->all();
  1889. // return Result::success($query);
  1890. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1891. $query->whereRaw("JSON_CONTAINS(article.city_arr_id, '" . intval($data['cityid']) . "')");
  1892. }
  1893. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1894. $query->whereRaw("JSON_CONTAINS(article.department_arr_id, '" . intval($data['department_id']) . "')");
  1895. }
  1896. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1897. $query->where('article.title', 'like', '%' . $data['keyword'] . '%');
  1898. }
  1899. // 计算总数
  1900. $count = $query->count();
  1901. // return Result::success($count);
  1902. // 分页查询
  1903. $articles = $query
  1904. ->select(
  1905. 'article.id',
  1906. 'article.title',
  1907. 'article.imgurl',
  1908. 'article.author',
  1909. 'article.updated_at',
  1910. 'article.introduce',
  1911. 'article.islink',
  1912. 'article.linkurl',
  1913. 'article.copyfrom',
  1914. 'article.cat_arr_id',
  1915. 'article.catid',
  1916. 'article.department_arr_id',
  1917. 'article.city_arr_id',
  1918. // 'article_ignore.c_show_time',
  1919. // 'article_ignore.is_ignore'
  1920. )
  1921. ->orderBy("updated_at", "desc")
  1922. ->offset(($data['page'] - 1) * $data['pageSize'])
  1923. ->limit($data['pageSize'])
  1924. ->get();
  1925. // return Result::success($articles);
  1926. foreach ($articles as $k => $v) {
  1927. $articles[$k]->category_name = $catiall[$v->catid]['alias'];
  1928. $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1929. }
  1930. if (empty($articles)) {
  1931. return Result::error("没有符合条件的资讯数据");
  1932. }
  1933. $result = [
  1934. 'rows' => $articles,
  1935. 'count' => $count,
  1936. ];
  1937. return Result::success($result);
  1938. }
  1939. /**
  1940. * 模块新闻加强版
  1941. * @param array $data
  1942. * @return array
  1943. */
  1944. public function getWebsiteCatidArticle(array $data): array
  1945. {
  1946. $where = [
  1947. 'website_category.category_id' => $data['catid'],
  1948. 'website_category.website_id' => $data['website_id'],
  1949. ];
  1950. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  1951. $child_catnum = $data['child_catnum'] ?? 1;
  1952. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  1953. $childCategoryIds = array_column($category['child'], 'category_id');
  1954. if (empty($childCategoryIds)) {
  1955. return Result::error("暂无子栏目", 0);
  1956. }
  1957. $imgArticles = [];
  1958. $textArticles = [];
  1959. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  1960. // 初始化子分类图片新闻和文字新闻数组
  1961. // 查询所有子级栏目的图文新闻
  1962. $imgArticles = Article::where('catid', $childCategoryIds[0])
  1963. ->where(function ($query) use ($data) {
  1964. $query->where(function ($subQuery) use ($data) {
  1965. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1966. })->orWhereNull("ignore_ids");
  1967. })
  1968. ->where('status', 1)
  1969. ->where('imgurl', '!=', '')
  1970. ->select('*')
  1971. ->orderBy('updated_at', 'desc')
  1972. ->limit($data['child_imgnum'])
  1973. ->get();
  1974. }
  1975. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  1976. // 查询所有子级栏目的文字新闻
  1977. $textArticles = Article::where('catid', $childCategoryIds[0])
  1978. ->where('status', 1)
  1979. ->where(function ($query) use ($data) {
  1980. $query->where(function ($subQuery) use ($data) {
  1981. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1982. })->orWhereNull("ignore_ids");
  1983. })
  1984. ->select('*')
  1985. ->orderBy('updated_at', 'desc')
  1986. ->limit($data['child_textnum'])
  1987. ->get();
  1988. }
  1989. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  1990. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  1991. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  1992. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  1993. return $child;
  1994. }, $category['child']);
  1995. }
  1996. // }
  1997. if (isset($data['img_num']) && !empty($data['img_num'])) {
  1998. $category['img'] = WebsiteCategory::where($where)
  1999. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  2000. ->where('article.status', 1)
  2001. ->where('article.imgurl', '!=', '')
  2002. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  2003. ->orderBy('article.updated_at', 'desc')
  2004. ->limit($data['img_num'])
  2005. ->get();
  2006. }
  2007. if (isset($data['text_num']) && !empty($data['text_num'])) {
  2008. $category['text'] = WebsiteCategory::where($where)
  2009. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  2010. ->where('article.status', 1)
  2011. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  2012. ->orderBy('article.updated_at', 'desc')
  2013. ->limit($data['text_num'])
  2014. ->get();
  2015. }
  2016. // $category = $category->get();
  2017. if (empty($category)) {
  2018. return Result::error("查询失败", 0);
  2019. }
  2020. return Result::success($category);
  2021. }
  2022. /**
  2023. * 模块新闻加强plus版
  2024. * @param array $data
  2025. * @return array
  2026. */
  2027. public function getWebsiteAllArticle(array $data): array
  2028. {
  2029. // return Result::success($data);
  2030. $time1 = microtime(true);
  2031. $wetbsite_id = $data['website_id'] ?? 2;
  2032. $data = json_decode($data['id'], true);
  2033. $website = Website::where('id', $wetbsite_id)->first();
  2034. if (empty($website)) {
  2035. return Result::error("网站不存在", 0);
  2036. }
  2037. // return Result::success($website);
  2038. $website_column = $website['website_column_arr_id'] ?? '[]';
  2039. $website_column = json_decode($website_column, true);
  2040. $categorys = $this->processArticlePro($wetbsite_id);
  2041. $cat_1st_arr = $categorys['cat_1st_arr'];
  2042. $catiall = $categorys['catiall'];
  2043. // return Result::success($catiall);
  2044. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  2045. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2046. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2047. }
  2048. $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
  2049. // return Result::success($categorys);
  2050. $parent_category = array_column($data, 'parent');
  2051. $parent_cat = [];
  2052. $child_category = array_column($data, 'child');
  2053. if (!empty($parent_category)) {
  2054. foreach ($parent_category as $key => $value) {
  2055. $arr = array_map('intval', explode(',', $value));
  2056. $parent_cat[$key] = $arr[0] ?? 0;
  2057. $parent_category = $arr[0] ?? 0;
  2058. $article_imgnum = $arr[1] ?? 0;
  2059. $article_textnum = $arr[2] ?? 0;
  2060. if ($parent_category != 0) {
  2061. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2062. // return Result::success($category_arr);
  2063. if ($article_imgnum != 0) {
  2064. $img_article = Article::whereIn('catid', $category_arr)
  2065. ->where('status', 1)
  2066. ->where('imgurl', '!=', '')
  2067. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2068. $query->from('article_ignore')
  2069. ->where('website_id', $wetbsite_id);
  2070. }, 'article_ignore', function ($join) {
  2071. $join->on('article_ignore.article_id', '=', 'article.id');
  2072. })
  2073. ->where(function ($query) {
  2074. $query->whereNull('article_ignore.article_id')
  2075. ->orWhere(function ($subQuery) {
  2076. $subQuery->whereNotNull('article_ignore.article_id')
  2077. ->where('article_ignore.is_ignore', 0)
  2078. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  2079. });
  2080. })
  2081. ->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')
  2082. ->orderBy('updated_at', 'desc')
  2083. ->limit($article_imgnum)
  2084. ->get()->all();
  2085. foreach ($img_article as $k => $v) {
  2086. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2087. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2088. }
  2089. } else {
  2090. $img_article = [];
  2091. }
  2092. if ($article_textnum != 0) {
  2093. $text_article = Article::whereIn('catid', $category_arr)
  2094. ->where('status', 1)
  2095. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2096. $query->from('article_ignore')
  2097. ->where('website_id', $wetbsite_id);
  2098. }, 'article_ignore', function ($join) {
  2099. $join->on('article_ignore.article_id', '=', 'article.id');
  2100. })
  2101. ->where(function ($query) {
  2102. $query->whereNull('article_ignore.article_id')
  2103. ->orWhere(function ($subQuery) {
  2104. $subQuery->whereNotNull('article_ignore.article_id')
  2105. ->where('article_ignore.is_ignore', 0)
  2106. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  2107. });
  2108. })
  2109. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2110. ->orderBy('updated_at', 'desc')
  2111. ->limit($article_textnum)
  2112. ->get()->all();
  2113. foreach ($text_article as $k => $v) {
  2114. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2115. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2116. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2117. }
  2118. } else {
  2119. $text_article = [];
  2120. }
  2121. $catiall[$parent_category]['imgnum'] = $img_article;
  2122. $catiall[$parent_category]['textnum'] = $text_article;
  2123. $parent[$key] = $catiall[$parent_category];
  2124. } else {
  2125. $parent[$key] = '';
  2126. }
  2127. }
  2128. }
  2129. if (!empty($child_category)) {
  2130. foreach ($child_category as $key => $value) {
  2131. $arr = array_map('intval', explode(',', $value));
  2132. $parent_category = $parent_cat[$key];
  2133. $child_category = $arr[0] ?? 0;
  2134. $article_imgnum = $arr[1] ?? 0;
  2135. $article_textnum = $arr[2] ?? 0;
  2136. if ($child_category != 0) {
  2137. $all_childcat = $cat_1st_arr[$parent_category];
  2138. $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
  2139. // 从 $websiteInfoIndexed 中获取对应的数据
  2140. $info = $websiteInfoIndexed[$v];
  2141. // 返回一个包含所需信息的数组
  2142. return [
  2143. 'alias' => $info->alias,
  2144. 'category_id' => $info->category_id,
  2145. 'aLIas_pinyin' => $info->aLIas_pinyin,
  2146. 'pid' => $info->pid,
  2147. 'type' => $info->type,
  2148. 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
  2149. 'pinyin' => $info->pinyin,
  2150. ];
  2151. }, $all_childcat);
  2152. if ($article_imgnum != 0) {
  2153. $img_article = Article::where('catid', $child_category)
  2154. ->where('status', 1)
  2155. ->where('imgurl', '!=', '')
  2156. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2157. $query->from('article_ignore')
  2158. ->where('website_id', $wetbsite_id);
  2159. }, 'article_ignore', function ($join) {
  2160. $join->on('article_ignore.article_id', '=', 'article.id');
  2161. })
  2162. ->where(function ($query) {
  2163. $query->whereNull('article_ignore.article_id')
  2164. ->orWhere(function ($subQuery) {
  2165. $subQuery->whereNotNull('article_ignore.article_id')
  2166. ->where('article_ignore.is_ignore', 0)
  2167. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  2168. });
  2169. })
  2170. ->select('id', 'title', 'imgurl', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2171. ->orderBy('updated_at', 'desc')
  2172. ->limit($article_imgnum)
  2173. ->get()->all();
  2174. foreach ($img_article as $k => $v) {
  2175. // var_dump($v);
  2176. // var_dump($k);
  2177. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2178. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2179. }
  2180. } else {
  2181. $img_article = [];
  2182. }
  2183. if ($article_textnum != 0) {
  2184. $text_article = Article::where('catid', $child_category)
  2185. ->where('status', 1)
  2186. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2187. $query->from('article_ignore')
  2188. ->where('website_id', $wetbsite_id);
  2189. }, 'article_ignore', function ($join) {
  2190. $join->on('article_ignore.article_id', '=', 'article.id');
  2191. })
  2192. ->where(function ($query) {
  2193. $query->whereNull('article_ignore.article_id')
  2194. ->orWhere(function ($subQuery) {
  2195. $subQuery->whereNotNull('article_ignore.article_id')
  2196. ->where('article_ignore.is_ignore', 0)
  2197. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  2198. });
  2199. })
  2200. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2201. ->orderBy('updated_at', 'desc')
  2202. ->limit($article_textnum)
  2203. ->get()->all();
  2204. foreach ($text_article as $k => $v) {
  2205. // var_dump($v);
  2206. // var_dump($k);
  2207. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2208. // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2209. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2210. }
  2211. } else {
  2212. $text_article = [];
  2213. }
  2214. $catiall[$child_category]['all_childcat'] = $processedChildCat;
  2215. $catiall[$child_category]['imgnum'] = $img_article;
  2216. $catiall[$child_category]['textnum'] = $text_article;
  2217. $child[$key] = $catiall[$child_category];
  2218. // var_dump($pids);
  2219. } else {
  2220. $child[$key] = '';
  2221. }
  2222. }
  2223. }
  2224. foreach ($parent as $key => $value) {
  2225. $result[$key] = $value;
  2226. if (!empty($child[$key])) {
  2227. // var_dump($child[$key]);
  2228. $result[$key]['child'] = $child[$key];
  2229. // $value[$key]['child'] = $child[$key];
  2230. } else {
  2231. $result[$key]['child'] = [
  2232. "alias" => null,
  2233. "category_id" => null,
  2234. "type" => null,
  2235. "pinyin" => null,
  2236. "all_childcat" => [],
  2237. "imgnum" => [],
  2238. "textnum" => []
  2239. ];
  2240. }
  2241. }
  2242. return Result::success($result);
  2243. }
  2244. /**
  2245. * 辅助方法:获取文章列表
  2246. */
  2247. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  2248. {
  2249. sleep(1);
  2250. $query = Article::where('article.status', 1)
  2251. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  2252. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  2253. ->where(function ($query) use ($website) {
  2254. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  2255. })
  2256. ->leftJoin('website_category', function ($join) use ($website) {
  2257. $join->on('article.catid', '=', 'website_category.category_id')
  2258. ->where('website_category.website_id', '=', $website['website_id']);
  2259. })
  2260. ->select(
  2261. 'article.id',
  2262. 'article.title',
  2263. 'article.imgurl',
  2264. 'article.author',
  2265. 'article.updated_at',
  2266. 'article.introduce',
  2267. 'article.islink',
  2268. 'article.linkurl',
  2269. 'article.copyfrom',
  2270. 'article.cat_arr_id',
  2271. 'article.catid',
  2272. 'website_category.alias as category_name'
  2273. )
  2274. ->orderBy('updated_at', 'desc')
  2275. ->limit($limit);
  2276. // 如果是图片文章,添加图片URL条件
  2277. if ($isImageArticle) {
  2278. $query->where('imgurl', '!=', '');
  2279. } else {
  2280. // 文字文章不需要imgurl字段
  2281. $query->addSelect('article.introduce');
  2282. }
  2283. $articles = $query->get();
  2284. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  2285. }
  2286. /**
  2287. * 乡村网-获取特殊新闻模块
  2288. * @param array $data
  2289. * @return array
  2290. */
  2291. public function getWebsiteArticles(array $data): array
  2292. {
  2293. $website_id = $data['website_id'];
  2294. $website = Website::where('id', $website_id)->first();
  2295. if (empty($website)) {
  2296. return Result::error("网站不存在", 0);
  2297. }
  2298. // return Result::success($website);
  2299. $website_column = $website['website_column_arr_id'] ?? '[]';
  2300. $website_column = json_decode($website_column, true);
  2301. $catids = json_decode($data['id'], true);
  2302. $parent_category = array_column($catids, 'parent');
  2303. if (!empty($parent_category) && is_array($parent_category)) {
  2304. $categorys = $this->processArticlePro($website_id);
  2305. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  2306. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2307. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2308. }
  2309. $catiall = $categorys['catiall'];
  2310. $cat_1st_arr = $categorys['cat_1st_arr'];
  2311. // return Result::success($categorys);
  2312. foreach ($parent_category as $key => $value) {
  2313. $arr = array_map('intval', explode(',', $value));
  2314. $parent_category = $arr[0] ?? 0;
  2315. $article_imgnum = $arr[1] ?? 0;
  2316. $article_textnum = $arr[2] ?? 0;
  2317. if ($parent_category != 0) {
  2318. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2319. // return Result::success($category_arr);
  2320. if ($article_imgnum != 0) {
  2321. $img_article = Article::whereIn('article.catid', $category_arr)
  2322. ->where('article.status', 1)
  2323. ->where('article.imgurl', '!=', '')
  2324. ->leftJoinSub(function ($query) use ($website_id) {
  2325. $query->from('article_ignore')
  2326. ->where('website_id', $website_id);
  2327. }, 'article_ignore', function ($join) {
  2328. $join->on('article_ignore.article_id', '=', 'article.id');
  2329. })
  2330. ->where(function ($query) {
  2331. $query->whereNull('article_ignore.article_id')
  2332. ->orWhere(function ($subQuery) {
  2333. $subQuery->whereNotNull('article_ignore.article_id')
  2334. ->where('article_ignore.is_ignore', 0)
  2335. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  2336. });
  2337. })
  2338. ->select(
  2339. 'article.id',
  2340. 'article.title',
  2341. 'article.imgurl',
  2342. 'article.author',
  2343. 'article.updated_at',
  2344. 'article.introduce',
  2345. 'article.islink',
  2346. 'article.linkurl',
  2347. 'article.copyfrom',
  2348. 'article.cat_arr_id',
  2349. 'article.catid as category_id'
  2350. )
  2351. ->orderBy('updated_at', 'desc')
  2352. ->limit($article_imgnum)
  2353. ->get()->all();
  2354. foreach ($img_article as $k => $v) {
  2355. $img_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2356. // return Result::success($v);
  2357. $img_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2358. }
  2359. } else {
  2360. $img_article = [];
  2361. }
  2362. if ($article_textnum != 0) {
  2363. $text_article = Article::whereIn('article.catid', $category_arr)
  2364. ->where('article.status', 1)
  2365. ->leftJoinSub(function ($query) use ($website_id) {
  2366. $query->from('article_ignore')
  2367. ->where('website_id', $website_id);
  2368. }, 'article_ignore', function ($join) {
  2369. $join->on('article_ignore.article_id', '=', 'article.id');
  2370. })
  2371. ->where(function ($query) {
  2372. $query->whereNull('article_ignore.article_id')
  2373. ->orWhere(function ($subQuery) {
  2374. $subQuery->whereNotNull('article_ignore.article_id')
  2375. ->where('article_ignore.is_ignore', 0)
  2376. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  2377. });
  2378. })
  2379. ->select(
  2380. 'article.id',
  2381. 'article.title',
  2382. 'article.author',
  2383. 'article.updated_at',
  2384. 'article.introduce',
  2385. 'article.islink',
  2386. 'article.linkurl',
  2387. 'article.copyfrom',
  2388. 'article.cat_arr_id',
  2389. 'article.catid as category_id'
  2390. )
  2391. ->orderBy('updated_at', 'desc')
  2392. ->limit($article_textnum)
  2393. ->get()->all();
  2394. foreach ($text_article as $k => $v) {
  2395. $text_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2396. $text_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2397. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2398. }
  2399. } else {
  2400. $text_article = [];
  2401. }
  2402. $catiall[$parent_category]['imgnum'] = $img_article ?? [];
  2403. $catiall[$parent_category]['textnum'] = $text_article ?? [];
  2404. $parent[$key] = $catiall[$parent_category];
  2405. } else {
  2406. $parent[$key] = [];
  2407. }
  2408. }
  2409. }
  2410. return Result::success($parent);
  2411. }
  2412. // 封装处理商品的路由问题
  2413. function processGoods($goods, $data)
  2414. {
  2415. return $goods->map(function ($good) use ($data) {
  2416. $catid = $good->catid ?? 0;
  2417. // $pinyin = '';
  2418. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2419. if (!empty($category->pid) && $category->pid != 0) {
  2420. $level = json_decode($category->category_arr_id, true);
  2421. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  2422. ->whereIn('category_id', $level)
  2423. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2424. ->get(['aLIas_pinyin'])
  2425. ->pluck('aLIas_pinyin')
  2426. ->implode('/');
  2427. } else {
  2428. $pinyin = $category->aLIas_pinyin ?? '';
  2429. }
  2430. if (isset($good->city_id) && !empty($good->city_id)) {
  2431. $city = District::where('id', $good->city_id)->first(['name']);
  2432. $good->city_name = $city->name ?? '';
  2433. }
  2434. // 解析imgurl JSON并取第一条数据
  2435. $imgUrls = json_decode($good->imgurl, true);
  2436. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  2437. $good->pinyin = $pinyin;
  2438. return $good;
  2439. });
  2440. }
  2441. /**
  2442. * 获取商城首页-根据栏目id
  2443. * @param array $data
  2444. * @return array
  2445. * */
  2446. function getWebsiteCatidshop(array $data): array
  2447. {
  2448. $input['catid'] = $data['catid'];
  2449. $input['website_id'] = $data['website_id'];
  2450. $data = json_decode($input['catid'] ?? '', true) ?? [];
  2451. $result = array_map(function ($item) use ($input) {
  2452. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  2453. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  2454. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  2455. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  2456. if (empty($category) || $category->type != 2) {
  2457. return Result::error("暂无此栏目", 0);
  2458. } else {
  2459. $website['website_id'] = $input['website_id'];
  2460. $goods = Good::where('good.status', 2)
  2461. ->where('good.website_id', $website['website_id'])
  2462. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  2463. ->select(
  2464. 'good.id',
  2465. 'good.name',
  2466. 'good.imgurl',
  2467. 'good.description',
  2468. 'good.updated_at',
  2469. 'good.catid',
  2470. 'good.type_id',
  2471. 'good.price',
  2472. 'good.com',
  2473. 'good.level',
  2474. 'good.unit'
  2475. )
  2476. ->orderBy('updated_at', 'desc')
  2477. ->offset($goodStart)
  2478. ->limit($goodNum);
  2479. $all_goods = $goods->get();
  2480. $all_goods = $this->processGoods($all_goods, $website);
  2481. }
  2482. return $all_goods ?? [];
  2483. }
  2484. }, $data);
  2485. return Result::success($result);
  2486. }
  2487. /**
  2488. * 获取商品模块
  2489. * @param array $data
  2490. * @return array
  2491. * */
  2492. public function getWebsiteshop(array $data): array
  2493. {
  2494. $input['id'] = $data['id'];
  2495. $input['website_id'] = $data['website_id'];
  2496. $catid = $data['catid'];
  2497. $data = json_decode($input['id'] ?? '', true) ?? [];
  2498. $result['goods'] = array_map(function ($item) use ($input) {
  2499. // 检查parent元素是否存在且不是undefined
  2500. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  2501. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  2502. $website = $input['website_id'];
  2503. $query = Good::where('good.status', 2)
  2504. ->where('good.website_id', $website);
  2505. switch ($Levelid) {
  2506. case 1:
  2507. case 2:
  2508. case 3:
  2509. $goods = $query->where(function ($q) use ($Levelid) {
  2510. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  2511. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  2512. });
  2513. break;
  2514. case 4:
  2515. $goods = $query;
  2516. break;
  2517. case 5:
  2518. $goods = $query->where('type_id', 1);
  2519. break;
  2520. case 6:
  2521. $goods = $query->where('type_id', 2);
  2522. break;
  2523. default:
  2524. return [];
  2525. }
  2526. $all_goods = $goods
  2527. ->select(
  2528. 'good.id',
  2529. 'good.name',
  2530. 'good.imgurl',
  2531. 'good.description',
  2532. 'good.updated_at',
  2533. 'good.catid',
  2534. 'good.type_id',
  2535. 'good.price',
  2536. 'good.level',
  2537. 'good.website_id'
  2538. )
  2539. ->orderBy('updated_at', 'desc')
  2540. ->offset($goodStart)
  2541. ->limit($goodNum)
  2542. ->get();
  2543. $web['website_id'] = $website;
  2544. $all_goods = $this->processGoods($all_goods, $web);
  2545. }
  2546. return $all_goods;
  2547. }, $data);
  2548. $website = $input['website_id'];
  2549. $result['article'] = Article::where(function ($query) use ($website) {
  2550. $query->where(function ($subQuery) use ($website) {
  2551. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  2552. })->orWhereNull("ignore_ids");
  2553. })
  2554. ->where('catid', $catid)
  2555. ->where('article.status', 1)
  2556. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  2557. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  2558. ->orderBy('article.updated_at', 'desc')
  2559. ->first();
  2560. return Result::success($result);
  2561. }
  2562. /**
  2563. * 获取商品分类
  2564. * @param array $data
  2565. * @return array
  2566. * */
  2567. public function getWebsiteshopCat(array $data): array
  2568. {
  2569. $website = $data['website_id'];
  2570. $category = WebsiteCategory::where('website_id', $website)
  2571. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  2572. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  2573. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  2574. ->orderBy('sort')
  2575. ->get();
  2576. $cat = $category->map(function ($item) use ($website) {
  2577. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  2578. $pid = $item->pid ?? 0;
  2579. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  2580. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  2581. ->where('website_id', $website)
  2582. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  2583. ->get(['aLIas_pinyin'])
  2584. ->pluck('aLIas_pinyin')
  2585. ->implode('/');
  2586. } else {
  2587. $pinyin = $item->aLIas_pinyin ?? '';
  2588. }
  2589. $item->pinyin = $pinyin;
  2590. });
  2591. if (empty($category)) {
  2592. return Result::error("栏目查询失败", 0);
  2593. }
  2594. $cat_tree = Result::buildMenuTree($category);
  2595. $web['website_id'] = $website;
  2596. $goods = Good::where('website_id', $website)
  2597. ->where('status', 2)
  2598. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  2599. ->latest('updated_at')
  2600. ->offset(($data['page'] - 1) * $data['pageSize'])
  2601. ->limit($data['pageSize'])
  2602. ->get();
  2603. if (!empty($goods)) {
  2604. if ($goods->count() > 1 && !empty($goods)) {
  2605. $goods = $this->processGoods($goods, $web);
  2606. }
  2607. } else {
  2608. $goods = [];
  2609. }
  2610. $result = [
  2611. 'category' => $cat_tree,
  2612. 'goods' => $goods,
  2613. ];
  2614. // $resul['goods'] = $goods;
  2615. if (empty($result)) {
  2616. return Result::error("查询失败", 0);
  2617. }
  2618. return Result::success($result);
  2619. }
  2620. /*
  2621. * 获取商品列表
  2622. * @param array $data
  2623. * @return array
  2624. * */
  2625. public function getWebsiteshopList(array $data): array
  2626. {
  2627. // return Result::success($data);
  2628. $where = [
  2629. 'status' => 2,
  2630. 'website_id' => $data['website_id'],
  2631. ];
  2632. // if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  2633. // return Result::error("查询失败", 0);
  2634. // }
  2635. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  2636. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  2637. $data['catid'] = $category->category_id ?? 0;
  2638. }
  2639. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2640. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  2641. }
  2642. if (isset($data['type_id']) && !empty($data['type_id'])) {
  2643. array_push($where, ['type_id', $data['type_id']]);
  2644. }
  2645. $query = Good::where($where)
  2646. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2647. $query->where(function ($q) use ($data) {
  2648. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  2649. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  2650. });
  2651. })
  2652. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2653. $query->where(function ($q) use ($data) {
  2654. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  2655. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  2656. });
  2657. })
  2658. ->select(
  2659. 'good.id',
  2660. 'good.name',
  2661. 'good.imgurl',
  2662. 'good.description',
  2663. 'good.updated_at',
  2664. 'good.com',
  2665. 'good.catid',
  2666. 'good.type_id',
  2667. 'good.website_id',
  2668. 'good.cat_arr_id',
  2669. 'good.created_at',
  2670. 'good.city_id'
  2671. )
  2672. ->latest('updated_at');
  2673. if (isset($data['ismix']) && $data['ismix'] == 1) {
  2674. $result['count'] = $query->clone()->count();
  2675. $result['goods'] = $this->processGoods(
  2676. $query->clone()
  2677. ->offset(($data['page'] - 1) * $data['pageSize'])
  2678. ->limit($data['pageSize'])
  2679. ->get(),
  2680. $data
  2681. );
  2682. } else {
  2683. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  2684. // 获取 type_id 为 1 的数据
  2685. $result['type1'] = $this->processGoods(
  2686. $query->clone()
  2687. ->where('type_id', 1)
  2688. ->offset(($data['page'] - 1) * $data['pageSize'])
  2689. ->limit($data['pageSize'])
  2690. ->get(),
  2691. $data
  2692. );
  2693. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2694. // 获取 type_id 为 2 的数据
  2695. $result['type2'] = $this->processGoods(
  2696. $query->clone()
  2697. ->where('type_id', 2)
  2698. ->offset(($data['page'] - 1) * $data['pageSize'])
  2699. ->limit($data['pageSize'])
  2700. ->get(),
  2701. $data
  2702. );
  2703. }
  2704. if (empty($result)) {
  2705. return Result::error("查询失败", 0);
  2706. }
  2707. return Result::success($result);
  2708. }
  2709. /**
  2710. * 获取商品详情
  2711. * @param array $data
  2712. * @return array
  2713. * */
  2714. public function getWebsiteshopInfo(array $data): array
  2715. {
  2716. $where = [
  2717. 'good.status' => 2,
  2718. 'good.website_id' => $data['website_id'],
  2719. 'good.id' => $data['id'],
  2720. ];
  2721. $goods = Good::where($where)
  2722. ->where('good.id', $data['id'])
  2723. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2724. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2725. ->first();
  2726. if (empty($goods)) {
  2727. return Result::error("查询失败", 0);
  2728. }
  2729. $goods->imgurl = json_decode($goods->imgurl, true);
  2730. return Result::success($goods);
  2731. }
  2732. /**
  2733. * plus pro 处理文章路由问题
  2734. */
  2735. function processArticlePro($website_id)
  2736. {
  2737. // $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2738. // // $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2739. // // 取出category_id 对应的aLIas_pinyin
  2740. // $categoryIds = array_column($categorys, 'category_id');
  2741. // $categoryPIds = array_column($categorys, 'pid');
  2742. // $aliasPinyins = array_column($categorys, 'path');
  2743. // $alias = array_column($categorys, 'alias');
  2744. // $cat_arr = array_combine($categoryIds, $aliasPinyins);
  2745. // $cat_alias_arr = array_combine($categoryIds, $categoryPIds);
  2746. // // return Result::success($cat_arr);
  2747. // // $catiall = [];
  2748. // //一级所有子级的记录
  2749. // $cat_alias_arr = array_combine($categoryIds, $alias);
  2750. // return [
  2751. // 'cat_1st_arr' => $cat_alias_arr,
  2752. // 'catiall' => $cat_arr,
  2753. // // 'websiteInfoIndexed' => $websiteInfoIndexed,
  2754. // 'categoryIds' => $categoryIds,
  2755. // ];
  2756. $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2757. $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2758. // 取出category_id 对应的aLIas_pinyin
  2759. $categoryIds = array_column($categorys, 'category_id');
  2760. $categoryPIds = array_values(array_unique(array_filter(array_column($categorys, 'pid'), function ($pid) {
  2761. return $pid != 0;
  2762. })));
  2763. $category_path = array_column($categorys, 'path');
  2764. $cat_arr = array_combine($categoryIds, $category_path);
  2765. // return Result::success(array_diff($categoryIds, $categoryPIds));
  2766. $catiall = [];
  2767. //一级所有子级的记录
  2768. $cat_1st_arr = [];
  2769. foreach ($categorys as $key => $value) {
  2770. // $category_arr_id = json_decode($value->category_arr_id);
  2771. // $pinyin_str = '';
  2772. // // 算出一级 并且算出子级
  2773. if ($value->pid != 0 && in_array($value->pid, $categoryIds)) {
  2774. $cat_1st_arr[$value->pid][] = $value->category_id;
  2775. }
  2776. // foreach ($category_arr_id as $k => $v) {
  2777. // $pinyin_str .= $cat_arr[$v] . '/';
  2778. // }
  2779. // $pinyin_str = rtrim($pinyin_str, '/');
  2780. $catiall[$value->category_id]['alias'] = $value->alias;
  2781. $catiall[$value->category_id]['category_id'] = $value->category_id;
  2782. $catiall[$value->category_id]['type'] = $value->type;
  2783. $catiall[$value->category_id]['pinyin'] = $cat_arr[$value->category_id];
  2784. $websiteInfoIndexed[$value->category_id]->pinyin = $cat_arr[$value->category_id];
  2785. }
  2786. return [
  2787. 'cat_1st_arr' => $cat_1st_arr,
  2788. 'catiall' => $catiall,
  2789. 'websiteInfoIndexed' => $websiteInfoIndexed,
  2790. 'categoryIds' => $categoryIds,
  2791. 'diff_pid_categoryIds' => array_diff($categoryPIds, $categoryIds),
  2792. 'categoryPIds' => $categoryPIds,
  2793. ];
  2794. }
  2795. /**
  2796. * 封装处理文章的路由问题
  2797. * */
  2798. function processArticles($articles, $data)
  2799. {
  2800. // 检查 $articles 是否为数组或可迭代对象
  2801. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  2802. return $articles->map(function ($article) use ($data) {
  2803. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  2804. $catid = $article->cat_arr_id ?? '';
  2805. }
  2806. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  2807. $catid = $article->category_arr_id ?? '';
  2808. }
  2809. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  2810. $level = json_decode($catid, true);
  2811. if (!is_array($level)) {
  2812. return $article;
  2813. } else {
  2814. $level = array_map('intval', $level);
  2815. }
  2816. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2817. ->where($data)
  2818. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2819. ->pluck('aLIas_pinyin')
  2820. ->implode('/');
  2821. $article->pinyin = $pinyin ?? '';
  2822. return $article;
  2823. });
  2824. } else {
  2825. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2826. $catid = $articles->cat_arr_id ?? '';
  2827. $level = json_decode($catid, true);
  2828. if (!is_array($level)) {
  2829. return $articles;
  2830. } else {
  2831. $level = array_map('intval', $level);
  2832. }
  2833. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2834. ->where($data)
  2835. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2836. ->pluck('aLIas_pinyin')
  2837. ->implode('/');
  2838. $articles->pinyin = $pinyin ?? '';
  2839. return $articles;
  2840. }
  2841. }
  2842. // 封装处理由问题
  2843. function processJob($job, $data)
  2844. {
  2845. return $job->map(function ($job) use ($data) {
  2846. $category = $job->cat_arr_id ?? '';
  2847. $cityid = $job->city_arr_id ?? '';
  2848. $city = json_decode($cityid, true);
  2849. $pinyin = '';
  2850. $level = json_decode($category, true);
  2851. // 路由
  2852. if (!empty($level) && is_array($level)) {
  2853. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2854. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2855. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2856. ->get(['aLIas_pinyin'])
  2857. ->pluck('aLIas_pinyin')
  2858. ->implode('/');
  2859. if (empty($pinyin)) {
  2860. $pinyin = $pinyin->aLIas_pinyin ?? '';
  2861. }
  2862. $job->pinyin = $pinyin;
  2863. }
  2864. // 取职位-城市 市??省
  2865. if (!empty($city) && is_array($city)) {
  2866. if (isset($city[1]) && !empty($city[1])) {
  2867. $city = District::where('id', $city[1])->first(['name']);
  2868. $job->city_name = $city->name ?? '';
  2869. } else if (isset($city[0]) && !empty($city[0])) {
  2870. $city = District::where('id', $city[0])->first(['name']);
  2871. $job->city_name = $city->name ?? '';
  2872. } else {
  2873. $job->city_name = '全国';
  2874. }
  2875. }
  2876. // 获取简历最后一级地区
  2877. if (isset($job->city_id) && !empty($job->city_id)) {
  2878. $city = District::where('id', $job->city_id)->first(['name']);
  2879. $job->hunt_cityname = $city->name ?? '';
  2880. }
  2881. // 组合详细地址
  2882. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  2883. $address_id = json_decode($job->address_arr_id, true) ?? [];
  2884. if (is_array($address_id) && !empty($address_id)) {
  2885. $address = District::whereIn('id', $address_id)
  2886. ->orderBy('level', 'asc')
  2887. ->get(['name'])
  2888. ->pluck('name')
  2889. ->implode('');
  2890. // $job->address_name = $address ?? '';
  2891. $job->address_name = ($address ?? '') . ($job->address ?? '');
  2892. }
  2893. }
  2894. // 取行业
  2895. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  2896. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  2897. if (!empty($job->industry)) {
  2898. $query->where('hyid', $job->industry);
  2899. } else if (!empty($job->hy_id)) {
  2900. $query->where('hyid', $job->hy_id);
  2901. } else if (!empty($job->company_hy_id)) {
  2902. $query->where('hyid', $job->company_hy_id);
  2903. } else {
  2904. $query->where('hyid', $job->job_industry);
  2905. }
  2906. })->first(['hyname']);
  2907. $job->hy_name = $hy_name->hyname ?? '';
  2908. }
  2909. // 取职位类别
  2910. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  2911. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  2912. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  2913. $job->zw_name = $zw_name->zwname ?? '';
  2914. }
  2915. // 取具体职位
  2916. 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))) {
  2917. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  2918. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  2919. $job->jtzw_name = $jtzw_name->zwname ?? '';
  2920. }
  2921. // 取工作经验
  2922. if (isset($job->experience) && !empty($job->experience)) {
  2923. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  2924. $job->experience_name = $experience->ename ?? '';
  2925. }
  2926. // 取学历
  2927. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  2928. $education = $job->educational ?? $job->school_education;
  2929. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  2930. $job->education_name = $education->ename ?? '';
  2931. }
  2932. // 语言
  2933. if (isset($job->language) && !empty($job->language)) {
  2934. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  2935. $job->language_name = $language->ename ?? '';
  2936. }
  2937. // 薪资
  2938. if (isset($job->salary) && !empty($job->salary)) {
  2939. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  2940. $job->salary_name = $salary->ename ?? '';
  2941. }
  2942. // 职位性质
  2943. if (isset($job->nature_id) && !empty($job->nature_id)) {
  2944. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  2945. $job->job_nature_name = $job_nature->ename ?? '';
  2946. }
  2947. // 公司规模
  2948. if (isset($job->company_size) && !empty($job->company_size)) {
  2949. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  2950. $job->company_size_name = $company_size->ename ?? '';
  2951. }
  2952. // 公司性质
  2953. if (isset($job->company_nature) && !empty($job->company_nature)) {
  2954. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  2955. $job->company_nature_name = $company_nature->nature_name ?? '';
  2956. }
  2957. // $job->pinyin = $pinyin;
  2958. return $job;
  2959. });
  2960. }
  2961. /**
  2962. * 获取书籍模块
  2963. * @param array $data
  2964. * @return array
  2965. * */
  2966. public function getWebsiteBook(array $data): array
  2967. {
  2968. $input['id'] = $data['id'];
  2969. $input['website_id'] = $data['website_id'];
  2970. // 将 JSON 字符串转换为 PHP 数组
  2971. $data = json_decode($input['id'], true);
  2972. // 使用 array_map 处理每个元素
  2973. $result = array_map(function ($item) use ($input) {
  2974. // 检查parent元素是否存在且不是undefined
  2975. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  2976. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2977. $website = [
  2978. 'website_id' => $input['website_id'],
  2979. ];
  2980. // 查询栏目名称
  2981. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2982. if (empty($category)) {
  2983. $parent_alias = '';
  2984. $parent_pinyin = null;
  2985. $imgBooks = [];
  2986. $textBooks = [];
  2987. } else {
  2988. $parent_alias = $category->alias ?? '';
  2989. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  2990. // 查找子分类ID数组
  2991. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  2992. array_push($childCategoryIds, $parentCatId);
  2993. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  2994. if ($parentImgNum != 0) {
  2995. // 查询图片新闻
  2996. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  2997. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2998. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2999. })
  3000. ->where('book.status', 2)
  3001. ->where('book.img_url', '!=', '')
  3002. ->where('book.website_id', $website['website_id'])
  3003. ->leftJoin('website_category', function ($join) use ($website) {
  3004. $join->on('book.cat_id', '=', 'website_category.category_id')
  3005. ->where('website_category.website_id', '=', $website['website_id']);
  3006. })
  3007. ->select(
  3008. 'book.id',
  3009. 'book.title',
  3010. 'book.img_url',
  3011. 'book.price',
  3012. 'book.market_price',
  3013. 'book.description',
  3014. 'book.cat_id',
  3015. 'book.description',
  3016. 'book.updated_at',
  3017. 'website_category.alias as category_name',
  3018. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3019. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3020. )
  3021. ->orderBy('updated_at', 'desc')
  3022. ->limit($parentImgNum)
  3023. ->get()->all();
  3024. // 查询文字新闻
  3025. }
  3026. if ($parentTextNum != 0) {
  3027. $textBooks = [];
  3028. $textBooks = Book::where(function ($query) use ($parentCatId) {
  3029. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  3030. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  3031. })
  3032. ->where('book.status', 2)
  3033. ->where('book.website_id', $website['website_id'])
  3034. ->leftJoin('website_category', function ($join) use ($website) {
  3035. $join->on('book.cat_id', '=', 'website_category.category_id')
  3036. ->where('website_category.website_id', '=', $website['website_id']);
  3037. })
  3038. ->select(
  3039. 'book.id',
  3040. 'book.title',
  3041. 'book.img_url',
  3042. 'book.price',
  3043. 'book.market_price',
  3044. 'book.description',
  3045. 'book.cat_id',
  3046. 'book.description',
  3047. 'book.updated_at',
  3048. 'website_category.alias as category_name',
  3049. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3050. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3051. )
  3052. ->orderBy('updated_at', 'desc')
  3053. ->limit($parentTextNum)
  3054. ->get()->all();
  3055. }
  3056. }
  3057. }
  3058. $resultItem = [
  3059. 'alias' => $parent_alias ?? '',
  3060. 'category_id' => $parentCatId ?? 0,
  3061. 'pinyin' => $parent_pinyin ?? null,
  3062. 'imgnum' => $imgBooks ?? [],
  3063. 'textnum' => $textBooks ?? [],
  3064. ];
  3065. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  3066. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  3067. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  3068. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3069. ->get()->all();
  3070. if (!empty($childCategory)) {
  3071. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  3072. // 查询子栏目名称
  3073. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  3074. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3075. ->first();
  3076. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  3077. $childImgArticles = [];
  3078. $childTextArticles = [];
  3079. $resultItem['child'] = [];
  3080. } else {
  3081. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  3082. // 查询子栏目图片新闻
  3083. $childImgArticles = Book::where('cat_id', $childCatId)
  3084. ->where('status', 2)
  3085. ->where('img_url', '!=', '')
  3086. ->where('book.website_id', $website['website_id'])
  3087. ->leftJoin('website_category', function ($join) use ($website) {
  3088. $join->on('book.cat_id', '=', 'website_category.category_id')
  3089. ->where('website_category.website_id', '=', $website['website_id']);
  3090. })
  3091. ->select(
  3092. 'book.id',
  3093. 'book.title',
  3094. 'book.img_url',
  3095. 'book.price',
  3096. 'book.market_price',
  3097. 'book.description',
  3098. 'book.cat_id',
  3099. 'book.description',
  3100. 'book.updated_at',
  3101. DB::raw("'$child_pinyin' as pinyin")
  3102. )
  3103. ->orderBy('updated_at', 'desc')
  3104. ->limit($childImgNum)
  3105. ->get()->all();
  3106. // 查询子栏目文字新闻
  3107. $childTextArticles = Book::where('cat_id', $childCatId)
  3108. ->where('status', 2)
  3109. ->where('book.website_id', $website['website_id'])
  3110. ->leftJoin('website_category', function ($join) use ($website) {
  3111. $join->on('book.cat_id', '=', 'website_category.category_id')
  3112. ->where('website_category.website_id', '=', $website['website_id']);
  3113. })
  3114. ->select(
  3115. 'book.id',
  3116. 'book.title',
  3117. 'book.img_url',
  3118. 'book.price',
  3119. 'book.market_price',
  3120. 'book.description',
  3121. 'book.cat_id',
  3122. 'book.description',
  3123. 'book.updated_at',
  3124. DB::raw("'$child_pinyin' as pinyin")
  3125. )
  3126. ->orderBy('updated_at', 'desc')
  3127. ->limit($childTextNum)
  3128. ->get()->all();
  3129. $resultItem['child'] = [
  3130. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  3131. 'category_id' => $childCatId,
  3132. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  3133. 'all_childcat' => $childCategory,
  3134. 'imgnum' => $childImgArticles,
  3135. 'textnum' => $childTextArticles,
  3136. ];
  3137. }
  3138. }
  3139. } else {
  3140. $resultItem['child'] = [];
  3141. }
  3142. return $resultItem;
  3143. }, $data);
  3144. return Result::success($result);
  3145. }
  3146. /**
  3147. * 获取书刊列表
  3148. * @param array $data
  3149. * @return array
  3150. * */
  3151. public function getWebsiteBookList(array $data): array
  3152. {
  3153. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3154. if (empty($web)) {
  3155. return Result::error("查询失败", 0);
  3156. }
  3157. $catid = $data['id'];
  3158. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  3159. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  3160. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  3161. $category_pinyin = $category ? $category->aLias_pinyin : '';
  3162. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  3163. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  3164. ->where('pid', $category['pid'])
  3165. ->select(
  3166. 'category_id',
  3167. 'alias',
  3168. 'aLIas_pinyin',
  3169. 'pid',
  3170. 'sort',
  3171. 'is_url',
  3172. 'web_url',
  3173. 'seo_title',
  3174. 'seo_keywords',
  3175. 'seo_description',
  3176. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  3177. )
  3178. ->orderBy('sort')
  3179. ->get()->all();
  3180. if (empty($category)) {
  3181. return Result::error("查询失败", 0);
  3182. }
  3183. $query = Book::where('book.status', 2)
  3184. ->where('book.website_id', $data['website_id'])
  3185. ->where('book.cat_id', $catid)
  3186. ->select(
  3187. 'book.id',
  3188. 'book.title',
  3189. 'book.img_url',
  3190. 'book.description',
  3191. 'book.updated_at',
  3192. 'book.cat_id',
  3193. DB::raw("'$pinyin' as pinyin")
  3194. )
  3195. ->orderBy('book.updated_at', 'desc');
  3196. $count = $query->count();
  3197. $query = clone $query;
  3198. $Book = $query
  3199. ->limit($data['pageSize'])
  3200. ->offset(($data['page'] - 1) * $data['pageSize'])
  3201. ->get()->all();
  3202. $result = [
  3203. 'category' => $categorys,
  3204. 'books' => $Book,
  3205. 'count' => $count,
  3206. ];
  3207. // if(empty($result)){
  3208. // return Result::error("查询失败", 0);
  3209. // }
  3210. return Result::success($result);
  3211. }
  3212. /**
  3213. * 获取书刊详情
  3214. * @param array $data
  3215. * @return array
  3216. * */
  3217. public function getWebsiteBookInfo(array $data): array
  3218. {
  3219. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3220. if (empty($web)) {
  3221. return Result::error("查询失败", 0);
  3222. }
  3223. $book = Book::where('status', 2)
  3224. ->where('website_id', $data['website_id'])
  3225. ->where('id', $data['id'])
  3226. ->select(
  3227. 'book.*',
  3228. )
  3229. ->orderBy('updated_at', 'desc')
  3230. ->first();
  3231. if (empty($book)) {
  3232. return Result::error("查询失败", 0);
  3233. }
  3234. // 先查询当前分类的 pid
  3235. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  3236. ->where('category_id', $book['cat_id'])
  3237. ->first(['pid', 'category_id']);
  3238. $query = WebsiteCategory::where('website_id', $data['website_id']);
  3239. if (!empty($carpid)) {
  3240. if ($carpid->pid != 0) {
  3241. $pid = $carpid['pid'];
  3242. // $parent_pinyin = '';
  3243. } else {
  3244. $pid = $carpid['category_id'];
  3245. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  3246. }
  3247. }
  3248. $categorys = $query->where('pid', $pid)
  3249. ->select(
  3250. 'category_id',
  3251. 'alias',
  3252. 'aLIas_pinyin',
  3253. 'pid',
  3254. 'sort',
  3255. 'is_url',
  3256. 'web_url',
  3257. 'category_arr_id as cat_arr_id',
  3258. )
  3259. ->orderBy('sort')
  3260. ->get();
  3261. $category = $this->processArticle($categorys, $data);
  3262. $result = [
  3263. 'category' => $category,
  3264. 'books' => $book,
  3265. ];
  3266. return Result::success($result);
  3267. }
  3268. /**
  3269. * 尝试
  3270. * @param array $data
  3271. * @return array
  3272. * */
  3273. public function test(array $data): array
  3274. {
  3275. $input['id'] = $data['id'];
  3276. $input['website_id'] = $data['website_id'];
  3277. // 将 JSON 字符串转换为 PHP 数组
  3278. $data = json_decode($input['id'], true);
  3279. $result = [];
  3280. $article = $data;
  3281. $result = array_map(function ($item) use ($input) {
  3282. $website = [
  3283. 'website_id' => $input['website_id'],
  3284. ];
  3285. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  3286. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  3287. $parent = [
  3288. 0 => $category['category_id'] ?? [],
  3289. 1 => $parentImgNum ?? [],
  3290. 2 => $parentTextNum ?? [],
  3291. ];
  3292. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  3293. $child = [];
  3294. $resultItem = [
  3295. // 'alias' => $parent_alias ?? '',
  3296. 'category_id' => $parentCatId ?? 0,
  3297. 'pinyin' => $parentImgNum ?? null,
  3298. 'imgnum' => $parentTextNum ?? [],
  3299. // 'textnum' => $textArticles ?? [],
  3300. ];
  3301. return $parent;
  3302. }, $data);
  3303. return Result::success($result);
  3304. // });
  3305. }
  3306. /**
  3307. * 封装处理文章的路由问题
  3308. * */
  3309. function processArticle($article, $data)
  3310. {
  3311. return $article->map(function ($article) use ($data) {
  3312. $catid = $article->cat_arr_id ?? '';
  3313. $level = json_decode($catid, true);
  3314. $pinyin = '';
  3315. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  3316. if (!empty($level) && is_array($level)) {
  3317. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  3318. ->where('website_id', $data['website_id'])
  3319. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  3320. ->get(['aLIas_pinyin'])
  3321. ->pluck('aLIas_pinyin')
  3322. ->implode('/');
  3323. } else {
  3324. $pinyin = '';
  3325. }
  3326. $article->pinyin = $pinyin;
  3327. return $article;
  3328. });
  3329. }
  3330. /**
  3331. * c端-获取招工招聘下拉选框
  3332. * @param array $data
  3333. * @return array
  3334. * */
  3335. public function getWebsiteJobSelect(array $data): array
  3336. {
  3337. $web = Website::where('id', $data['website_id'])->first();
  3338. if (empty($web)) {
  3339. return Result::error("该网站不存在", 0);
  3340. }
  3341. $hy = JobIndustry::get()->all();
  3342. $zw = JobPosition::where('zwpid', 0)->get()->all();
  3343. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  3344. $result = [
  3345. 'hy' => $hy,
  3346. 'zw' => $zw,
  3347. 'jtzw' => $jtzw,
  3348. ];
  3349. if (empty($result)) {
  3350. return Result::error("查询失败", 0);
  3351. }
  3352. return Result::success($result);
  3353. }
  3354. /**
  3355. * c端-获取招工招聘
  3356. * @param array $data
  3357. * @return array
  3358. * */
  3359. public function getWebsiteJob(array $data): array
  3360. {
  3361. $web = Website::where('id', $data['website_id'])->first();
  3362. if (empty($web)) {
  3363. return Result::error("该网站不存在", 0);
  3364. }
  3365. $job_hunting = JobHunting::where('job_hunting.status', 2)
  3366. ->where('job_hunting.website_id', $data['website_id'])
  3367. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3368. $query->where(function ($q) use ($data) {
  3369. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3370. });
  3371. })
  3372. ->select(
  3373. 'job_hunting.id',
  3374. 'job_hunting.catid',
  3375. 'job_hunting.cat_arr_id',
  3376. 'job_hunting.job_name_get',
  3377. 'job_hunting.industry',
  3378. 'job_hunting.name',
  3379. 'job_hunting.sexy',
  3380. 'job_hunting.origin',
  3381. 'job_hunting.city_arr_id',
  3382. 'job_hunting.experience',
  3383. 'job_hunting.updated_at',
  3384. 'job_hunting.salary',
  3385. 'job_hunting.skillList',
  3386. 'job_hunting.slelf_evaluation',
  3387. )
  3388. ->orderBy('updated_at', 'desc')
  3389. ->limit($data['job1_num'])
  3390. ->get();
  3391. $web['website_id'] = $data['website_id'];
  3392. if (empty($job_hunting)) {
  3393. $job_huntings = "未查询到相关简历信息";
  3394. } else {
  3395. $job_huntings = $this->processJob($job_hunting, $web);
  3396. }
  3397. // 0:待审核 1:已通过 2:已拒绝
  3398. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3399. ->where('job_recruiting.website_id', $data['website_id'])
  3400. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3401. $query->where(function ($q) use ($data) {
  3402. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3403. });
  3404. })
  3405. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3406. ->select(
  3407. 'job_recruiting.id',
  3408. 'job_recruiting.catid',
  3409. 'job_recruiting.cat_arr_id',
  3410. 'job_recruiting.title',
  3411. 'job_recruiting.jtzw_id',
  3412. 'job_recruiting.hy_id',
  3413. 'job_recruiting.city_arr_id',
  3414. 'job_recruiting.due_data',
  3415. 'job_recruiting.updated_at',
  3416. 'job_recruiting.experience',
  3417. 'job_recruiting.educational',
  3418. 'job_recruiting.salary',
  3419. 'job_recruiting.zw_id',
  3420. 'job_company.business_name',
  3421. 'job_recruiting.keyword',
  3422. 'job_recruiting.description',
  3423. )
  3424. ->orderBy('updated_at', 'desc')
  3425. ->limit($data['job2_num'])
  3426. ->get();
  3427. if (empty($job_recruiting->toArray())) {
  3428. $job_recruitings = "未查询到相关职位信息";
  3429. } else {
  3430. $job_recruitings = $this->processJob($job_recruiting, $web);
  3431. }
  3432. $result = [
  3433. 'job_hunting' => $job_huntings,
  3434. 'job_recuiting' => $job_recruitings,
  3435. ];
  3436. return Result::success($result);
  3437. }
  3438. /**
  3439. * c端-获取招工招聘列表
  3440. * @param array $data
  3441. * @return array
  3442. * */
  3443. public function getWebsiteJobList(array $data): array
  3444. {
  3445. $recruit_where = [];
  3446. $hunt_where = [];
  3447. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3448. if (empty($web)) {
  3449. return Result::error("此网站不存在", 0);
  3450. }
  3451. $website_id['website_id'] = $data['website_id'];
  3452. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  3453. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3454. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  3455. }
  3456. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3457. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  3458. }
  3459. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3460. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  3461. }
  3462. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3463. array_push($recruit_where, ['title', 'like', '%' . $data['keyword'] . '%']);
  3464. }
  3465. $query = JobRecruiting::where('job_recruiting.status', 1)
  3466. ->where('job_recruiting.website_id', $data['website_id'])
  3467. ->where($recruit_where)
  3468. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3469. $query->where(function ($q) use ($data) {
  3470. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3471. });
  3472. })
  3473. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  3474. $query->where(function ($q) use ($data) {
  3475. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  3476. });
  3477. })
  3478. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3479. ->select(
  3480. 'job_recruiting.id',
  3481. 'job_recruiting.catid',
  3482. 'job_recruiting.hy_id',
  3483. 'job_recruiting.title',
  3484. 'job_recruiting.zw_id',
  3485. 'job_recruiting.educational',
  3486. 'job_recruiting.jtzw_id',
  3487. 'job_recruiting.city_arr_id',
  3488. 'job_recruiting.due_data',
  3489. 'job_recruiting.experience',
  3490. 'job_recruiting.cat_arr_id',
  3491. 'job_recruiting.updated_at',
  3492. 'job_company.business_name',
  3493. 'job_recruiting.keyword',
  3494. 'job_recruiting.description',
  3495. )
  3496. ->orderBy('job_recruiting.updated_at', 'desc');
  3497. $recruit_count = $query->count();
  3498. $query = clone $query;
  3499. $JobRecruiting = $query
  3500. ->offset(($data['page'] - 1) * $data['pageSize'])
  3501. ->limit($data['pageSize'])
  3502. ->get();
  3503. if (empty($JobRecruiting)) {
  3504. $JobRecruiting = "暂无相关职位信息";
  3505. } else {
  3506. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  3507. }
  3508. }
  3509. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  3510. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3511. array_push($hunt_where, ['job_hunting.job', $data['zw_id']]);
  3512. }
  3513. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3514. array_push($hunt_where, ['job_hunting.job_name_get', $data['jtzw_id']]);
  3515. }
  3516. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3517. array_push($hunt_where, ['job_hunting.industry', $data['hy_id']]);
  3518. }
  3519. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3520. array_push($hunt_where, ['job_position.zwname', 'like', '%' . $data['keyword'] . '%']);
  3521. }
  3522. $query = JobHunting::where('job_hunting.status', 2)
  3523. ->where('job_hunting.website_id', $data['website_id'])
  3524. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3525. ->where($hunt_where)
  3526. // ->when(isset($data['keyword']) &&!empty($data['keyword']), function ($query) use ($data) {
  3527. // $query->where('job_position.zwname','like','%'.$data['keyword'].'%');
  3528. // })
  3529. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3530. $query->where(function ($q) use ($data) {
  3531. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3532. });
  3533. })
  3534. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  3535. $query->where(function ($q) use ($data) {
  3536. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  3537. });
  3538. })
  3539. ->select(
  3540. 'job_hunting.id',
  3541. 'job_hunting.catid',
  3542. 'job_hunting.sexy',
  3543. 'job_hunting.experience',
  3544. 'job_hunting.origin',
  3545. 'job_hunting.industry',
  3546. 'job_hunting.name',
  3547. 'job_hunting.job',
  3548. 'job_hunting.job_name_get',
  3549. 'job_hunting.city_arr_id',
  3550. 'job_hunting.cat_arr_id',
  3551. 'job_hunting.created_at',
  3552. 'job_hunting.updated_at',
  3553. 'job_position.zwname as job_name',
  3554. 'job_hunting.skillList',
  3555. 'job_hunting.slelf_evaluation',
  3556. )
  3557. ->orderBy('job_hunting.updated_at', 'desc');
  3558. $hunt_count = $query->count();
  3559. $query = clone $query;
  3560. $JobHunting = $query
  3561. ->offset(($data['page'] - 1) * $data['pageSize'])
  3562. ->limit($data['pageSize'])
  3563. ->get();
  3564. if (empty($JobHunting)) {
  3565. $JobRecruiting = "暂无相关简历信息";
  3566. } else {
  3567. $JobHunting = $this->processJob($JobHunting, $website_id);
  3568. }
  3569. }
  3570. $result = [
  3571. 'JobRecruiting' => $JobRecruiting ?? [],
  3572. 'recruit_count' => $recruit_count ?? 0,
  3573. 'JobHunting' => $JobHunting ?? [],
  3574. 'hunt_count' => $hunt_count ?? 0,
  3575. ];
  3576. return Result::success($result);
  3577. }
  3578. /**
  3579. * c端-获取招工招聘详情
  3580. * @param array $data
  3581. * @return array
  3582. * */
  3583. public function getWebsiteJobInfo(array $data): array
  3584. {
  3585. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3586. if (empty($web)) {
  3587. return Result::error("该网站不存在", 0);
  3588. }
  3589. $webid = [
  3590. 'website_id' => $data['website_id'],
  3591. ];
  3592. // 职位相关信息
  3593. if ($data['type'] == 1) {
  3594. $query = JobRecruiting::where('status', 1)
  3595. ->where('website_id', $data['website_id'])
  3596. ->select('*');
  3597. $job = $query->where('job_recruiting.id', $data['id'])->get();
  3598. $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();
  3599. if (!empty($company)) {
  3600. $result['company'] = $this->processJob($company, $webid);
  3601. }
  3602. $other_job = JobRecruiting::where('status', 1)
  3603. ->where('website_id', $data['website_id'])
  3604. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  3605. ->where('id', '!=', $data['id'])
  3606. ->where('user_id', '=', $job[0]['user_id'])
  3607. ->limit($data['pageSize'])
  3608. ->get();
  3609. if (!empty($other_job)) {
  3610. $result['other_job'] = $this->processJob($other_job, $webid);
  3611. }
  3612. } else {
  3613. // 简历相关信息
  3614. $job = JobHunting::where('job_hunting.status', 2)
  3615. ->where('job_hunting.website_id', $data['website_id'])
  3616. ->where('job_hunting.id', $data['id'])
  3617. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3618. ->select('job_hunting.*', 'user_name')
  3619. ->get();
  3620. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  3621. if (!empty($resume->toArray())) {
  3622. $result['resume'] = 1;
  3623. } else {
  3624. $result['resume'] = 0;
  3625. }
  3626. }
  3627. if (empty($job->toArray())) {
  3628. return Result::error("id参数错误", 0);
  3629. }
  3630. if (!empty($job[0]['job_experience'])) {
  3631. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  3632. if (!empty($job_experience)) {
  3633. // $hy = [];
  3634. foreach ($job_experience as $key => $value) {
  3635. // $id = $value['id'];
  3636. $hy[$key] = $value['job_industry'];
  3637. $zw_id[$key] = $value['job_typename'];
  3638. $jtzw_id[$key] = $value['job_name'];
  3639. }
  3640. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  3641. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  3642. // 先将关联表转换为索引数组,提高查找效率
  3643. $hyLookup = [];
  3644. foreach ($hy_table as $item) {
  3645. $hyLookup[$item['hyid']] = $item['hyname'];
  3646. }
  3647. $zwLookup = [];
  3648. foreach ($zw_table as $item) {
  3649. $zwLookup[$item['zwid']] = $item['zwname'];
  3650. }
  3651. foreach ($job_experience as $key => &$value) {
  3652. // 处理行业名称
  3653. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  3654. $value['hy_name'] = $hyLookup[$hy[$key]];
  3655. }
  3656. // 处理职位名称
  3657. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  3658. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  3659. }
  3660. // 处理具体职位名称
  3661. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  3662. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  3663. }
  3664. }
  3665. // 释放引用,防止意外修改后续代码
  3666. unset($value);
  3667. }
  3668. $result['job_experience'] = $job_experience ?? [];
  3669. }
  3670. if (!empty($job[0]['education_experience'])) {
  3671. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  3672. if (!empty($education_experience)) {
  3673. foreach ($education_experience as $key => $value) {
  3674. // $id = $value['id'];
  3675. $education[$key] = $value['school_education'];
  3676. }
  3677. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  3678. // // 先将关联表转换为索引数组,提高查找效率
  3679. $educationLookup = [];
  3680. foreach ($education_table as $item) {
  3681. $educationLookup[$item['evalue']] = $item['ename'];
  3682. }
  3683. foreach ($education_experience as $key => &$value) {
  3684. // 处理学历名称
  3685. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  3686. $value['education_name'] = $educationLookup[$education[$key]];
  3687. }
  3688. }
  3689. }
  3690. $result['education_experience'] = $job_experience ?? [];
  3691. }
  3692. $result['job'] = $this->processJob($job, $webid);
  3693. // // 返现对应的栏目
  3694. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  3695. $category = WebsiteCategory::where('website_id', $data['website_id'])
  3696. ->whereIn('category_id', $catid)
  3697. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  3698. ->orderBy('pid')->get()->all();
  3699. if (!empty($category)) {
  3700. $result['category'] = $category;
  3701. }
  3702. $result['job'] = $job;
  3703. $result['job_experience'] = $job_experience ?? [];
  3704. $result['education_experience'] = $education_experience ?? [];
  3705. if (empty($result)) {
  3706. return Result::error("参数错误", 0);
  3707. }
  3708. return Result::success($result);
  3709. }
  3710. /**
  3711. * c端-申请职位
  3712. * @param array $data
  3713. * @return array
  3714. * */
  3715. public function getWebsiteJobApply(array $data): array
  3716. {
  3717. // 首先验证网站是否存在
  3718. // return Result::success($data);
  3719. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3720. if (empty($web)) {
  3721. return Result::error("该网站不存在", 0);
  3722. }
  3723. // 验证用户是否存在且为个人会员/管理员
  3724. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3725. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3726. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  3727. return Result::error("用户不存在", 0);
  3728. }
  3729. // 去除重复元素和空元素,并保持原始顺序
  3730. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  3731. return !empty($value);
  3732. }));
  3733. // 验证职位是否存在 1:审核通过
  3734. $recruiting = JobRecruiting::where('status', 1)
  3735. ->where('website_id', $data['website_id'])
  3736. ->whereIn('id', $data['recruit_id'])
  3737. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  3738. if (empty($recruiting)) {
  3739. return Result::error("该职位不存在", 0);
  3740. }
  3741. // 简历是否存在
  3742. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  3743. if (empty($hunt_id)) {
  3744. return Result::error("该简历不存在", 0);
  3745. }
  3746. $data['hunt_id'] = $hunt_id['hunt_id'];
  3747. // // 验证是否已投递过该职位
  3748. $apply = JobApply::where('user_id', $data['user_id'])
  3749. ->where('hunt_id', $data['hunt_id'])
  3750. ->where('website_id', $data['website_id'])
  3751. ->whereIn('recruit_id', $data['recruit_id'])
  3752. ->get(['recruit_id']);
  3753. if (!empty($apply->toArray())) {
  3754. return Result::error("您已投递过该职位!");
  3755. }
  3756. $insertData = array_map(function ($recruiting) use ($data) {
  3757. return [
  3758. 'user_id' => $data['user_id'],
  3759. 'hunt_id' => $data['hunt_id'],
  3760. 'website_id' => $data['website_id'],
  3761. 'recruit_id' => $recruiting['recruit_id'],
  3762. 'receiver_id' => $recruiting['receiver_id'],
  3763. 'status' => 1,
  3764. ];
  3765. }, $recruiting);
  3766. // 批量插入数据
  3767. $result = JobApply::insert($insertData);
  3768. if (empty($result)) {
  3769. return Result::error("投递失败", 0);
  3770. }
  3771. return Result::success($result);
  3772. }
  3773. /**
  3774. * 招工招聘-沟通简历
  3775. * @param array $data
  3776. * @return array
  3777. * */
  3778. public function getWebsiteJobResume(array $data): array
  3779. {
  3780. // 首先验证网站是否存在
  3781. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3782. if (empty($web)) {
  3783. return Result::error("该网站不存在", 0);
  3784. }
  3785. // return Result::success($data);
  3786. // 验证用户是否存在且为企业会员/管理员
  3787. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3788. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3789. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3790. return Result::error("用户不存在", 0);
  3791. }
  3792. // 去除重复元素和空元素,并保持原始顺序
  3793. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  3794. return !empty($value);
  3795. }));
  3796. // 验证简历是否存在
  3797. $hunting = JobHunting::where('status', 2)
  3798. ->where('website_id', $data['website_id'])
  3799. ->whereIn('id', $data['hunt_id'])
  3800. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  3801. if (empty($hunting)) {
  3802. return Result::error("该简历不存在", 0);
  3803. }
  3804. // 验证是否已沟通过该简历
  3805. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3806. ->where('recruit_id', $data['recruit_id'])
  3807. ->where('website_id', $data['website_id'])
  3808. ->whereIn('hunt_id', $data['hunt_id'])
  3809. ->get(['hunt_id']);
  3810. if (!empty($remuse->toArray())) {
  3811. return Result::error("您已沟通过该简历!");
  3812. }
  3813. // 准备要插入的数据数组
  3814. $insertData = array_map(function ($hunting) use ($data) {
  3815. return [
  3816. 'user_id' => $data['user_id'],
  3817. 'recruit_id' => $data['recruit_id'],
  3818. 'website_id' => $data['website_id'],
  3819. 'hunt_id' => $hunting['hunt_id'],
  3820. 'receiver_id' => $hunting['receiver_id'],
  3821. 'status' => 1,
  3822. ];
  3823. }, $hunting);
  3824. // 批量插入数据
  3825. $result = JobRemuse::insert($insertData);
  3826. if (empty($result)) {
  3827. return Result::error("沟通失败", 0);
  3828. }
  3829. return Result::success($result);
  3830. }
  3831. /**
  3832. * 招工招聘 -我的职位(企业会员)
  3833. * @param array $data
  3834. * @return array
  3835. */
  3836. public function getWebsiteJobRecruiting(array $data): array
  3837. {
  3838. $web = Website::where('id', $data['website_id'])->first('id');
  3839. if (empty($web)) {
  3840. return Result::error("该网站不存在", 0);
  3841. }
  3842. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3843. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3844. return Result::error("用户暂无权限!", 0);
  3845. }
  3846. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3847. $result = JobRecruiting::where('website_id', $data['website_id'])
  3848. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  3849. $query->where('user_id', $user['id']);
  3850. })
  3851. ->where('status', 1)
  3852. ->select('id', 'title', 'website_id', 'user_id', 'updated_at', 'keyword', 'catid', 'description')
  3853. ->orderBy('updated_at', 'desc')
  3854. ->limit($data['pageSize'])
  3855. ->get();
  3856. if (empty($result)) {
  3857. return Result::error("暂无相关职位信息", 0);
  3858. }
  3859. return Result::success($result);
  3860. }
  3861. /**
  3862. * c端 - 验证路由
  3863. * @param array $data
  3864. * @return array
  3865. */
  3866. /**
  3867. * c端 - 验证路由
  3868. * @param array $data
  3869. * @return array
  3870. */
  3871. public function checkWebsiteRoute(array $data): array
  3872. {
  3873. // 测试001111111222
  3874. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name', 'status']);
  3875. if (empty($web)) {
  3876. return Result::error("该网站不存在", 0);
  3877. } elseif ($web['status'] != 1) {
  3878. return Result::error("网站已经关闭", 0);
  3879. }
  3880. if (isset($data['other_route']) && !empty($data['other_route'])) {
  3881. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  3882. // 验证路由是否存在
  3883. if (empty($whiteRouterInfo)) {
  3884. $whiteRouterInfo = WhiteRouter::where("router_type", 1)->where('router_url', $data['other_route'])->first();
  3885. }
  3886. if (!empty($whiteRouterInfo)) {
  3887. return Result::success($whiteRouterInfo->toArray());
  3888. }
  3889. }
  3890. // 验证栏目路由
  3891. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  3892. ->where('path', $data['all_route'])
  3893. ->get()->all();
  3894. if (count($last_category) == 0) {
  3895. return Result::error("该栏目不存在", 0);
  3896. }
  3897. if (count($last_category) > 1) {
  3898. return Result::error("该栏目路由存在多个,路由验证失败!", 0);
  3899. }
  3900. if (count($last_category) == 1) {
  3901. $last_category = $last_category[0];
  3902. }
  3903. // return Result::success($last_category);
  3904. if (isset($data['id']) && !empty($data['id'])) {
  3905. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  3906. switch ($last_category['type']) {
  3907. case 1:
  3908. // 文章
  3909. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  3910. $article = Article::where('status', 1)
  3911. ->where('id', $data['id'])
  3912. ->where(function ($query) use ($data) {
  3913. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  3914. ->orWhereNull("ignore_ids");
  3915. })
  3916. ->first(['catid']);
  3917. if (empty($article)) {
  3918. return Result::error("该文章不存在", 0);
  3919. }
  3920. // return Result::success($article);
  3921. break;
  3922. case 2:
  3923. // 商品
  3924. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3925. $article = Good::where('website_id', $data['website_id'])
  3926. ->where('status', 2)
  3927. ->where('id', $data['id'])
  3928. ->first(['cat_arr_id']);
  3929. if (empty($article)) {
  3930. return Result::error("该商品不存在", 0);
  3931. }
  3932. break;
  3933. case 3:
  3934. // 书刊信息
  3935. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3936. $article = Book::where('website_id', $data['website_id'])
  3937. ->where('status', 2)
  3938. ->where('id', $data['id'])
  3939. ->first(['id', 'cat_arr_id']);
  3940. if (empty($article)) {
  3941. return Result::error("该书刊不存在", 0);
  3942. }
  3943. break;
  3944. case 4:
  3945. // 招聘
  3946. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核通过;(只有企业会员需要审核)',
  3947. $article = JobRecruiting::where('website_id', $data['website_id'])
  3948. ->where('status', 1)
  3949. ->where('id', $data['id'])
  3950. ->first(['cat_arr_id']);
  3951. if (empty($article)) {
  3952. return Result::error("该招聘不存在", 0);
  3953. }
  3954. break;
  3955. case 5:
  3956. // 求职
  3957. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3958. $article = JobHunting::where('website_id', $data['website_id'])
  3959. ->where('status', 2)
  3960. ->where('id', $data['id'])
  3961. ->first(['cat_arr_id']);
  3962. if (empty($article)) {
  3963. return Result::error("该求职不存在", 0);
  3964. }
  3965. break;
  3966. case 6:
  3967. // 企业
  3968. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3969. $article = Company::
  3970. // where('website_id', $data['website_id'])
  3971. // ->
  3972. where('status', 1)
  3973. ->where('id', $data['id'])
  3974. ->first(['cat_arr_id']);
  3975. if (empty($article)) {
  3976. return Result::error("该企业不存在", 0);
  3977. }
  3978. break;
  3979. case 7:
  3980. // 项目
  3981. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3982. $article = Project::where('website_id', $data['website_id'])
  3983. ->where('status', 1)
  3984. ->where('id', $data['id'])
  3985. ->first(['cat_arr_id']);
  3986. if (empty($article)) {
  3987. return Result::error("该项目不存在", 0);
  3988. }
  3989. break;
  3990. default:
  3991. return Result::error("该数据不存在", 0);
  3992. break;
  3993. }
  3994. // return Result::success($article);
  3995. // $catid =0 ;
  3996. if (!isset($article['cat_arr_id'])) {
  3997. $catid = isset($article['catid']) ? $article['catid'] : (isset($article['category_id']) ? $article['category_id'] : null);
  3998. } else {
  3999. $catidArray = json_decode($article['cat_arr_id'], true);
  4000. $catid = !empty($catidArray) ? end($catidArray) : null;
  4001. }
  4002. // return Result::success($catid);
  4003. // // return Result::success($article['cat_arr_id']);
  4004. if (empty($catid)) {
  4005. return Result::error("该栏目路径不存在", 0);
  4006. }
  4007. $path = WebsiteCategory::where('website_id', $data['website_id'])
  4008. ->where('category_id', $catid)
  4009. ->first('path');
  4010. }
  4011. // else{
  4012. // // if ($last_category['pid'] != 0) {
  4013. // $cat_arr = json_decode($last_category['category_arr_id'], true);
  4014. // $catid = !empty($cat_arr) && is_array($cat_arr) ? end($cat_arr) : null;
  4015. // $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  4016. // ->where('category_id',$catid)
  4017. // ->where('path',$data['all_route'])
  4018. // ->first('path');
  4019. // // } else {
  4020. // // $pinyin[0] = $last_category['aLIas_pinyin'];
  4021. // // }
  4022. // }
  4023. // return Result::success($path);
  4024. if (!empty($path) && $path['path'] != $data['all_route']) {
  4025. return Result::error('非法路径!');
  4026. } else {
  4027. return Result::success($last_category['path']);
  4028. }
  4029. }
  4030. /**
  4031. * 招工招聘 - 获取推荐职位
  4032. * @param array $data
  4033. * @return array
  4034. */
  4035. public function getWebsiteLevelJob(array $data): array
  4036. {
  4037. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  4038. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  4039. ->where('job_recruiting.status', 1)
  4040. ->where('job_level', $data['job_level'])
  4041. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4042. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  4043. ->orderBy('job_recruiting.updated_at', 'desc')
  4044. ->limit($data['pageSize'])
  4045. ->get();
  4046. $web = ['website_id' => $data['website_id']];
  4047. if (!empty($job)) {
  4048. $result = $this->processJob($job, $web);
  4049. }
  4050. if (empty($result)) {
  4051. return Result::error("暂无相关职位信息", 0);
  4052. }
  4053. return Result::success($result);
  4054. }
  4055. /**
  4056. * 验证导航名称是否重复
  4057. * @return void
  4058. */
  4059. //20250226 产品列表
  4060. public function getGoodList(array $data): array
  4061. {
  4062. var_dump($data, '---------1-2--');
  4063. $type_id = isset($data['user_type_id']) ? $data['user_type_id'] : '';
  4064. unset($data['user_type_id']);
  4065. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4066. $where = [];
  4067. if ($type_id != '10000') {
  4068. $where = [
  4069. 'good.user_id' => $user_id,
  4070. ];
  4071. }
  4072. //类型
  4073. if (isset($data['type_id']) && $data['type_id']) {
  4074. $where['good.type_id'] = $data['type_id'];
  4075. }
  4076. //名称
  4077. if (isset($data['name']) && $data['name']) {
  4078. $where[] = ['good.name', 'like', '%' . $data['name'] . '%'];
  4079. }
  4080. //status
  4081. if (isset($data['status']) && $data['status'] != '') {
  4082. $where['good.status'] = $data['status'];
  4083. }
  4084. //status1
  4085. // if (isset($data['status1']) && $data['status1'] == 1) {
  4086. // $status1 = 1;
  4087. // }
  4088. $where1 = [];
  4089. //website_id
  4090. // if (isset($data['website_id']) && $data['website_id']) {
  4091. // $where1 = [
  4092. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  4093. // ];
  4094. // }
  4095. // website_name
  4096. if (isset($data['website_name']) && $data['website_name']) {
  4097. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  4098. }
  4099. // catid
  4100. if (isset($data['category_name']) && $data['category_name']) {
  4101. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  4102. }
  4103. // $result = Good::where($where)
  4104. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  4105. var_dump($where, '---------1---');
  4106. $result = Good::where($where)
  4107. ->when(!empty($where1), function ($query) use ($where1) {
  4108. return $query->where($where1);
  4109. })
  4110. //status 1待审核2已审核3已拒绝
  4111. ->when(isset($data['status1']), function ($query) {
  4112. return $query->whereIn('good.status', [1, 3]);
  4113. })
  4114. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4115. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4116. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4117. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4118. ->orderBy("updated_at", "desc")
  4119. ->limit($data['page_size'])
  4120. ->offset(($data['page'] - 1) * $data['page_size'])
  4121. ->get();
  4122. $count = Good::where($where)
  4123. ->when(!empty($where1), function ($query) use ($where1) {
  4124. return $query->where($where1);
  4125. })
  4126. //status 1待审核2已审核3已拒绝
  4127. ->when(isset($data['status1']), function ($query) {
  4128. return $query->whereIn('good.status', [1, 3]);
  4129. })
  4130. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4131. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4132. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4133. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4134. ->orderBy("updated_at", "desc")->count();
  4135. $data = [
  4136. 'rows' => $result->toArray(),
  4137. 'count' => $count,
  4138. ];
  4139. if (empty($result)) {
  4140. return Result::error("此栏目暂无相关产品", 0);
  4141. }
  4142. return Result::success($data);
  4143. }
  4144. public function getGoodInfo(array $data): array
  4145. {
  4146. $result = Good::where('id', $data['id'])->first();
  4147. if (empty($result)) {
  4148. return Result::error("此产品不存在", 0);
  4149. }
  4150. return Result::success($result);
  4151. }
  4152. public function addGood(array $data): array
  4153. {
  4154. // unset($data['city_arr_id']);
  4155. // unset($data['cat_arr_id']);
  4156. $data['city_id'] = end($data['city_arr_id']);
  4157. $data['catid'] = end($data['cat_arr_id']);
  4158. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4159. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4160. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4161. unset($data['imgUrl']); //大小写
  4162. if (isset($data['price']) && $data['price'] == '') {
  4163. $data['price'] = 0;
  4164. }
  4165. if ($data['imgurl'] == '') {
  4166. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4167. preg_match_all($reg, $data['detail'], $matches);
  4168. if (isset($matches[1][0])) {
  4169. //截取varchar240
  4170. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4171. }
  4172. }
  4173. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4174. //提取标题+内容中的关键词
  4175. $data['keyword'] = $data['name'];
  4176. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4177. Jieba::init(); // 初始化 jieba-php
  4178. Finalseg::init();
  4179. $segList = Jieba::cut($data['keyword']);
  4180. $segList1 = array_slice($segList, 0, 8);
  4181. $data['keyword'] = implode(',', $segList1);
  4182. }
  4183. if ($data['description'] == '') {
  4184. //提取内容中的描述
  4185. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4186. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4187. // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  4188. }
  4189. if ($data['status'] == 1) {
  4190. $this->sendMessage([
  4191. 'talk_type' => 200,
  4192. 'title' => $data['name'],
  4193. 'content' => '提交了审核',
  4194. 'messageType' => 3,
  4195. ]);
  4196. }
  4197. $result = Good::insert($data);
  4198. if (empty($result)) {
  4199. return Result::error("添加失败", 0);
  4200. }
  4201. return Result::success($result);
  4202. }
  4203. public function updateGood(array $data): array
  4204. {
  4205. $data['city_id'] = end($data['city_arr_id']);
  4206. $data['catid'] = end($data['cat_arr_id']);
  4207. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4208. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4209. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4210. //设置东八区
  4211. date_default_timezone_set('Asia/Shanghai');
  4212. $data['updated_at'] = date('Y-m-d H:i:s');
  4213. if (isset($data['price']) && $data['price'] == '') {
  4214. $data['price'] = 0;
  4215. }
  4216. if ($data['imgurl'] == '') {
  4217. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4218. preg_match_all($reg, $data['detail'], $matches);
  4219. if (isset($matches[1][0])) {
  4220. //截取varchar240
  4221. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4222. }
  4223. }
  4224. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4225. //提取标题+内容中的关键词
  4226. $data['keyword'] = $data['name'];
  4227. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4228. Jieba::init(); // 初始化 jieba-php
  4229. Finalseg::init();
  4230. $segList = Jieba::cut($data['keyword']);
  4231. $segList1 = array_slice($segList, 0, 8);
  4232. $data['keyword'] = implode(',', $segList1);
  4233. }
  4234. if ($data['description'] == '') {
  4235. //提取内容中的描述
  4236. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4237. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4238. }
  4239. if ($data['status'] == 1) {
  4240. $this->sendMessage([
  4241. 'talk_type' => 200,
  4242. 'title' => $data['name'],
  4243. 'content' => '提交了审核',
  4244. 'messageType' => 3,
  4245. ]);
  4246. }
  4247. $result = Good::where('id', $data['id'])->update($data);
  4248. if (empty($result)) {
  4249. return Result::error("更新失败", 0);
  4250. }
  4251. return Result::success($result);
  4252. }
  4253. public function delGood(array $data): array
  4254. {
  4255. $result = Good::where('id', $data['id'])->delete();
  4256. if (empty($result)) {
  4257. return Result::error("删除失败", 0);
  4258. }
  4259. return Result::success($result);
  4260. }
  4261. //20250226 产品列表
  4262. //20250306 求职信息
  4263. public function getJobHuntingList(array $data): array
  4264. {
  4265. $where = [];
  4266. if (isset($data['username']) && !empty($data['username'])) {
  4267. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4268. }
  4269. //status 1待审核2已审核3已拒绝
  4270. if (isset($data['status']) && $data['status'] != '') {
  4271. $where = [
  4272. 'job_hunting.status' => $data['status'],
  4273. ];
  4274. }
  4275. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4276. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4277. unset($data['type_id']);
  4278. if ($type_id != '10000') {
  4279. $where[] = ['job_hunting.user_id', '=', $user_id];
  4280. }
  4281. $result = JobHunting::where($where)
  4282. ->when(!empty($data['status1']), function ($query) use ($data) {
  4283. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4284. })
  4285. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4286. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4287. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  4288. ->orderBy("updated_at", "desc")
  4289. ->limit($data['page_size'])
  4290. ->offset(($data['page'] - 1) * $data['page_size'])
  4291. ->get();
  4292. if (empty($result)) {
  4293. return Result::error("查询失败", 0);
  4294. }
  4295. $count = JobHunting::where($where)
  4296. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4297. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4298. ->count();
  4299. $data = [
  4300. 'rows' => $result->toArray(),
  4301. 'count' => $count,
  4302. ];
  4303. return Result::success($data);
  4304. }
  4305. public function getJobHuntingApply(array $data): array
  4306. {
  4307. var_dump($data, '-----------------test--------1-');
  4308. $where = [];
  4309. if (isset($data['username']) && !empty($data['username'])) {
  4310. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4311. }
  4312. if (isset($data['salary']) && !empty($data['salary'])) {
  4313. $where[] = [
  4314. 'job_hunting.salary',
  4315. '=',
  4316. $data['salary'],
  4317. ];
  4318. }
  4319. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4320. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4321. unset($data['type_id']);
  4322. if ($type_id != '10000') {
  4323. $where[] = ['job_apply.receiver_id', '=', $user_id];
  4324. }
  4325. var_dump($where, '-----------------test---------');
  4326. $result = jobApply::where($where)
  4327. // ->when(!empty($data['status1']), function ($query) use ($data) {
  4328. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4329. // })
  4330. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  4331. ->where('job_enum.egroup', '=', 'income')
  4332. ->where('job_hunting.status', 2) //已审核
  4333. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4334. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4335. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4336. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4337. //职位----是申请职位
  4338. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4339. ->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')
  4340. ->orderBy("job_hunting.updated_at", "desc")
  4341. ->limit($data['page_size'])
  4342. ->offset(($data['page'] - 1) * $data['page_size'])
  4343. ->get();
  4344. if (empty($result)) {
  4345. return Result::error("查询失败", 0);
  4346. }
  4347. $count = jobApply::where($where)
  4348. ->where('job_enum.egroup', '=', 'income')
  4349. ->where('job_hunting.status', 2) //已审核
  4350. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4351. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4352. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4353. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4354. //职位----是申请职位
  4355. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4356. ->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')
  4357. ->count();
  4358. $data = [
  4359. 'rows' => $result->toArray(),
  4360. 'count' => $count,
  4361. ];
  4362. return Result::success($data);
  4363. }
  4364. public function addJobHunting(array $data): array
  4365. {
  4366. date_default_timezone_set('Asia/Shanghai');
  4367. unset($data['company_name']);
  4368. unset($data['job_industry']);
  4369. unset($data['job_name']);
  4370. unset($data['department']);
  4371. unset($data['job_timeList']);
  4372. unset($data['job_content']);
  4373. unset($data['job_typename']); //不知道这是啥,
  4374. $data['created_at'] = date('Y-m-d H:i:s');
  4375. $data['updated_at'] = date('Y-m-d H:i:s');
  4376. //根据用户 user_id 只能添加一次
  4377. $result = JobHunting::where('user_id', $data['user_id'])->first();
  4378. if (!empty($result)) {
  4379. return Result::error("您已添加过求职信息", 0);
  4380. }
  4381. var_dump($result, '-----------------test---------');
  4382. if (isset($data['city_arr_id']) && !empty($data['city_arr_id'])) {
  4383. if (is_string($data['city_arr_id'])) {
  4384. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4385. $cityArr = json_decode($data['city_arr_id'], true);
  4386. // 确保 $cityArr 是数组
  4387. if (is_array($cityArr)) {
  4388. $data['city_id'] = end($cityArr);
  4389. }
  4390. } else {
  4391. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4392. if (is_array($data['city_arr_id'])) {
  4393. $data['city_id'] = end($data['city_arr_id']);
  4394. }
  4395. }
  4396. }
  4397. // 处理求职所绑定栏目
  4398. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id'])) {
  4399. if (is_string($data['cat_arr_id'])) {
  4400. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4401. // 先清理可能存在的无效 JSON 字符
  4402. $cleanedCatArrStr = trim($data['cat_arr_id']);
  4403. $catArr = json_decode($cleanedCatArrStr, true);
  4404. // 检查 JSON 解码是否成功且结果是数组
  4405. if (json_last_error() === JSON_ERROR_NONE && is_array($catArr)) {
  4406. $data['catid'] = end($catArr);
  4407. }
  4408. } else {
  4409. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4410. if (is_array($data['cat_arr_id'])) {
  4411. $data['catid'] = end($data['cat_arr_id']);
  4412. }
  4413. }
  4414. }
  4415. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4416. $this->sendMessage([
  4417. 'talk_type' => 600,
  4418. 'title' => $data['name'],
  4419. 'content' => '提交了审核',
  4420. 'messageType' => 11,
  4421. ]);
  4422. }
  4423. $result = JobHunting::create($data);
  4424. if (empty($result)) {
  4425. return Result::error("添加失败", 0);
  4426. }
  4427. return Result::success($result);
  4428. }
  4429. public function delJobHunting(array $data): array
  4430. {
  4431. $result = JobHunting::where('id', $data['id'])->delete();
  4432. if (empty($result)) {
  4433. return Result::error("删除失败", 0);
  4434. }
  4435. return Result::success($result);
  4436. }
  4437. public function updateJobHunting(array $data): array
  4438. {
  4439. //设置东八区
  4440. date_default_timezone_set('Asia/Shanghai');
  4441. unset($data['company_name']);
  4442. unset($data['job_industry']);
  4443. unset($data['job_name']);
  4444. unset($data['department']);
  4445. unset($data['job_timeList']);
  4446. unset($data['job_content']);
  4447. unset($data['job_typename']); //不知道这是啥,
  4448. $data['created_at'] = date('Y-m-d H:i:s');
  4449. $data['updated_at'] = date('Y-m-d H:i:s');
  4450. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  4451. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4452. $cityArr = json_decode($data['city_arr_id'], true);
  4453. $data['city_id'] = end($cityArr);
  4454. } else {
  4455. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4456. $data['city_id'] = end($data['city_arr_id']);
  4457. }
  4458. // 处理求职所绑定栏目
  4459. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_string($data['cat_arr_id'])) {
  4460. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4461. $catArr = json_decode($data['cat_arr_id'], true);
  4462. $data['catid'] = end($catArr);
  4463. } else {
  4464. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4465. $data['catid'] = end($data['cat_arr_id']);
  4466. }
  4467. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4468. $this->sendMessage([
  4469. 'talk_type' => 600,
  4470. 'title' => $data['name'],
  4471. 'content' => '提交了审核',
  4472. 'messageType' => 11,
  4473. ]);
  4474. }
  4475. $result = JobHunting::where('id', $data['id'])->update($data);
  4476. if (empty($result)) {
  4477. return Result::error("更新失败", 0);
  4478. }
  4479. return Result::success($result);
  4480. }
  4481. public function getJobHuntingInfo(array $data): array
  4482. {
  4483. $result = JobHunting::where('id', $data['id'])->first();
  4484. if (empty($result)) {
  4485. return Result::error("查询失败", 0);
  4486. }
  4487. return Result::success($result);
  4488. }
  4489. public function getJobHuntingData(array $data): array
  4490. {
  4491. $jobEnum = JobEnum::get();
  4492. $jobIndustry = JobIndustry::get();
  4493. $jobNature = JobNature::get();
  4494. $jobPosition = JobPosition::get();
  4495. $data = [
  4496. 'jobEnum' => $jobEnum,
  4497. 'jobIndustry' => $jobIndustry,
  4498. 'jobNature' => $jobNature,
  4499. 'jobPosition' => $jobPosition,
  4500. ];
  4501. return Result::success($data);
  4502. }
  4503. public function delJobHuntingInfo(array $data): array
  4504. {
  4505. $result = JobHunting::where('id', $data['id'])->delete();
  4506. return Result::success();
  4507. }
  4508. //20250324 通知,公告,消息
  4509. public function delNotice(array $data): array
  4510. {
  4511. $result = Notice::where('id', $data['id'])->delete();
  4512. if ($result) {
  4513. return Result::success();
  4514. } else {
  4515. return Result::error("删除失败", 0);
  4516. }
  4517. }
  4518. public function getNoticeInfo(array $data): array
  4519. {
  4520. $result = Notice::where('id', $data['id'])->first();
  4521. // var_dump($result['re_user_ids'], '--------------------');
  4522. if (empty($result)) {
  4523. return Result::error("查询失败", 0);
  4524. }
  4525. return Result::success($result);
  4526. }
  4527. public function readNotice(array $data): array
  4528. {
  4529. $result = Notice::where('id', $data['id'])->first();
  4530. // var_dump($result['re_user_ids'], '--------------------');
  4531. if (empty($result)) {
  4532. return Result::error("查询失败", 0);
  4533. }
  4534. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4535. $re_user_ids = json_decode($result['re_user_ids'], true);
  4536. var_dump($re_user_ids, '--------------1---test---------');
  4537. var_dump($data, '--------------1---test---------');
  4538. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4539. //如果已经存在,就不再添加
  4540. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4541. $read_id = json_decode($result['read_id'], true);
  4542. if (!is_array($read_id)) {
  4543. $read_id = [];
  4544. }
  4545. if (!in_array($data['user_id'], $read_id)) {
  4546. $read_id[] = $data['user_id'];
  4547. $result['read_id'] = json_encode($read_id);
  4548. Notice::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4549. }
  4550. } else {
  4551. //如果不存在,就添加
  4552. $result['read_id'] = json_encode([$data['user_id']]);
  4553. Notice::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4554. }
  4555. }
  4556. return Result::success($result);
  4557. }
  4558. public function addNotice(array $data): array
  4559. {
  4560. date_default_timezone_set('Asia/Shanghai');
  4561. $data['created_at'] = date('Y-m-d H:i:s');
  4562. $data['updated_at'] = date('Y-m-d H:i:s');
  4563. $user_id = UserInfo::
  4564. //city_id不是null
  4565. whereNotNull('city_id')
  4566. ->whereNotNull('department_id')
  4567. ->where(function ($query) use ($data) {
  4568. $query->where(function ($subQuery) use ($data) {
  4569. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4570. });
  4571. })
  4572. ->where(function ($query) use ($data) {
  4573. $query->where(function ($subQuery) use ($data) {
  4574. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4575. });
  4576. })
  4577. ->pluck('user_id')->toArray();
  4578. $user_id = array_unique($user_id);
  4579. $chat_ids = $user_id;
  4580. $user_id = json_encode($user_id);
  4581. $data['re_user_ids'] = $user_id;
  4582. $this->sendMessage([
  4583. 'talk_type' => 700,
  4584. 'title' => $data['title'],
  4585. 'content' => '提交了审核',
  4586. 'messageType' => 5,
  4587. ]);
  4588. $result = Notice::insertGetId($data);
  4589. if (empty($result)) {
  4590. return Result::error("添加失败", 0);
  4591. }
  4592. return Result::success($result);
  4593. }
  4594. public function updateNotice(array $data): array
  4595. {
  4596. date_default_timezone_set('Asia/Shanghai');
  4597. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  4598. $user_id = UserInfo::
  4599. //city_id不是null
  4600. whereNotNull('city_id')
  4601. ->whereNotNull('department_id')
  4602. ->where(function ($query) use ($data) {
  4603. $query->where(function ($subQuery) use ($data) {
  4604. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4605. });
  4606. })
  4607. ->where(function ($query) use ($data) {
  4608. $query->where(function ($subQuery) use ($data) {
  4609. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4610. });
  4611. })
  4612. ->pluck('user_id')->toArray();
  4613. $user_id = array_unique($user_id);
  4614. $user_id = json_encode($user_id);
  4615. $data['re_user_ids'] = $user_id;
  4616. $data['updated_at'] = date('Y-m-d H:i:s');
  4617. $this->sendMessage([
  4618. 'talk_type' => 700,
  4619. 'title' => $data['title'],
  4620. 'content' => '提交了审核',
  4621. 'messageType' => 5,
  4622. ]);
  4623. $result = Notice::where('id', $data['id'])->update($data);
  4624. return Result::success($result);
  4625. }
  4626. public function getNoticeList(array $data): array
  4627. {
  4628. $where = [];
  4629. //title
  4630. if (isset($data['title']) && !empty($data['title'])) {
  4631. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4632. }
  4633. //level
  4634. if (isset($data['level']) && !empty($data['level'])) {
  4635. $where[] = ['notice.level', '=', $data['level']];
  4636. }
  4637. //status
  4638. if (isset($data['status']) && !empty($data['status'])) {
  4639. $where[] = ['notice.status', '=', $data['status']];
  4640. }
  4641. //type
  4642. if (isset($data['type']) && !empty($data['type'])) {
  4643. $where[] = ['notice.type', '=', $data['type']];
  4644. }
  4645. var_dump($data, '------------11111-2----test---------');
  4646. if ($data['type_id'] == 10000) {
  4647. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4648. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4649. })
  4650. ->where($where)
  4651. ->orderBy('updated_at', 'desc')
  4652. ->limit($data['page_size'])
  4653. ->offset(($data['page'] - 1) * $data['page_size'])
  4654. ->get();
  4655. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4656. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4657. })
  4658. ->where($where)
  4659. ->orderBy('updated_at', 'desc')
  4660. ->count();
  4661. } else {
  4662. $result = Notice::where($where)
  4663. // ->where('user_id', $data['user_id'])
  4664. ->Where(function ($query) use ($data) {
  4665. $query->Where(function ($q) use ($data) {
  4666. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4667. ->orWhere('notice.user_id', $data['user_id']);
  4668. });
  4669. })
  4670. ->when(!empty($data['status1']), function ($query) use ($data) {
  4671. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4672. })
  4673. ->orderBy('updated_at', 'desc')
  4674. ->limit($data['page_size'])
  4675. ->offset(($data['page'] - 1) * $data['page_size'])
  4676. ->get();
  4677. $total = Notice::where($where)
  4678. ->when(!empty($data['status1']), function ($query) use ($data) {
  4679. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4680. })
  4681. // ->where('user_id', $data['user_id'])
  4682. ->Where(function ($query) use ($data) {
  4683. $query->Where(function ($q) use ($data) {
  4684. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4685. ->orWhere('notice.user_id', $data['user_id']);
  4686. });
  4687. })
  4688. ->count();
  4689. }
  4690. if (empty($result)) {
  4691. return Result::error("查询失败", 0);
  4692. }
  4693. $data = [
  4694. 'rows' => $result,
  4695. 'count' => $total,
  4696. ];
  4697. return Result::success($data);
  4698. }
  4699. public function noticeList(array $data): array
  4700. {
  4701. $where = [];
  4702. //title
  4703. if (isset($data['title']) && !empty($data['title'])) {
  4704. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4705. }
  4706. //level
  4707. if (isset($data['level']) && !empty($data['level'])) {
  4708. $where[] = ['notice.level', '=', $data['level']];
  4709. }
  4710. //status
  4711. if (isset($data['status']) && !empty($data['status'])) {
  4712. $where[] = ['notice.status', '=', $data['status']];
  4713. }
  4714. //type
  4715. if (isset($data['type']) && !empty($data['type'])) {
  4716. $where[] = ['notice.type', '=', $data['type']];
  4717. }
  4718. var_dump($data, '------------11111-2----test---------');
  4719. if ($data['type_id'] == 10000) {
  4720. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4721. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4722. })
  4723. ->where($where)
  4724. ->orderBy('updated_at', 'desc')
  4725. ->limit($data['page_size'])
  4726. ->offset(($data['page'] - 1) * $data['page_size'])
  4727. ->get();
  4728. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4729. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4730. })
  4731. ->where($where)
  4732. ->orderBy('updated_at', 'desc')
  4733. ->count();
  4734. } else {
  4735. $result = Notice::where($where)
  4736. // ->where('user_id', $data['user_id'])
  4737. ->Where(function ($query) use ($data) {
  4738. $query->Where(function ($q) use ($data) {
  4739. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4740. ->orWhere('notice.user_id', $data['user_id']);
  4741. });
  4742. })
  4743. ->when(!empty($data['status1']), function ($query) use ($data) {
  4744. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4745. })
  4746. ->orderBy('updated_at', 'desc')
  4747. ->limit($data['page_size'])
  4748. ->offset(($data['page'] - 1) * $data['page_size'])
  4749. ->get();
  4750. $total = Notice::where($where)
  4751. ->when(!empty($data['status1']), function ($query) use ($data) {
  4752. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4753. })
  4754. // ->where('user_id', $data['user_id'])
  4755. ->Where(function ($query) use ($data) {
  4756. $query->Where(function ($q) use ($data) {
  4757. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4758. ->orWhere('notice.user_id', $data['user_id']);
  4759. });
  4760. })
  4761. ->count();
  4762. }
  4763. if (empty($result)) {
  4764. return Result::error("查询失败", 0);
  4765. }
  4766. $data = [
  4767. 'rows' => $result,
  4768. 'count' => $total,
  4769. ];
  4770. return Result::success($data);
  4771. }
  4772. public function getNoticeDetail(array $data): array
  4773. {
  4774. $result = Notice::where('id', $data['id'])->first();
  4775. if (empty($result)) {
  4776. return Result::error("查询失败", 0);
  4777. }
  4778. return Result::success($result);
  4779. }
  4780. public function deleteNotice(array $data): array
  4781. {
  4782. $notice = Notice::where('id', $data['id'])->first();
  4783. if (empty($notice)) {
  4784. return Result::error("删除失败", 0);
  4785. }
  4786. $chat_group_id = $notice->group_id;
  4787. if ($chat_group_id) {
  4788. //删除群聊
  4789. ChatGroups::where('id', $chat_group_id)->delete();
  4790. //删除群成员
  4791. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  4792. //删除群聊记录
  4793. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  4794. }
  4795. $result = Notice::where('id', $data['id'])->delete();
  4796. return Result::success($result);
  4797. }
  4798. public function complaintList(array $data): array
  4799. {
  4800. var_dump($data, '---------1---------');
  4801. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4802. unset($data['type_id']);
  4803. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4804. $where = [];
  4805. if ($type_id != 10000 && empty($data['deal_user'])) {
  4806. // $where['complaint.user_id'] = $user_id;
  4807. }
  4808. if (!empty($data['title'])) {
  4809. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4810. }
  4811. if (!empty($data['department_id'])) {
  4812. $where['complaint.department_id'] = $data['department_id'];
  4813. }
  4814. if (!empty($data['deal'])) {
  4815. $where['complaint.deal'] = $data['deal'];
  4816. }
  4817. if (!empty($data['status'])) {
  4818. $where['complaint.status'] = $data['status'];
  4819. }
  4820. var_dump(!empty($data['deal_user']), '----------1');
  4821. var_dump($where, '----------2');
  4822. $result = Complaint::where($where)
  4823. ->when(!empty($data['status1']), function ($query) use ($data) {
  4824. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4825. })
  4826. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4827. //json re_user_ids data[user_id]是不是在里面
  4828. $query->Where(function ($q) use ($data) {
  4829. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4830. ->where('complaint.status', 2);
  4831. });
  4832. })
  4833. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4834. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4835. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4836. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4837. ->orderBy('updated_at', 'desc')
  4838. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4839. //sql输出
  4840. if (empty($result)) {
  4841. return Result::error("暂无投诉信息", 0);
  4842. }
  4843. // 取出数据
  4844. $rows = $result->items();
  4845. $count = $result->total();
  4846. $responseData = [
  4847. 'rows' => $rows,
  4848. 'count' => $count,
  4849. ];
  4850. return Result::success($responseData);
  4851. }
  4852. public function getComplaintList(array $data): array
  4853. {
  4854. var_dump($data, '00000001000000000000');
  4855. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4856. unset($data['type_id']);
  4857. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4858. $where = [];
  4859. if ($type_id != 10000 && empty($data['deal_user'])) {
  4860. $where['complaint.user_id'] = $user_id;
  4861. }
  4862. if (!empty($data['title'])) {
  4863. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4864. }
  4865. if (!empty($data['department_id'])) {
  4866. $where['complaint.department_id'] = $data['department_id'];
  4867. }
  4868. if (!empty($data['deal'])) {
  4869. $where['complaint.deal'] = $data['deal'];
  4870. }
  4871. if (!empty($data['status'])) {
  4872. $where['complaint.status'] = $data['status'];
  4873. }
  4874. var_dump(!empty($data['deal_user']), '----------1');
  4875. var_dump($where, '----------2');
  4876. $result = Complaint::where($where)
  4877. ->when(!empty($data['status1']), function ($query) use ($data) {
  4878. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4879. })
  4880. // ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4881. // //json re_user_ids data[user_id]是不是在里面
  4882. // $query->Where(function ($q) use ($data) {
  4883. // $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4884. // ->where('complaint.status', 2);
  4885. // });
  4886. // })
  4887. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4888. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4889. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4890. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4891. ->orderBy('updated_at', 'desc')
  4892. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4893. //sql输出
  4894. if (empty($result)) {
  4895. return Result::error("暂无投诉信息", 0);
  4896. }
  4897. // 取出数据
  4898. $rows = $result->items();
  4899. $count = $result->total();
  4900. $responseData = [
  4901. 'rows' => $rows,
  4902. 'count' => $count,
  4903. ];
  4904. return Result::success($responseData);
  4905. }
  4906. public function getComplaintInfo(array $data): array
  4907. {
  4908. $result = Complaint::where('id', $data['id'])->first();
  4909. if (empty($result)) {
  4910. return Result::error("查询失败", 0);
  4911. }
  4912. return Result::success($result);
  4913. }
  4914. public function readComplaint(array $data): array
  4915. {
  4916. $result = Complaint::where('id', $data['id'])->first();
  4917. if (empty($result)) {
  4918. return Result::error("查询失败", 0);
  4919. }
  4920. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4921. $re_user_ids = json_decode($result['re_user_ids'], true);
  4922. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4923. //如果已经存在,就不再添加
  4924. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4925. $read_id = json_decode($result['read_id'], true);
  4926. if (!is_array($read_id)) {
  4927. $read_id = [];
  4928. }
  4929. if (!in_array($data['user_id'], $read_id)) {
  4930. $read_id[] = $data['user_id'];
  4931. $result['read_id'] = json_encode($read_id);
  4932. Complaint::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4933. }
  4934. } else {
  4935. //如果不存在,就添加
  4936. $result['read_id'] = json_encode([$data['user_id']]);
  4937. Complaint::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4938. }
  4939. }
  4940. return Result::success($result);
  4941. }
  4942. public function addComplaint(array $data): array
  4943. {
  4944. date_default_timezone_set('Asia/Shanghai');
  4945. $data['created_at'] = date('Y-m-d H:i:s');
  4946. $data['updated_at'] = date('Y-m-d H:i:s');
  4947. $this->sendMessage([
  4948. 'talk_type' => 800,
  4949. 'title' => $data['title'],
  4950. 'content' => '提交了审核',
  4951. 'messageType' => 6,
  4952. ]);
  4953. $result = Complaint::create($data);
  4954. return Result::success($result);
  4955. }
  4956. public function updateComplaint(array $data): array
  4957. {
  4958. date_default_timezone_set('Asia/Shanghai');
  4959. $data['updated_at'] = date('Y-m-d H:i:s');
  4960. $user_id = $data['user_id'] ?? 0;
  4961. $type_id = $data['type_id'] ?? 0;
  4962. unset($data['user_id']);
  4963. unset($data['type_id']);
  4964. $this->sendMessage([
  4965. 'talk_type' => 800,
  4966. 'title' => $data['title'],
  4967. 'content' => '提交了审核',
  4968. 'messageType' => 6,
  4969. ]);
  4970. $result = Complaint::where('id', $data['id'])->update($data);
  4971. return Result::success($result);
  4972. }
  4973. public function deleteComplaint(array $data): array
  4974. {
  4975. $result = Complaint::where('id', $data['id'])->delete();
  4976. return Result::success($result);
  4977. }
  4978. public function getComplainInfo(array $data): array
  4979. {
  4980. $result = Complaint::where('id', $data['id'])->first();
  4981. if (empty($result)) {
  4982. return Result::error("查询失败", 0);
  4983. }
  4984. return Result::success($result);
  4985. }
  4986. public function updateComplaintStatus(array $data): array
  4987. {
  4988. date_default_timezone_set('Asia/Shanghai');
  4989. $data['updated_at'] = date('Y-m-d H:i:s');
  4990. $user_id = $data['user_id'] ?? 0;
  4991. $type_id = $data['type_id'] ?? 0;
  4992. unset($data['user_id']);
  4993. unset($data['type_id']);
  4994. //处理, 写入处理人
  4995. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  4996. $data['real_deal_user'] = $user_id;
  4997. }
  4998. //如果是deal 23,则判断是不是处理人
  4999. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  5000. $complaintInof = Complaint::where('id', $data['id'])
  5001. ->where('real_deal_user', $user_id)
  5002. ->first();
  5003. if (empty($complaintInof)) {
  5004. return Result::error("处理人错误", 0);
  5005. }
  5006. }
  5007. $complaintInfo = Complaint::where('id', $data['id'])->first();
  5008. if ($data['status'] == 1) {
  5009. $this->sendMessage([
  5010. 'talk_type' => 800,
  5011. 'title' => $complaintInfo['title'],
  5012. 'content' => '提交了审核',
  5013. 'messageType' => 6,
  5014. ]);
  5015. }
  5016. if ($data['status'] == 2 && !isset($data['deal'])) {
  5017. $this->sendMessage([
  5018. 'talk_type' => 801,
  5019. 'title' => $complaintInfo['title'],
  5020. 'content' => '审核通过',
  5021. 'messageType' => 6,
  5022. 'user_id' => $complaintInfo['user_id'],
  5023. ]);
  5024. $this->sendMessage([
  5025. 'talk_type' => 802,
  5026. 'title' => $complaintInfo['title'],
  5027. 'content' => '待处理',
  5028. 'messageType' => 6,
  5029. 'user_id' => $complaintInfo['re_user_ids'],
  5030. ]);
  5031. }
  5032. if ($data['status'] == 3 && !isset($data['deal'])) {
  5033. $this->sendMessage([
  5034. 'talk_type' => 801,
  5035. 'title' => $complaintInfo['title'],
  5036. 'content' => '审核拒绝',
  5037. 'messageType' => 6,
  5038. 'user_id' => $complaintInfo['user_id'],
  5039. ]);
  5040. }
  5041. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 2) {
  5042. $this->sendMessage([
  5043. 'talk_type' => 802,
  5044. 'title' => $complaintInfo['title'],
  5045. 'content' => '处理中',
  5046. 'messageType' => 6,
  5047. 'user_id' => $complaintInfo['re_user_ids'],
  5048. ]);
  5049. }
  5050. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 4) {
  5051. $this->sendMessage([
  5052. 'talk_type' => 802,
  5053. 'title' => $complaintInfo['title'],
  5054. 'content' => '不予处理',
  5055. 'messageType' => 6,
  5056. 'user_id' => $complaintInfo['re_user_ids'],
  5057. ]);
  5058. }
  5059. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 3) {
  5060. $this->sendMessage([
  5061. 'talk_type' => 802,
  5062. 'title' => $complaintInfo['title'],
  5063. 'content' => '已完结',
  5064. 'messageType' => 6,
  5065. 'user_id' => $complaintInfo['re_user_ids'],
  5066. ]);
  5067. }
  5068. $result = complaint::where('id', $data['id'])->update($data);
  5069. return Result::success($result);
  5070. }
  5071. public function updateGoodStatus(array $data): array
  5072. {
  5073. $user_id = $data['user_id'] ?? 0;
  5074. $type_id = $data['type_id'] ?? 0;
  5075. unset($data['user_id']);
  5076. unset($data['type_id']);
  5077. $goodInfo = Good::where('id', $data['id'])->first();
  5078. if ($data['status'] == 2) {
  5079. $this->sendMessage([
  5080. 'talk_type' => 201,
  5081. 'title' => $goodInfo['name'],
  5082. 'content' => '审核通过',
  5083. 'messageType' => 3,
  5084. 'user_id' => $goodInfo['user_id'],
  5085. ]);
  5086. }
  5087. if ($data['status'] == 3) {
  5088. $this->sendMessage([
  5089. 'talk_type' => 201,
  5090. 'title' => $goodInfo['name'],
  5091. 'content' => '审核拒绝',
  5092. 'messageType' => 3,
  5093. 'user_id' => $goodInfo['user_id'],
  5094. ]);
  5095. }
  5096. if ($data['status'] == 1) {
  5097. $this->sendMessage([
  5098. 'talk_type' => 200,
  5099. 'title' => $goodInfo['name'],
  5100. 'content' => '提交了审核',
  5101. 'messageType' => 3,
  5102. ]);
  5103. }
  5104. $result = Good::where('id', $data['id'])->update($data);
  5105. return Result::success($result);
  5106. }
  5107. public function updateJobHuntingStatus(array $data): array
  5108. {
  5109. $user_id = $data['user_id'] ?? 0;
  5110. $type_id = $data['type_id'] ?? 0;
  5111. unset($data['user_id']);
  5112. unset($data['type_id']);
  5113. $jogHuntingInfo = JobHunting::where('id', $data['id'])->first();
  5114. if ($data['status'] == 2) {
  5115. $this->sendMessage([
  5116. 'talk_type' => 601,
  5117. 'title' => $jogHuntingInfo['name'],
  5118. 'content' => '审核通过',
  5119. 'messageType' => 11,
  5120. 'user_id' => $jogHuntingInfo['user_id'],
  5121. ]);
  5122. }
  5123. if ($data['status'] == 3) {
  5124. $this->sendMessage([
  5125. 'talk_type' => 601,
  5126. 'title' => $jogHuntingInfo['name'],
  5127. 'content' => '审核拒绝',
  5128. 'messageType' => 11,
  5129. 'user_id' => $jogHuntingInfo['user_id'],
  5130. ]);
  5131. }
  5132. if ($data['status'] == 1) {
  5133. $this->sendMessage([
  5134. 'talk_type' => 600,
  5135. 'title' => $jogHuntingInfo['name'],
  5136. 'content' => '提交了审核',
  5137. 'messageType' => 11,
  5138. ]);
  5139. }
  5140. $result = JobHunting::where('id', $data['id'])->update($data);
  5141. return Result::success($result);
  5142. }
  5143. public function updateNoticeStatus(array $data): array
  5144. {
  5145. $user_id = $data['user_id'] ?? 0;
  5146. $type_id = $data['type_id'] ?? 0;
  5147. unset($data['user_id']);
  5148. unset($data['type_id']);
  5149. //查询公告
  5150. $notice = Notice::where('id', $data['id'])->first();
  5151. if (empty($notice)) {
  5152. return Result::error("公告不存在", 0);
  5153. }
  5154. //$chat_ids 去除掉$data['user_id']
  5155. $chat_ids = json_decode($notice['re_user_ids'], true);
  5156. $chat_ids = array_diff($chat_ids, [$notice['user_id']]);
  5157. //如果公告的状态是2,且是群聊公告,且状态是1,则创建群聊,第一次审核通过的时候处理成群聊
  5158. if ($data['status'] == 2 && $notice['is_group'] == 1 && ($notice['status'] == 1 || $notice['status'] == 3) && empty($notice['group_id'])) {
  5159. //chat_group
  5160. $group_id = PublicData::uuid();
  5161. $groupData = [
  5162. 'id' => $group_id,
  5163. 'creator_id' => $notice['user_id'],
  5164. 'group_name' => $notice['group_name'] ?? '',
  5165. 'profile' => $notice['profile'] ?? 0,
  5166. ];
  5167. var_dump($groupData, '-----------------groupData-------');
  5168. $groupResult = ChatGroups::insertGetId($groupData);
  5169. var_dump($groupResult, '-----------------groupid-------');
  5170. $groupMemberData = [
  5171. 'id' => PublicData::uuid(),
  5172. 'user_id' => $notice['user_id'],
  5173. 'group_id' => $group_id,
  5174. 'leader' => 2,
  5175. ];
  5176. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  5177. //插入群成员表
  5178. $groupMemberDataUser = [];
  5179. $chatData = [];
  5180. foreach ($chat_ids as $key => $value) {
  5181. $groupMemberDataUser[] = [
  5182. 'id' => PublicData::uuid(),
  5183. 'user_id' => $value,
  5184. 'group_id' => $group_id,
  5185. 'leader' => 1,
  5186. ];
  5187. $chatData[] = [
  5188. 'user_id' => $value,
  5189. 'msg_type' => 1,
  5190. 'receiver_id' => $group_id,
  5191. 'content' => '通过通知创建群聊',
  5192. 'group_receiver_id' => $notice['user_id'],
  5193. 'action' => 'recieved',
  5194. 'created_at' => date('Y-m-d H:i:s'),
  5195. ];
  5196. }
  5197. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  5198. ChatGroupsMember::insert($groupMemberDataUser);
  5199. //插入一条管理员聊天记录
  5200. $chatData[] = [
  5201. 'user_id' => $notice['user_id'],
  5202. 'msg_type' => 1,
  5203. 'receiver_id' => $group_id,
  5204. 'content' => '通过通知创建群聊',
  5205. 'group_receiver_id' => $notice['user_id'],
  5206. 'action' => 'said',
  5207. 'created_at' => date('Y-m-d H:i:s'),
  5208. ];
  5209. var_dump($chatData, '-----------------chatData-------');
  5210. $chatResult = ChatRecords::insert($chatData);
  5211. //处理imp
  5212. $group = [
  5213. 'type' => 1,
  5214. 'name' => $notice['group_name'] ?? '',
  5215. 'profile' => '',
  5216. 'avatar' => '',
  5217. 'creator_id' => $notice['user_id'],
  5218. ];
  5219. $groupResult = GroupImp::insertGetId($group);
  5220. var_dump($groupResult, '获取imp group_id');
  5221. $groupMember = [
  5222. 'user_id' => $notice['user_id'],
  5223. 'group_id' => $groupResult,
  5224. 'leader' => 1,
  5225. 'join_time' => Date('Y-m-d H:i:s')
  5226. ];
  5227. $groupMemberResult = GroupMemberImp::insertGetId($groupMember);
  5228. $talk_session = [
  5229. 'user_id' => $notice['user_id'],
  5230. 'to_from_id' => $groupResult,
  5231. 'talk_mode' => 2,
  5232. 'created_at' => Date('Y-m-d H:i:s'),
  5233. 'updated_at' => Date('Y-m-d H:i:s'),
  5234. ];
  5235. $talk_session_result = GroupTalkImp::insertGetId($talk_session);
  5236. //被通知人员处理
  5237. foreach ($chat_ids as $key => $value) {
  5238. $groupMemberdata[] = [
  5239. 'user_id' => $value,
  5240. 'group_id' => $groupResult,
  5241. 'leader' => 3,
  5242. 'join_time' => Date('Y-m-d H:i:s')
  5243. ];
  5244. $talk_sessionData[] = [
  5245. 'user_id' => $value,
  5246. 'to_from_id' => $groupResult,
  5247. 'talk_mode' => 2,
  5248. 'created_at' => Date('Y-m-d H:i:s'),
  5249. 'updated_at' => Date('Y-m-d H:i:s'),
  5250. ];
  5251. }
  5252. $groupResult1 = GroupMemberImp::insert($groupMemberdata);
  5253. $talk_sessionResult = GroupTalkImp::insert($talk_sessionData);
  5254. $group_id = $groupResult;
  5255. //更新result的 group_id
  5256. $data['group_id'] = $group_id;
  5257. Notice::where(['id' => $data['id']])->update($data);
  5258. }
  5259. if (($data['status'] == 1 || $data['status'] == 3) && $notice['is_group'] == 1 && $notice['status'] == 2 && !empty($notice['group_id'])) {
  5260. //删除掉信息
  5261. GroupImp::where('id', $notice['group_id'])->delete();
  5262. GroupMemberImp::where('group_id', $notice['group_id'])->delete();
  5263. GroupTalkImp::where('to_from_id', $notice['group_id'])->delete();
  5264. foreach ($chat_ids as $key => $value) {
  5265. }
  5266. //聊天记录删除
  5267. //如果是群聊公告,且已经有群聊id,则更新公告的group_id
  5268. $data['group_id'] = null;
  5269. Notice::where(['id' => $data['id']])->update($data);
  5270. }
  5271. $result = Notice::where('id', $data['id'])->update($data);
  5272. $noticeInfo = Notice::where('id', $data['id'])->first();
  5273. if ($data['status'] == 2) {
  5274. $this->sendMessage([
  5275. 'talk_type' => 701,
  5276. 'title' => $noticeInfo['title'],
  5277. 'content' => '审核通过',
  5278. 'messageType' => 3,
  5279. 'user_id' => $noticeInfo['user_id'],
  5280. ]);
  5281. }
  5282. if ($data['status'] == 3) {
  5283. $this->sendMessage([
  5284. 'talk_type' => 701,
  5285. 'title' => $noticeInfo['title'],
  5286. 'content' => '审核拒绝',
  5287. 'messageType' => 3,
  5288. 'user_id' => $noticeInfo['user_id'],
  5289. ]);
  5290. }
  5291. if ($data['status'] == 1) {
  5292. $this->sendMessage([
  5293. 'talk_type' => 700,
  5294. 'title' => $noticeInfo['title'],
  5295. 'content' => '提交了审核',
  5296. 'messageType' => 3,
  5297. ]);
  5298. }
  5299. return Result::success($result);
  5300. }
  5301. public function getDUser(array $data): array
  5302. {
  5303. if (!empty($data['ids'])) {
  5304. $user = User::whereIn('id', $data['ids'])->getall();
  5305. if (empty($user)) {
  5306. return Result::error('无数据', 0);
  5307. }
  5308. return Result::success($user);
  5309. }
  5310. $where = [];
  5311. if (!empty($data['department_id'])) {
  5312. $where['department_id'] = $data['department_id'];
  5313. }
  5314. if (!empty($data['city_id'])) {
  5315. $where['city_id'] = $data['city_id'];
  5316. }
  5317. $result = User::where('type_id', 2)
  5318. ->where('status', 1)
  5319. ->where($where)
  5320. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  5321. ->get();
  5322. if (empty($result)) {
  5323. return Result::error("查询失败", 0);
  5324. }
  5325. return Result::success($result);
  5326. }
  5327. /**
  5328. * 验证导航名称是否重复
  5329. * @return void
  5330. */
  5331. public function checkCategoryName(array $data): array
  5332. {
  5333. $result = Category::when($data, function ($query) use ($data) {
  5334. if (isset($data['name']) && $data['name']) {
  5335. $query->where("name", $data['name']);
  5336. }
  5337. if (isset($data['id']) && $data['id']) {
  5338. $query->where("id", "!=", $data['id']);
  5339. }
  5340. })->first();
  5341. if ($result) {
  5342. return Result::error("已存在");
  5343. } else {
  5344. return Result::success();
  5345. }
  5346. }
  5347. //20250226 产品列表
  5348. // 20250306 -------招聘--------fr
  5349. /*
  5350. * 招聘列表
  5351. * */
  5352. public function getJobRecruitingList(array $data): array
  5353. {
  5354. $where = [];
  5355. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  5356. if ($data['checkout'] == 0) {
  5357. $job_status = [0, 2];
  5358. } else {
  5359. $job_status = [1];
  5360. }
  5361. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5362. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  5363. }
  5364. $user = User::where('id', $data['user_id'])->first();
  5365. if (empty($user)) {
  5366. return Result::error("用户不存在", 0);
  5367. }
  5368. // 3:企业会员
  5369. if ($user['type_id'] == 3) {
  5370. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  5371. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  5372. }
  5373. // 如果 $where 为空,则不添加 where 条件
  5374. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5375. return $query->where($where);
  5376. })
  5377. ->whereIn('job_recruiting.status', $job_status)
  5378. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5379. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  5380. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  5381. ->orderBy("updated_at", "desc")
  5382. ->offset(($data['page'] - 1) * $data['page_size'])
  5383. ->limit($data['page_size'])
  5384. ->get()
  5385. ->all();
  5386. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5387. return $query->where($where);
  5388. })
  5389. ->whereIn('job_recruiting.status', $job_status)
  5390. ->count();
  5391. if (empty($result)) {
  5392. return Result::error("暂无招聘信息", 0);
  5393. }
  5394. return Result::success($result);
  5395. }
  5396. /*
  5397. * 招聘信息添加
  5398. * */
  5399. public function addJobRecruiting(array $data): array
  5400. {
  5401. // var_dump('添加招聘进入news------data',$data);
  5402. // return Result::success($data);
  5403. $user = User::where('user.id', $data['user_id'])
  5404. ->where('user.status', 1)
  5405. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5406. ->select(
  5407. 'user.type_id',
  5408. 'user.mobile',
  5409. 'user.email',
  5410. 'user_info.business_name',
  5411. 'user_info.company_hy_id',
  5412. 'user_info.company_nature',
  5413. 'user_info.company_size',
  5414. 'user_info.introduction',
  5415. 'user_info.real_name',
  5416. 'user_info.company_url',
  5417. 'user_info.address_arr_id',
  5418. 'user_info.address'
  5419. )
  5420. ->first();
  5421. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5422. return Result::error("用户不存在", 0);
  5423. }
  5424. $web = Website::where('id', $data['website_id'])->first();
  5425. if (empty($web)) {
  5426. return Result::error("网站不存在", 0);
  5427. }
  5428. // var_dump('添加招聘进入news---user---user',$user);
  5429. // 处理招聘关键词
  5430. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5431. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5432. } else {
  5433. Jieba::init(); // 初始化 jieba-php
  5434. Finalseg::init();
  5435. $segList = Jieba::cut($data['title']);
  5436. $segList1 = array_slice($segList, 0, 8);
  5437. $data['keyword'] = implode(',', $segList1);
  5438. }
  5439. if (!isset($data['seo_description']) || empty($data['seo_description'])) {
  5440. $content = $data['description'];
  5441. // 去除 <style> 和 <script> 标签及其内容
  5442. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5443. // 去除所有 HTML 标签
  5444. $content = strip_tags($content);
  5445. // 去除 HTML 实体
  5446. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5447. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5448. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5449. // 去除多余空白
  5450. $content = preg_replace('/\s+/u', '', $content);
  5451. // 截取 100 个字符
  5452. $data['seo_description'] = mb_substr($content, 0, 100);
  5453. }
  5454. // return Result::success($user);
  5455. $data['action_id'] = $data['user_id'] ?? null;
  5456. $data['user_type'] = $user['type_id'] ?? null;
  5457. $data['cat_arr_id'] = isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) ? array_values(array_unique($data['cat_arr_id'])) : [];
  5458. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5459. $data['catid'] = end($data['cat_arr_id']);
  5460. } else {
  5461. $data['catid'] = 0;
  5462. }
  5463. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? array_values(array_unique($data['city_arr_id'])) : [];
  5464. $data['cat_arr_id'] = isset($data['cat_arr_id']) && $data['cat_arr_id'] != [] ? json_encode(array_map('intval', $data['cat_arr_id'])) : '[]';
  5465. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '[]';
  5466. // 公司地址 管理员必填
  5467. $data['address_arr_id'] = isset($data['address_arr_id']) && !empty($data['address_arr_id']) ? array_values(array_unique($data['address_arr_id'])) : [];
  5468. $data['address_arr_id'] = isset($data['address_arr_id']) && $data['address_arr_id'] != [] ? json_encode(array_map('intval', $data['address_arr_id'])) : '[]';
  5469. // 管理员-企业相关信息
  5470. $company = [
  5471. // 'user_id' => $data['user_id']?? null,
  5472. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5473. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5474. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5475. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5476. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5477. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5478. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5479. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5480. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5481. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5482. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5483. ];
  5484. //去掉相关企业信息
  5485. $job = array_diff_key($data, array_flip(array_keys($company)));
  5486. // var_dump('添加招聘进入news---job---user',$job);
  5487. Db::beginTransaction();
  5488. try {
  5489. // // 先添加职位相关信息
  5490. if ($user['type_id'] == 10000) {
  5491. $job['status'] = 1;
  5492. }
  5493. $job['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5494. $job['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5495. $job['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5496. $job['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5497. $job['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5498. $job['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5499. $job['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5500. // return Result::success($job);
  5501. $jobId = JobRecruiting::insertGetId($job);
  5502. if (empty($jobId)) {
  5503. Db::rollBack();
  5504. return Result::error("添加失败");
  5505. }
  5506. // 添加公司信息
  5507. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5508. $company['job_id'] = $jobId;
  5509. $company['user_type'] = isset($user['type_id']) && $user['type_id'] !== '' ? $user['type_id'] : null;
  5510. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5511. if ($user['type_id'] == 10000) {
  5512. // 管理员添加企业信息
  5513. $companyId = JobCompany::insertGetId($company);
  5514. if (empty($companyId)) {
  5515. Db::rollBack();
  5516. return Result::error("添加失败");
  5517. }
  5518. } else {
  5519. // 企业会员添加企业信息
  5520. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5521. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5522. $company['user_type'] = isset($data['user_type']) && $data['user_type'] !== '' ? $data['user_type'] : null;
  5523. $company['job_id'] = $jobId;
  5524. $companyId = JobCompany::insertGetId($company);
  5525. if (empty($companyId)) {
  5526. Db::rollBack();
  5527. return Result::error("添加失败");
  5528. }
  5529. }
  5530. Db::commit();
  5531. $result = [
  5532. 'job_id' => $jobId,
  5533. 'company_id' => $companyId,
  5534. ];
  5535. return Result::success($result);
  5536. } catch (\Exception $e) {
  5537. Db::rollBack();
  5538. return Result::error($e->getMessage(), 0);
  5539. }
  5540. // return Result::success($result);
  5541. }
  5542. /*
  5543. * 获取招聘信息详情
  5544. * */
  5545. public function getJobRecruitingInfo(array $data): array
  5546. {
  5547. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  5548. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5549. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5550. ->select(
  5551. 'job_recruiting.*',
  5552. 'website.website_name as website_name',
  5553. 'job_company.business_name',
  5554. 'job_company.company_hy_id',
  5555. 'job_company.company_size',
  5556. 'job_company.company_nature',
  5557. 'job_company.introduction',
  5558. 'job_company.real_name',
  5559. 'job_company.mobile',
  5560. 'job_company.company_url',
  5561. 'job_company.address_arr_id',
  5562. 'job_company.address',
  5563. 'job_company.email'
  5564. )
  5565. ->first();
  5566. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  5567. if (!empty($cityId)) {
  5568. if (isset($cityId[1]) && $cityId[1] != null) {
  5569. $city = District::where('id', $cityId[1])->first(['name']);
  5570. } else {
  5571. $city = District::where('id', $cityId[0])->first(['name']);
  5572. }
  5573. $result['city'] = $city['name'] ?? '';
  5574. }
  5575. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  5576. if (is_array($addressId) && !empty($addressId)) {
  5577. $address = District::whereIn('id', $addressId)
  5578. ->orderBy('level', 'asc')
  5579. ->get(['name'])
  5580. ->pluck('name')
  5581. ->implode('');
  5582. // $job->address_name = $address ?? '';
  5583. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  5584. }
  5585. if (empty($result)) {
  5586. return Result::error("招聘信息不存在", 0);
  5587. }
  5588. // return Result::success($job);
  5589. return Result::success($result);
  5590. }
  5591. /*
  5592. * 修改招聘信息
  5593. * */
  5594. public function upJobRecruiting(array $data): array
  5595. {
  5596. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  5597. // return Result::success($job);
  5598. if (empty($job)) {
  5599. return Result::error("招聘信息不存在", 0);
  5600. }
  5601. $user = User::where('id', $data['user_id'])->first();
  5602. // return Result::success($user);
  5603. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5604. return Result::error("用户不存在", 0);
  5605. }
  5606. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5607. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5608. }
  5609. // 处理招聘关键词
  5610. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5611. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5612. } else {
  5613. Jieba::init(); // 初始化 jieba-php
  5614. Finalseg::init();
  5615. $segList = Jieba::cut($data['title']);
  5616. $segList1 = array_slice($segList, 0, 8);
  5617. $data['keyword'] = implode(',', $segList1);
  5618. }
  5619. if(!isset($data['seo_description']) || empty($data['seo_description'])){
  5620. $content = $data['description'];
  5621. // 去除 <style> 和 <script> 标签及其内容
  5622. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5623. // 去除所有 HTML 标签
  5624. $content = strip_tags($content);
  5625. // 去除 HTML 实体
  5626. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5627. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5628. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5629. // 去除多余空白
  5630. $content = preg_replace('/\s+/u', '', $content);
  5631. // 截取 100 个字符
  5632. $data['seo_description'] = mb_substr($content, 0, 100);
  5633. }
  5634. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  5635. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5636. $data['catid'] = end($data['cat_arr_id']);
  5637. } else {
  5638. }
  5639. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  5640. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  5641. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  5642. // 公司地址 管理员必填
  5643. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  5644. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5645. // 管理员-企业相关信息
  5646. $company = [
  5647. // 'user_id' => $data['user_id']?? null,
  5648. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5649. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5650. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5651. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5652. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5653. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5654. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5655. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5656. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5657. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5658. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5659. ];
  5660. //去掉相关企业信息
  5661. $data = array_diff_key($data, array_flip(array_keys($company)));
  5662. $jobId = $data['id'];
  5663. $web = $data['website_id'];
  5664. $data['action_id'] = $data['user_id'];
  5665. unset($data['user_id']);
  5666. unset($data['user_type']);
  5667. unset($data['id']);
  5668. unset($data['website_id']);
  5669. // return Result::success($data);
  5670. Db::beginTransaction();
  5671. try {
  5672. // 管理员修改招聘信息
  5673. if ($user['type_id'] == 10000) {
  5674. $data['website_id'] = $web;
  5675. $company['website_id'] = $data['website_id'];
  5676. $data['status'] = 1;
  5677. } else {
  5678. $data['status'] = 0;
  5679. }
  5680. $data['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5681. $data['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5682. $data['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5683. $data['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5684. $data['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5685. $data['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5686. $data['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5687. // return Result::success($job);
  5688. // Db::rollBack();
  5689. // return Result::success($company);
  5690. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  5691. $this->sendMessage([
  5692. 'talk_type' => 500,
  5693. 'title' => $data['title'],
  5694. 'content' => '提交了审核',
  5695. 'messageType' => 10,
  5696. ]);
  5697. }
  5698. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  5699. if (empty($result['job'])) {
  5700. Db::rollBack();
  5701. return Result::error("修改招聘信息失败");
  5702. }
  5703. // 管理员修改企业相关信息
  5704. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  5705. if (empty($result['company'])) {
  5706. Db::rollBack();
  5707. return Result::error("修改企业相关信息失败");
  5708. }
  5709. Db::commit();
  5710. // return Result::success($result);
  5711. } catch (\Exception $e) {
  5712. Db::rollBack();
  5713. return Result::error($e->getMessage(), 0);
  5714. }
  5715. return Result::success($result);
  5716. }
  5717. /*
  5718. * 招聘信息删除
  5719. * */
  5720. public function delJobRecruiting(array $data): array
  5721. {
  5722. $user = User::where('id', $data['user_id'])->first();
  5723. if (empty($user)) {
  5724. return Result::error("用户不存在", 0);
  5725. }
  5726. $job = JobRecruiting::where('id', $data['id'])->first();
  5727. if (empty($job)) {
  5728. return Result::error("招聘信息不存在", 0);
  5729. }
  5730. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5731. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5732. }
  5733. Db::beginTransaction();
  5734. try {
  5735. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  5736. if (empty($result['job'])) {
  5737. Db::rollBack();
  5738. return Result::error("删除招聘信息失败");
  5739. }
  5740. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  5741. if (empty($result['company'])) {
  5742. Db::rollBack();
  5743. return Result::error("删除企业相关信息失败");
  5744. }
  5745. Db::commit();
  5746. } catch (\Exception $e) {
  5747. Db::rollBack();
  5748. return Result::error($e->getMessage(), 0);
  5749. }
  5750. return Result::success($result);
  5751. }
  5752. /*
  5753. * 获取公司信息
  5754. * */
  5755. public function getJobCompany(array $data): array
  5756. {
  5757. $user = User::where('user.id', $data['user_id'])
  5758. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5759. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  5760. ->first();
  5761. // return Result::success($user);
  5762. if (empty($user)) {
  5763. return Result::error("用户不存在", 0);
  5764. }
  5765. if ($user['type_id'] == 3) {
  5766. $result = [
  5767. // 'id' => 0,
  5768. 'user_id' => $data['user_id'],
  5769. 'website_id' => $data['website_id'],
  5770. 'business_name' => $user['business_name'], // 企业名称
  5771. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  5772. 'company_nature' => $user['company_nature'], // 公司性质
  5773. 'company_size' => $user['company_size'], // 公司规模
  5774. 'introduction' => $user['introduction'], // 公司简介
  5775. 'real_name' => $user['real_name'], // 企业联系人
  5776. 'mobile' => $user['mobile'], // 企业联系电话
  5777. 'company_url' => $user['company_url'], // 企业网址
  5778. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  5779. 'address' => $user['address'], // 企业地址
  5780. 'email' => $user['email'], // 企业邮箱
  5781. ];
  5782. } else {
  5783. return Result::error("用户类型错误", 0);
  5784. }
  5785. if (empty($result)) {
  5786. return Result::error("公司信息不存在", 0);
  5787. }
  5788. return Result::success($result);
  5789. }
  5790. /*
  5791. * 修改公司信息
  5792. * */
  5793. public function upJobCompany(array $data): array
  5794. {
  5795. // return Result::success($data);
  5796. $user = User::where('user.id', $data['user_id'])
  5797. ->where('user.status', 1)
  5798. ->select('user.user_name', 'user.type_id')
  5799. ->first();
  5800. if (empty($user)) {
  5801. return Result::error("用户不存在", 0);
  5802. }
  5803. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5804. $job_company = JobCompany::where('user_id', $data['user_id'])->first();
  5805. $company = [
  5806. 'business_name' => $data['business_name'], // 企业名称
  5807. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5808. 'company_nature' => $data['company_nature'], // 公司性质
  5809. 'company_size' => $data['company_size'], // 公司规模
  5810. 'introduction' => $data['introduction'], // 公司简介
  5811. // 'real_name' => $data['real_name'], // 企业联系人
  5812. 'company_url' => $data['company_url'], // 企业网址
  5813. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5814. 'address' => $data['address'], // 企业详细地址
  5815. // 'email' => $data['email'], // 企业邮箱
  5816. ];
  5817. if ($user['type_id'] == 3) {
  5818. Db::beginTransaction();
  5819. try {
  5820. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  5821. 'business_name' => $data['business_name'], // 企业名称
  5822. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5823. 'company_nature' => $data['company_nature'], // 公司性质
  5824. 'company_size' => $data['company_size'], // 公司规模
  5825. 'introduction' => $data['introduction'], // 公司简介
  5826. // 'real_name' => $data['real_name'], // 企业联系人
  5827. 'company_url' => $data['company_url'], // 企业网址
  5828. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5829. 'address' => $data['address'], // 企业详细地址
  5830. ]);
  5831. if (empty($result['userinfo'])) {
  5832. Db::rollBack();
  5833. return Result::error('修改企业会员信息失败!');
  5834. }
  5835. $result['user'] = User::where('id', $data['user_id'])->update([
  5836. 'email' => $data['email'], // 企业邮箱
  5837. ]);
  5838. if (empty($result['user'])) {
  5839. Db::rollBack();
  5840. return Result::error('修改个人中心信息失败!');
  5841. }
  5842. // 该企业会员若是未发布招聘信息则暂无该企业会员的企业信息
  5843. if (!empty($job_company)) {
  5844. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  5845. if (empty($result['job_company'])) {
  5846. Db::rollBack();
  5847. return Result::error('修改企业会员信息失败!');
  5848. }
  5849. }
  5850. Db::commit();
  5851. return Result::success($result);
  5852. } catch (\Exception $e) {
  5853. Db::rollBack();
  5854. return Result::error($e->getMessage(), 0);
  5855. }
  5856. } else {
  5857. return Result::error("用户类型错误", 0);
  5858. }
  5859. }
  5860. /*
  5861. * 获取省-市
  5862. * */
  5863. public function getJobRecruitingArea(array $data): array
  5864. {
  5865. if (isset($data['pid']) && $data['pid'] != null) {
  5866. $result = District::where('pid', $data['pid'])->get()->all();
  5867. } else {
  5868. $result = District::where('level', 1)->get()->all();
  5869. }
  5870. if (empty($result)) {
  5871. return Result::error("暂无此省市", 0);
  5872. }
  5873. return Result::success($result);
  5874. }
  5875. /*
  5876. * 获取行业分类
  5877. * */
  5878. public function getIndustry(array $data): array
  5879. {
  5880. $result = JobIndustry::get()->all();
  5881. if (empty($result)) {
  5882. return Result::error("暂无行业分类", 0);
  5883. }
  5884. return Result::success($result);
  5885. }
  5886. /*
  5887. * 获取职位
  5888. * */
  5889. public function getPositionList(array $data): array
  5890. {
  5891. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  5892. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  5893. } else {
  5894. $result = JobPosition::where('zwpid', 0)->get()->all();
  5895. }
  5896. if (empty($result)) {
  5897. return Result::error("暂无此职位", 0);
  5898. }
  5899. return Result::success($result);
  5900. }
  5901. /*
  5902. * 获取工作性质-菜单
  5903. * */
  5904. public function getJobNature(array $data): array
  5905. {
  5906. $result = JobEnum::where('egroup', 'nature')->get()->all();
  5907. if (empty($result)) {
  5908. return Result::error("暂无工作性质", 0);
  5909. }
  5910. return Result::success($result);
  5911. }
  5912. /*
  5913. * 获取工作经验-菜单
  5914. * */
  5915. public function getExperience(array $data): array
  5916. {
  5917. $result = JobEnum::where('egroup', 'years')->get()->all();
  5918. if (empty($result)) {
  5919. return Result::error("暂无工作经验", 0);
  5920. }
  5921. return Result::success($result);
  5922. }
  5923. /*
  5924. * 获取学历-菜单
  5925. * */
  5926. public function getEducation(array $data): array
  5927. {
  5928. $result = JobEnum::where('egroup', 'education')->get()->all();
  5929. if (empty($result)) {
  5930. return Result::error("暂无学历", 0);
  5931. }
  5932. return Result::success($result);
  5933. }
  5934. /*
  5935. * 获取薪资-菜单
  5936. * */
  5937. public function getSalary(array $data): array
  5938. {
  5939. $result = JobEnum::where('egroup', 'income')->get()->all();
  5940. if (empty($result)) {
  5941. return Result::error("暂无薪资", 0);
  5942. }
  5943. return Result::success($result);
  5944. }
  5945. /*
  5946. * 获取语言-菜单
  5947. * */
  5948. public function getLanguage(array $data): array
  5949. {
  5950. $result = JobEnum::where('egroup', 'language')->get()->all();
  5951. if (empty($result)) {
  5952. return Result::error("暂无语言", 0);
  5953. }
  5954. return Result::success($result);
  5955. }
  5956. /*
  5957. * 获取掌握程度-菜单
  5958. * */
  5959. public function getLevel(array $data): array
  5960. {
  5961. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  5962. if (empty($result)) {
  5963. return Result::error("暂无工作性质", 0);
  5964. }
  5965. return Result::success($result);
  5966. }
  5967. // 公司信息
  5968. /*
  5969. * 获取公司性质-菜单
  5970. * */
  5971. public function getCompanyNature(array $data): array
  5972. {
  5973. $result = JobNature::get()->all();
  5974. if (empty($result)) {
  5975. return Result::error("暂无公司性质", 0);
  5976. }
  5977. return Result::success($result);
  5978. }
  5979. /*
  5980. * 获取公司规模-菜单
  5981. * */
  5982. public function getCompanySize(array $data): array
  5983. {
  5984. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  5985. if (empty($result)) {
  5986. return Result::error("暂无公司规模", 0);
  5987. }
  5988. return Result::success($result);
  5989. }
  5990. /*
  5991. * 招聘信息审核
  5992. * */
  5993. public function checkJobRecruiting(array $data): array
  5994. {
  5995. $user = User::where('id', $data['user_id'])->first();
  5996. if (empty($user)) {
  5997. return Result::error("用户不存在", 0);
  5998. }
  5999. $job = JobRecruiting::where('id', $data['id'])->first();
  6000. if (empty($job)) {
  6001. return Result::error("招聘信息不存在", 0);
  6002. }
  6003. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  6004. if ($user['type_id'] != 10000) {
  6005. return Result::error("用户暂无权限审核此招聘信息!", 0);
  6006. }
  6007. // 驳回原因
  6008. if ($data['status'] == 2) {
  6009. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  6010. }
  6011. $data['action_id'] = $data['user_id'];
  6012. unset($data['user_id']);
  6013. if ($data['status'] == 1) {
  6014. $this->sendMessage([
  6015. 'talk_type' => 501,
  6016. 'title' => $job['title'],
  6017. 'content' => '审核通过',
  6018. 'messageType' => 10,
  6019. 'user_id' => $job['user_id'],
  6020. ]);
  6021. }
  6022. if ($data['status'] == 2) {
  6023. $this->sendMessage([
  6024. 'talk_type' => 501,
  6025. 'title' => $job['title'],
  6026. 'content' => '审核拒绝',
  6027. 'messageType' => 10,
  6028. 'user_id' => $job['user_id'],
  6029. ]);
  6030. }
  6031. if ($data['status'] == 0) {
  6032. $this->sendMessage([
  6033. 'talk_type' => 500,
  6034. 'title' => $job['title'],
  6035. 'content' => '提交了审核',
  6036. 'messageType' => 10,
  6037. ]);
  6038. }
  6039. $result = JobRecruiting::where('id', $data['id'])->update($data);
  6040. if (empty($result)) {
  6041. return Result::error("审核失败", 0);
  6042. }
  6043. return Result::success($result);
  6044. }
  6045. public function myApplyList(array $data): array
  6046. {
  6047. var_dump($data, '------参数');
  6048. $user = User::where('id', $data['user_id'])->first();
  6049. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6050. return Result::error("用户不存在", 0);
  6051. }
  6052. // 1:个人会员 职场机会
  6053. if ($user['type_id'] == 1) {
  6054. $where['user_id'] = $user['id'];
  6055. }
  6056. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  6057. $query->where('user_id', $user['id']);
  6058. })
  6059. ->pluck('recruit_id');
  6060. $where = [];
  6061. if (isset($data['salary']) && $data['salary'] != null) {
  6062. $where['job_recruiting.salary'] = $data['salary'];
  6063. }
  6064. if (isset($data['experience']) && $data['experience'] != null) {
  6065. $where['job_recruiting.experience'] = $data['experience'];
  6066. }
  6067. if (isset($data['business_name']) && $data['business_name'] != null) {
  6068. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6069. }
  6070. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6071. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6072. ->where($where);
  6073. // ->count();
  6074. $count = $query->count();
  6075. $query = clone $query;
  6076. $job = $query
  6077. ->leftJoin('job_enum as income_enum', function ($join) {
  6078. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6079. ->where('income_enum.egroup', 'income');
  6080. })
  6081. ->leftJoin('job_enum as years_enum', function ($join) {
  6082. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6083. ->where('years_enum.egroup', 'years');
  6084. })
  6085. // ->where($where)
  6086. ->orderBy('job_recruiting.updated_at', 'desc')
  6087. ->select(
  6088. 'job_recruiting.id',
  6089. 'job_recruiting.title',
  6090. 'job_company.business_name',
  6091. 'income_enum.evalue as salary_evalue',
  6092. 'income_enum.ename as salary_ename',
  6093. 'years_enum.evalue as experience_evalue',
  6094. 'years_enum.ename as experience_ename',
  6095. 'job_recruiting.updated_at'
  6096. )
  6097. ->offset(($data['page'] - 1) * $data['pageSize'])
  6098. ->limit($data['pageSize'])
  6099. ->get()
  6100. ->all();
  6101. if (empty($job)) {
  6102. return Result::error("暂无招聘信息", 0);
  6103. }
  6104. $result = [
  6105. 'row' => $job,
  6106. 'count' => $count,
  6107. ];
  6108. return Result::success($result);
  6109. }
  6110. public function readJobApply(array $data): array
  6111. {
  6112. $result = JobApply::where('id', $data['id'])->first();
  6113. if (empty($result)) {
  6114. return Result::error("查询失败", 0);
  6115. }
  6116. $result = JobApply::where('id', $data['id'])->update([
  6117. 'status' => 2,
  6118. ]);
  6119. return Result::success($result);
  6120. }
  6121. /*
  6122. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  6123. * */
  6124. public function getRecruitingList(array $data): array
  6125. {
  6126. $user = User::where('id', $data['user_id'])->first();
  6127. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6128. return Result::error("用户不存在", 0);
  6129. }
  6130. // 1:个人会员 职场机会
  6131. if ($user['type_id'] == 1) {
  6132. $where['user_id'] = $user['id'];
  6133. }
  6134. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  6135. $query->where('receiver_id', $user['id']);
  6136. })
  6137. ->pluck('recruit_id');
  6138. // return Result::success($recruitingId);
  6139. $where = [];
  6140. if (isset($data['salary']) && $data['salary'] != null) {
  6141. $where['job_recruiting.salary'] = $data['salary'];
  6142. }
  6143. if (isset($data['experience']) && $data['experience'] != null) {
  6144. $where['job_recruiting.experience'] = $data['experience'];
  6145. }
  6146. if (isset($data['business_name']) && $data['business_name'] != null) {
  6147. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6148. }
  6149. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6150. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6151. ->where($where);
  6152. // ->count();
  6153. $count = $query->count();
  6154. $query = clone $query;
  6155. $job = $query
  6156. ->leftJoin('job_enum as income_enum', function ($join) {
  6157. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6158. ->where('income_enum.egroup', 'income');
  6159. })
  6160. ->leftJoin('job_enum as years_enum', function ($join) {
  6161. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6162. ->where('years_enum.egroup', 'years');
  6163. })
  6164. // ->where($where)
  6165. ->orderBy('job_recruiting.updated_at', 'desc')
  6166. ->select(
  6167. 'job_recruiting.id',
  6168. 'job_recruiting.title',
  6169. 'job_company.business_name',
  6170. 'income_enum.evalue as salary_evalue',
  6171. 'income_enum.ename as salary_ename',
  6172. 'years_enum.evalue as experience_evalue',
  6173. 'years_enum.ename as experience_ename',
  6174. 'job_recruiting.updated_at'
  6175. )
  6176. ->offset(($data['page'] - 1) * $data['pageSize'])
  6177. ->limit($data['pageSize'])
  6178. ->get()
  6179. ->all();
  6180. if (empty($job)) {
  6181. return Result::error("暂无招聘信息", 0);
  6182. }
  6183. $result = [
  6184. 'row' => $job,
  6185. 'count' => $count,
  6186. ];
  6187. return Result::success($result);
  6188. }
  6189. /*
  6190. * 获取企业会员-招聘信息列表
  6191. * */
  6192. public function getRecruitingInfo(array $data): array
  6193. {
  6194. $user = User::where('id', $data['user_id'])->first();
  6195. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6196. return Result::error("用户不存在", 0);
  6197. }
  6198. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  6199. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6200. ->select(
  6201. 'job_recruiting.*',
  6202. 'job_company.business_name',
  6203. 'job_company.company_hy_id',
  6204. 'job_company.company_size',
  6205. 'job_company.company_nature',
  6206. 'job_company.introduction',
  6207. 'job_company.real_name',
  6208. 'job_company.mobile',
  6209. 'job_company.company_url',
  6210. 'job_company.address_arr_id',
  6211. 'job_company.address',
  6212. 'job_company.email'
  6213. )
  6214. ->get();
  6215. if (empty($recruiting)) {
  6216. return Result::error("暂无招聘信息", 0);
  6217. }
  6218. return Result::success($recruiting);
  6219. }
  6220. /*
  6221. * 获取企业会员-我的沟通
  6222. * */
  6223. public function getJobResumeList(array $data): array
  6224. {
  6225. $user = User::where('id', $data['user_id'])->first();
  6226. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  6227. return Result::error("用户不存在", 0);
  6228. }
  6229. $where = [];
  6230. if (isset($data['salary']) && $data['salary'] != null) {
  6231. $where['job_hunting.salary'] = $data['salary'];
  6232. }
  6233. if (isset($data['user_name']) && $data['user_name'] != null) {
  6234. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  6235. }
  6236. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  6237. $query->where('job_resume.user_id', $user['id']);
  6238. })
  6239. ->when(!empty($where), function ($query) use ($where) {
  6240. $query->where($where);
  6241. })
  6242. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  6243. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  6244. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  6245. ->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');
  6246. $count = $job->count();
  6247. if ($count == 0) {
  6248. return Result::error("暂无沟通记录", 0);
  6249. }
  6250. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  6251. ->offset(($data['page'] - 1) * $data['pageSize'])
  6252. ->limit($data['pageSize'])
  6253. ->get();
  6254. if (empty($jobs)) {
  6255. return Result::error("暂无沟通记录", 0);
  6256. }
  6257. $result['row'] = $this->processJob($jobs, '');
  6258. $result['count'] = $count;
  6259. return Result::success($result);
  6260. }
  6261. public function readJobResume(array $data): array
  6262. {
  6263. $result = JobResume::where('id', $data['id'])->first();
  6264. if (empty($result)) {
  6265. return Result::error("查询失败", 0);
  6266. }
  6267. $result = JobResume::where('id', $data['id'])->update([
  6268. 'status' => 2,
  6269. ]);
  6270. return Result::success($result);
  6271. }
  6272. // 20250306 招聘
  6273. //20250422 书刊音像
  6274. public function addBook(array $data): array
  6275. {
  6276. $user_id = $data['user_id'] ?? 0;
  6277. $type_id = $data['type_id'] ?? 0;
  6278. // $website_id = $data['website_id'] ?? 0;
  6279. // unset($data['user_id']);
  6280. unset($data['type_id']);
  6281. // unset($data['website_id']);
  6282. //处理数组
  6283. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6284. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6285. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6286. if ($data['img_url'] == '') {
  6287. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6288. preg_match_all($reg, $data['detail'], $matches);
  6289. if (isset($matches[1][0])) {
  6290. //截取varchar240
  6291. $data['img_url'] = substr($matches[1][0], 0, 240);
  6292. }
  6293. }
  6294. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  6295. //提取标题+内容中的关键词
  6296. $data['keyword'] = $data['title'];
  6297. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6298. Jieba::init(); // 初始化 jieba-php
  6299. Finalseg::init();
  6300. $segList = Jieba::cut($data['keyword']);
  6301. $segList1 = array_slice($segList, 0, 8);
  6302. $data['keyword'] = implode(',', $segList1);
  6303. }
  6304. if ($data['description'] == '') {
  6305. //提取内容中的描述
  6306. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6307. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6308. }
  6309. var_dump($data, '--');
  6310. if ($data['status'] == 1) {
  6311. $this->sendMessage([
  6312. 'talk_type' => 400,
  6313. 'title' => $data['title'],
  6314. 'content' => '提交了审核',
  6315. 'messageType' => 7,
  6316. ]);
  6317. }
  6318. $result = Book::insertGetId($data);
  6319. if (empty($result)) {
  6320. return Result::error("添加失败", 0);
  6321. }
  6322. return Result::success($result);
  6323. }
  6324. public function getBookList(array $data): array
  6325. {
  6326. $where = [];
  6327. if (!empty($data["title"])) {
  6328. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  6329. }
  6330. if (!empty($data['website_name'])) {
  6331. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  6332. }
  6333. if (!empty($data['status'])) {
  6334. $where[] = ['book.status', '=', $data['status']];
  6335. }
  6336. $user_id = $data['user_id'];
  6337. $type_id = $data['type_id'];
  6338. // $type_id = 4;
  6339. var_dump($type_id, '------1--------');
  6340. if ($type_id != 10000) {
  6341. $where[] = ['book.user_id', '=', $user_id];
  6342. }
  6343. var_dump(!empty($data['status1']), '=-===1');
  6344. $result = Book::where($where)
  6345. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  6346. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  6347. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  6348. ->when(isset($data['status1']), function ($query) use ($data) {
  6349. $query->whereIn('book.status', [1, 3]);
  6350. })
  6351. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  6352. ->orderBy("updated_at", "desc")
  6353. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  6354. if (empty($result)) {
  6355. return Result::error("暂无数据", 0);
  6356. }
  6357. // 取出数据
  6358. $rows = $result->items();
  6359. $count = $result->total();
  6360. $responseData = [
  6361. 'rows' => $rows,
  6362. 'count' => $count,
  6363. ];
  6364. return Result::success($responseData);
  6365. }
  6366. public function deleteBook(array $data): array
  6367. {
  6368. $result = Book::where('id', $data['id'])->delete();
  6369. if (empty($result)) {
  6370. return Result::error("删除失败", 0);
  6371. }
  6372. return Result::success($result);
  6373. }
  6374. public function updateBook(array $data): array
  6375. {
  6376. // $user_id = $data['user_id'] ?? 0;
  6377. $type_id = $data['type_id'] ?? 0;
  6378. // $website_id = $data['website_id'] ?? 0;
  6379. unset($data['user_id']);
  6380. unset($data['type_id']);
  6381. // unset($data['website_id']);
  6382. //处理数组
  6383. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6384. if ($data['img_url'] == '') {
  6385. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6386. preg_match_all($reg, $data['detail'], $matches);
  6387. if (isset($matches[1][0])) {
  6388. //截取varchar240
  6389. $data['img_url'] = substr($matches[1][0], 0, 240);
  6390. }
  6391. }
  6392. if ($data['keyword'] == '') {
  6393. //提取标题+内容中的关键词
  6394. $data['keyword'] = $data['title'];
  6395. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6396. Jieba::init(); // 初始化 jieba-php
  6397. Finalseg::init();
  6398. $segList = Jieba::cut($data['keyword']);
  6399. $segList1 = array_slice($segList, 0, 8);
  6400. $data['keyword'] = implode(',', $segList1);
  6401. }
  6402. if ($data['description'] == '') {
  6403. //提取内容中的描述
  6404. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6405. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6406. }
  6407. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6408. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6409. if ($data['status'] == 1) {
  6410. $this->sendMessage([
  6411. 'talk_type' => 400,
  6412. 'title' => $data['title'],
  6413. 'content' => '提交了审核',
  6414. 'messageType' => 7,
  6415. ]);
  6416. }
  6417. $result = Book::where("id", $data["id"])->update($data);
  6418. if (empty($result)) {
  6419. return Result::error("更新失败", 0);
  6420. }
  6421. return Result::success($result);
  6422. }
  6423. public function getBookInfo(array $data): array
  6424. {
  6425. $result = Book::where("id", $data["id"])->first();
  6426. if (empty($result)) {
  6427. return Result::error("获取失败", 0);
  6428. }
  6429. return Result::success($result);
  6430. }
  6431. public function updateBookStatus(array $data): array
  6432. {
  6433. //审核
  6434. unset($data['user_id']);
  6435. $bookInfo = Book::where("id", $data["id"])->first();
  6436. var_dump($bookInfo, '----');
  6437. if ($data['status'] == 2) {
  6438. $this->sendMessage([
  6439. 'talk_type' => 401,
  6440. 'title' => $bookInfo['title'],
  6441. 'content' => '审核通过',
  6442. 'messageType' => 7,
  6443. 'user_id' => $bookInfo['user_id'],
  6444. ]);
  6445. }
  6446. if ($data['status'] == 3) {
  6447. $this->sendMessage([
  6448. 'talk_type' => 401,
  6449. 'title' => $bookInfo['title'],
  6450. 'content' => '审核拒绝',
  6451. 'messageType' => 7,
  6452. 'user_id' => $bookInfo['user_id'],
  6453. ]);
  6454. }
  6455. if ($data['status'] == 1) {
  6456. $this->sendMessage([
  6457. 'talk_type' => 400,
  6458. 'title' => $bookInfo['title'],
  6459. 'content' => '提交了审核',
  6460. 'messageType' => 7,
  6461. // 'user_id'=>$bookInfo['user_id'],
  6462. ]);
  6463. }
  6464. $result = Book::where("id", $data["id"])->update($data);
  6465. if (empty($result)) {
  6466. return Result::error("更新失败", 0);
  6467. }
  6468. return Result::success($result);
  6469. }
  6470. //20250422 书刊音像
  6471. /**
  6472. * 贴身宝贝
  6473. * @param array $data
  6474. * @return array
  6475. */
  6476. public function getWebsiteTsbb(array $data): array
  6477. {
  6478. $month = $data['month'] ?? date('m');
  6479. $day = $data['day'] ?? date('d');
  6480. // 使用缓存键
  6481. $cacheKey = "tsbb_data_{$month}_{$day}";
  6482. // 尝试从缓存获取数据
  6483. $container = \Hyperf\Context\ApplicationContext::getContainer();
  6484. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  6485. if ($cachedData = $cache->get($cacheKey)) {
  6486. return Result::success(unserialize($cachedData));
  6487. }
  6488. //查询老黄历
  6489. try {
  6490. $date = date('Y-m-d');
  6491. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  6492. // 使用 curl 替代 file_get_contents
  6493. $ch = curl_init();
  6494. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  6495. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  6496. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  6497. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  6498. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  6499. 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');
  6500. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  6501. 'Accept: application/json',
  6502. 'Content-Type: application/json',
  6503. 'Referer: https://www.36jxs.com/'
  6504. ]);
  6505. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  6506. curl_setopt($ch, CURLOPT_ENCODING, '');
  6507. $almanacResponse = curl_exec($ch);
  6508. var_dump("====:", $almanacResponse);
  6509. if (curl_errno($ch)) {
  6510. var_dump('Curl error:', curl_error($ch));
  6511. throw new \Exception('Curl error: ' . curl_error($ch));
  6512. }
  6513. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  6514. curl_close($ch);
  6515. if ($almanacResponse === false) {
  6516. throw new \Exception('Failed to fetch almanac data');
  6517. }
  6518. $almanacData = json_decode($almanacResponse, true);
  6519. if (json_last_error() !== JSON_ERROR_NONE) {
  6520. throw new \Exception('Failed to parse almanac data');
  6521. }
  6522. $almanacInfo = $almanacData['data'] ?? [];
  6523. } catch (\Exception $e) {
  6524. var_dump('Exception:', $e->getMessage());
  6525. $almanacInfo = [];
  6526. }
  6527. // 获取历史上的今天数据
  6528. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6529. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  6530. ->orderBy('year', 'asc')
  6531. ->select("title", "id", "year", DB::raw('1 as type'))
  6532. ->limit(16)
  6533. ->get();
  6534. // 获取节日数据 - 从今天开始获取未来4条
  6535. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  6536. ->orderBy('showtime', 'asc')
  6537. ->select("title", "id", "showtime", DB::raw('2 as type'))
  6538. ->limit(16)
  6539. ->get();
  6540. //说文解字
  6541. $chartacterList = Character::orderBy('updated_at', 'desc')
  6542. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  6543. ->limit(6)
  6544. ->get();
  6545. //谜语沙龙
  6546. $riddletList = Riddle::orderBy('updated_at', 'desc')
  6547. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  6548. ->limit(4)
  6549. ->get();
  6550. //成语欣赏
  6551. $idiomList = Idiom::orderBy('updated_at', 'desc')
  6552. ->select("id", "title", "duyin", DB::raw('5 as type'))
  6553. ->limit(32)
  6554. ->get();
  6555. //名联赏析
  6556. $coupletList = Couplet::orderBy('updated_at', 'desc')
  6557. ->select("id", "first", "second", DB::raw('6 as type'))
  6558. ->limit(6)
  6559. ->get();
  6560. // 获取分类文章数据
  6561. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  6562. ->pluck('category_id')
  6563. ->toArray();
  6564. $articlesList = [];
  6565. foreach ($categoryIds as $catid) {
  6566. // 先查有图片的
  6567. $withImg = DB::table('article')
  6568. ->where('status', 1)
  6569. ->where('catid', $catid)
  6570. ->whereNotNull('imgurl')
  6571. ->where('imgurl', '!=', '')
  6572. ->orderBy('updated_at', 'desc')
  6573. ->limit(6)
  6574. ->get();
  6575. $count = $withImg->count();
  6576. if ($count < 6) {
  6577. // 不足6条再查无图片的补足
  6578. $withoutImg = DB::table('article')
  6579. ->where('status', 1)
  6580. ->where('catid', $catid)
  6581. ->where(function ($q) {
  6582. $q->whereNull('imgurl')->orWhere('imgurl', '');
  6583. })
  6584. ->orderBy('updated_at', 'desc')
  6585. ->limit(6 - $count)
  6586. ->get();
  6587. $articles = $withImg->concat($withoutImg);
  6588. } else {
  6589. $articles = $withImg;
  6590. }
  6591. // 组装
  6592. $category = \App\Model\Category::find($catid);
  6593. $websiteCategory = WebsiteCategory::where('category_id', $catid)->first();
  6594. $articlesList[] = [
  6595. 'category_name' => $category ? $category->name : '',
  6596. 'catid' => $catid,
  6597. 'pinyin' => $websiteCategory ? $websiteCategory->aLIas_pinyin : '',
  6598. 'type' => 100,
  6599. 'list' => $articles->map(function ($item) {
  6600. return [
  6601. 'id' => $item->id,
  6602. 'title' => $item->title,
  6603. 'imgurl' => $item->imgurl,
  6604. 'created_at' => $item->created_at
  6605. ];
  6606. })->values()
  6607. ];
  6608. }
  6609. $result = [
  6610. 'almanac' => $almanacInfo,
  6611. 'historyTodayList' => [
  6612. 'category_name' => '历史上的今天',
  6613. 'list' => $historyTodayList,
  6614. 'type' => 1
  6615. ],
  6616. 'festivalList' => [
  6617. 'category_name' => '节日预告',
  6618. 'list' => $festivalList,
  6619. 'type' => 2
  6620. ],
  6621. 'chartacterList' => [
  6622. 'category_name' => '说文解字',
  6623. 'list' => $chartacterList,
  6624. 'type' => 3
  6625. ],
  6626. 'coupletList' => [
  6627. 'category_name' => '名联赏析',
  6628. 'list' => $coupletList,
  6629. 'type' => 6
  6630. ],
  6631. 'riddletList' => [
  6632. 'category_name' => '谜语沙龙',
  6633. 'list' => $riddletList,
  6634. 'type' => 4
  6635. ],
  6636. 'idiomList' => [
  6637. 'category_name' => '成语欣赏',
  6638. 'list' => $idiomList,
  6639. 'type' => 5
  6640. ],
  6641. 'articlesList' => $articlesList
  6642. ];
  6643. // 缓存结果,设置1小时过期
  6644. $cache->set($cacheKey, serialize($result), 3600);
  6645. return Result::success($result);
  6646. }
  6647. /**
  6648. * 获取资讯列表
  6649. */
  6650. public function getWebsiteTsbbList(array $data): array
  6651. {
  6652. $page = $data['page'] ?? 1;
  6653. $pageSize = $data['pageSize'] ?? 10;
  6654. // 如果没有传入月份和日期,则使用今天的日期
  6655. $month = $data['month'] ?? date('m');
  6656. $day = $data['day'] ?? date('d');
  6657. $total = 0;
  6658. $result = [];
  6659. $data['type'] = intval($data['type']);
  6660. var_dump("接收参数:", $data);
  6661. switch ($data['type']) {
  6662. case 1:
  6663. $query = HistoryToday::where(function ($q) use ($month, $day) {
  6664. // 当前月份之后的数据
  6665. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  6666. // 或者当前月份且日期大于等于当前日期的数据
  6667. ->orWhere(function ($q) use ($month, $day) {
  6668. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6669. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  6670. });
  6671. })
  6672. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  6673. $total = $query->count();
  6674. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  6675. ->offset(($page - 1) * $pageSize)
  6676. ->limit($pageSize)
  6677. ->get();
  6678. break;
  6679. case 2:
  6680. $query = Festival::where(function ($q) use ($month, $day) {
  6681. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  6682. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  6683. ->orWhere(function ($q) use ($month, $day) {
  6684. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  6685. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  6686. });
  6687. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  6688. $total = $query->count();
  6689. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  6690. ->offset(($page - 1) * $pageSize)
  6691. ->limit($pageSize)
  6692. ->get();
  6693. break;
  6694. case 3:
  6695. $query = Character::orderBy("updated_at", "desc");
  6696. $total = $query->count();
  6697. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  6698. ->offset(($page - 1) * $pageSize)
  6699. ->limit($pageSize)
  6700. ->get();
  6701. break;
  6702. case 4:
  6703. $query = Riddle::orderBy("updated_at", "desc");
  6704. $total = $query->count();
  6705. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  6706. ->offset(($page - 1) * $pageSize)
  6707. ->limit($pageSize)
  6708. ->get();
  6709. break;
  6710. case 5:
  6711. $query = Idiom::orderBy("updated_at", "desc");
  6712. $total = $query->count();
  6713. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  6714. ->offset(($page - 1) * $pageSize)
  6715. ->limit($pageSize)
  6716. ->get();
  6717. break;
  6718. case 6:
  6719. $query = Couplet::orderBy("updated_at", "desc");
  6720. $total = $query->count();
  6721. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  6722. ->offset(($page - 1) * $pageSize)
  6723. ->limit($pageSize)
  6724. ->get();
  6725. break;
  6726. default:
  6727. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  6728. $total = $query->count();
  6729. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  6730. ->offset(($page - 1) * $pageSize)
  6731. ->limit($pageSize)
  6732. ->get();
  6733. }
  6734. return Result::success([
  6735. 'list' => $result,
  6736. 'total' => $total,
  6737. 'page' => (int)$page,
  6738. 'pageSize' => (int)$pageSize,
  6739. 'month' => $month,
  6740. 'day' => $day
  6741. ]);
  6742. }
  6743. /**
  6744. * 1:历史上的今天
  6745. * 2:节日
  6746. * 3:文章
  6747. *
  6748. * 资讯详情信息
  6749. */
  6750. public function getWebsiteTsbbDetail(array $data): array
  6751. {
  6752. $data['type'] = intval($data['type']);
  6753. switch ($data['type']) {
  6754. case 1:
  6755. $result = HistoryToday::where("id", $data['id'])->first();
  6756. break;
  6757. case 2:
  6758. $result = Festival::where("id", $data['id'])->first();
  6759. break;
  6760. case 3:
  6761. $result = Character::where("id", $data['id'])->first();
  6762. break;
  6763. case 4:
  6764. $result = Riddle::where("id", $data['id'])->first();
  6765. break;
  6766. case 5:
  6767. $result = Idiom::where("id", $data['id'])->first();
  6768. break;
  6769. case 6:
  6770. $result = Couplet::where("id", $data['id'])->first();
  6771. break;
  6772. default:
  6773. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  6774. break;
  6775. }
  6776. return Result::success($result);
  6777. }
  6778. /**
  6779. * 农网导航首页数据
  6780. */
  6781. public function getWebsiteNwHomeList(array $data): array
  6782. {
  6783. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  6784. ->pluck('category_id')
  6785. ->toArray();
  6786. // 使用子查询优化
  6787. $articlesList = DB::table('article')
  6788. ->select([
  6789. 'article.id',
  6790. 'article.title',
  6791. 'article.imgurl',
  6792. 'article.created_at',
  6793. 'category.name as category_name',
  6794. 'category.id as category_id',
  6795. 'website_category.aLIas_pinyin as pinyin',
  6796. 'parent_wc.aLIas_pinyin as parent_pinyin',
  6797. DB::raw('100 as type')
  6798. ])
  6799. ->join('category', 'article.catid', '=', 'category.id')
  6800. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  6801. ->leftJoin('website_category as parent_wc', function ($join) {
  6802. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  6803. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  6804. })
  6805. ->where('website_category.website_id', $data['website_id'])
  6806. ->where('article.status', 1)
  6807. ->whereIn('category.id', $categoryIds)
  6808. ->orderBy('article.created_at', 'desc')
  6809. ->get()
  6810. ->groupBy('category_id')
  6811. ->map(function ($group) {
  6812. // 确保第一条数据有图片
  6813. $firstWithImage = $group->first(function ($item) {
  6814. return !empty($item->imgurl);
  6815. });
  6816. if ($firstWithImage) {
  6817. // 如果有带图片的文章,将其放在第一位
  6818. $group = $group->filter(function ($item) use ($firstWithImage) {
  6819. return $item->id !== $firstWithImage->id;
  6820. })->prepend($firstWithImage);
  6821. }
  6822. return [
  6823. 'category_name' => $group->first()->category_name,
  6824. 'catid' => $group->first()->category_id,
  6825. 'pinyin' => $group->first()->pinyin,
  6826. 'parent_pinyin' => $group->first()->parent_pinyin,
  6827. 'list' => $group->take(4)->map(function ($item) {
  6828. return [
  6829. 'id' => $item->id,
  6830. 'title' => $item->title,
  6831. ];
  6832. })->values()
  6833. ];
  6834. })
  6835. ->values()
  6836. ->toArray();
  6837. return Result::success($articlesList);
  6838. }
  6839. /**
  6840. * 企业管理
  6841. * @param array $data
  6842. * @return array
  6843. */
  6844. public function getCompanyList(array $data): array
  6845. {
  6846. // return Result::success($data);
  6847. $where = [];
  6848. $user = User::where('id', $data['user_id'])->first();
  6849. if (empty($user)) {
  6850. return Result::error('用户不存在!');
  6851. }
  6852. if ($user['type_id'] != 10000) {
  6853. $where['user_id'] = $data['user_id'];
  6854. }
  6855. if (isset($data['title']) && !empty($data['title'])) {
  6856. array_push($where, ['company.title', 'like', '%' . $data['title'] . '%']);
  6857. }
  6858. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6859. array_push($where, ['website.id', $data['website_id']]);
  6860. }
  6861. if (isset($data['ischeck']) && !empty($data['ischeck'])) {
  6862. if ($data['ischeck'] == 1) {
  6863. if (isset($data['status']) && $data['status'] != '') {
  6864. array_push($where, ['company.status', $data['status']]);
  6865. $query = Company::where($where);
  6866. } else {
  6867. $query = Company::whereIn('company.status', [0, 2]);
  6868. }
  6869. } else {
  6870. $query = Company::where('company.status', 1);
  6871. }
  6872. }
  6873. $result = $query->where($where)
  6874. ->leftJoin('website_category', function ($query) {
  6875. $query->on('website_category.category_id', '=', 'company.category_id')
  6876. ->on('website_category.website_id', '=', 'company.website_id');
  6877. })
  6878. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  6879. ->select(
  6880. 'company.id',
  6881. 'company.title',
  6882. 'company.website_id',
  6883. 'company.category_id',
  6884. 'website.website_name',
  6885. 'website_category.alias as category_name',
  6886. 'company.status',
  6887. 'company.updated_at',
  6888. 'company.user_id'
  6889. )
  6890. ->orderBy('company.updated_at', 'desc')
  6891. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  6892. if ($result->isEmpty()) {
  6893. return Result::error("暂无企业", 0);
  6894. }
  6895. return Result::success($result);
  6896. }
  6897. /**
  6898. * 添加企业
  6899. * @param array $data
  6900. * @return array
  6901. */
  6902. public function addCompany(array $data): array
  6903. {
  6904. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  6905. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6906. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6907. $data['cat_arr_id'] = json_encode($car_arr_id);
  6908. } else {
  6909. $data['cat_arr_id'] = '';
  6910. }
  6911. if ($data['imgurl'] == '') {
  6912. //content中提取图片第一个图,正则提取
  6913. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6914. preg_match_all($reg, $data['content'], $matches);
  6915. if (isset($matches[1][0])) {
  6916. //截取varchar240
  6917. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6918. }
  6919. }
  6920. if ($data['keyword'] == '') {
  6921. //提取标题+内容中的关键词
  6922. $data['keyword'] = $data['title'];
  6923. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6924. Jieba::init(); // 初始化 jieba-php
  6925. Finalseg::init();
  6926. $segList = Jieba::cut($data['keyword']);
  6927. $segList1 = array_slice($segList, 0, 8);
  6928. $data['keyword'] = implode(',', $segList1);
  6929. }
  6930. if ($data['introduce'] == '' || empty($data['introduce'])) {
  6931. //提取内容中的描述
  6932. $content = $data['content'];
  6933. // 去除 <style> 和 <script> 标签及其内容
  6934. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6935. // 去除所有 HTML 标签
  6936. $content = strip_tags($content);
  6937. // 去除 HTML 实体
  6938. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6939. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6940. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6941. // 去除多余空白
  6942. $content = preg_replace('/\s+/u', '', $content);
  6943. // 截取 100 个字符
  6944. $data['introduce'] = mb_substr($content, 0, 100);
  6945. }
  6946. $user = User::where('id', $data['user_id'])->first();
  6947. if (empty($user)) {
  6948. return Result::error('用户不存在!');
  6949. }
  6950. if ($user['type_id'] == 10000) {
  6951. $data['status'] = 1;
  6952. }
  6953. if (isset($data['level']) && $data['level'] != null) {
  6954. $data['level'] = intval($data['level']);
  6955. } else {
  6956. $data['level'] = null;
  6957. }
  6958. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  6959. $this->sendMessage([
  6960. 'talk_type' => 900,
  6961. 'title' => $data['title'],
  6962. 'content' => '提交了审核',
  6963. 'messageType' => 8,
  6964. ]);
  6965. }
  6966. $result = Company::insertGetId($data);
  6967. if ($result) {
  6968. return Result::success($result);
  6969. } else {
  6970. return Result::error('添加失败');
  6971. }
  6972. }
  6973. /**
  6974. * 更新企业
  6975. * @param array $data
  6976. * @return array
  6977. */
  6978. public function upCompany(array $data): array
  6979. {
  6980. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6981. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6982. $data['cat_arr_id'] = json_encode($car_arr_id);
  6983. $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
  6984. } else {
  6985. $data['cat_arr_id'] = '';
  6986. }
  6987. if ($data['imgurl'] == '') {
  6988. //content中提取图片第一个图,正则提取
  6989. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6990. preg_match_all($reg, $data['content'], $matches);
  6991. if (isset($matches[1][0])) {
  6992. //截取varchar
  6993. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6994. }
  6995. }
  6996. if ($data['keyword'] == '') {
  6997. //提取标题+内容中的关键词
  6998. $data['keyword'] = $data['title'];
  6999. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7000. Jieba::init(); // 初始化 jieba-php
  7001. Finalseg::init();
  7002. $segList = Jieba::cut($data['keyword']);
  7003. $segList1 = array_slice($segList, 0, 8);
  7004. $data['keyword'] = implode(',', $segList1);
  7005. }
  7006. if ($data['introduce'] == '') {
  7007. //提取内容中的描述
  7008. $content = $data['content'];
  7009. // 去除 <style> 和 <script> 标签及其内容
  7010. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7011. // 去除所有 HTML 标签
  7012. $content = strip_tags($content);
  7013. // 去除 HTML 实体
  7014. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7015. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7016. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7017. // 去除多余空白
  7018. $content = preg_replace('/\s+/u', '', $content);
  7019. // 截取 100 个字符
  7020. $data['introduce'] = mb_substr($content, 0, 100);
  7021. }
  7022. if (isset($data['level']) && $data['level'] != null) {
  7023. $data['level'] = intval($data['level']);
  7024. } else {
  7025. $data['level'] = null;
  7026. }
  7027. $user = User::where('id', $data['user_id'])->first();
  7028. if (empty($user)) {
  7029. return Result::error('用户不存在!');
  7030. }
  7031. if ($user['type_id'] == 10000) {
  7032. $data['status'] = 1;
  7033. } else {
  7034. $data['status'] = 0;
  7035. }
  7036. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  7037. $this->sendMessage([
  7038. 'talk_type' => 900,
  7039. 'title' => $data['title'],
  7040. 'content' => '提交了审核',
  7041. 'messageType' => 8,
  7042. ]);
  7043. }
  7044. $result = Company::where('id', $data['id'])->update($data);
  7045. if ($result) {
  7046. return Result::success($result);
  7047. } else {
  7048. return Result::error('修改失败');
  7049. }
  7050. }
  7051. /**
  7052. * 删除企业
  7053. * @param array $data
  7054. * @return array
  7055. */
  7056. public function delCompany(array $data): array
  7057. {
  7058. $result = Company::where('id', $data['id'])->delete();
  7059. if ($result) {
  7060. return Result::success($result);
  7061. } else {
  7062. return Result::error('删除失败');
  7063. }
  7064. }
  7065. /**
  7066. * 审核企业
  7067. * @param array $data
  7068. * @return array
  7069. */
  7070. public function checkCompany(array $data): array
  7071. {
  7072. $user = User::where('id', $data['user_id'])->first();
  7073. if (empty($user)) {
  7074. return Result::error('用户不存在!');
  7075. }
  7076. $company = Company::where('id', $data['id'])->first();
  7077. if (empty($company)) {
  7078. return Result::error('企业不存在!');
  7079. }
  7080. // 状态:0:未审核 1:已审核 2:已拒绝
  7081. if ($data['status'] == 2 || $data['status'] == '2') {
  7082. $this->sendMessage([
  7083. 'talk_type' => 901,
  7084. 'title' => $company['title'],
  7085. 'content' => '审核拒绝',
  7086. 'messageType' => 8,
  7087. 'user_id' => $company['user_id'],
  7088. ]);
  7089. $result = Company::where('id', $data['id'])->update(['status' => $data['status'], 'reject_reason' => $data['reason']]);
  7090. } else {
  7091. if ($data['status'] == 1) {
  7092. $this->sendMessage([
  7093. 'talk_type' => 901,
  7094. 'title' => $company['title'],
  7095. 'content' => '审核通过',
  7096. 'messageType' => 8,
  7097. 'user_id' => $company['user_id'],
  7098. ]);
  7099. } else if ($data['status'] == 0) {
  7100. $this->sendMessage([
  7101. 'talk_type' => 900,
  7102. 'title' => $company['title'],
  7103. 'content' => '提交了审核',
  7104. 'messageType' => 8,
  7105. ]);
  7106. }
  7107. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  7108. }
  7109. if (empty($result)) {
  7110. return Result::error('审核失败!');
  7111. } else {
  7112. return Result::success($result);
  7113. }
  7114. }
  7115. /**
  7116. * 获取企业信息
  7117. * @param array $data
  7118. * @return array
  7119. */
  7120. public function getCompanyInfo(array $data): array
  7121. {
  7122. $result = Company::where('id', $data['id'])->first();
  7123. $city_arr = json_decode($result['city_arr_id']);
  7124. $result['city_name'] = District::whereIn('id', $city_arr)
  7125. ->pluck('name')
  7126. ->implode('-');
  7127. if (empty($result)) {
  7128. return Result::error('企业不存在!');
  7129. } else {
  7130. return Result::success($result);
  7131. }
  7132. }
  7133. /**
  7134. * @param array $data
  7135. * @return array
  7136. */
  7137. public function getWebsiteCompany(array $data): array
  7138. {
  7139. $categorys = json_decode($data['id'], true);
  7140. $category_arr = $this->processArticlePro($data['website_id']);
  7141. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7142. $catiall = $category_arr['catiall'];
  7143. $categoryIds = $category_arr['categoryIds'];
  7144. // return Result::success($category_arr);
  7145. foreach ($categorys as $key => $value) {
  7146. if (array_key_exists('level', $value)) {
  7147. $parts = explode(',', $value['level']);
  7148. $level = $parts[0] ?? null;
  7149. $imgnum = $parts[1] ?? null;
  7150. $textnum = $parts[2] ?? null;
  7151. if (!empty($textnum) && $textnum > 0) {
  7152. $text_num = Company::where('level', $level)
  7153. ->whereIn('category_id', $categoryIds)
  7154. ->where('status', 1)
  7155. ->select(
  7156. 'company.id',
  7157. 'company.title',
  7158. 'company.description',
  7159. 'company.updated_at',
  7160. 'company.category_id',
  7161. 'company.cat_arr_id'
  7162. )
  7163. ->orderBy('updated_at', 'desc')
  7164. ->limit($textnum)
  7165. ->get()->all();
  7166. }
  7167. if (!empty($imgnum) && $imgnum > 0) {
  7168. $img_num = Company::where('level', $level)
  7169. ->whereIn('category_id', $categoryIds)
  7170. ->where('status', 1)
  7171. ->where('imgurl', '!=', '')
  7172. ->whereNotNull('imgurl')
  7173. ->select(
  7174. 'company.id',
  7175. 'company.title',
  7176. 'company.description',
  7177. 'company.updated_at',
  7178. 'company.imgurl as imgs',
  7179. 'company.category_id',
  7180. 'company.cat_arr_id'
  7181. )
  7182. ->orderBy('updated_at', 'desc')
  7183. ->limit($imgnum)
  7184. ->get()->all();
  7185. }
  7186. }
  7187. if (array_key_exists('id', $value)) {
  7188. $parts = explode(',', $value['id']);
  7189. $category_id = $parts[0] ?? null;
  7190. $imgnum = $parts[1] ?? null;
  7191. $textnum = $parts[2] ?? null;
  7192. $category_arr = array_merge([$category_id], $cat_1st_arr[$category_id] ?? [0]);
  7193. if (!empty($textnum) && $textnum > 0) {
  7194. $text_num = Company::whereIn('category_id', $category_arr)
  7195. // ->where('website_id', $data['website_id'])
  7196. ->where('status', 1)
  7197. ->select(
  7198. 'company.id',
  7199. 'company.title',
  7200. 'company.description',
  7201. 'company.updated_at',
  7202. 'company.category_id',
  7203. 'company.cat_arr_id'
  7204. )
  7205. ->orderBy('updated_at', 'desc')
  7206. ->limit($textnum)
  7207. ->get()->all();
  7208. }
  7209. if (!empty($imgnum) && $imgnum > 0) {
  7210. $img_num = Company::whereIn('category_id', $category_arr)
  7211. // ->where('website_id', $data['website_id'])
  7212. ->where('status', 1)
  7213. ->where('imgurl', '!=', '')
  7214. ->whereNotNull('imgurl')
  7215. ->select(
  7216. 'company.id',
  7217. 'company.title',
  7218. 'company.description',
  7219. 'company.updated_at',
  7220. 'company.imgurl as imgs',
  7221. 'company.category_id',
  7222. 'company.cat_arr_id'
  7223. )
  7224. ->orderBy('updated_at', 'desc')
  7225. ->limit($imgnum)
  7226. ->get()->all();
  7227. }
  7228. }
  7229. if (!empty($text_num)) {
  7230. foreach ($text_num as $k => $v) {
  7231. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7232. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7233. }
  7234. }
  7235. if (!empty($img_num)) {
  7236. foreach ($img_num as $k => $v) {
  7237. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7238. $imgurl = json_decode($v['imgs'], true);
  7239. if (!empty($imgurl)) {
  7240. $img_num[$k]->imgurl = $imgurl[0];
  7241. }
  7242. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7243. }
  7244. }
  7245. $company[$key]['img_num'] = $img_num ?? [];
  7246. $company[$key]['text_num'] = $text_num ?? [];
  7247. }
  7248. if (empty($company)) {
  7249. return Result::error("暂无相关企业信息", 0);
  7250. }
  7251. return Result::success($company);
  7252. }
  7253. /**
  7254. * @param array $data
  7255. * @return array
  7256. */
  7257. public function getWebsiteCompanyList(array $data): array
  7258. {
  7259. $where['website_id'] = $data['website_id'];
  7260. $where['status'] = 1;
  7261. $categoryIds = [];
  7262. if (isset($data['category_id']) && !empty($data['category_id'])) {
  7263. $category_id = $data['category_id'];
  7264. }
  7265. $category_arr = $this->processArticlePro($data['website_id']);
  7266. $categoryIds = $category_arr['categoryIds'];
  7267. // return Result::success($cat_1st_arr);
  7268. $company = Company::when(isset($data['keyword']) && !empty($data['keyword']), function ($query) use ($data) {
  7269. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  7270. })
  7271. ->when(!isset($category_id) || empty($category_id), function ($query) use ($categoryIds) {
  7272. $query->whereIn('category_id', $categoryIds);
  7273. })
  7274. ->when(isset($data['category_id']) && !empty($data['category_id']), function ($query) use ($category_id) {
  7275. $query->where('category_id', $category_id);
  7276. })
  7277. ->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id', 'updated_at')
  7278. ->orderBy('updated_at', 'desc')
  7279. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  7280. if (empty($company)) {
  7281. return Result::error("暂无相关公司信息", 0);
  7282. }
  7283. $result = [
  7284. 'count' => $company->total(),
  7285. 'data' => $company->items(), // 使用 items() 方法替代不存在的 data() 方法
  7286. ];
  7287. return Result::success($result);
  7288. }
  7289. /**
  7290. * 获取项目列表
  7291. * @param array $data
  7292. * @return array
  7293. */
  7294. public function getProjectList(array $data): array
  7295. {
  7296. $where = [];
  7297. $user = User::where('id', $data['user_id'])->first();
  7298. if (empty($user)) {
  7299. return Result::error('用户不存在!');
  7300. }
  7301. if ($user->type_id != 10000) {
  7302. array_push($where, ['project.user_id', $data['user_id']]);
  7303. }
  7304. $query = Project::query();
  7305. if (isset($data['website_id']) && !empty($data['website_id'])) {
  7306. array_push($where, ['project.website_id', $data['website_id']]);
  7307. }
  7308. if (isset($data['title']) && !empty($data['title'])) {
  7309. array_push($where, ['project.title', 'like', '%' . $data['title'] . '%']);
  7310. }
  7311. if ($data['status'] != 3) {
  7312. array_push($where, ['project.status', $data['status']]);
  7313. }
  7314. $query = Project::where($where)
  7315. ->when($data['status'] == 3, function ($query) {
  7316. $query->whereIn('project.status', [0, 2]);
  7317. });
  7318. $count = $query->clone()
  7319. ->count();
  7320. $rows = $query->clone()
  7321. ->leftJoin('website', 'project.website_id', 'website.id')
  7322. ->leftJoin('website_category', function ($join) {
  7323. $join->on('project.website_id', '=', 'website_category.website_id')
  7324. ->on('project.category_id', '=', 'website_category.category_id');
  7325. })
  7326. ->select(
  7327. 'project.id',
  7328. 'project.title',
  7329. 'project.updated_at',
  7330. 'project.status',
  7331. 'website.website_name',
  7332. 'website_category.alias as category_name',
  7333. 'project.website_id',
  7334. 'project.user_id'
  7335. )
  7336. ->orderBy('project.updated_at', 'desc')
  7337. ->offset(($data['page'] - 1) * $data['pageSize'])
  7338. ->limit($data['pageSize'])
  7339. ->get();
  7340. if ($rows->isEmpty()) {
  7341. return Result::error("暂无相关项目信息", 0);
  7342. }
  7343. $result = [
  7344. 'count' => $count,
  7345. 'rows' => $rows,
  7346. ];
  7347. return Result::success($result);
  7348. }
  7349. /**
  7350. * 添加项目
  7351. * @param array $data
  7352. * @return array
  7353. */
  7354. public function addProject(array $data): array
  7355. {
  7356. $user = User::where('id', $data['user_id'])->first();
  7357. if (empty($user)) {
  7358. return Result::error("暂无相关用户信息", 0);
  7359. }
  7360. if ($user->type_id == 10000) {
  7361. $data['status'] = 1;
  7362. } else {
  7363. $data['status'] = 0;
  7364. }
  7365. if ($data['keyword'] == '') {
  7366. //提取标题+内容中的关键词
  7367. $data['keyword'] = $data['title'];
  7368. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7369. Jieba::init(); // 初始化 jieba-php
  7370. Finalseg::init();
  7371. $segList = Jieba::cut($data['keyword']);
  7372. $segList1 = array_slice($segList, 0, 8);
  7373. $data['keyword'] = implode(',', $segList1);
  7374. }
  7375. if ($data['description'] == '') {
  7376. //提取内容中的描述
  7377. // var_dump(11111);
  7378. //提取内容中的描述
  7379. $content = $data['introduce'];
  7380. // 去除 <style> 和 <script> 标签及其内容
  7381. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7382. // 去除所有 HTML 标签
  7383. $content = strip_tags($content);
  7384. // 去除 HTML 实体
  7385. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7386. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7387. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7388. // 去除多余空白
  7389. $content = preg_replace('/\s+/u', '', $content);
  7390. // 截取 100 个字符
  7391. $data['description'] = mb_substr($content, 0, 100);
  7392. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7393. }
  7394. if ($data['status'] == 0) {
  7395. $this->sendMessage([
  7396. 'talk_type' => 1000,
  7397. 'title' => $data['title'],
  7398. 'content' => '提交了审核',
  7399. 'messageType' => 9,
  7400. ]);
  7401. }
  7402. $project = Project::insertGetId($data);
  7403. if (empty($project)) {
  7404. return Result::error("暂无相关项目信息", 0);
  7405. }
  7406. return Result::success($project);
  7407. }
  7408. /**
  7409. * 更新项目
  7410. * @param array $data
  7411. * @return array
  7412. */
  7413. public function upProject(array $data): array
  7414. {
  7415. $project = Project::where('id', $data['id'])->first();
  7416. if (empty($project)) {
  7417. return Result::error("暂无相关项目信息", 0);
  7418. }
  7419. $id = $data['id'];
  7420. unset($data['id']);
  7421. $user = User::where('id', $data['user_id'])->first();
  7422. if (empty($user)) {
  7423. return Result::error("暂无相关用户信息", 0);
  7424. }
  7425. if ($user->type_id == 10000) {
  7426. $data['status'] = 1;
  7427. } else {
  7428. $data['status'] = 0;
  7429. }
  7430. unset($data['user_id']);
  7431. if ($data['keyword'] == '') {
  7432. //提取标题+内容中的关键词
  7433. $data['keyword'] = $data['title'];
  7434. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7435. Jieba::init(); // 初始化 jieba-php
  7436. Finalseg::init();
  7437. $segList = Jieba::cut($data['keyword']);
  7438. $segList1 = array_slice($segList, 0, 8);
  7439. $data['keyword'] = implode(',', $segList1);
  7440. }
  7441. if ($data['description'] == '') {
  7442. //提取内容中的描述
  7443. // var_dump(11111);
  7444. //提取内容中的描述
  7445. $content = $data['introduce'];
  7446. // 去除 <style> 和 <script> 标签及其内容
  7447. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7448. // 去除所有 HTML 标签
  7449. $content = strip_tags($content);
  7450. // 去除 HTML 实体
  7451. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7452. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7453. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7454. // 去除多余空白
  7455. $content = preg_replace('/\s+/u', '', $content);
  7456. // 截取 100 个字符
  7457. $data['description'] = mb_substr($content, 0, 100);
  7458. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7459. }
  7460. if ($data['status'] == 0) {
  7461. $this->sendMessage([
  7462. 'talk_type' => 1000,
  7463. 'title' => $data['title'],
  7464. 'content' => '提交了审核',
  7465. 'messageType' => 9,
  7466. ]);
  7467. }
  7468. $result = Project::where('id', $id)->update($data);
  7469. if (empty($result)) {
  7470. return Result::error("更新失败", 0);
  7471. }
  7472. return Result::success($result);
  7473. }
  7474. /**
  7475. * 删除项目
  7476. * @param array $data
  7477. * @return array
  7478. */
  7479. public function delProject(array $data): array
  7480. {
  7481. $user = User::where('id', $data['user_id'])->first();
  7482. if (empty($user)) {
  7483. return Result::error("暂无相关用户信息", 0);
  7484. }
  7485. $project = Project::where('id', $data['id'])->first();
  7486. if (empty($project)) {
  7487. return Result::error("暂无相关项目信息", 0);
  7488. }
  7489. $result = Project::where('id', $data['id'])->delete();
  7490. if (empty($result)) {
  7491. return Result::error("删除失败", 0);
  7492. }
  7493. return Result::success($result);
  7494. }
  7495. /**
  7496. * 审核项目
  7497. * @param array $data
  7498. * @return array
  7499. */
  7500. public function checkProject(array $data): array
  7501. {
  7502. $user = User::where('id', $data['user_id'])->first();
  7503. if (empty($user)) {
  7504. return Result::error("暂无相关用户信息", 0);
  7505. }
  7506. // 0:未审核; 1:已审核; 2:已拒绝;
  7507. if ($user->type_id != 10000) {
  7508. if ($data['status'] == 1 || $data['status'] == 2) {
  7509. return Result::error("此用户权限不足", 0);
  7510. }
  7511. }
  7512. $project = Project::where('id', $data['id'])->first();
  7513. if (empty($project)) {
  7514. return Result::error("暂无相关项目信息", 0);
  7515. }
  7516. if ($data['status'] == 2) {
  7517. $this->sendMessage([
  7518. 'talk_type' => 1001,
  7519. 'title' => $project['title'],
  7520. 'content' => '审核拒绝',
  7521. 'messageType' => 9,
  7522. 'user_id' => $project['user_id'],
  7523. ]);
  7524. $result = Project::where('id', $data['id'])->update(['status' => $data['status'], 'refuse_reason' => $data['refuse_reason']]);
  7525. } else {
  7526. if ($data['status'] == 1) {
  7527. $this->sendMessage([
  7528. 'talk_type' => 1001,
  7529. 'title' => $project['title'],
  7530. 'content' => '审核通过',
  7531. 'messageType' => 9,
  7532. 'user_id' => $project['user_id'],
  7533. ]);
  7534. } else if ($data['status'] == 0) {
  7535. $this->sendMessage([
  7536. 'talk_type' => 1000,
  7537. 'title' => $project['title'],
  7538. 'content' => '提交了审核',
  7539. 'messageType' => 9,
  7540. ]);
  7541. }
  7542. $result = Project::where('id', $data['id'])->update(['status' => $data['status']]);
  7543. }
  7544. if (empty($result)) {
  7545. return Result::error("审核失败", 0);
  7546. }
  7547. return Result::success($result);
  7548. }
  7549. /**
  7550. * 获取项目详情
  7551. * @param array $data
  7552. * @return array
  7553. */
  7554. public function getProjectInfo(array $data): array
  7555. {
  7556. $project = Project::where('id', $data['id'])->first();
  7557. if (empty($project)) {
  7558. return Result::error("暂无相关项目信息", 0);
  7559. }
  7560. return Result::success($project);
  7561. }
  7562. public function getWebsiteCompanyInfo(array $data): array
  7563. {
  7564. $company = Company::where('id', $data['id'])
  7565. ->leftJoin('job_industry', 'job_industry.hyid', 'company.hy_id')
  7566. ->where('status', 1)
  7567. // ->where('website_id', $data['website_id'])
  7568. ->select('company.*', 'job_industry.hyname as hy_name')
  7569. ->first();
  7570. // 企业性质:0:市场监管;1:信访纪检;2:公检法司;3:高关注机构
  7571. switch ($company->jobnature_id) {
  7572. case null:
  7573. $company->jobnature_name = '';
  7574. break;
  7575. case 0:
  7576. $company->jobnature_name = '市场监督';
  7577. break;
  7578. case 1:
  7579. $company->jobnature_name = '信访纪检';
  7580. break;
  7581. case 2:
  7582. $company->jobnature_name = '公检法司';
  7583. break;
  7584. case 3:
  7585. $company->jobnature_name = '高关注机构';
  7586. break;
  7587. default:
  7588. $company->jobnature_name = '';
  7589. break;
  7590. }
  7591. $city_arr = $company->city_arr_id;
  7592. if (!empty($city_arr)) {
  7593. $city_arr = json_decode($city_arr, true);
  7594. $cityNames = District::whereIn('id', $city_arr)
  7595. ->pluck('name')
  7596. ->implode('-');
  7597. $company->city_name = $cityNames;
  7598. } else {
  7599. $company->city_name = '';
  7600. }
  7601. if (empty($company)) {
  7602. return Result::error("暂无相关公司信息", 0);
  7603. }
  7604. return Result::success($company);
  7605. }
  7606. public function getMSG(array $data): array
  7607. {
  7608. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  7609. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  7610. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  7611. $result = [];
  7612. if ($type_id == 1 or $type_id == 2 or $type_id == 3 or $type_id == 4) {
  7613. //最近的5篇已审的文章
  7614. $apply_articale = Article::where('status', 1)
  7615. ->where('admin_user_id', $user_id)
  7616. ->orderBy('updated_at', 'desc')
  7617. // ->limit(5)
  7618. ->get();
  7619. //获取5条用户的已审核商品
  7620. $good = Good::where('status', 2)
  7621. ->where('user_id', $user_id)
  7622. ->orderBy('updated_at', 'desc')
  7623. // ->limit(5)
  7624. ->get();
  7625. //获取5条用户待审核的公告
  7626. $notice = Notice::where('status', 2)
  7627. ->where('user_id', $user_id)
  7628. ->orderBy('updated_at', 'desc')
  7629. ->limit(5)->get();
  7630. //获取5条用户的待审核投诉
  7631. $complaint = Complaint::where('status', 2)
  7632. ->where('user_id', $user_id)
  7633. ->orderBy('updated_at', 'desc')
  7634. // ->limit(5)
  7635. ->get();
  7636. //获取5条用户的book
  7637. $book = Book::where('status', 2)
  7638. ->where('user_id', $user_id)
  7639. ->orderBy('updated_at', 'desc')
  7640. // ->limit(5)
  7641. ->get();
  7642. //获取5条用户的求职
  7643. //获取5条用户的求职 1
  7644. $job_hunting = JobHunting::where('job_hunting.status', 2)
  7645. ->where('job_hunting.user_id', $user_id)
  7646. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7647. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7648. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7649. ->orderBy('updated_at', 'desc')
  7650. // ->limit(5)
  7651. ->get();
  7652. //获取5条用户的求职 2
  7653. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  7654. ->where('job_recruiting.user_id', $user_id)
  7655. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7656. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7657. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7658. ->orderBy('updated_at', 'desc')
  7659. // ->limit(5)
  7660. ->get();
  7661. //人才库 1
  7662. $job_apply = JobApply::where('job_apply.status', 1)
  7663. ->where('job_apply.receiver_id', $user_id)
  7664. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7665. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7666. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7667. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7668. ->select('job_recruiting', 'job_recruiting.', '', '')
  7669. ->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')
  7670. ->orderBy('updated_at', 'desc')
  7671. // ->limit(5)
  7672. ->get();
  7673. // 职场机会 2
  7674. $job_resume = JobResume::where('job_resume.status', 1)
  7675. ->where('job_resume.receiver_id', $user_id)
  7676. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7677. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7678. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7679. ->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')
  7680. ->orderBy('updated_at', 'desc')
  7681. // ->limit(5)
  7682. ->get();
  7683. //获取5条用户待处理的投诉
  7684. $complaint_deal = Complaint::where('status', 2)
  7685. ->where('deal', 1)
  7686. ->whereJsonContains('re_user_ids', $user_id)
  7687. ->orderBy('updated_at', 'desc')
  7688. // ->limit(5)
  7689. ->get();
  7690. //获取 被通知者未读信息
  7691. $notice_unread = Notice::where('status', 2)
  7692. ->whereJsonContains('re_user_ids', $user_id)
  7693. //未读消息
  7694. ->where(function ($query) use ($user_id) {
  7695. $query->whereJsonDoesntContain('read_id', $user_id)
  7696. ->orWhereNull('read_id');
  7697. })
  7698. ->orderBy('updated_at', 'desc')
  7699. ->get();
  7700. $complaint_unread = Complaint::where('status', 2)
  7701. ->whereJsonContains('re_user_ids', $user_id)
  7702. //未读消息
  7703. ->where(function ($query) use ($user_id) {
  7704. $query->whereJsonDoesntContain('read_id', $user_id)
  7705. ->orWhereNull('read_id');
  7706. })
  7707. ->orderBy('updated_at', 'desc')
  7708. ->get();
  7709. //获取5条用户的yijing审核公司 :0:未审核;1:已审核;2:已拒绝
  7710. $complany = Company::where('status', 1)
  7711. ->where('user_id', $user_id)
  7712. ->orderBy('updated_at', 'desc')
  7713. // ->limit(5)
  7714. ->get();
  7715. //获取5条单聊未读聊天消息
  7716. // $chat = ChatRecords::where('is_read', 0)
  7717. // ->where('user_id', $user_id)
  7718. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7719. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7720. // ->where('action', 'recieved')
  7721. // ->where('talk_type', 1)
  7722. // ->orderBy('created_at', 'desc')
  7723. // // ->limit(5)
  7724. // ->get();
  7725. //获取5条未读群聊信息
  7726. // $chat_group = ChatRecords::where('is_read', 0)
  7727. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7728. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7729. // ->where('user_id', $user_id)
  7730. // ->where('talk_type', 2)
  7731. // ->orderBy('created_at', 'desc')
  7732. // // ->limit(5)
  7733. // ->get();
  7734. //获取5条用户的待审核项目
  7735. $project = Project::where('status', 1)
  7736. ->where('user_id', $user_id)
  7737. ->orderBy('updated_at', 'desc')
  7738. // ->limit(5)
  7739. ->get();
  7740. // count($chat) + count($chat_group) +
  7741. $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)
  7742. + count($complany)
  7743. + count($project)
  7744. + count($notice_unread)
  7745. + count($complaint_unread)
  7746. // + count($chat) + count($chat_group)
  7747. ;
  7748. $result = [
  7749. 'apply_articale' => $apply_articale,
  7750. // 'chat' => $chat,
  7751. // 'chat_group' => $chat_group,
  7752. 'good' => $good,
  7753. 'notice' => $notice,
  7754. 'complaint' => $complaint,
  7755. 'book' => $book,
  7756. 'job_hunting' => $job_hunting,
  7757. 'job_recruiting' => $job_recruiting,
  7758. 'job_apply' => $job_apply,
  7759. 'job_resume' => $job_resume,
  7760. 'complaint_deal' => $complaint_deal,
  7761. 'complany' => $complany,
  7762. 'project' => $project,
  7763. 'notice_unread' => $notice_unread,
  7764. 'complaint_unread' => $complaint_unread,
  7765. 'count' => $count,
  7766. ];
  7767. } elseif ($type_id == 12) {
  7768. //最近的5篇已审的文章
  7769. $apply_articale = Article::where('status', 1)
  7770. ->where('admin_user_id', $user_id)
  7771. ->limit(5)->get();
  7772. //获取5条单聊未读聊天消息
  7773. $chat = ChatRecords::where('is_read', 0)
  7774. ->where('user_id', $user_id)
  7775. ->where('talk_type', 1)
  7776. ->orderBy('created_at', 'desc')
  7777. ->limit(5)->get();
  7778. //获取5条未读群聊信息
  7779. $chat_group = ChatRecords::where('is_read', 0)
  7780. ->where('user_id', $user_id)
  7781. ->where('talk_type', 2)
  7782. ->orderBy('created_at', 'desc')
  7783. ->limit(5)->get();
  7784. //获取5条用户的已审核商品
  7785. $good = Good::where('status', 2)
  7786. ->where('user_id', $user_id)
  7787. ->orderBy('updated_at', 'desc')
  7788. ->limit(5)->get();
  7789. //获取5条用户的book
  7790. $book = Book::where('status', 2)
  7791. ->where('user_id', $user_id)
  7792. ->orderBy('updated_at', 'desc')
  7793. ->limit(5)->get();
  7794. //获取5条用户的求职
  7795. //获取5条用户的求职 1
  7796. //count($chat) + count($chat_group)
  7797. $count = count($apply_articale) + count($good);
  7798. $result = [
  7799. 'apply_articale' => $apply_articale,
  7800. 'chat' => $chat,
  7801. 'chat_group' => $chat_group,
  7802. 'good' => $good,
  7803. 'book' => $book,
  7804. 'count' => $count,
  7805. ];
  7806. } elseif ($type_id == 13) {
  7807. //最近的5篇已审的文章
  7808. $apply_articale = Article::where('status', 1)
  7809. ->where('admin_user_id', $user_id)
  7810. ->limit(5)->get();
  7811. //获取5条单聊未读聊天消息
  7812. $chat = ChatRecords::where('is_read', 0)
  7813. ->where('user_id', $user_id)
  7814. ->where('talk_type', 1)
  7815. ->orderBy('created_at', 'desc')
  7816. ->limit(5)->get();
  7817. //获取5条未读群聊信息
  7818. $chat_group = ChatRecords::where('is_read', 0)
  7819. ->where('user_id', $user_id)
  7820. ->where('talk_type', 2)
  7821. ->orderBy('created_at', 'desc')
  7822. ->limit(5)->get();
  7823. //获取5条用户的已审核商品
  7824. $good = Good::where('status', 2)
  7825. ->where('user_id', $user_id)
  7826. ->orderBy('updated_at', 'desc')
  7827. ->limit(5)->get();
  7828. //count($chat) + count($chat_group) +
  7829. $count = count($apply_articale) + count($good);
  7830. $result = [
  7831. 'apply_articale' => $apply_articale,
  7832. 'chat' => $chat,
  7833. 'chat_group' => $chat_group,
  7834. 'good' => $good,
  7835. 'count' => $count,
  7836. ];
  7837. } elseif ($type_id == 14) {
  7838. //最近的5篇已审的文章
  7839. $apply_articale = Article::where('status', 1)
  7840. ->where('admin_user_id', $user_id)
  7841. // ->limit(5)
  7842. ->get();
  7843. //获取5条用户的已审核商品
  7844. $good = Good::where('status', 2)
  7845. ->where('user_id', $user_id)
  7846. ->orderBy('updated_at', 'desc')
  7847. // ->limit(5)
  7848. ->get();
  7849. $count = count($apply_articale) + count($good);
  7850. $result = [
  7851. 'apply_articale' => $apply_articale,
  7852. 'chat' => '',
  7853. 'chat_group' => '',
  7854. 'good' => $good,
  7855. 'count' => $count,
  7856. ];
  7857. } elseif ($type_id == 10000) {
  7858. //获取未审核的5篇文章
  7859. $apply_articale = Article::where('status', 0)
  7860. ->orderBy('updated_at', 'desc')
  7861. // ->limit(5)
  7862. ->get();
  7863. //获取5条单聊未读聊天消息
  7864. //获取5条单聊未读聊天消息
  7865. // $chat = ChatRecords::where('is_read', 0)
  7866. // ->where('user_id', $user_id)
  7867. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7868. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7869. // ->where('action', 'recieved')
  7870. // ->where('talk_type', 1)
  7871. // ->orderBy('created_at', 'desc')
  7872. // // ->limit(5)
  7873. // ->get();
  7874. // //获取5条未读群聊信息
  7875. // $chat_group = ChatRecords::where('is_read', 0)
  7876. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7877. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7878. // ->where('user_id', $user_id)
  7879. // ->where('talk_type', 2)
  7880. // ->orderBy('created_at', 'desc')
  7881. // // ->limit(5)
  7882. // ->get();
  7883. //获取5条用户的已审核商品
  7884. $good = Good::where('status', 1)
  7885. // ->where('user_id', $user_id)
  7886. ->orderBy('updated_at', 'desc')
  7887. // ->limit(5)
  7888. ->get();
  7889. //获取5条用户待审核的公告
  7890. $notice = Notice::where('status', 1)
  7891. ->orderBy('updated_at', 'desc')
  7892. // ->limit(5)
  7893. ->get();
  7894. //获取5条用户的待审核投诉
  7895. $complaint = Complaint::where('status', 1)
  7896. ->orderBy('updated_at', 'desc')
  7897. // ->limit(5)
  7898. ->get();
  7899. //获取5条用户的book
  7900. $book = Book::where('status', 1)
  7901. ->orderBy('updated_at', 'desc')
  7902. // ->limit(5)
  7903. ->get();
  7904. //获取5条用户的求职 1
  7905. $job_hunting = JobHunting::where('job_hunting.status', 1)
  7906. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7907. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7908. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7909. ->orderBy('updated_at', 'desc')
  7910. // ->limit(5)
  7911. ->get();
  7912. //获取5条用户的求职 2
  7913. $job_recruiting = JobRecruiting::where('job_recruiting.status', 0)
  7914. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7915. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7916. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7917. ->orderBy('updated_at', 'desc')
  7918. // ->limit(5)
  7919. ->get();
  7920. //人才库 1
  7921. $job_apply = JobApply::where('job_apply.status', 1)
  7922. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7923. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7924. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7925. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7926. ->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')
  7927. ->orderBy('updated_at', 'desc')
  7928. // ->limit(5)
  7929. ->get();
  7930. // 职场机会 2
  7931. $job_resume = JobResume::where('job_resume.status', 1)
  7932. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7933. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7934. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7935. ->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')
  7936. ->orderBy('updated_at', 'desc')
  7937. // ->limit(5)
  7938. ->get();
  7939. //待审核数据com pro
  7940. $complany = Company::where('status', 0)
  7941. ->orderBy('updated_at', 'desc')
  7942. // ->limit(5)
  7943. ->get();
  7944. $project = Project::where('status', 0)
  7945. ->orderBy('updated_at', 'desc')
  7946. // ->limit(5)
  7947. ->get();
  7948. $count =
  7949. // count($chat) +
  7950. // count($chat_group) +
  7951. count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting)
  7952. // + count($job_apply)
  7953. // + count($job_resume)
  7954. + count($complany)
  7955. + count($project);
  7956. $result = [
  7957. 'apply_articale' => $apply_articale,
  7958. // 'chat' => $chat,
  7959. // 'chat_group' => $chat_group,
  7960. 'good' => $good,
  7961. 'notice' => $notice,
  7962. 'complaint' => $complaint,
  7963. 'book' => $book,
  7964. 'job_hunting' => $job_hunting,
  7965. 'job_recruiting' => $job_recruiting,
  7966. // 'job_apply' => $job_apply,
  7967. // 'job_resume' => $job_resume,
  7968. 'complany' => $complany,
  7969. 'project' => $project,
  7970. 'count' => $count,
  7971. ];
  7972. } elseif ($type_id == 20000) {
  7973. }
  7974. var_dump($type_id, '-----------------test---------');
  7975. return Result::success($result);
  7976. }
  7977. /**
  7978. * @param array $data
  7979. * @return array
  7980. */
  7981. public function getWebsiteProject(array $data): array
  7982. {
  7983. $categorys = json_decode($data['id'], true);
  7984. if (!empty($categorys)) {
  7985. $category_arr = $this->processArticlePro($data['website_id']);
  7986. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7987. $catiall = $category_arr['catiall'];
  7988. // return Result::success($catiall);
  7989. foreach ($categorys as $key => $val) {
  7990. if (isset($val['level'][0]) && !empty($val['level'][0])) {
  7991. $level = explode(',', $val['level'])[0];
  7992. $imgnum = explode(',', $val['level'])[1] ?? null;
  7993. $textnum = explode(',', $val['level'])[2] ?? null;
  7994. if ($level == 1) {
  7995. if (!empty($textnum) && $textnum > 0) {
  7996. $text_num = Project::where('level', $level)
  7997. ->where('website_id', $data['website_id'])
  7998. ->where('status', 1)
  7999. ->select(
  8000. 'project.id',
  8001. 'project.title',
  8002. 'project.description',
  8003. 'project.updated_at',
  8004. 'project.category_id',
  8005. 'project.cat_arr_id'
  8006. )
  8007. ->orderBy('updated_at', 'desc')
  8008. ->limit($textnum)
  8009. ->get()->all();
  8010. }
  8011. if (!empty($imgnum) && $imgnum > 0) {
  8012. $img_num = Project::where('level', $level)
  8013. ->where('website_id', $data['website_id'])
  8014. ->where('status', 1)
  8015. ->where('imgurl', '!=', '')
  8016. ->whereNotNull('imgurl')
  8017. ->select(
  8018. 'project.id',
  8019. 'project.title',
  8020. 'project.description',
  8021. 'project.updated_at',
  8022. 'project.imgurl as imgs',
  8023. 'project.category_id',
  8024. 'project.cat_arr_id'
  8025. )
  8026. ->orderBy('updated_at', 'desc')
  8027. ->limit($imgnum)
  8028. ->get()->all();
  8029. }
  8030. } else {
  8031. if (!empty($textnum) && $textnum > 0) {
  8032. $text_num = Project::where('website_id', $data['website_id'])
  8033. ->where('status', 1)
  8034. ->select(
  8035. 'project.id',
  8036. 'project.title',
  8037. 'project.description',
  8038. 'project.updated_at',
  8039. 'project.category_id',
  8040. 'project.cat_arr_id',
  8041. 'project.website_id',
  8042. 'project.updated_at',
  8043. 'project.created_at'
  8044. )
  8045. ->orderBy('updated_at', 'desc')
  8046. ->limit($textnum)
  8047. ->get()->all();
  8048. }
  8049. if (!empty($imgnum) && $imgnum > 0) {
  8050. $img_num = Project::where('website_id', $data['website_id'])
  8051. ->where('status', 1)
  8052. ->where('imgurl', '!=', '')
  8053. ->whereNotNull('imgurl')
  8054. ->select(
  8055. 'project.id',
  8056. 'project.title',
  8057. 'project.description',
  8058. 'project.updated_at',
  8059. 'project.imgurl as imgs',
  8060. 'project.category_id',
  8061. 'project.cat_arr_id'
  8062. )
  8063. ->orderBy('updated_at', 'desc')
  8064. ->limit($imgnum)
  8065. ->get()->all();
  8066. }
  8067. }
  8068. }
  8069. if (isset($val['id'][0]) && !empty($val['id'][0])) {
  8070. $category_ids = explode(',', $val['id'])[0];
  8071. $cat_imgnum = explode(',', $val['id'])[1] ?? null;
  8072. $cat_textnum = explode(',', $val['id'])[2] ?? null;
  8073. $category_arr = array_merge([$category_ids], $cat_1st_arr[$category_ids] ?? [0]);
  8074. if (!empty($cat_textnum) && $cat_textnum > 0) {
  8075. $text_num = Project::whereIn('category_id', $category_arr)
  8076. ->where('website_id', $data['website_id'])
  8077. ->where('status', 1)
  8078. ->select(
  8079. 'project.id',
  8080. 'project.title',
  8081. 'project.description',
  8082. 'project.updated_at',
  8083. 'project.category_id',
  8084. 'project.cat_arr_id'
  8085. )
  8086. ->orderBy('updated_at', 'desc')
  8087. ->limit($cat_textnum)
  8088. ->get()->all();
  8089. }
  8090. if (!empty($cat_imgnum) && $cat_imgnum > 0) {
  8091. $img_num = Project::whereIn('category_id', $category_arr)
  8092. ->where('website_id', $data['website_id'])
  8093. ->where('status', 1)
  8094. ->where('imgurl', '!=', '')
  8095. ->whereNotNull('imgurl')
  8096. ->select(
  8097. 'project.id',
  8098. 'project.title',
  8099. 'project.description',
  8100. 'project.updated_at',
  8101. 'project.imgurl as imgs',
  8102. 'project.category_id',
  8103. 'project.cat_arr_id'
  8104. )
  8105. ->orderBy('updated_at', 'desc')
  8106. ->limit($cat_imgnum)
  8107. ->get()->all();
  8108. }
  8109. }
  8110. if (!empty($img_num)) {
  8111. foreach ($img_num as $k => $v) {
  8112. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8113. $imgurl = json_decode($v['imgs'], true);
  8114. if (!empty($imgurl)) {
  8115. $img_num[$k]->imgurl = $imgurl[0];
  8116. }
  8117. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8118. }
  8119. }
  8120. if (!empty($text_num)) {
  8121. foreach ($text_num as $k => $v) {
  8122. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8123. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8124. }
  8125. }
  8126. $project[$key]['img_num'] = $img_num ?? [];
  8127. $project[$key]['text_num'] = $text_num ?? [];
  8128. }
  8129. }
  8130. if (empty($project)) {
  8131. return Result::error("暂无相关项目信息", 0);
  8132. }
  8133. return Result::success($project);
  8134. }
  8135. /**
  8136. * @param array $data
  8137. * @return array
  8138. */
  8139. public function getWebsiteProjectInfo(array $data): array
  8140. {
  8141. $project = Project::where('id', $data['id'])
  8142. ->where('status', 1)
  8143. ->where('website_id', $data['website_id'])
  8144. ->select('project.*')
  8145. ->first();
  8146. if (empty($project)) {
  8147. return Result::error("暂无相关项目信息", 0);
  8148. }
  8149. return Result::success($project);
  8150. }
  8151. /**
  8152. * @param array $data
  8153. * @return array
  8154. */
  8155. public function getWebsiteProjectList(array $data): array
  8156. {
  8157. $where = [];
  8158. if (isset($data['category_id']) && !empty($data['category_id'])) {
  8159. $where['category_id'] = $data['category_id'];
  8160. }
  8161. if (isset($data['keyword']) && !empty($data['keyword'])) {
  8162. $where[] = ['title', 'like', '%' . $data['keyword'] . '%'];
  8163. }
  8164. $query = Project::where($where)
  8165. ->where('status', 1)
  8166. ->where('website_id', $data['website_id'])
  8167. ->select(
  8168. 'project.id',
  8169. 'project.title',
  8170. 'project.description',
  8171. 'project.imgurl as imgs',
  8172. 'project.category_id',
  8173. 'project.cat_arr_id'
  8174. )
  8175. ->orderBy('updated_at', 'desc');
  8176. $count = $query->count();
  8177. $project = $query->clone()
  8178. ->offset(($data['page'] - 1) * $data['pageSize'])
  8179. ->limit($data['pageSize'])
  8180. ->get()->all();
  8181. if (empty($project)) {
  8182. return Result::error("暂无相关项目信息", 0);
  8183. }
  8184. $categorys = $this->processArticlePro($data['website_id']);
  8185. $catiall = $categorys['catiall'];
  8186. foreach ($project as $key => $val) {
  8187. $project[$key]->category_name = $catiall[$val->category_id]['alias'];
  8188. if (!empty($val['imgs'])) {
  8189. $imgurl = json_decode($val['imgs'], true);
  8190. if (!empty($imgurl)) {
  8191. $project[$key]->imgurl = $imgurl[0];
  8192. }
  8193. } else {
  8194. $project[$key]->imgurl = '';
  8195. }
  8196. $project[$key]->pinyin = $catiall[$val->category_id]['pinyin'];
  8197. }
  8198. $result = [
  8199. 'rows' => $project,
  8200. 'count' => $count,
  8201. ];
  8202. return Result::success($result);
  8203. }
  8204. /**
  8205. * @param array $data
  8206. * @return array
  8207. */
  8208. public function getWebsiteCategoryJob(array $data): array
  8209. {
  8210. $categorys = json_decode($data['id'], true);
  8211. if (!empty($categorys)) {
  8212. $category_arr = $this->processArticlePro($data['website_id']);
  8213. $cat_1st_arr = $category_arr['cat_1st_arr'];
  8214. $catiall = $category_arr['catiall'];
  8215. foreach ($categorys as $key => $val) {
  8216. if (isset($val['id']) && !empty($val['id'])) {
  8217. $catid = explode(',', $val['id'])[0] ?? null;
  8218. $type = explode(',', $val['id'])[1] ?? null;
  8219. $textnum = explode(',', $val['id'])[2] ?? null;
  8220. }
  8221. // 4:招聘;5:求职;
  8222. if ($textnum > 0 && $type == 4 && !empty($catid)) {
  8223. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  8224. $job = JobRecruiting::WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($catid) . "') = 1")
  8225. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  8226. ->where('job_recruiting.status', 1)
  8227. ->where('job_recruiting.website_id', $data['website_id'])
  8228. ->select(
  8229. 'job_recruiting.id',
  8230. 'job_recruiting.title',
  8231. 'job_company.business_name',
  8232. 'job_recruiting.updated_at',
  8233. 'job_recruiting.cat_arr_id',
  8234. 'job_recruiting.keyword',
  8235. 'job_recruiting.description'
  8236. )
  8237. ->orderBy('job_recruiting.updated_at', 'desc')
  8238. ->limit($textnum)
  8239. ->get()->all();
  8240. } else if ($textnum > 0 && $type == 5 && !empty($catid)) {
  8241. // 状态 审核状态,1待审核2已审核3已拒绝
  8242. $job = JobHunting::WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($catid) . "') = 1")
  8243. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  8244. ->where('job_hunting.status', 2)
  8245. ->where('job_hunting.website_id', $data['website_id'])
  8246. ->select(
  8247. 'job_hunting.id',
  8248. 'job_hunting.name',
  8249. 'job_hunting.cat_arr_id',
  8250. 'job_position.zwname as job_name',
  8251. 'job_hunting.updated_at',
  8252. 'job_hunting.keyword',
  8253. 'job_hunting.slelf_evaluation'
  8254. )
  8255. ->orderBy('updated_at', 'desc')
  8256. ->limit($textnum)
  8257. ->get()->all();
  8258. } else {
  8259. $job = [];
  8260. }
  8261. // var_dump($catid.'222uuuuuuu'.$key);
  8262. if (!empty($job)) {
  8263. foreach ($job as $k => $value) {
  8264. if (isset($value->cat_arr_id)) {
  8265. $catArr = json_decode($value->cat_arr_id, true);
  8266. $catId = end($catArr);
  8267. } else {
  8268. continue;
  8269. }
  8270. if (isset($catiall[$catId])) {
  8271. $job[$k]->pinyin = $catiall[$catId]['pinyin'];
  8272. }
  8273. }
  8274. }
  8275. // var_dump($catid.'xxxxx'.$key);
  8276. $result[$key] = $job ?? [];
  8277. }
  8278. }
  8279. if (empty($result)) {
  8280. return Result::error("暂无相关分类信息", 0);
  8281. }
  8282. return Result::success($result);
  8283. }
  8284. /**
  8285. * 发送消息
  8286. * @param array $messageData
  8287. * @return void
  8288. */
  8289. public function sendMessage($messageData)
  8290. {
  8291. $msg = [
  8292. 'talk_type' => $messageData['talk_type'],
  8293. 'title' => $messageData['title'],
  8294. 'content' => $messageData['content'],
  8295. 'messageType' => $messageData['messageType'],
  8296. 'user_id' => $messageData['user_id'] ?? '',
  8297. 'time' => microtime(),
  8298. ];
  8299. $message = new MqProducer($msg);
  8300. $producer = ContextApplicationContext::getContainer()->get(Producer::class);
  8301. $producer->produce($message);
  8302. }
  8303. }