NewsService.php 294 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126
  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. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  69. class NewsService implements NewsServiceInterface
  70. {
  71. #[Inject]
  72. protected Redis $redis;
  73. /**
  74. * 获取导航池列表
  75. * @param array $data
  76. * @return array
  77. */
  78. public function getCategoryList(array $data): array
  79. {
  80. $search = $data['name'] ?? '';
  81. $page = (int)($data['page'] ?? 1);
  82. $perPage = (int)($data['pageSize'] ?? 10);
  83. // 1. 查出所有匹配的分类id
  84. if ($search) {
  85. $matchedIds = Category::where('name', 'like', "%{$search}%")->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  86. if (empty($matchedIds)) {
  87. return Result::success(['rows' => [], 'total' => 0]);
  88. }
  89. // 2. 递归查所有父级,直到一级分类
  90. $idsStr = implode(',', $matchedIds);
  91. $sql = "
  92. WITH RECURSIVE parents AS (
  93. SELECT * FROM category WHERE id IN ($idsStr)
  94. UNION ALL
  95. SELECT c.* FROM category c
  96. INNER JOIN parents p ON c.id = p.pid
  97. )
  98. SELECT * FROM parents
  99. ";
  100. $parents = Db::select($sql);
  101. $parentIds = [];
  102. foreach ($parents as $row) {
  103. if ($row->pid == 0) {
  104. $parentIds[] = $row->id;
  105. }
  106. }
  107. $parentIds = array_unique($parentIds);
  108. } else {
  109. // 没有搜索,一级分类就是根
  110. $parentIds = Category::where('pid', 0)->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  111. }
  112. // 3. 一级分类分页
  113. $total = count($parentIds);
  114. $parentIds = array_slice($parentIds, ($page - 1) * $perPage, $perPage);
  115. if (empty($parentIds)) {
  116. return Result::success(['rows' => [], 'total' => $total]);
  117. }
  118. // 4. 递归查所有子孙
  119. $idsStr = implode(',', $parentIds);
  120. $sql = "
  121. WITH RECURSIVE subcategories AS (
  122. SELECT * FROM category WHERE id IN ($idsStr)
  123. UNION ALL
  124. SELECT c.* FROM category c
  125. INNER JOIN subcategories s ON c.pid = s.id
  126. )
  127. SELECT * FROM subcategories ORDER BY updated_at DESC
  128. ";
  129. $allCategories = Db::select($sql);
  130. // 5. 组装树结构
  131. $categoryMap = [];
  132. foreach ($allCategories as $cat) {
  133. $cat = (array)$cat;
  134. $cat['children'] = [];
  135. $categoryMap[$cat['id']] = $cat;
  136. }
  137. foreach ($categoryMap as $id => &$cat) {
  138. if ($cat['pid'] && isset($categoryMap[$cat['pid']])) {
  139. $categoryMap[$cat['pid']]['children'][] = &$cat;
  140. }
  141. }
  142. unset($cat);
  143. $categoryTree = [];
  144. foreach ($parentIds as $id) {
  145. if (isset($categoryMap[$id])) {
  146. $categoryTree[] = $categoryMap[$id];
  147. }
  148. }
  149. return Result::success([
  150. 'rows' => $categoryTree,
  151. 'total' => $total,
  152. ]);
  153. }
  154. private function findMatchedCategories($search)
  155. {
  156. if ($search) {
  157. return Category::where('name', 'like', "%{$search}%")
  158. ->orderBy('updated_at', 'desc')
  159. ->get();
  160. }
  161. return Category::orderBy('updated_at', 'desc') // 按 updated_at 字段倒序排序
  162. ->get();
  163. }
  164. private function findAllParents($categories)
  165. {
  166. $allCategories = [];
  167. foreach ($categories as $category) {
  168. $parentId = $category->pid;
  169. while ($parentId > 0) {
  170. $parent = Category::find($parentId);
  171. if ($parent) {
  172. $allCategories[$parent->id] = $parent;
  173. $parentId = $parent->pid;
  174. } else {
  175. break;
  176. }
  177. }
  178. $allCategories[$category->id] = $category;
  179. }
  180. return array_values($allCategories);
  181. }
  182. private function buildCategoryTree($category, $allRequiredCategories)
  183. {
  184. $categoryData = $category->toArray();
  185. $children = [];
  186. foreach ($allRequiredCategories as $c) {
  187. if ($c->pid === $category->id) {
  188. $children[] = $this->buildCategoryTree($c, $allRequiredCategories);
  189. }
  190. }
  191. if (!empty($children)) {
  192. $categoryData['children'] = $children;
  193. }
  194. return $categoryData;
  195. }
  196. public function myCategoryList(array $data): array
  197. {
  198. $sszq = $data['sszq'] ?? '';
  199. unset($data['sszq']);
  200. //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
  201. $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
  202. $where[] = [
  203. 'pid',
  204. '=',
  205. $data['pid'],
  206. ];
  207. if (isset($data['name'])) {
  208. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  209. }
  210. var_dump($where);
  211. //根据分类id,从category表中取出分类信息
  212. $result = Category::where($where)
  213. ->whereIn('category.id', $catorytids)
  214. ->select('category.*', 'category.id as category_id')->get();
  215. if (empty($result)) {
  216. return Result::error("没有栏目数据");
  217. }
  218. return Result::success($result);
  219. }
  220. /**
  221. * @param array $data
  222. * @return array
  223. */
  224. public function categoryList(array $data): array
  225. {
  226. $where[] = [
  227. 'pid',
  228. '=',
  229. $data['pid']
  230. ];
  231. if (isset($data['name'])) {
  232. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  233. }
  234. var_dump($where);
  235. $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
  236. if (empty($result)) {
  237. return Result::error("没有栏目数据");
  238. }
  239. return Result::success($result);
  240. }
  241. /**
  242. * @param array $data
  243. * @return array
  244. */
  245. public function addCategory(array $data): array
  246. {
  247. if (isset($data['id'])) {
  248. unset($data['id']);
  249. }
  250. $id = Category::insertGetId($data);
  251. if (empty($id)) {
  252. return Result::error("添加失败");
  253. }
  254. return Result::success(['id' => $id]);
  255. }
  256. /**
  257. * @param array $data
  258. * @return array
  259. */
  260. public function delCategory(array $data): array
  261. {
  262. Db::beginTransaction();
  263. try {
  264. $categoryList = Category::where(['pid' => $data['id']])->get();
  265. if ($categoryList->toArray()) {
  266. Db::rollBack();
  267. return Result::error("分类下面有子分类不能删除");
  268. }
  269. $articleList = Article::where(['catid' => $data['id']])->get();
  270. if ($articleList->toArray()) {
  271. Db::rollBack();
  272. return Result::error("分类下面有资讯不能删除");
  273. }
  274. $result = Category::where($data)->delete();
  275. WebsiteCategory::where(['category_id' => $data['id']])->delete();
  276. if (!$result) {
  277. Db::rollBack();
  278. return Result::error("删除失败");
  279. }
  280. Db::commit();
  281. return Result::success($result);
  282. } catch (\Exception $e) {
  283. Db::rollBack();
  284. return Result::error("删除失败" . $e->getMessage());
  285. }
  286. }
  287. /**
  288. * @param array $data
  289. * @return array
  290. */
  291. public function updateCategory(array $data): array
  292. {
  293. $where = [
  294. 'id' => $data['id'],
  295. ];
  296. $result = Category::where($where)->update($data);
  297. if ($result) {
  298. return Result::success($result);
  299. } else {
  300. return Result::error("更新失败");
  301. }
  302. }
  303. /**
  304. * 获取导航池信息
  305. * @param array $data
  306. * @return array
  307. */
  308. public function getCategoryInfo(array $data): array
  309. {
  310. $where = [
  311. 'id' => $data['id'],
  312. ];
  313. $result = Category::where($where)->first();
  314. if ($result) {
  315. return Result::success($result);
  316. } else {
  317. return Result::error("更新失败");
  318. }
  319. }
  320. public function getArticleCommend(array $data): array
  321. {
  322. $where = [
  323. 'website_id' => $data['website_id'],
  324. ];
  325. $ids = WebsiteCategory::where($where)->pluck('category_id')->toArray();
  326. var_dump($ids);
  327. if (empty($ids)) {
  328. return Result::error("没有推荐数据");
  329. }
  330. //id
  331. $whereArticle = [];
  332. if (isset($data['id'])) {
  333. $whereArticle['id'] = $data['id'];
  334. }
  335. //title like
  336. if (isset($data['title'])) {
  337. array_push($whereArticle, ['title', 'like', "%{$data['title']}%"]);
  338. }
  339. $article = Article::whereIn('catid', values: $ids)->where('status', 1)
  340. ->where($whereArticle)
  341. ->orderBy('id', 'desc')
  342. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  343. if ($article) {
  344. $data = [
  345. 'rows' => $article->items(),
  346. 'count' => $article->total(),
  347. ];
  348. return Result::success($data);
  349. } else {
  350. return Result::error("获取失败失败");
  351. }
  352. }
  353. /**
  354. * @param array $data
  355. * @return array
  356. */
  357. public function getArticleList(array $data): array
  358. {
  359. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  360. $type_id = $data['type_id'];
  361. unset($data['type_id']);
  362. $user_id = $data['user_id'];
  363. unset($data['user_id']);
  364. $where = [];
  365. $status1 = [];
  366. if (isset($data['id']) && $data['id']) {
  367. array_push($where, ['article.id', '=', $data['id']]);
  368. }
  369. if (isset($data['title']) && $data['title']) {
  370. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  371. }
  372. if (isset($data['category_name']) && $data['category_name']) {
  373. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  374. }
  375. if (isset($data['catid']) && $data['catid']) {
  376. array_push($where, ['article.catid', '=', $data['catid']]);
  377. }
  378. if (isset($data['author']) && $data['author']) {
  379. array_push($where, ['article.author', '=', $data['author']]);
  380. }
  381. if (isset($data['islink']) && $data['islink'] !== "") {
  382. array_push($where, ['article.islink', '=', $data['islink']]);
  383. }
  384. if (isset($data['status']) && $data['status'] !== "") {
  385. array_push($where, ['article.status', '=', $data['status']]);
  386. }
  387. if (isset($data['status1'])) {
  388. $status1 = json_decode(($data['status1']));
  389. }
  390. //不是管理员展示个人数据;
  391. if ($type_id != 10000) {
  392. $where[] = ['article.admin_user_id', '=', $user_id];
  393. }
  394. $rep = Article::where($where)
  395. ->whereNotIn('article.status', [404])
  396. ->when($status1, function ($query) use ($status1) {
  397. if (isset($status1) && $status1) {
  398. $query->whereIn('article.status', $status1);
  399. }
  400. })
  401. ->leftJoin('category', 'article.catid', 'category.id')
  402. ->leftJoin('website_category', function ($join) {
  403. $join->on('article.web_site_id', '=', 'website_category.website_id')
  404. ->on('article.catid', '=', 'website_category.category_id');
  405. })
  406. ->select("article.*", "category.name as category_name", "website_category.alias")
  407. ->orderBy("article.updated_at", "desc")
  408. ->limit($data['pageSize'])
  409. ->offset(($data['page'] - 1) * $data['pageSize'])->get();
  410. $count = Article::where($where)->whereNotIn('article.status', [404])
  411. ->when($status1, function ($query) use ($status1) {
  412. if (isset($status1) && $status1) {
  413. $query->whereIn('article.status', $status1);
  414. }
  415. })
  416. ->leftJoin('category', 'article.catid', 'category.id')->count();
  417. $data = [
  418. 'rows' => $rep->toArray(),
  419. 'count' => $count,
  420. ];
  421. if (empty($rep)) {
  422. return Result::error("没有信息数据");
  423. }
  424. return Result::success($data);
  425. }
  426. /**
  427. * @param array $data
  428. * @return array
  429. */
  430. public function addArticle(array $data): array
  431. {
  432. var_dump($data, '----------12-----------1');
  433. unset($data['user_type']);
  434. unset($data['nav_add_pool_id']);
  435. // unset($data['commend_id']);
  436. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  437. Db::beginTransaction();
  438. try {
  439. //处理投票
  440. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  441. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  442. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  443. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  444. unset($data['is_survey']);
  445. unset($data['survey_name']);
  446. unset($data['suvey_array']);
  447. // unset($data['website_id']);
  448. // unset($data['web_site_id']);
  449. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  450. if ($data['hits'] == '') {
  451. $data['hits'] = 0;
  452. }
  453. if ($data['is_original'] == '') {
  454. $data['is_original'] = 0;
  455. }
  456. if ($data['status'] == '') {
  457. $data['status'] = 0;
  458. }
  459. $articleData = $data;
  460. unset($articleData['content']);
  461. //自动处理缩略图、关键字、描述
  462. if ($articleData['imgurl'] == '') {
  463. //如果没有图,设置level=0
  464. $levelArr = json_decode($articleData['level'], true);
  465. var_dump($levelArr, '----------levelArr-----------1');
  466. //content中提取图片第一个图,正则提取
  467. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  468. preg_match_all($reg, $data['content'], $matches);
  469. if (isset($matches[1][0])) {
  470. //截取varchar240
  471. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  472. //如果有图,设置level=3
  473. if (!in_array(3, $levelArr)) {
  474. $levelArr[] = 3;
  475. }
  476. $articleData['level'] = json_encode($levelArr);
  477. } else {
  478. if (!in_array(0, $levelArr)) {
  479. $levelArr[] = 0;
  480. }
  481. $articleData['level'] = json_encode($levelArr);
  482. }
  483. }
  484. var_dump($articleData['level'], '----------$articleData[level]----------1');
  485. if ($articleData['keyword'] == '') {
  486. //提取标题+内容中的关键词
  487. $articleData['keyword'] = $data['title'];
  488. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  489. Jieba::init(); // 初始化 jieba-php
  490. Finalseg::init();
  491. $segList = Jieba::cut($articleData['keyword']);
  492. $segList1 = array_slice($segList, 0, 8);
  493. $articleData['keyword'] = implode(',', $segList1);
  494. }
  495. if ($articleData['introduce'] == '') {
  496. //提取内容中的描述
  497. $content = $data['content'];
  498. // 去除 <style> 和 <script> 标签及其内容
  499. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  500. // 去除所有 HTML 标签
  501. $content = strip_tags($content);
  502. // 去除 HTML 实体
  503. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  504. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  505. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  506. // 去除多余空白
  507. $content = preg_replace('/\s+/u', '', $content);
  508. // 截取 100 个字符
  509. $articleData['introduce'] = mb_substr($content, 0, 100);
  510. }
  511. if ($articleData['status'] == 0) {
  512. $this->sendMessage([
  513. 'talk_type' => 100,
  514. 'title' => $articleData['title'],
  515. 'content' => '提交了审核',
  516. 'messageType' => 2,
  517. ]);
  518. }
  519. $id = Article::insertGetId($articleData);
  520. $articleDataContent = [
  521. 'article_id' => $id,
  522. 'content' => $data['content'],
  523. ];
  524. ArticleData::insertGetId($articleDataContent);
  525. //处理投票
  526. if ($is_survey == 1) {
  527. //生成年月日时分秒+8位随机数
  528. $uuid = date('YmdHis') . rand(10000000, 99999999);
  529. var_dump($suvey_array, 'suvey_array________');
  530. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  531. var_dump($suveys_array, '---------------------1');
  532. var_dump($suvey_array, '---------------------2');
  533. $suvey_data = [];
  534. foreach ($suveys_array as $key => $value) {
  535. if ($value == '') {
  536. continue;
  537. }
  538. if (is_array($value)) {
  539. $suvey_data[] = [
  540. 'sur_id' => $uuid,
  541. 'art_id' => $id,
  542. 'website_id' => $website_id ?? 2,
  543. 'survey_name' => $survey_name,
  544. 'choice_name' => $value[1],
  545. 'is_other' => 1,
  546. 'other_id' => 0,
  547. 'results' => 0,
  548. ];
  549. } else {
  550. $suvey_data[] = [
  551. 'sur_id' => $uuid,
  552. 'art_id' => $id,
  553. 'website_id' => $website_id ?? 2,
  554. 'survey_name' => $survey_name,
  555. 'choice_name' => $value,
  556. 'is_other' => 0,
  557. 'other_id' => 0,
  558. 'results' => 0,
  559. ];
  560. }
  561. if (empty($suvey_data)) {
  562. throw new \Exception("投票数据为空");
  563. }
  564. }
  565. $result = ArticleSurvey::insert($suvey_data);
  566. if (!$result) {
  567. throw new \Exception("投票失败,ArticleSurvey插入失败");
  568. }
  569. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  570. if (!$result) {
  571. throw new \Exception("投票失败,更新主表失败");
  572. }
  573. }
  574. Db::commit();
  575. return Result::success(['id' => $id]);
  576. } catch (\Throwable $ex) {
  577. Db::rollBack();
  578. var_dump($ex->getMessage());
  579. return Result::error("创建失败", 0);
  580. }
  581. }
  582. /**
  583. * @param array $data
  584. * @return array
  585. */
  586. public function delArticle(array $data): array
  587. {
  588. $result = Article::where($data)->delete();
  589. //survey投票删除
  590. articleSurvey::where(['art_id' => $data['id']])->delete();
  591. if (!$result) {
  592. return Result::error("删除失败");
  593. }
  594. return Result::success($result);
  595. }
  596. /**
  597. * @param array $data
  598. * @return array
  599. */
  600. public function updateArticle(array $data): array
  601. {
  602. var_dump($data, '----------12-----------1');
  603. Db::beginTransaction();
  604. unset($data['user_type']);
  605. // unset($data['web_site_id']);
  606. unset($data['nav_add_pool_id']);
  607. try {
  608. //处理投票
  609. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  610. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  611. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  612. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  613. unset($data['is_survey']);
  614. unset($data['survey_name']);
  615. unset($data['suvey_array']);
  616. unset($data['website_id']);
  617. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  618. if ($data['hits'] == '') {
  619. $data['hits'] = 0;
  620. }
  621. if ($data['is_original'] == '') {
  622. $data['is_original'] = 0;
  623. }
  624. if ($data['status'] == '') {
  625. $data['status'] = 0;
  626. }
  627. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  628. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  629. $articleData = $data;
  630. unset($articleData['content']);
  631. unset($articleData['status_name']);
  632. unset($articleData['name']);
  633. unset($articleData['content']);
  634. unset($articleData['pid_arr']);
  635. unset($articleData['pid']);
  636. //自动处理缩略图、关键字、描述
  637. if ($articleData['imgurl'] == '') {
  638. //如果没有图,设置level=0
  639. $levelArr = json_decode($articleData['level'], true);
  640. var_dump($levelArr, '----------levelArr-----------1');
  641. //content中提取图片第一个图,正则提取
  642. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  643. preg_match_all($reg, $data['content'], $matches);
  644. if (isset($matches[1][0])) {
  645. //截取varchar240
  646. // 截取到第一个<
  647. $articleData['imgurl'] = $matches[1][0];
  648. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  649. $pos = strpos($articleData['imgurl'], '"');
  650. if ($pos !== false) {
  651. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  652. }
  653. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  654. //如果有图,设置level=3
  655. if (!in_array(3, $levelArr)) {
  656. $levelArr[] = 3;
  657. }
  658. $articleData['level'] = json_encode($levelArr);
  659. } else {
  660. if (!in_array(0, $levelArr)) {
  661. $levelArr[] = 0;
  662. }
  663. $articleData['level'] = json_encode($levelArr);
  664. }
  665. }
  666. var_dump($articleData['level'], '----------$articleData[level]----------1');
  667. if ($articleData['keyword'] == '') {
  668. //提取标题+内容中的关键词
  669. $articleData['keyword'] = $data['title'];
  670. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  671. Jieba::init(); // 初始化 jieba-php
  672. Finalseg::init();
  673. $segList = Jieba::cut($articleData['keyword']);
  674. $segList1 = array_slice($segList, 0, 8);
  675. $articleData['keyword'] = implode(',', $segList1);
  676. }
  677. if ($articleData['introduce'] == '') {
  678. //提取内容中的描述
  679. $content = $data['content'];
  680. // 去除 <style> 和 <script> 标签及其内容
  681. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  682. // 去除所有 HTML 标签
  683. $content = strip_tags($content);
  684. // 去除 HTML 实体
  685. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  686. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  687. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  688. // 去除多余空白
  689. $content = preg_replace('/\s+/u', '', $content);
  690. // 截取 100 个字符
  691. $articleData['introduce'] = mb_substr($content, 0, 100);
  692. }
  693. if ($articleData['status'] == 0) {
  694. $this->sendMessage([
  695. 'talk_type' => 100,
  696. 'title' => $articleData['title'],
  697. 'content' => '提交了审核',
  698. 'messageType' => 2,
  699. ]);
  700. }
  701. $id = Article::where(['id' => $data['id']])->update($articleData);
  702. $articleDataContent = [
  703. 'content' => $data['content'],
  704. ];
  705. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  706. //处理投票
  707. $id = $data['id'];
  708. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  709. var_dump($suvey_array, 'suvey_array________delete');
  710. //处理投票
  711. if ($is_survey == 1) {
  712. //生成年月日时分秒+8位随机数
  713. $uuid = date('YmdHis') . rand(10000000, 99999999);
  714. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  715. var_dump($suveys_array, '---------------------1');
  716. $suvey_data = [];
  717. if (is_array($suveys_array)) {
  718. foreach ($suveys_array as $key => $value) {
  719. if ($value == '') {
  720. continue;
  721. }
  722. if (is_array($value)) {
  723. $suvey_data[] = [
  724. 'sur_id' => $uuid,
  725. 'art_id' => $id,
  726. 'website_id' => $website_id ?? 2,
  727. 'survey_name' => $survey_name,
  728. 'choice_name' => $value[1],
  729. 'is_other' => 1,
  730. 'other_id' => 0,
  731. 'results' => 0,
  732. ];
  733. } else {
  734. $suvey_data[] = [
  735. 'sur_id' => $uuid,
  736. 'art_id' => $id,
  737. 'website_id' => $website_id ?? 2,
  738. 'survey_name' => $survey_name,
  739. 'choice_name' => $value,
  740. 'is_other' => 0,
  741. 'other_id' => 0,
  742. 'results' => 0,
  743. ];
  744. }
  745. if (empty($suvey_data)) {
  746. throw new \Exception("投票数据为空");
  747. }
  748. }
  749. }
  750. $result = ArticleSurvey::insert($suvey_data);
  751. if (!$result) {
  752. throw new \Exception("投票失败");
  753. }
  754. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  755. if (!$result) {
  756. throw new \Exception("投票失败");
  757. }
  758. } else {
  759. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  760. }
  761. Db::commit();
  762. return Result::success([]);
  763. } catch (\Throwable $ex) {
  764. Db::rollBack();
  765. var_dump($ex->getMessage());
  766. return Result::error("更新失败" . $ex->getMessage(), 0);
  767. }
  768. }
  769. /**
  770. * 更新资讯状态
  771. * @param array $data
  772. * @return array
  773. */
  774. public function upArticleStatus(array $data): array
  775. {
  776. $articleData = Article::where(['id' => $data['id']])->first();
  777. //发送10次
  778. for ($i = 0; $i < 10; $i++) {
  779. $this->sendMessage([
  780. 'talk_type' => 100,
  781. 'title' => $i . $articleData['title'],
  782. 'content' => '审核通过',
  783. 'messageType' => 2,
  784. 'user_id' => $articleData['admin_user_id'],
  785. ]);
  786. }
  787. var_dump($data['status'], 'status');
  788. return Result::success();
  789. if ($data['status'] == 1) {
  790. $this->sendMessage([
  791. 'talk_type' => 101,
  792. 'title' => $articleData['title'],
  793. 'content' => '审核通过',
  794. 'messageType' => 2,
  795. 'user_id' => $articleData['admin_user_id'],
  796. ]);
  797. }
  798. if ($data['status'] == 2) {
  799. $this->sendMessage([
  800. 'talk_type' => 101,
  801. 'title' => $articleData['title'],
  802. 'content' => '审核拒绝',
  803. 'messageType' => 2,
  804. 'user_id' => $articleData['admin_user_id'],
  805. ]);
  806. }
  807. if ($data['status'] == 0) {
  808. $this->sendMessage([
  809. 'talk_type' => 100,
  810. 'title' => $articleData['title'],
  811. 'content' => '提交了审核',
  812. 'messageType' => 2,
  813. ]);
  814. }
  815. $result = Article::where(['id' => $data['id']])->update($data);
  816. if (isset($data['ignore_ids']) && !empty($data['ignore_ids'])) {
  817. //article_ignore 表插入数据 db操作
  818. //转成数组
  819. //删掉数据重新写入
  820. DB::table('article_ignore')->where('article_id', $data['id'])->delete();
  821. $website_ids = is_array($data['ignore_ids']) ? $data['ignore_ids'] : json_decode($data['ignore_ids'], true);
  822. $insert_data = [];
  823. foreach ($website_ids as $key => $value) {
  824. $insert_data[] = [
  825. 'article_id' => $data['id'],
  826. 'website_id' => $value,
  827. ];
  828. }
  829. DB::table('article_ignore')->insert($insert_data);
  830. }
  831. if ($result) {
  832. return Result::success();
  833. } else {
  834. return Result::error("更新状态失败", 0);
  835. }
  836. }
  837. /**
  838. * 获取新闻详情
  839. * @param array $data
  840. * @return array
  841. */
  842. public function getArticleInfo(array $data): array
  843. {
  844. $where = [
  845. 'article.id' => $data['id'],
  846. // 'article.status' => 1,
  847. ];
  848. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  849. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  850. $info = $result;
  851. // var_dump($info, 'info');
  852. $info['survey_array'] = $articleSurvey;
  853. if ($result) {
  854. return Result::success($info);
  855. } else {
  856. return Result::error("查询失败", 0);
  857. }
  858. }
  859. /**
  860. * 获取头条新闻
  861. * @param array $data
  862. * @return array
  863. */
  864. public function getWebsiteArticlett(array $data): array
  865. {
  866. $website_id = $data['website_id'];
  867. $website = Website::where('id', $data['website_id'])->first();
  868. if(empty($website)){
  869. return Result::error("网站不存在",0);
  870. }
  871. $categorys = $this->processArticlePro($website_id);
  872. $catiall = $categorys['catiall'];
  873. $categoryIds = $categorys['categoryIds'];
  874. $where = [
  875. 'status' => 1
  876. ];
  877. // $website_column = $website['column'];
  878. if(!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]'){
  879. $website_column = json_decode($website['website_column_arr_id'],true);
  880. }
  881. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  882. // return Result::success($diff_pid_categoryIds);
  883. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  884. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  885. }
  886. // $website_id = $data['website_id'];
  887. $month = date("Y-m-d H:i:s", strtotime("-30 day"));
  888. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  889. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  890. switch ($data['level']) {
  891. case 1:
  892. case 2:
  893. case 3:
  894. case 6: //1.头条资讯;2.轮播图;3.推荐图;6.今日热点
  895. $query = Article::where($where)
  896. ->where('level', 'like', '%' . $data['level'] . '%')
  897. ->orderBy('updated_at', 'desc');
  898. break;
  899. case 4: //最新资讯
  900. $query = Article::where($where)->orderBy('updated_at', 'desc');
  901. break;
  902. case 5: //资讯推荐
  903. $query = Article::where($where)
  904. ->where('updated_at', '>', $month);
  905. break;
  906. case 7: //资讯分类
  907. if (isset($data['id']) && !empty($data['id'])) {
  908. $keyword = Article::where('id', $data['id'])->value('keyword');
  909. $keywordArray = explode(',', $keyword);
  910. $whereL7 = [];
  911. foreach ($keywordArray as $k => $v) {
  912. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  913. }
  914. $query = Article::where($where)->where($whereL7)->orderBy('updated_at', 'desc');;
  915. break;
  916. } else {
  917. return Result::error("请输入资讯ID", 0);
  918. break;
  919. }
  920. default:
  921. break;
  922. }
  923. // $whereL7 = [];
  924. // if(isset($data['id']) && !empty($data['id'])){
  925. // $keyword = Article::where('id', $data['id'])->value('keyword');
  926. // $keywordArray = explode(',', $keyword);
  927. // foreach ($keywordArray as $k => $v) {
  928. // $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  929. // }
  930. // }
  931. // $query = Article::where($where)
  932. // ->when(isset($data['level']) && !empty($data['level']), function ($query) use ($data,$whereL7) {
  933. // if($data['level'] == 1 || $data['level'] == 2 || $data['level'] == 3 || $data['level'] == 6){
  934. // $query = $query->where('article.level','like','%'.$data['level'].'%')->orderBy('updated_at','desc');
  935. // }
  936. // if($data['level'] == 7){
  937. // $query = $query->where($whereL7)->orderBy('updated_at','desc');
  938. // }
  939. // if($data['level'] == 4){
  940. // $query = $query->inRandomOrder()
  941. // ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  942. // }
  943. // if($data['level'] == 5){
  944. // $query = $query->orderBy('updated_at','desc');
  945. // }
  946. // });
  947. if ($data['textnum'] > 0) {
  948. $query = clone $query;
  949. $result['text'] = $query
  950. ->whereIn('catid', $categoryIds)
  951. ->leftJoinSub(function ($query) use ($website_id) {
  952. $query->from('article_ignore')
  953. ->where('website_id', $website_id);
  954. }, 'article_ignore', function ($join) {
  955. $join->on('article_ignore.article_id', '=', 'article.id');
  956. })
  957. ->where(function ($query) use ($website_id) {
  958. $query->whereNull('article_ignore.article_id')
  959. ->orWhere('article_ignore.website_id', '!=', $website_id);
  960. })
  961. ->select(
  962. 'article.id',
  963. 'article.title',
  964. 'article.author',
  965. 'article.updated_at',
  966. 'article.introduce',
  967. 'article.islink',
  968. 'article.linkurl',
  969. 'article.copyfrom',
  970. 'article.cat_arr_id',
  971. 'article.catid',
  972. 'article.level'
  973. )
  974. ->offset($data['placeid'])
  975. ->limit($data['textnum'])
  976. ->get()->all();
  977. foreach ($result['text'] as $k => $v) {
  978. $result['text'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  979. $result['text'][$k]->alias = $catiall[$v->catid]['alias'];
  980. }
  981. }
  982. if ($data['imgnum'] > 0) {
  983. $query = clone $query;
  984. $result['img'] = $query
  985. ->whereIn('catid', $categoryIds)
  986. ->where('article.imgurl', '!=', '')
  987. ->select(
  988. 'article.id',
  989. 'article.title',
  990. 'article.imgurl',
  991. 'article.author',
  992. 'article.updated_at',
  993. 'article.introduce',
  994. 'article.islink',
  995. 'article.linkurl',
  996. 'article.copyfrom',
  997. 'article.cat_arr_id',
  998. 'article.catid',
  999. 'article.level'
  1000. )
  1001. ->offset($data['placeid'])
  1002. ->limit($data['imgnum'])
  1003. ->get()->all();
  1004. foreach ($result['img'] as $k => $v) {
  1005. $result['img'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1006. $result['img'][$k]->alias = $catiall[$v->catid]['alias'];
  1007. }
  1008. }
  1009. if (empty($result)) {
  1010. return Result::error("暂无相关资讯", 0);
  1011. }
  1012. return Result::success($result);
  1013. }
  1014. /**
  1015. * 获取模块新闻
  1016. * @param array $data
  1017. * @return array
  1018. */
  1019. public function getWebsiteModelArticles(array $data): array
  1020. {
  1021. $catid = $data['catid'];
  1022. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  1023. $category = $category->toArray();
  1024. if (!empty($category)) {
  1025. $where = [
  1026. 'status' => 1,
  1027. 'catid' => $catid,
  1028. ];
  1029. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  1030. // 1:文字新闻;2:轮播图;3:图文;
  1031. // 级别:0:未分类
  1032. // 3:推荐图片
  1033. if ($data['level'] == 1) {
  1034. $data['level'] = 0;
  1035. }
  1036. $result = Article::where($where)
  1037. ->where(function ($query) use ($data) {
  1038. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  1039. ->orWhereNull("level")
  1040. ->orWhereRaw("level = '[]'");
  1041. })
  1042. ->where(function ($query) use ($data) {
  1043. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1044. ->orWhereNull("ignore_ids");
  1045. })
  1046. ->orderBy("updated_at", "desc")
  1047. ->offset($placeid)
  1048. ->limit($data['pagesize'])
  1049. ->get();
  1050. if (empty($result)) {
  1051. return Result::error("此栏目暂无相关新闻", 0);
  1052. }
  1053. } else {
  1054. return Result::error("此网站暂无此栏目", 0);
  1055. }
  1056. return Result::success($result);
  1057. }
  1058. /**
  1059. *获取新闻列表
  1060. * @param array $data
  1061. * @return array
  1062. */
  1063. public function getWebsiteArticleList(array $data): array
  1064. {
  1065. // return Result::success($data);
  1066. $where[] = ['status', '=', 1];
  1067. $website_id = $data['website_id'];
  1068. $website = Website::where('id', $data['website_id'])->first();
  1069. if(empty($website)){
  1070. return Result::error("网站不存在",0);
  1071. }
  1072. // $website_column = $website['column'];
  1073. if(!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]'){
  1074. $website_column = json_decode($website['website_column_arr_id'],true);
  1075. }
  1076. $categorys = $this->processArticlePro($website_id);
  1077. $cat_1st_arr = $categorys['cat_1st_arr'];
  1078. $catiall = $categorys['catiall'];
  1079. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1080. // return Result::success($diff_pid_categoryIds);
  1081. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1082. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1083. }
  1084. if (isset($data['catid']) && !empty($data['catid'])) {
  1085. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  1086. if (empty($category)) {
  1087. return Result::error("此网站暂无此栏目", 0);
  1088. }
  1089. array_push($where, ['catid', '=', $data['catid']]);
  1090. }
  1091. // return Result::success($where);
  1092. $query = Article::where($where)
  1093. ->leftJoinSub(function ($query) use ($website_id) {
  1094. $query->from('article_ignore')
  1095. ->where('website_id', $website_id);
  1096. }, 'article_ignore', function ($join) {
  1097. $join->on('article_ignore.article_id', '=', 'article.id');
  1098. })
  1099. ->where(function ($query) use ($website_id) {
  1100. $query->whereNull('article_ignore.article_id')
  1101. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1102. })
  1103. ->select(
  1104. 'article.id',
  1105. 'article.title',
  1106. 'article.imgurl',
  1107. 'article.author',
  1108. 'article.updated_at',
  1109. 'article.introduce',
  1110. 'article.islink',
  1111. 'article.linkurl',
  1112. 'article.copyfrom',
  1113. 'article.cat_arr_id',
  1114. 'article.catid'
  1115. );
  1116. $count = $query->count();
  1117. $rep = $query->orderBy("updated_at", "desc")
  1118. ->offset(($data['page'] - 1) * $data['pageSize'])
  1119. ->limit($data['pageSize'])
  1120. ->get()->all();
  1121. $categorys = $this->processArticlePro($website_id);
  1122. $cat_1st_arr = $categorys['cat_1st_arr'];
  1123. $catiall = $categorys['catiall'];
  1124. // $web['website_id'] = $data['website_id'];
  1125. foreach ($rep as $k => $v) {
  1126. $rep[$k]->category_name = $catiall[$v->catid]['alias'];
  1127. $rep[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1128. }
  1129. // $rep = $this->processArticles($rep,$web);
  1130. $data = [
  1131. 'rows' => $rep,
  1132. 'count' => $count,
  1133. ];
  1134. if (empty($rep)) {
  1135. return Result::error("没有信息数据");
  1136. }
  1137. return Result::success($data);
  1138. }
  1139. /**
  1140. * 前端-获取新闻详情
  1141. * @param array $data
  1142. * @return array
  1143. */
  1144. public function selectWebsiteArticleInfo(array $data): array
  1145. {
  1146. $where = [
  1147. 'article.id' => $data['id'],
  1148. 'article.status' => 1,
  1149. ];
  1150. $result = Article::where($where)
  1151. ->leftJoin("article_data", "article.id", "article_data.article_id")
  1152. ->leftJoin("article_extend", "article_extend.article_id", "article.id")
  1153. ->where(function ($query) use ($data) {
  1154. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1155. ->orWhereNull("ignore_ids");
  1156. })
  1157. ->select(
  1158. 'article.*',
  1159. 'article_data.content',
  1160. 'article_data.article_id',
  1161. 'article_extend.website_url',
  1162. 'article_extend.email',
  1163. 'article_extend.contacts',
  1164. 'article_extend.contacts_mobile',
  1165. 'article_extend.contacts_address',
  1166. 'article_extend.zip_code',
  1167. 'article_extend.enterprise_name'
  1168. )
  1169. ->first();
  1170. if (empty($result)) {
  1171. return Result::error("暂无此新闻!", 0);
  1172. }
  1173. if (!empty($result['publiced_at'])) {
  1174. $result['updated_at'] = $result['publiced_at'];
  1175. }
  1176. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  1177. ->select('website_category.*', 'website.website_name', 'website.suffix')
  1178. ->where('website_category.website_id', $data['website_id'])
  1179. ->where(['website_category.category_id' => $result['catid']])
  1180. ->first();
  1181. if (empty($category)) {
  1182. return Result::error("查询失败", 0);
  1183. }
  1184. //手动推荐文章
  1185. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  1186. if (empty($commend_ids)) {
  1187. $commendArticle = [];
  1188. } else {
  1189. //去除不存在的文章ID
  1190. $commendArticle = Article::whereIn('article.id', $commend_ids)
  1191. ->leftjoin('website_category', 'website_category.category_id', '=', 'article.catid')
  1192. ->where('article.status', 1)
  1193. ->where('website_category.website_id', $data['website_id'])
  1194. ->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')
  1195. ->orderByRaw("FIELD(article.id, " . implode(',', $commend_ids) . ")")
  1196. // ->orderBy('article.updated_at', 'desc')
  1197. ->limit(5)
  1198. ->get();
  1199. //循环数组,取出cat_arr_id中的不重复值,再从website_category取出alias_pinyin,再将cat_arr_id的json转成路径/隔开
  1200. foreach ($commendArticle as $k => $v) {
  1201. $cat_arr_id = json_decode($v->cat_arr_id, true);
  1202. if (!empty($cat_arr_id) && is_array($cat_arr_id)) {
  1203. $cat_arr_id = array_unique($cat_arr_id);
  1204. // 从website_category取出alias_pinyin
  1205. $cat_arr = WebsiteCategory::where('website_id', $data['website_id'])
  1206. ->whereIn('category_id', $cat_arr_id)
  1207. ->pluck('alias_pinyin', 'category_id')
  1208. ->toArray();
  1209. // 将cat_arr_id的json转成路径/隔开
  1210. $path_parts = [];
  1211. foreach ($cat_arr_id as $cat_id) {
  1212. if (isset($cat_arr[$cat_id])) {
  1213. $path_parts[] = $cat_arr[$cat_id];
  1214. }
  1215. }
  1216. $v->alias_pinyin = implode('/', $path_parts);
  1217. } else {
  1218. $v->alias_pinyin = '';
  1219. }
  1220. }
  1221. }
  1222. $result['category_id'] = $category['category_id'];
  1223. $result['cat_name'] = $category['alias'];
  1224. $result['website_name'] = $category['website_name'] ?? "";
  1225. $result['suffix'] = $category['suffix'] ?? "";
  1226. $result['commendArticle'] = $commendArticle;
  1227. $result['commend_ids'] = $commend_ids;
  1228. return Result::success($result);
  1229. }
  1230. /**
  1231. * 前端-获取网站调查问卷
  1232. * @param array $data
  1233. * @return array
  1234. */
  1235. public function getWebsiteSurvey(array $data): array
  1236. {
  1237. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1238. $website = Website::where('id', $data['website_id'])->first();
  1239. if (empty($website)) {
  1240. return Result::error("暂无此网站", 0);
  1241. }
  1242. }
  1243. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1244. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1245. if (empty($article)) {
  1246. return Result::error("暂无此文章", 0);
  1247. }
  1248. // return Result::error($data,0);
  1249. $where['art_id'] = $data['art_id'];
  1250. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1251. } else {
  1252. $survey = Article::where(function ($query) {
  1253. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1254. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1255. })
  1256. ->where('status', 1)
  1257. ->where('is_survey', 1)
  1258. ->select('survey_id')
  1259. ->orderBy('updated_at', 'desc')
  1260. ->first();
  1261. if (empty($survey)) {
  1262. return Result::error("暂无调查问卷", 0);
  1263. }
  1264. $where['sur_id'] = $survey['survey_id'];
  1265. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1266. }
  1267. // return Result::success($where);
  1268. $result = ArticleSurvey::where($where)
  1269. ->where(function ($query) {
  1270. $query->where('is_other', 0)
  1271. ->orWhere(function ($subQuery) {
  1272. $subQuery->where('is_other', 1)
  1273. ->where('other_id', 0);
  1274. });
  1275. })
  1276. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1277. ->select('article_survey.*', 'article.survey_type')
  1278. ->get()->all();
  1279. if (empty($result)) {
  1280. return Result::error("此文章暂无调查问卷", 0);
  1281. }
  1282. return Result::success($result);
  1283. }
  1284. /**
  1285. * 前端-添加网站调查问卷选项
  1286. * @param array $data
  1287. * @return array
  1288. */
  1289. public function addWebsiteSurveyOption(array $data): array
  1290. {
  1291. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1292. $website = Website::where('id', $data['website_id'])->first();
  1293. if (empty($website)) {
  1294. return Result::error("暂无此网站", 0);
  1295. }
  1296. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1297. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1298. if (empty($survey)) {
  1299. return Result::error("此调查问卷不可添加选项", 0);
  1300. }
  1301. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1302. $choice = [
  1303. 'art_id' => $survey['art_id'],
  1304. 'website_id' => $data['website_id'],
  1305. 'survey_name' => $survey['survey_name'],
  1306. 'choice_name' => $data['choice_name'],
  1307. 'sur_id' => $survey['sur_id'],
  1308. 'is_other' => 1,
  1309. 'other_id' => $survey['id'],
  1310. ];
  1311. $result = ArticleSurvey::insertGetId($choice);
  1312. if (empty($result)) {
  1313. return Result::error("添加失败", 0);
  1314. }
  1315. return Result::success($result);
  1316. }
  1317. }
  1318. return Result::error("添加失败", 0);
  1319. }
  1320. return Result::error("添加失败", 0);
  1321. }
  1322. /**
  1323. * 前端-调查问卷投票
  1324. * @param array $data
  1325. * @return array
  1326. */
  1327. public function addWebsiteSurveyVote(array $data): array
  1328. {
  1329. // return Result::success($data);
  1330. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1331. $website = Website::where('id', $data['website_id'])->first();
  1332. if (empty($website)) {
  1333. return Result::error("暂无此网站", 0);
  1334. }
  1335. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1336. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1337. // return Result::success($survey);
  1338. if (empty($is_survey)) {
  1339. return Result::error("此调查问卷不存在", 0);
  1340. }
  1341. // return Result::success($survey);
  1342. // 调查问卷类型
  1343. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1344. //多选 若是json型则转化成数组类型
  1345. if (strpos($data['choice_id'], '[') === 0) {
  1346. $data['choice_id'] = json_decode($data['choice_id'], true);
  1347. } else {
  1348. // 单选 也转换成数组
  1349. $data['choice_id'] = [$data['choice_id']];
  1350. }
  1351. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1352. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1353. // ->where('website_id',$data['website_id'])
  1354. ->where('is_other', 1)
  1355. ->where('other_id', 0)
  1356. ->first();
  1357. if (!empty($other)) {
  1358. return Result::error("请选择已有的选项!", 0);
  1359. }
  1360. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1361. // ->where('website_id',$data['website_id'])
  1362. ->where('is_other', 1)
  1363. ->where('other_id', '!=', 0)
  1364. ->first();
  1365. // return Result::success($choice['other']);
  1366. $choice_id = $data['choice_id'];
  1367. if (!empty($choice['other'])) {
  1368. // array_push($data['choice_id'],$choice['other']['other_id']);
  1369. if (!empty($choice_id)) {
  1370. $key = array_search($choice['other']['id'], $choice_id);
  1371. if ($key !== false) {
  1372. unset($choice_id[$key]);
  1373. $choice_id = array_values($choice_id);
  1374. }
  1375. array_push($choice_id, $choice['other']['other_id']);
  1376. } else {
  1377. $choice_id[0] = $choice['other']['other_id'];
  1378. }
  1379. array_push($data['choice_id'], $choice['other']['other_id']);
  1380. }
  1381. // return Result::success($data);
  1382. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1383. // ->where('website_id',$data['website_id'])
  1384. ->increment('results', 1);
  1385. if (empty($choice)) {
  1386. return Result::error("请选择已有的选项!", 0);
  1387. }
  1388. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1389. // ->where('website_id',$data['website_id'])
  1390. ->where('other_id', 0)
  1391. ->get();
  1392. $survey['choice'] = $choice_id;
  1393. return Result::success($survey);
  1394. }
  1395. return Result::error("参数必填!");
  1396. }
  1397. return Result::error("此调查问卷不存在", 0);
  1398. }
  1399. return Result::error("参数必填!");
  1400. }
  1401. /**
  1402. * 后端-获取网站调查问卷列表
  1403. * @param array $data
  1404. * @return array
  1405. */
  1406. public function getSurveyList(array $data): array
  1407. {
  1408. $where = [];
  1409. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1410. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1411. }
  1412. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  1413. array_push($where, ['survey_type', '=', $data['survey_type']]);
  1414. }
  1415. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  1416. array_push($where, ['is_survey', '=', $data['is_survey']]);
  1417. }
  1418. // return Result::success($where);
  1419. if (!empty($where)) {
  1420. $query = Article::where($where)->where(function ($q) {
  1421. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1422. });
  1423. } else {
  1424. $query = Article::where(function ($q) {
  1425. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1426. });
  1427. }
  1428. $count = $query->count();
  1429. $survey = $query->orderByDesc('id')
  1430. ->limit($data['pageSize'])
  1431. ->offset(($data['page'] - 1) * $data['pageSize'])
  1432. ->get();
  1433. if (empty($survey->toArray())) {
  1434. return Result::error("暂无调查问卷!", 0);
  1435. }
  1436. $result = [
  1437. 'rows' => $survey,
  1438. 'count' => $count,
  1439. ];
  1440. return Result::success($result);
  1441. }
  1442. /**
  1443. * 后端-获取网站调查问卷详情
  1444. * @param array $data
  1445. * @return array
  1446. */
  1447. public function getSurveyInfo(array $data): array
  1448. {
  1449. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1450. $where = ['sur_id' => $data['sur_id']];
  1451. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1452. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1453. ->select('article_survey.*', 'article.survey_type')
  1454. ->get()->all();
  1455. if (empty($choose)) {
  1456. return Result::error("此调查问卷不存在", 0);
  1457. }
  1458. $resultsArray = array_column($choose, 'results');
  1459. $total = array_sum($resultsArray);
  1460. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1461. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1462. // $total = 0;
  1463. if (!empty($other)) {
  1464. $total = $total + $other['results'];
  1465. $other['choice_name'] = '(其他)';
  1466. if (!empty($others)) {
  1467. $other['hasChildren'] = true;
  1468. // array_push($other,['hasChildren','=',true]);
  1469. $other['children'] = $others;
  1470. $other_choices = [$other->toArray()];
  1471. $mer_choice = array_merge($choose, $other_choices);
  1472. $value_choice = array_values($mer_choice);
  1473. } else {
  1474. // return Result::error('1111');
  1475. $other_choices = [$other->toArray()];
  1476. $other_choices = array_merge($choose, $other_choices);
  1477. $value_choice = array_values($other_choices);
  1478. // return Result::success($result);
  1479. }
  1480. } else {
  1481. $value_choice = $choose;
  1482. }
  1483. $result = [
  1484. 'choose' => $value_choice,
  1485. 'total' => $total,
  1486. ];
  1487. }
  1488. return Result::success($result);
  1489. }
  1490. /**
  1491. * 前端-搜索新闻列表
  1492. * @param array $data
  1493. * @return array
  1494. */
  1495. public function selectWebsiteArticle(array $data): array
  1496. {
  1497. $website = Website::where('id', $data['website_id'])->first();
  1498. if(empty($website)){
  1499. return Result::error("网站不存在",0);
  1500. }
  1501. // $website_column = $website['column'];
  1502. if(!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]'){
  1503. $website_column = json_decode($website['website_column_arr_id'],true);
  1504. }
  1505. $website_id = $data['website_id'];
  1506. $categorys = $this->processArticlePro($website_id);
  1507. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1508. // return Result::success($diff_pid_categoryIds);
  1509. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1510. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1511. }
  1512. // return Result::success(reset($diff_pid_categoryIds) == 0);
  1513. // $cat_1st_arr = $categorys['cat_1st_arr'];
  1514. $catiall = $categorys['catiall'];
  1515. $categoryIds = $categorys['categoryIds'];
  1516. // return Result::success($categoryIds);
  1517. $query = Article::where('status', 1)
  1518. ->whereIn('catid', $categoryIds)
  1519. ->leftJoinSub(function ($query) use ($website_id) {
  1520. $query->from('article_ignore')
  1521. ->where('website_id', $website_id);
  1522. }, 'article_ignore', function ($join) {
  1523. $join->on('article_ignore.article_id', '=', 'article.id');
  1524. })
  1525. ->where(function ($query) use ($website_id) {
  1526. $query->whereNull('article_ignore.article_id')
  1527. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1528. });
  1529. // ->get()->all();
  1530. // return Result::success($query);
  1531. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1532. $query->whereRaw("JSON_CONTAINS(city_arr_id, '" . intval($data['cityid']) . "')");
  1533. }
  1534. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1535. $query->whereRaw("JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "')");
  1536. }
  1537. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1538. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  1539. }
  1540. // 计算总数
  1541. $count = $query->count();
  1542. // return Result::success($count);
  1543. // 分页查询
  1544. $articles = $query
  1545. ->select(
  1546. 'article.id',
  1547. 'article.title',
  1548. 'article.imgurl',
  1549. 'article.author',
  1550. 'article.updated_at',
  1551. 'article.introduce',
  1552. 'article.islink',
  1553. 'article.linkurl',
  1554. 'article.copyfrom',
  1555. 'article.cat_arr_id',
  1556. 'article.catid',
  1557. 'article.department_arr_id',
  1558. 'article.city_arr_id',
  1559. )
  1560. ->orderBy("updated_at", "desc")
  1561. ->offset(($data['page'] - 1) * $data['pageSize'])
  1562. ->limit($data['pageSize'])
  1563. ->get();
  1564. // return Result::success($articles);
  1565. foreach ($articles as $k => $v) {
  1566. $articles[$k]->category_name = $catiall[$v->catid]['alias'];
  1567. $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1568. }
  1569. if (empty($articles)) {
  1570. return Result::error("没有符合条件的资讯数据");
  1571. }
  1572. $result = [
  1573. 'rows' => $articles,
  1574. 'count' => $count,
  1575. ];
  1576. return Result::success($result);
  1577. }
  1578. /**
  1579. * 模块新闻加强版
  1580. * @param array $data
  1581. * @return array
  1582. */
  1583. public function getWebsiteCatidArticle(array $data): array
  1584. {
  1585. $where = [
  1586. 'website_category.category_id' => $data['catid'],
  1587. 'website_category.website_id' => $data['website_id'],
  1588. ];
  1589. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  1590. $child_catnum = $data['child_catnum'] ?? 1;
  1591. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  1592. $childCategoryIds = array_column($category['child'], 'category_id');
  1593. if (empty($childCategoryIds)) {
  1594. return Result::error("暂无子栏目", 0);
  1595. }
  1596. $imgArticles = [];
  1597. $textArticles = [];
  1598. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  1599. // 初始化子分类图片新闻和文字新闻数组
  1600. // 查询所有子级栏目的图文新闻
  1601. $imgArticles = Article::where('catid', $childCategoryIds[0])
  1602. ->where(function ($query) use ($data) {
  1603. $query->where(function ($subQuery) use ($data) {
  1604. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1605. })->orWhereNull("ignore_ids");
  1606. })
  1607. ->where('status', 1)
  1608. ->where('imgurl', '!=', '')
  1609. ->select('*')
  1610. ->orderBy('updated_at', 'desc')
  1611. ->limit($data['child_imgnum'])
  1612. ->get();
  1613. }
  1614. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  1615. // 查询所有子级栏目的文字新闻
  1616. $textArticles = Article::where('catid', $childCategoryIds[0])
  1617. ->where('status', 1)
  1618. ->where(function ($query) use ($data) {
  1619. $query->where(function ($subQuery) use ($data) {
  1620. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1621. })->orWhereNull("ignore_ids");
  1622. })
  1623. ->select('*')
  1624. ->orderBy('updated_at', 'desc')
  1625. ->limit($data['child_textnum'])
  1626. ->get();
  1627. }
  1628. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  1629. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  1630. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  1631. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  1632. return $child;
  1633. }, $category['child']);
  1634. }
  1635. // }
  1636. if (isset($data['img_num']) && !empty($data['img_num'])) {
  1637. $category['img'] = WebsiteCategory::where($where)
  1638. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1639. ->where('article.status', 1)
  1640. ->where('article.imgurl', '!=', '')
  1641. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1642. ->orderBy('article.updated_at', 'desc')
  1643. ->limit($data['img_num'])
  1644. ->get();
  1645. }
  1646. if (isset($data['text_num']) && !empty($data['text_num'])) {
  1647. $category['text'] = WebsiteCategory::where($where)
  1648. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1649. ->where('article.status', 1)
  1650. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1651. ->orderBy('article.updated_at', 'desc')
  1652. ->limit($data['text_num'])
  1653. ->get();
  1654. }
  1655. // $category = $category->get();
  1656. if (empty($category)) {
  1657. return Result::error("查询失败", 0);
  1658. }
  1659. return Result::success($category);
  1660. }
  1661. /**
  1662. * 模块新闻加强plus版
  1663. * @param array $data
  1664. * @return array
  1665. */
  1666. public function getWebsiteAllArticle(array $data): array
  1667. {
  1668. // return Result::success($data);
  1669. $time1 = microtime(true);
  1670. $wetbsite_id = $data['website_id'] ?? 2;
  1671. $data = json_decode($data['id'], true);
  1672. $website = Website::where('id', $wetbsite_id)->first();
  1673. if(empty($website)){
  1674. return Result::error("网站不存在",0);
  1675. }
  1676. // return Result::success($website);
  1677. $website_column = $website['website_column_arr_id'] ?? '[]';
  1678. $website_column = json_decode($website_column,true);
  1679. $categorys = $this->processArticlePro($wetbsite_id);
  1680. $cat_1st_arr = $categorys['cat_1st_arr'];
  1681. $catiall = $categorys['catiall'];
  1682. // return Result::success($catiall);
  1683. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  1684. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1685. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1686. }
  1687. $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
  1688. // return Result::success($categorys);
  1689. $parent_category = array_column($data, 'parent');
  1690. $parent_cat = [];
  1691. $child_category = array_column($data, 'child');
  1692. if (!empty($parent_category)) {
  1693. foreach ($parent_category as $key => $value) {
  1694. $arr = array_map('intval', explode(',', $value));
  1695. $parent_cat[$key] = $arr[0] ?? 0;
  1696. $parent_category = $arr[0] ?? 0;
  1697. $article_imgnum = $arr[1] ?? 0;
  1698. $article_textnum = $arr[2] ?? 0;
  1699. if ($parent_category != 0) {
  1700. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  1701. // return Result::success($category_arr);
  1702. if ($article_imgnum != 0) {
  1703. $img_article = Article::whereIn('catid', $category_arr)
  1704. ->where('status', 1)
  1705. ->where('imgurl', '!=', '')
  1706. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1707. $query->from('article_ignore')
  1708. ->where('website_id', $wetbsite_id);
  1709. }, 'article_ignore', function ($join) {
  1710. $join->on('article_ignore.article_id', '=', 'article.id');
  1711. })
  1712. ->where(function ($query) use ($wetbsite_id) {
  1713. $query->whereNull('article_ignore.article_id')
  1714. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1715. })
  1716. ->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')
  1717. ->orderBy('updated_at', 'desc')
  1718. ->limit($article_imgnum)
  1719. ->get()->all();
  1720. foreach ($img_article as $k => $v) {
  1721. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1722. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1723. }
  1724. } else {
  1725. $img_article = [];
  1726. }
  1727. if ($article_textnum != 0) {
  1728. $text_article = Article::whereIn('catid', $category_arr)
  1729. ->where('status', 1)
  1730. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1731. $query->from('article_ignore')
  1732. ->where('website_id', $wetbsite_id);
  1733. }, 'article_ignore', function ($join) {
  1734. $join->on('article_ignore.article_id', '=', 'article.id');
  1735. })
  1736. ->where(function ($query) use ($wetbsite_id) {
  1737. $query->whereNull('article_ignore.article_id')
  1738. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1739. })
  1740. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1741. ->orderBy('updated_at', 'desc')
  1742. ->limit($article_textnum)
  1743. ->get()->all();
  1744. foreach ($text_article as $k => $v) {
  1745. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1746. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1747. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  1748. }
  1749. } else {
  1750. $text_article = [];
  1751. }
  1752. $catiall[$parent_category]['imgnum'] = $img_article;
  1753. $catiall[$parent_category]['textnum'] = $text_article;
  1754. $parent[$key] = $catiall[$parent_category];
  1755. } else {
  1756. $parent[$key] = '';
  1757. }
  1758. }
  1759. }
  1760. if (!empty($child_category)) {
  1761. foreach ($child_category as $key => $value) {
  1762. $arr = array_map('intval', explode(',', $value));
  1763. $parent_category = $parent_cat[$key];
  1764. $child_category = $arr[0] ?? 0;
  1765. $article_imgnum = $arr[1] ?? 0;
  1766. $article_textnum = $arr[2] ?? 0;
  1767. if ($child_category != 0) {
  1768. $all_childcat = $cat_1st_arr[$parent_category];
  1769. $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
  1770. // 从 $websiteInfoIndexed 中获取对应的数据
  1771. $info = $websiteInfoIndexed[$v];
  1772. // 返回一个包含所需信息的数组
  1773. return [
  1774. 'alias' => $info->alias,
  1775. 'category_id' => $info->category_id,
  1776. 'aLIas_pinyin' => $info->aLIas_pinyin,
  1777. 'pid' => $info->pid,
  1778. 'type' => $info->type,
  1779. 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
  1780. 'pinyin' => $info->pinyin,
  1781. ];
  1782. }, $all_childcat);
  1783. if ($article_imgnum != 0) {
  1784. $img_article = Article::where('catid', $child_category)
  1785. ->where('status', 1)
  1786. ->where('imgurl', '!=', '')
  1787. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1788. $query->from('article_ignore')
  1789. ->where('website_id', $wetbsite_id);
  1790. }, 'article_ignore', function ($join) {
  1791. $join->on('article_ignore.article_id', '=', 'article.id');
  1792. })
  1793. ->where(function ($query) use ($wetbsite_id) {
  1794. $query->whereNull('article_ignore.article_id')
  1795. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1796. })
  1797. ->select('id', 'title', 'imgurl', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1798. ->orderBy('updated_at', 'desc')
  1799. ->limit($article_imgnum)
  1800. ->get()->all();
  1801. foreach ($img_article as $k => $v) {
  1802. // var_dump($v);
  1803. // var_dump($k);
  1804. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1805. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1806. }
  1807. } else {
  1808. $img_article = [];
  1809. }
  1810. if ($article_textnum != 0) {
  1811. $text_article = Article::where('catid', $child_category)
  1812. ->where('status', 1)
  1813. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1814. $query->from('article_ignore')
  1815. ->where('website_id', $wetbsite_id);
  1816. }, 'article_ignore', function ($join) {
  1817. $join->on('article_ignore.article_id', '=', 'article.id');
  1818. })
  1819. ->where(function ($query) use ($wetbsite_id) {
  1820. $query->whereNull('article_ignore.article_id')
  1821. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1822. })
  1823. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1824. ->orderBy('updated_at', 'desc')
  1825. ->limit($article_textnum)
  1826. ->get()->all();
  1827. foreach ($text_article as $k => $v) {
  1828. // var_dump($v);
  1829. // var_dump($k);
  1830. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1831. // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1832. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1833. }
  1834. } else {
  1835. $text_article = [];
  1836. }
  1837. $catiall[$child_category]['all_childcat'] = $processedChildCat;
  1838. $catiall[$child_category]['imgnum'] = $img_article;
  1839. $catiall[$child_category]['textnum'] = $text_article;
  1840. $child[$key] = $catiall[$child_category];
  1841. // var_dump($pids);
  1842. } else {
  1843. $child[$key] = '';
  1844. }
  1845. }
  1846. }
  1847. foreach ($parent as $key => $value) {
  1848. $result[$key] = $value;
  1849. if (!empty($child[$key])) {
  1850. // var_dump($child[$key]);
  1851. $result[$key]['child'] = $child[$key];
  1852. // $value[$key]['child'] = $child[$key];
  1853. } else {
  1854. $result[$key]['child'] = [
  1855. "alias" => null,
  1856. "category_id" => null,
  1857. "type" => null,
  1858. "pinyin" => null,
  1859. "all_childcat" => [],
  1860. "imgnum" => [],
  1861. "textnum" => []
  1862. ];
  1863. }
  1864. }
  1865. return Result::success($result);
  1866. }
  1867. /**
  1868. * 辅助方法:获取文章列表
  1869. */
  1870. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  1871. {
  1872. sleep(1);
  1873. $query = Article::where('article.status', 1)
  1874. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  1875. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  1876. ->where(function ($query) use ($website) {
  1877. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  1878. })
  1879. ->leftJoin('website_category', function ($join) use ($website) {
  1880. $join->on('article.catid', '=', 'website_category.category_id')
  1881. ->where('website_category.website_id', '=', $website['website_id']);
  1882. })
  1883. ->select(
  1884. 'article.id',
  1885. 'article.title',
  1886. 'article.imgurl',
  1887. 'article.author',
  1888. 'article.updated_at',
  1889. 'article.introduce',
  1890. 'article.islink',
  1891. 'article.linkurl',
  1892. 'article.copyfrom',
  1893. 'article.cat_arr_id',
  1894. 'article.catid',
  1895. 'website_category.alias as category_name'
  1896. )
  1897. ->orderBy('updated_at', 'desc')
  1898. ->limit($limit);
  1899. // 如果是图片文章,添加图片URL条件
  1900. if ($isImageArticle) {
  1901. $query->where('imgurl', '!=', '');
  1902. } else {
  1903. // 文字文章不需要imgurl字段
  1904. $query->addSelect('article.introduce');
  1905. }
  1906. $articles = $query->get();
  1907. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  1908. }
  1909. /**
  1910. * 乡村网-获取特殊新闻模块
  1911. * @param array $data
  1912. * @return array
  1913. */
  1914. public function getWebsiteArticles(array $data): array
  1915. {
  1916. $website_id = $data['website_id'];
  1917. $website = Website::where('id', $website_id)->first();
  1918. if(empty($website)){
  1919. return Result::error("网站不存在",0);
  1920. }
  1921. // return Result::success($website);
  1922. $website_column = $website['website_column_arr_id'] ?? '[]';
  1923. $website_column = json_decode($website_column, true);
  1924. $catids = json_decode($data['id'], true);
  1925. $parent_category = array_column($catids, 'parent');
  1926. if(!empty($parent_category) && is_array($parent_category)) {
  1927. $categorys = $this->processArticlePro($website_id);
  1928. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  1929. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1930. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1931. }
  1932. $catiall = $categorys['catiall'];
  1933. $cat_1st_arr = $categorys['cat_1st_arr'];
  1934. // return Result::success($categorys);
  1935. foreach ($parent_category as $key => $value) {
  1936. $arr = array_map('intval', explode(',', $value));
  1937. $parent_category = $arr[0] ?? 0;
  1938. $article_imgnum = $arr[1] ?? 0;
  1939. $article_textnum = $arr[2] ?? 0;
  1940. if ($parent_category != 0) {
  1941. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  1942. // return Result::success($category_arr);
  1943. if ($article_imgnum != 0) {
  1944. $img_article = Article::whereIn('catid', $category_arr)
  1945. ->where('status', 1)
  1946. ->where('imgurl', '!=', '')
  1947. ->leftJoinSub(function ($query) use ($website_id) {
  1948. $query->from('article_ignore')
  1949. ->where('website_id', $website_id);
  1950. }, 'article_ignore', function ($join) {
  1951. $join->on('article_ignore.article_id', '=', 'article.id');
  1952. })
  1953. ->where(function ($query) use ($website_id) {
  1954. $query->whereNull('article_ignore.article_id')
  1955. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1956. })
  1957. ->select(
  1958. 'id',
  1959. 'title',
  1960. 'imgurl',
  1961. 'author',
  1962. 'updated_at',
  1963. 'introduce',
  1964. 'islink',
  1965. 'linkurl',
  1966. 'copyfrom',
  1967. 'cat_arr_id',
  1968. 'catid as category_id'
  1969. )
  1970. ->orderBy('updated_at', 'desc')
  1971. ->limit($article_imgnum)
  1972. ->get()->all();
  1973. foreach ($img_article as $k => $v) {
  1974. $img_article[$k]->alias = $catiall[$v->category_id]['alias'];
  1975. // return Result::success($v);
  1976. $img_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  1977. }
  1978. } else {
  1979. $img_article = [];
  1980. }
  1981. if ($article_textnum != 0) {
  1982. $text_article = Article::whereIn('catid', $category_arr)
  1983. ->where('status', 1)
  1984. ->leftJoinSub(function ($query) use ($website_id) {
  1985. $query->from('article_ignore')
  1986. ->where('website_id', $website_id);
  1987. }, 'article_ignore', function ($join) {
  1988. $join->on('article_ignore.article_id', '=', 'article.id');
  1989. })
  1990. ->where(function ($query) use ($website_id) {
  1991. $query->whereNull('article_ignore.article_id')
  1992. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1993. })
  1994. ->select(
  1995. 'id',
  1996. 'title',
  1997. 'author',
  1998. 'updated_at',
  1999. 'introduce',
  2000. 'islink',
  2001. 'linkurl',
  2002. 'copyfrom',
  2003. 'cat_arr_id',
  2004. 'catid as category_id'
  2005. )
  2006. ->orderBy('updated_at', 'desc')
  2007. ->limit($article_textnum)
  2008. ->get()->all();
  2009. foreach ($text_article as $k => $v) {
  2010. $text_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2011. $text_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2012. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2013. }
  2014. } else {
  2015. $text_article = [];
  2016. }
  2017. $catiall[$parent_category]['imgnum'] = $img_article ?? [];
  2018. $catiall[$parent_category]['textnum'] = $text_article ?? [];
  2019. $parent[$key] = $catiall[$parent_category];
  2020. } else {
  2021. $parent[$key] = [];
  2022. }
  2023. }
  2024. }
  2025. return Result::success($parent);
  2026. }
  2027. // 封装处理商品的路由问题
  2028. function processGoods($goods, $data)
  2029. {
  2030. return $goods->map(function ($good) use ($data) {
  2031. $catid = $good->catid ?? 0;
  2032. // $pinyin = '';
  2033. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2034. if (!empty($category->pid) && $category->pid != 0) {
  2035. $level = json_decode($category->category_arr_id, true);
  2036. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  2037. ->whereIn('category_id', $level)
  2038. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2039. ->get(['aLIas_pinyin'])
  2040. ->pluck('aLIas_pinyin')
  2041. ->implode('/');
  2042. } else {
  2043. $pinyin = $category->aLIas_pinyin ?? '';
  2044. }
  2045. if (isset($good->city_id) && !empty($good->city_id)) {
  2046. $city = District::where('id', $good->city_id)->first(['name']);
  2047. $good->city_name = $city->name ?? '';
  2048. }
  2049. // 解析imgurl JSON并取第一条数据
  2050. $imgUrls = json_decode($good->imgurl, true);
  2051. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  2052. $good->pinyin = $pinyin;
  2053. return $good;
  2054. });
  2055. }
  2056. /**
  2057. * 获取商城首页-根据栏目id
  2058. * @param array $data
  2059. * @return array
  2060. * */
  2061. function getWebsiteCatidshop(array $data): array
  2062. {
  2063. $input['catid'] = $data['catid'];
  2064. $input['website_id'] = $data['website_id'];
  2065. $data = json_decode($input['catid'] ?? '', true) ?? [];
  2066. $result = array_map(function ($item) use ($input) {
  2067. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  2068. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  2069. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  2070. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  2071. if (empty($category) || $category->type != 2) {
  2072. return Result::error("暂无此栏目", 0);
  2073. } else {
  2074. $website['website_id'] = $input['website_id'];
  2075. $goods = Good::where('good.status', 2)
  2076. ->where('good.website_id', $website['website_id'])
  2077. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  2078. ->select(
  2079. 'good.id',
  2080. 'good.name',
  2081. 'good.imgurl',
  2082. 'good.description',
  2083. 'good.updated_at',
  2084. 'good.catid',
  2085. 'good.type_id',
  2086. 'good.price',
  2087. 'good.com',
  2088. 'good.level',
  2089. 'good.unit'
  2090. )
  2091. ->orderBy('updated_at', 'desc')
  2092. ->offset($goodStart)
  2093. ->limit($goodNum);
  2094. $all_goods = $goods->get();
  2095. $all_goods = $this->processGoods($all_goods, $website);
  2096. }
  2097. return $all_goods ?? [];
  2098. }
  2099. }, $data);
  2100. return Result::success($result);
  2101. }
  2102. /**
  2103. * 获取商品模块
  2104. * @param array $data
  2105. * @return array
  2106. * */
  2107. public function getWebsiteshop(array $data): array
  2108. {
  2109. $input['id'] = $data['id'];
  2110. $input['website_id'] = $data['website_id'];
  2111. $catid = $data['catid'];
  2112. $data = json_decode($input['id'] ?? '', true) ?? [];
  2113. $result['goods'] = array_map(function ($item) use ($input) {
  2114. // 检查parent元素是否存在且不是undefined
  2115. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  2116. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  2117. $website = $input['website_id'];
  2118. $query = Good::where('good.status', 2)
  2119. ->where('good.website_id', $website);
  2120. switch ($Levelid) {
  2121. case 1:
  2122. case 2:
  2123. case 3:
  2124. $goods = $query->where(function ($q) use ($Levelid) {
  2125. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  2126. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  2127. });
  2128. break;
  2129. case 4:
  2130. $goods = $query;
  2131. break;
  2132. case 5:
  2133. $goods = $query->where('type_id', 1);
  2134. break;
  2135. case 6:
  2136. $goods = $query->where('type_id', 2);
  2137. break;
  2138. default:
  2139. return [];
  2140. }
  2141. $all_goods = $goods
  2142. ->select(
  2143. 'good.id',
  2144. 'good.name',
  2145. 'good.imgurl',
  2146. 'good.description',
  2147. 'good.updated_at',
  2148. 'good.catid',
  2149. 'good.type_id',
  2150. 'good.price',
  2151. 'good.level',
  2152. 'good.website_id'
  2153. )
  2154. ->orderBy('updated_at', 'desc')
  2155. ->offset($goodStart)
  2156. ->limit($goodNum)
  2157. ->get();
  2158. $web['website_id'] = $website;
  2159. $all_goods = $this->processGoods($all_goods, $web);
  2160. }
  2161. return $all_goods;
  2162. }, $data);
  2163. $website = $input['website_id'];
  2164. $result['article'] = Article::where(function ($query) use ($website) {
  2165. $query->where(function ($subQuery) use ($website) {
  2166. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  2167. })->orWhereNull("ignore_ids");
  2168. })
  2169. ->where('catid', $catid)
  2170. ->where('article.status', 1)
  2171. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  2172. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  2173. ->orderBy('article.updated_at', 'desc')
  2174. ->first();
  2175. return Result::success($result);
  2176. }
  2177. /**
  2178. * 获取商品分类
  2179. * @param array $data
  2180. * @return array
  2181. * */
  2182. public function getWebsiteshopCat(array $data): array
  2183. {
  2184. $website = $data['website_id'];
  2185. $category = WebsiteCategory::where('website_id', $website)
  2186. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  2187. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  2188. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  2189. ->orderBy('sort')
  2190. ->get();
  2191. $cat = $category->map(function ($item) use ($website) {
  2192. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  2193. $pid = $item->pid ?? 0;
  2194. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  2195. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  2196. ->where('website_id', $website)
  2197. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  2198. ->get(['aLIas_pinyin'])
  2199. ->pluck('aLIas_pinyin')
  2200. ->implode('/');
  2201. } else {
  2202. $pinyin = $item->aLIas_pinyin ?? '';
  2203. }
  2204. $item->pinyin = $pinyin;
  2205. });
  2206. if (empty($category)) {
  2207. return Result::error("栏目查询失败", 0);
  2208. }
  2209. $cat_tree = Result::buildMenuTree($category);
  2210. $web['website_id'] = $website;
  2211. $goods = Good::where('website_id', $website)
  2212. ->where('status', 2)
  2213. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  2214. ->latest('updated_at')
  2215. ->offset(($data['page'] - 1) * $data['pageSize'])
  2216. ->limit($data['pageSize'])
  2217. ->get();
  2218. if (!empty($goods)) {
  2219. if ($goods->count() > 1 && !empty($goods)) {
  2220. $goods = $this->processGoods($goods, $web);
  2221. }
  2222. } else {
  2223. $goods = [];
  2224. }
  2225. $result = [
  2226. 'category' => $cat_tree,
  2227. 'goods' => $goods,
  2228. ];
  2229. // $resul['goods'] = $goods;
  2230. if (empty($result)) {
  2231. return Result::error("查询失败", 0);
  2232. }
  2233. return Result::success($result);
  2234. }
  2235. /*
  2236. * 获取商品列表
  2237. * @param array $data
  2238. * @return array
  2239. * */
  2240. public function getWebsiteshopList(array $data): array
  2241. {
  2242. // return Result::success($data);
  2243. $where = [
  2244. 'status' => 2,
  2245. 'website_id' => $data['website_id'],
  2246. ];
  2247. // if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  2248. // return Result::error("查询失败", 0);
  2249. // }
  2250. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  2251. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  2252. $data['catid'] = $category->category_id ?? 0;
  2253. }
  2254. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2255. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  2256. }
  2257. if (isset($data['type_id']) && !empty($data['type_id'])) {
  2258. array_push($where, ['type_id', $data['type_id']]);
  2259. }
  2260. $query = Good::where($where)
  2261. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2262. $query->where(function ($q) use ($data) {
  2263. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  2264. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  2265. });
  2266. })
  2267. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2268. $query->where(function ($q) use ($data) {
  2269. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  2270. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  2271. });
  2272. })
  2273. ->select(
  2274. 'good.id',
  2275. 'good.name',
  2276. 'good.imgurl',
  2277. 'good.description',
  2278. 'good.updated_at',
  2279. 'good.com',
  2280. 'good.catid',
  2281. 'good.type_id',
  2282. 'good.website_id',
  2283. 'good.cat_arr_id',
  2284. 'good.created_at',
  2285. 'good.city_id'
  2286. )
  2287. ->latest('updated_at');
  2288. if (isset($data['ismix']) && $data['ismix'] == 1) {
  2289. $result['count'] = $query->clone()->count();
  2290. $result['goods'] = $this->processGoods(
  2291. $query->clone()
  2292. ->offset(($data['page'] - 1) * $data['pageSize'])
  2293. ->limit($data['pageSize'])
  2294. ->get(),
  2295. $data
  2296. );
  2297. } else {
  2298. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  2299. // 获取 type_id 为 1 的数据
  2300. $result['type1'] = $this->processGoods(
  2301. $query->clone()
  2302. ->where('type_id', 1)
  2303. ->offset(($data['page'] - 1) * $data['pageSize'])
  2304. ->limit($data['pageSize'])
  2305. ->get(),
  2306. $data
  2307. );
  2308. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2309. // 获取 type_id 为 2 的数据
  2310. $result['type2'] = $this->processGoods(
  2311. $query->clone()
  2312. ->where('type_id', 2)
  2313. ->offset(($data['page'] - 1) * $data['pageSize'])
  2314. ->limit($data['pageSize'])
  2315. ->get(),
  2316. $data
  2317. );
  2318. }
  2319. if (empty($result)) {
  2320. return Result::error("查询失败", 0);
  2321. }
  2322. return Result::success($result);
  2323. }
  2324. /**
  2325. * 获取商品详情
  2326. * @param array $data
  2327. * @return array
  2328. * */
  2329. public function getWebsiteshopInfo(array $data): array
  2330. {
  2331. $where = [
  2332. 'good.status' => 2,
  2333. 'good.website_id' => $data['website_id'],
  2334. 'good.id' => $data['id'],
  2335. ];
  2336. $goods = Good::where($where)
  2337. ->where('good.id', $data['id'])
  2338. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2339. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2340. ->first();
  2341. if (empty($goods)) {
  2342. return Result::error("查询失败", 0);
  2343. }
  2344. $goods->imgurl = json_decode($goods->imgurl, true);
  2345. return Result::success($goods);
  2346. }
  2347. /**
  2348. * plus pro 处理文章路由问题
  2349. */
  2350. function processArticlePro($website_id)
  2351. {
  2352. // $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2353. // // $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2354. // // 取出category_id 对应的aLIas_pinyin
  2355. // $categoryIds = array_column($categorys, 'category_id');
  2356. // $categoryPIds = array_column($categorys, 'pid');
  2357. // $aliasPinyins = array_column($categorys, 'path');
  2358. // $alias = array_column($categorys, 'alias');
  2359. // $cat_arr = array_combine($categoryIds, $aliasPinyins);
  2360. // $cat_alias_arr = array_combine($categoryIds, $categoryPIds);
  2361. // // return Result::success($cat_arr);
  2362. // // $catiall = [];
  2363. // //一级所有子级的记录
  2364. // $cat_alias_arr = array_combine($categoryIds, $alias);
  2365. // return [
  2366. // 'cat_1st_arr' => $cat_alias_arr,
  2367. // 'catiall' => $cat_arr,
  2368. // // 'websiteInfoIndexed' => $websiteInfoIndexed,
  2369. // 'categoryIds' => $categoryIds,
  2370. // ];
  2371. $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2372. $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2373. // 取出category_id 对应的aLIas_pinyin
  2374. $categoryIds = array_column($categorys, 'category_id');
  2375. $categoryPIds = array_values(array_unique(array_filter(array_column($categorys, 'pid'), function($pid) {
  2376. return $pid != 0;
  2377. })));
  2378. $category_path = array_column($categorys, 'path');
  2379. $cat_arr = array_combine($categoryIds, $category_path);
  2380. // return Result::success(array_diff($categoryIds, $categoryPIds));
  2381. $catiall = [];
  2382. //一级所有子级的记录
  2383. $cat_1st_arr = [];
  2384. foreach ($categorys as $key => $value) {
  2385. // $category_arr_id = json_decode($value->category_arr_id);
  2386. // $pinyin_str = '';
  2387. // // 算出一级 并且算出子级
  2388. if ($value->pid != 0 && in_array($value->pid,$categoryIds)) {
  2389. $cat_1st_arr[$value->pid][] = $value->category_id;
  2390. }
  2391. // foreach ($category_arr_id as $k => $v) {
  2392. // $pinyin_str .= $cat_arr[$v] . '/';
  2393. // }
  2394. // $pinyin_str = rtrim($pinyin_str, '/');
  2395. $catiall[$value->category_id]['alias'] = $value->alias;
  2396. $catiall[$value->category_id]['category_id'] = $value->category_id;
  2397. $catiall[$value->category_id]['type'] = $value->type;
  2398. $catiall[$value->category_id]['pinyin'] = $cat_arr[$value->category_id];
  2399. $websiteInfoIndexed[$value->category_id]->pinyin = $cat_arr[$value->category_id];
  2400. }
  2401. return [
  2402. 'cat_1st_arr' => $cat_1st_arr,
  2403. 'catiall' => $catiall,
  2404. 'websiteInfoIndexed' => $websiteInfoIndexed,
  2405. 'categoryIds' => $categoryIds,
  2406. 'diff_pid_categoryIds' => array_diff($categoryPIds,$categoryIds),
  2407. 'categoryPIds' => $categoryPIds,
  2408. ];
  2409. }
  2410. /**
  2411. * 封装处理文章的路由问题
  2412. * */
  2413. function processArticles($articles, $data)
  2414. {
  2415. // 检查 $articles 是否为数组或可迭代对象
  2416. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  2417. return $articles->map(function ($article) use ($data) {
  2418. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  2419. $catid = $article->cat_arr_id ?? '';
  2420. }
  2421. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  2422. $catid = $article->category_arr_id ?? '';
  2423. }
  2424. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  2425. $level = json_decode($catid, true);
  2426. if (!is_array($level)) {
  2427. return $article;
  2428. } else {
  2429. $level = array_map('intval', $level);
  2430. }
  2431. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2432. ->where($data)
  2433. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2434. ->pluck('aLIas_pinyin')
  2435. ->implode('/');
  2436. $article->pinyin = $pinyin ?? '';
  2437. return $article;
  2438. });
  2439. } else {
  2440. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2441. $catid = $articles->cat_arr_id ?? '';
  2442. $level = json_decode($catid, true);
  2443. if (!is_array($level)) {
  2444. return $articles;
  2445. } else {
  2446. $level = array_map('intval', $level);
  2447. }
  2448. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2449. ->where($data)
  2450. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2451. ->pluck('aLIas_pinyin')
  2452. ->implode('/');
  2453. $articles->pinyin = $pinyin ?? '';
  2454. return $articles;
  2455. }
  2456. }
  2457. // 封装处理由问题
  2458. function processJob($job, $data)
  2459. {
  2460. return $job->map(function ($job) use ($data) {
  2461. $category = $job->cat_arr_id ?? '';
  2462. $cityid = $job->city_arr_id ?? '';
  2463. $city = json_decode($cityid, true);
  2464. $pinyin = '';
  2465. $level = json_decode($category, true);
  2466. // 路由
  2467. if (!empty($level) && is_array($level)) {
  2468. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2469. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2470. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2471. ->get(['aLIas_pinyin'])
  2472. ->pluck('aLIas_pinyin')
  2473. ->implode('/');
  2474. if (empty($pinyin)) {
  2475. $pinyin = $pinyin->aLIas_pinyin ?? '';
  2476. }
  2477. $job->pinyin = $pinyin;
  2478. }
  2479. // 取职位-城市 市??省
  2480. if (!empty($city) && is_array($city)) {
  2481. if (isset($city[1]) && !empty($city[1])) {
  2482. $city = District::where('id', $city[1])->first(['name']);
  2483. $job->city_name = $city->name ?? '';
  2484. } else if (isset($city[0]) && !empty($city[0])) {
  2485. $city = District::where('id', $city[0])->first(['name']);
  2486. $job->city_name = $city->name ?? '';
  2487. } else {
  2488. $job->city_name = '全国';
  2489. }
  2490. }
  2491. // 获取简历最后一级地区
  2492. if (isset($job->city_id) && !empty($job->city_id)) {
  2493. $city = District::where('id', $job->city_id)->first(['name']);
  2494. $job->hunt_cityname = $city->name ?? '';
  2495. }
  2496. // 组合详细地址
  2497. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  2498. $address_id = json_decode($job->address_arr_id, true) ?? [];
  2499. if (is_array($address_id) && !empty($address_id)) {
  2500. $address = District::whereIn('id', $address_id)
  2501. ->orderBy('level', 'asc')
  2502. ->get(['name'])
  2503. ->pluck('name')
  2504. ->implode('');
  2505. // $job->address_name = $address ?? '';
  2506. $job->address_name = ($address ?? '') . ($job->address ?? '');
  2507. }
  2508. }
  2509. // 取行业
  2510. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  2511. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  2512. if (!empty($job->industry)) {
  2513. $query->where('hyid', $job->industry);
  2514. } else if (!empty($job->hy_id)) {
  2515. $query->where('hyid', $job->hy_id);
  2516. } else if (!empty($job->company_hy_id)) {
  2517. $query->where('hyid', $job->company_hy_id);
  2518. } else {
  2519. $query->where('hyid', $job->job_industry);
  2520. }
  2521. })->first(['hyname']);
  2522. $job->hy_name = $hy_name->hyname ?? '';
  2523. }
  2524. // 取职位类别
  2525. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  2526. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  2527. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  2528. $job->zw_name = $zw_name->zwname ?? '';
  2529. }
  2530. // 取具体职位
  2531. 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))) {
  2532. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  2533. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  2534. $job->jtzw_name = $jtzw_name->zwname ?? '';
  2535. }
  2536. // 取工作经验
  2537. if (isset($job->experience) && !empty($job->experience)) {
  2538. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  2539. $job->experience_name = $experience->ename ?? '';
  2540. }
  2541. // 取学历
  2542. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  2543. $education = $job->educational ?? $job->school_education;
  2544. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  2545. $job->education_name = $education->ename ?? '';
  2546. }
  2547. // 语言
  2548. if (isset($job->language) && !empty($job->language)) {
  2549. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  2550. $job->language_name = $language->ename ?? '';
  2551. }
  2552. // 薪资
  2553. if (isset($job->salary) && !empty($job->salary)) {
  2554. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  2555. $job->salary_name = $salary->ename ?? '';
  2556. }
  2557. // 职位性质
  2558. if (isset($job->nature_id) && !empty($job->nature_id)) {
  2559. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  2560. $job->job_nature_name = $job_nature->ename ?? '';
  2561. }
  2562. // 公司规模
  2563. if (isset($job->company_size) && !empty($job->company_size)) {
  2564. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  2565. $job->company_size_name = $company_size->ename ?? '';
  2566. }
  2567. // 公司性质
  2568. if (isset($job->company_nature) && !empty($job->company_nature)) {
  2569. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  2570. $job->company_nature_name = $company_nature->nature_name ?? '';
  2571. }
  2572. // $job->pinyin = $pinyin;
  2573. return $job;
  2574. });
  2575. }
  2576. /**
  2577. * 获取书籍模块
  2578. * @param array $data
  2579. * @return array
  2580. * */
  2581. public function getWebsiteBook(array $data): array
  2582. {
  2583. $input['id'] = $data['id'];
  2584. $input['website_id'] = $data['website_id'];
  2585. // 将 JSON 字符串转换为 PHP 数组
  2586. $data = json_decode($input['id'], true);
  2587. // 使用 array_map 处理每个元素
  2588. $result = array_map(function ($item) use ($input) {
  2589. // 检查parent元素是否存在且不是undefined
  2590. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  2591. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2592. $website = [
  2593. 'website_id' => $input['website_id'],
  2594. ];
  2595. // 查询栏目名称
  2596. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2597. if (empty($category)) {
  2598. $parent_alias = '';
  2599. $parent_pinyin = null;
  2600. $imgBooks = [];
  2601. $textBooks = [];
  2602. } else {
  2603. $parent_alias = $category->alias ?? '';
  2604. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  2605. // 查找子分类ID数组
  2606. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  2607. array_push($childCategoryIds, $parentCatId);
  2608. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  2609. if ($parentImgNum != 0) {
  2610. // 查询图片新闻
  2611. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  2612. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2613. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2614. })
  2615. ->where('book.status', 2)
  2616. ->where('book.img_url', '!=', '')
  2617. ->leftJoin('website_category', function ($join) use ($website) {
  2618. $join->on('book.cat_id', '=', 'website_category.category_id')
  2619. ->where('website_category.website_id', '=', $website['website_id']);
  2620. })
  2621. ->select(
  2622. 'book.id',
  2623. 'book.title',
  2624. 'book.img_url',
  2625. 'book.price',
  2626. 'book.market_price',
  2627. 'book.description',
  2628. 'book.cat_id',
  2629. 'book.description',
  2630. 'book.updated_at',
  2631. 'website_category.alias as category_name',
  2632. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2633. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2634. )
  2635. ->orderBy('updated_at', 'desc')
  2636. ->limit($parentImgNum)
  2637. ->get()->all();
  2638. // 查询文字新闻
  2639. }
  2640. if ($parentTextNum != 0) {
  2641. $textBooks = [];
  2642. $textBooks = Book::where(function ($query) use ($parentCatId) {
  2643. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2644. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2645. })
  2646. ->where('book.status', 2)
  2647. ->leftJoin('website_category', function ($join) use ($website) {
  2648. $join->on('book.cat_id', '=', 'website_category.category_id')
  2649. ->where('website_category.website_id', '=', $website['website_id']);
  2650. })
  2651. ->select(
  2652. 'book.id',
  2653. 'book.title',
  2654. 'book.img_url',
  2655. 'book.price',
  2656. 'book.market_price',
  2657. 'book.description',
  2658. 'book.cat_id',
  2659. 'book.description',
  2660. 'book.updated_at',
  2661. 'website_category.alias as category_name',
  2662. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2663. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2664. )
  2665. ->orderBy('updated_at', 'desc')
  2666. ->limit($parentTextNum)
  2667. ->get()->all();
  2668. }
  2669. }
  2670. }
  2671. $resultItem = [
  2672. 'alias' => $parent_alias ?? '',
  2673. 'category_id' => $parentCatId ?? 0,
  2674. 'pinyin' => $parent_pinyin ?? null,
  2675. 'imgnum' => $imgBooks ?? [],
  2676. 'textnum' => $textBooks ?? [],
  2677. ];
  2678. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  2679. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  2680. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  2681. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2682. ->get()->all();
  2683. if (!empty($childCategory)) {
  2684. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  2685. // 查询子栏目名称
  2686. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  2687. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2688. ->first();
  2689. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  2690. $childImgArticles = [];
  2691. $childTextArticles = [];
  2692. $resultItem['child'] = [];
  2693. } else {
  2694. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  2695. // 查询子栏目图片新闻
  2696. $childImgArticles = Book::where('cat_id', $childCatId)
  2697. ->where('status', 2)
  2698. ->where('img_url', '!=', '')
  2699. ->leftJoin('website_category', function ($join) use ($website) {
  2700. $join->on('book.cat_id', '=', 'website_category.category_id')
  2701. ->where('website_category.website_id', '=', $website['website_id']);
  2702. })
  2703. ->select(
  2704. 'book.id',
  2705. 'book.title',
  2706. 'book.img_url',
  2707. 'book.price',
  2708. 'book.market_price',
  2709. 'book.description',
  2710. 'book.cat_id',
  2711. 'book.description',
  2712. 'book.updated_at',
  2713. DB::raw("'$child_pinyin' as pinyin")
  2714. )
  2715. ->orderBy('updated_at', 'desc')
  2716. ->limit($childImgNum)
  2717. ->get()->all();
  2718. // 查询子栏目文字新闻
  2719. $childTextArticles = Book::where('cat_id', $childCatId)
  2720. ->where('status', 2)
  2721. ->leftJoin('website_category', function ($join) use ($website) {
  2722. $join->on('book.cat_id', '=', 'website_category.category_id')
  2723. ->where('website_category.website_id', '=', $website['website_id']);
  2724. })
  2725. ->select(
  2726. 'book.id',
  2727. 'book.title',
  2728. 'book.img_url',
  2729. 'book.price',
  2730. 'book.market_price',
  2731. 'book.description',
  2732. 'book.cat_id',
  2733. 'book.description',
  2734. 'book.updated_at',
  2735. DB::raw("'$child_pinyin' as pinyin")
  2736. )
  2737. ->orderBy('updated_at', 'desc')
  2738. ->limit($childTextNum)
  2739. ->get()->all();
  2740. $resultItem['child'] = [
  2741. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  2742. 'category_id' => $childCatId,
  2743. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  2744. 'all_childcat' => $childCategory,
  2745. 'imgnum' => $childImgArticles,
  2746. 'textnum' => $childTextArticles,
  2747. ];
  2748. }
  2749. }
  2750. } else {
  2751. $resultItem['child'] = [];
  2752. }
  2753. return $resultItem;
  2754. }, $data);
  2755. return Result::success($result);
  2756. }
  2757. /**
  2758. * 获取书刊列表
  2759. * @param array $data
  2760. * @return array
  2761. * */
  2762. public function getWebsiteBookList(array $data): array
  2763. {
  2764. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2765. if (empty($web)) {
  2766. return Result::error("查询失败", 0);
  2767. }
  2768. $catid = $data['id'];
  2769. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  2770. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  2771. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  2772. $category_pinyin = $category ? $category->aLias_pinyin : '';
  2773. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  2774. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  2775. ->where('pid', $category['pid'])
  2776. ->select(
  2777. 'category_id',
  2778. 'alias',
  2779. 'aLIas_pinyin',
  2780. 'pid',
  2781. 'sort',
  2782. 'is_url',
  2783. 'web_url',
  2784. 'seo_title',
  2785. 'seo_keywords',
  2786. 'seo_description',
  2787. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  2788. )
  2789. ->orderBy('sort')
  2790. ->get()->all();
  2791. if (empty($category)) {
  2792. return Result::error("查询失败", 0);
  2793. }
  2794. $query = Book::where('book.status', 2)
  2795. ->where('book.website_id', $data['website_id'])
  2796. ->where('book.cat_id', $catid)
  2797. ->select(
  2798. 'book.id',
  2799. 'book.title',
  2800. 'book.img_url',
  2801. 'book.description',
  2802. 'book.updated_at',
  2803. 'book.cat_id',
  2804. DB::raw("'$pinyin' as pinyin")
  2805. )
  2806. ->orderBy('book.updated_at', 'desc');
  2807. $count = $query->count();
  2808. $query = clone $query;
  2809. $Book = $query
  2810. ->limit($data['pageSize'])
  2811. ->offset(($data['page'] - 1) * $data['pageSize'])
  2812. ->get()->all();
  2813. $result = [
  2814. 'category' => $categorys,
  2815. 'books' => $Book,
  2816. 'count' => $count,
  2817. ];
  2818. // if(empty($result)){
  2819. // return Result::error("查询失败", 0);
  2820. // }
  2821. return Result::success($result);
  2822. }
  2823. /**
  2824. * 获取书刊详情
  2825. * @param array $data
  2826. * @return array
  2827. * */
  2828. public function getWebsiteBookInfo(array $data): array
  2829. {
  2830. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2831. if (empty($web)) {
  2832. return Result::error("查询失败", 0);
  2833. }
  2834. $book = Book::where('status', 2)
  2835. ->where('website_id', $data['website_id'])
  2836. ->where('id', $data['id'])
  2837. ->select(
  2838. 'book.*',
  2839. )
  2840. ->orderBy('updated_at', 'desc')
  2841. ->first();
  2842. if (empty($book)) {
  2843. return Result::error("查询失败", 0);
  2844. }
  2845. // 先查询当前分类的 pid
  2846. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  2847. ->where('category_id', $book['cat_id'])
  2848. ->first(['pid', 'category_id']);
  2849. $query = WebsiteCategory::where('website_id', $data['website_id']);
  2850. if (!empty($carpid)) {
  2851. if ($carpid->pid != 0) {
  2852. $pid = $carpid['pid'];
  2853. // $parent_pinyin = '';
  2854. } else {
  2855. $pid = $carpid['category_id'];
  2856. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  2857. }
  2858. }
  2859. $categorys = $query->where('pid', $pid)
  2860. ->select(
  2861. 'category_id',
  2862. 'alias',
  2863. 'aLIas_pinyin',
  2864. 'pid',
  2865. 'sort',
  2866. 'is_url',
  2867. 'web_url',
  2868. 'category_arr_id as cat_arr_id',
  2869. )
  2870. ->orderBy('sort')
  2871. ->get();
  2872. $category = $this->processArticle($categorys, $data);
  2873. $result = [
  2874. 'category' => $category,
  2875. 'books' => $book,
  2876. ];
  2877. return Result::success($result);
  2878. }
  2879. /**
  2880. * 尝试
  2881. * @param array $data
  2882. * @return array
  2883. * */
  2884. public function test(array $data): array
  2885. {
  2886. $input['id'] = $data['id'];
  2887. $input['website_id'] = $data['website_id'];
  2888. // 将 JSON 字符串转换为 PHP 数组
  2889. $data = json_decode($input['id'], true);
  2890. $result = [];
  2891. $article = $data;
  2892. $result = array_map(function ($item) use ($input) {
  2893. $website = [
  2894. 'website_id' => $input['website_id'],
  2895. ];
  2896. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2897. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2898. $parent = [
  2899. 0 => $category['category_id'] ?? [],
  2900. 1 => $parentImgNum ?? [],
  2901. 2 => $parentTextNum ?? [],
  2902. ];
  2903. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  2904. $child = [];
  2905. $resultItem = [
  2906. // 'alias' => $parent_alias ?? '',
  2907. 'category_id' => $parentCatId ?? 0,
  2908. 'pinyin' => $parentImgNum ?? null,
  2909. 'imgnum' => $parentTextNum ?? [],
  2910. // 'textnum' => $textArticles ?? [],
  2911. ];
  2912. return $parent;
  2913. }, $data);
  2914. return Result::success($result);
  2915. // });
  2916. }
  2917. /**
  2918. * 封装处理文章的路由问题
  2919. * */
  2920. function processArticle($article, $data)
  2921. {
  2922. return $article->map(function ($article) use ($data) {
  2923. $catid = $article->cat_arr_id ?? '';
  2924. $level = json_decode($catid, true);
  2925. $pinyin = '';
  2926. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2927. if (!empty($level) && is_array($level)) {
  2928. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2929. ->where('website_id', $data['website_id'])
  2930. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2931. ->get(['aLIas_pinyin'])
  2932. ->pluck('aLIas_pinyin')
  2933. ->implode('/');
  2934. } else {
  2935. $pinyin = '';
  2936. }
  2937. $article->pinyin = $pinyin;
  2938. return $article;
  2939. });
  2940. }
  2941. /**
  2942. * c端-获取招工招聘下拉选框
  2943. * @param array $data
  2944. * @return array
  2945. * */
  2946. public function getWebsiteJobSelect(array $data): array
  2947. {
  2948. $web = Website::where('id', $data['website_id'])->first();
  2949. if (empty($web)) {
  2950. return Result::error("该网站不存在", 0);
  2951. }
  2952. $hy = JobIndustry::get()->all();
  2953. $zw = JobPosition::where('zwpid', 0)->get()->all();
  2954. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  2955. $result = [
  2956. 'hy' => $hy,
  2957. 'zw' => $zw,
  2958. 'jtzw' => $jtzw,
  2959. ];
  2960. if (empty($result)) {
  2961. return Result::error("查询失败", 0);
  2962. }
  2963. return Result::success($result);
  2964. }
  2965. /**
  2966. * c端-获取招工招聘
  2967. * @param array $data
  2968. * @return array
  2969. * */
  2970. public function getWebsiteJob(array $data): array
  2971. {
  2972. $web = Website::where('id', $data['website_id'])->first();
  2973. if (empty($web)) {
  2974. return Result::error("该网站不存在", 0);
  2975. }
  2976. $job_hunting = JobHunting::where('job_hunting.status', 2)
  2977. ->where('job_hunting.website_id', $data['website_id'])
  2978. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2979. $query->where(function ($q) use ($data) {
  2980. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2981. });
  2982. })
  2983. ->select(
  2984. 'job_hunting.id',
  2985. 'job_hunting.catid',
  2986. 'job_hunting.cat_arr_id',
  2987. 'job_hunting.job_name_get',
  2988. 'job_hunting.industry',
  2989. 'job_hunting.name',
  2990. 'job_hunting.sexy',
  2991. 'job_hunting.origin',
  2992. 'job_hunting.city_arr_id',
  2993. 'job_hunting.experience',
  2994. 'job_hunting.updated_at',
  2995. 'job_hunting.salary',
  2996. 'job_hunting.skillList',
  2997. 'job_hunting.slelf_evaluation',
  2998. )
  2999. ->orderBy('updated_at', 'desc')
  3000. ->limit($data['job1_num'])
  3001. ->get();
  3002. $web['website_id'] = $data['website_id'];
  3003. if (empty($job_hunting)) {
  3004. $job_huntings = "未查询到相关简历信息";
  3005. } else {
  3006. $job_huntings = $this->processJob($job_hunting, $web);
  3007. }
  3008. // 0:待审核 1:已通过 2:已拒绝
  3009. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3010. ->where('job_recruiting.website_id', $data['website_id'])
  3011. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3012. $query->where(function ($q) use ($data) {
  3013. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3014. });
  3015. })
  3016. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3017. ->select(
  3018. 'job_recruiting.id',
  3019. 'job_recruiting.catid',
  3020. 'job_recruiting.cat_arr_id',
  3021. 'job_recruiting.title',
  3022. 'job_recruiting.jtzw_id',
  3023. 'job_recruiting.hy_id',
  3024. 'job_recruiting.city_arr_id',
  3025. 'job_recruiting.due_data',
  3026. 'job_recruiting.updated_at',
  3027. 'job_recruiting.experience',
  3028. 'job_recruiting.educational',
  3029. 'job_recruiting.salary',
  3030. 'job_recruiting.zw_id',
  3031. 'job_company.business_name',
  3032. 'job_recruiting.keyword',
  3033. 'job_recruiting.description',
  3034. )
  3035. ->orderBy('updated_at', 'desc')
  3036. ->limit($data['job2_num'])
  3037. ->get();
  3038. if (empty($job_recruiting->toArray())) {
  3039. $job_recruitings = "未查询到相关职位信息";
  3040. } else {
  3041. $job_recruitings = $this->processJob($job_recruiting, $web);
  3042. }
  3043. $result = [
  3044. 'job_hunting' => $job_huntings,
  3045. 'job_recuiting' => $job_recruitings,
  3046. ];
  3047. return Result::success($result);
  3048. }
  3049. /**
  3050. * c端-获取招工招聘列表
  3051. * @param array $data
  3052. * @return array
  3053. * */
  3054. public function getWebsiteJobList(array $data): array
  3055. {
  3056. $recruit_where = [];
  3057. $hunt_where = [];
  3058. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3059. if (empty($web)) {
  3060. return Result::error("此网站不存在", 0);
  3061. }
  3062. $website_id['website_id'] = $data['website_id'];
  3063. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  3064. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3065. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  3066. }
  3067. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3068. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  3069. }
  3070. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3071. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  3072. }
  3073. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3074. array_push($recruit_where, ['title', 'like', '%' . $data['keyword'] . '%']);
  3075. }
  3076. $query = JobRecruiting::where('job_recruiting.status', 1)
  3077. ->where('job_recruiting.website_id', $data['website_id'])
  3078. ->where($recruit_where)
  3079. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3080. $query->where(function ($q) use ($data) {
  3081. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3082. });
  3083. })
  3084. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  3085. $query->where(function ($q) use ($data) {
  3086. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  3087. });
  3088. })
  3089. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3090. ->select(
  3091. 'job_recruiting.id',
  3092. 'job_recruiting.catid',
  3093. 'job_recruiting.hy_id',
  3094. 'job_recruiting.title',
  3095. 'job_recruiting.zw_id',
  3096. 'job_recruiting.educational',
  3097. 'job_recruiting.jtzw_id',
  3098. 'job_recruiting.city_arr_id',
  3099. 'job_recruiting.due_data',
  3100. 'job_recruiting.experience',
  3101. 'job_recruiting.cat_arr_id',
  3102. 'job_recruiting.updated_at',
  3103. 'job_company.business_name',
  3104. 'job_recruiting.keyword',
  3105. 'job_recruiting.description',
  3106. )
  3107. ->orderBy('job_recruiting.updated_at', 'desc');
  3108. $recruit_count = $query->count();
  3109. $query = clone $query;
  3110. $JobRecruiting = $query
  3111. ->offset(($data['page'] - 1) * $data['pageSize'])
  3112. ->limit($data['pageSize'])
  3113. ->get();
  3114. if (empty($JobRecruiting)) {
  3115. $JobRecruiting = "暂无相关职位信息";
  3116. } else {
  3117. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  3118. }
  3119. }
  3120. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  3121. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3122. array_push($hunt_where, ['job_hunting.job', $data['zw_id']]);
  3123. }
  3124. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3125. array_push($hunt_where, ['job_hunting.job_name_get', $data['jtzw_id']]);
  3126. }
  3127. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3128. array_push($hunt_where, ['job_hunting.industry', $data['hy_id']]);
  3129. }
  3130. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3131. array_push($hunt_where, ['job_position.zwname', 'like', '%' . $data['keyword'] . '%']);
  3132. }
  3133. $query = JobHunting::where('job_hunting.status', 2)
  3134. ->where('job_hunting.website_id', $data['website_id'])
  3135. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3136. ->where($hunt_where)
  3137. // ->when(isset($data['keyword']) &&!empty($data['keyword']), function ($query) use ($data) {
  3138. // $query->where('job_position.zwname','like','%'.$data['keyword'].'%');
  3139. // })
  3140. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3141. $query->where(function ($q) use ($data) {
  3142. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3143. });
  3144. })
  3145. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  3146. $query->where(function ($q) use ($data) {
  3147. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  3148. });
  3149. })
  3150. ->select(
  3151. 'job_hunting.id',
  3152. 'job_hunting.catid',
  3153. 'job_hunting.sexy',
  3154. 'job_hunting.experience',
  3155. 'job_hunting.origin',
  3156. 'job_hunting.industry',
  3157. 'job_hunting.name',
  3158. 'job_hunting.job',
  3159. 'job_hunting.job_name_get',
  3160. 'job_hunting.city_arr_id',
  3161. 'job_hunting.cat_arr_id',
  3162. 'job_hunting.created_at',
  3163. 'job_hunting.updated_at',
  3164. 'job_position.zwname as job_name',
  3165. 'job_hunting.skillList',
  3166. 'job_hunting.slelf_evaluation',
  3167. )
  3168. ->orderBy('job_hunting.updated_at', 'desc');
  3169. $hunt_count = $query->count();
  3170. $query = clone $query;
  3171. $JobHunting = $query
  3172. ->offset(($data['page'] - 1) * $data['pageSize'])
  3173. ->limit($data['pageSize'])
  3174. ->get();
  3175. if (empty($JobHunting)) {
  3176. $JobRecruiting = "暂无相关简历信息";
  3177. } else {
  3178. $JobHunting = $this->processJob($JobHunting, $website_id);
  3179. }
  3180. }
  3181. $result = [
  3182. 'JobRecruiting' => $JobRecruiting ?? [],
  3183. 'recruit_count' => $recruit_count ?? 0,
  3184. 'JobHunting' => $JobHunting ?? [],
  3185. 'hunt_count' => $hunt_count ?? 0,
  3186. ];
  3187. return Result::success($result);
  3188. }
  3189. /**
  3190. * c端-获取招工招聘详情
  3191. * @param array $data
  3192. * @return array
  3193. * */
  3194. public function getWebsiteJobInfo(array $data): array
  3195. {
  3196. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3197. if (empty($web)) {
  3198. return Result::error("该网站不存在", 0);
  3199. }
  3200. $webid = [
  3201. 'website_id' => $data['website_id'],
  3202. ];
  3203. // 职位相关信息
  3204. if ($data['type'] == 1) {
  3205. $query = JobRecruiting::where('status', 1)
  3206. ->where('website_id', $data['website_id'])
  3207. ->select('*');
  3208. $job = $query->where('job_recruiting.id', $data['id'])->get();
  3209. $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();
  3210. if (!empty($company)) {
  3211. $result['company'] = $this->processJob($company, $webid);
  3212. }
  3213. $other_job = JobRecruiting::where('status', 1)
  3214. ->where('website_id', $data['website_id'])
  3215. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  3216. ->where('id', '!=', $data['id'])
  3217. ->where('user_id', '=', $job[0]['user_id'])
  3218. ->limit($data['pageSize'])
  3219. ->get();
  3220. if (!empty($other_job)) {
  3221. $result['other_job'] = $this->processJob($other_job, $webid);
  3222. }
  3223. } else {
  3224. // 简历相关信息
  3225. $job = JobHunting::where('job_hunting.status', 2)
  3226. ->where('job_hunting.website_id', $data['website_id'])
  3227. ->where('job_hunting.id', $data['id'])
  3228. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3229. ->select('job_hunting.*', 'user_name')
  3230. ->get();
  3231. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  3232. if (!empty($resume->toArray())) {
  3233. $result['resume'] = 1;
  3234. } else {
  3235. $result['resume'] = 0;
  3236. }
  3237. }
  3238. if (empty($job->toArray())) {
  3239. return Result::error("id参数错误", 0);
  3240. }
  3241. if (!empty($job[0]['job_experience'])) {
  3242. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  3243. if (!empty($job_experience)) {
  3244. // $hy = [];
  3245. foreach ($job_experience as $key => $value) {
  3246. // $id = $value['id'];
  3247. $hy[$key] = $value['job_industry'];
  3248. $zw_id[$key] = $value['job_typename'];
  3249. $jtzw_id[$key] = $value['job_name'];
  3250. }
  3251. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  3252. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  3253. // 先将关联表转换为索引数组,提高查找效率
  3254. $hyLookup = [];
  3255. foreach ($hy_table as $item) {
  3256. $hyLookup[$item['hyid']] = $item['hyname'];
  3257. }
  3258. $zwLookup = [];
  3259. foreach ($zw_table as $item) {
  3260. $zwLookup[$item['zwid']] = $item['zwname'];
  3261. }
  3262. foreach ($job_experience as $key => &$value) {
  3263. // 处理行业名称
  3264. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  3265. $value['hy_name'] = $hyLookup[$hy[$key]];
  3266. }
  3267. // 处理职位名称
  3268. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  3269. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  3270. }
  3271. // 处理具体职位名称
  3272. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  3273. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  3274. }
  3275. }
  3276. // 释放引用,防止意外修改后续代码
  3277. unset($value);
  3278. }
  3279. $result['job_experience'] = $job_experience ?? [];
  3280. }
  3281. if (!empty($job[0]['education_experience'])) {
  3282. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  3283. if (!empty($education_experience)) {
  3284. foreach ($education_experience as $key => $value) {
  3285. // $id = $value['id'];
  3286. $education[$key] = $value['school_education'];
  3287. }
  3288. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  3289. // // 先将关联表转换为索引数组,提高查找效率
  3290. $educationLookup = [];
  3291. foreach ($education_table as $item) {
  3292. $educationLookup[$item['evalue']] = $item['ename'];
  3293. }
  3294. foreach ($education_experience as $key => &$value) {
  3295. // 处理学历名称
  3296. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  3297. $value['education_name'] = $educationLookup[$education[$key]];
  3298. }
  3299. }
  3300. }
  3301. $result['education_experience'] = $job_experience ?? [];
  3302. }
  3303. $result['job'] = $this->processJob($job, $webid);
  3304. // // 返现对应的栏目
  3305. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  3306. $category = WebsiteCategory::where('website_id', $data['website_id'])
  3307. ->whereIn('category_id', $catid)
  3308. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  3309. ->orderBy('pid')->get()->all();
  3310. if (!empty($category)) {
  3311. $result['category'] = $category;
  3312. }
  3313. $result['job'] = $job;
  3314. $result['job_experience'] = $job_experience ?? [];
  3315. $result['education_experience'] = $education_experience ?? [];
  3316. if (empty($result)) {
  3317. return Result::error("参数错误", 0);
  3318. }
  3319. return Result::success($result);
  3320. }
  3321. /**
  3322. * c端-申请职位
  3323. * @param array $data
  3324. * @return array
  3325. * */
  3326. public function getWebsiteJobApply(array $data): array
  3327. {
  3328. // 首先验证网站是否存在
  3329. // return Result::success($data);
  3330. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3331. if (empty($web)) {
  3332. return Result::error("该网站不存在", 0);
  3333. }
  3334. // 验证用户是否存在且为个人会员/管理员
  3335. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3336. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3337. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  3338. return Result::error("用户不存在", 0);
  3339. }
  3340. // 去除重复元素和空元素,并保持原始顺序
  3341. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  3342. return !empty($value);
  3343. }));
  3344. // 验证职位是否存在 1:审核通过
  3345. $recruiting = JobRecruiting::where('status', 1)
  3346. ->where('website_id', $data['website_id'])
  3347. ->whereIn('id', $data['recruit_id'])
  3348. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  3349. if (empty($recruiting)) {
  3350. return Result::error("该职位不存在", 0);
  3351. }
  3352. // 简历是否存在
  3353. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  3354. if (empty($hunt_id)) {
  3355. return Result::error("该简历不存在", 0);
  3356. }
  3357. $data['hunt_id'] = $hunt_id['hunt_id'];
  3358. // // 验证是否已投递过该职位
  3359. $apply = JobApply::where('user_id', $data['user_id'])
  3360. ->where('hunt_id', $data['hunt_id'])
  3361. ->where('website_id', $data['website_id'])
  3362. ->whereIn('recruit_id', $data['recruit_id'])
  3363. ->get(['recruit_id']);
  3364. if (!empty($apply->toArray())) {
  3365. return Result::error("您已投递过该职位!");
  3366. }
  3367. $insertData = array_map(function ($recruiting) use ($data) {
  3368. return [
  3369. 'user_id' => $data['user_id'],
  3370. 'hunt_id' => $data['hunt_id'],
  3371. 'website_id' => $data['website_id'],
  3372. 'recruit_id' => $recruiting['recruit_id'],
  3373. 'receiver_id' => $recruiting['receiver_id'],
  3374. 'status' => 1,
  3375. ];
  3376. }, $recruiting);
  3377. // 批量插入数据
  3378. $result = JobApply::insert($insertData);
  3379. if (empty($result)) {
  3380. return Result::error("投递失败", 0);
  3381. }
  3382. return Result::success($result);
  3383. }
  3384. /**
  3385. * 招工招聘-沟通简历
  3386. * @param array $data
  3387. * @return array
  3388. * */
  3389. public function getWebsiteJobResume(array $data): array
  3390. {
  3391. // 首先验证网站是否存在
  3392. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3393. if (empty($web)) {
  3394. return Result::error("该网站不存在", 0);
  3395. }
  3396. // return Result::success($data);
  3397. // 验证用户是否存在且为企业会员/管理员
  3398. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3399. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3400. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3401. return Result::error("用户不存在", 0);
  3402. }
  3403. // 去除重复元素和空元素,并保持原始顺序
  3404. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  3405. return !empty($value);
  3406. }));
  3407. // 验证简历是否存在
  3408. $hunting = JobHunting::where('status', 2)
  3409. ->where('website_id', $data['website_id'])
  3410. ->whereIn('id', $data['hunt_id'])
  3411. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  3412. if (empty($hunting)) {
  3413. return Result::error("该简历不存在", 0);
  3414. }
  3415. // 验证是否已沟通过该简历
  3416. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3417. ->where('recruit_id', $data['recruit_id'])
  3418. ->where('website_id', $data['website_id'])
  3419. ->whereIn('hunt_id', $data['hunt_id'])
  3420. ->get(['hunt_id']);
  3421. if (!empty($remuse->toArray())) {
  3422. return Result::error("您已沟通过该简历!");
  3423. }
  3424. // 准备要插入的数据数组
  3425. $insertData = array_map(function ($hunting) use ($data) {
  3426. return [
  3427. 'user_id' => $data['user_id'],
  3428. 'recruit_id' => $data['recruit_id'],
  3429. 'website_id' => $data['website_id'],
  3430. 'hunt_id' => $hunting['hunt_id'],
  3431. 'receiver_id' => $hunting['receiver_id'],
  3432. 'status' => 1,
  3433. ];
  3434. }, $hunting);
  3435. // 批量插入数据
  3436. $result = JobRemuse::insert($insertData);
  3437. if (empty($result)) {
  3438. return Result::error("沟通失败", 0);
  3439. }
  3440. return Result::success($result);
  3441. }
  3442. /**
  3443. * 招工招聘 -我的职位(企业会员)
  3444. * @param array $data
  3445. * @return array
  3446. */
  3447. public function getWebsiteJobRecruiting(array $data): array
  3448. {
  3449. $web = Website::where('id', $data['website_id'])->first('id');
  3450. if (empty($web)) {
  3451. return Result::error("该网站不存在", 0);
  3452. }
  3453. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3454. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3455. return Result::error("用户暂无权限!", 0);
  3456. }
  3457. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3458. $result = JobRecruiting::where('website_id', $data['website_id'])
  3459. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  3460. $query->where('user_id', $user['id']);
  3461. })
  3462. ->where('status', 1)
  3463. ->select('id', 'title', 'website_id', 'user_id', 'updated_at','keyword','catid','description')
  3464. ->orderBy('updated_at', 'desc')
  3465. ->limit($data['pageSize'])
  3466. ->get();
  3467. if (empty($result)) {
  3468. return Result::error("暂无相关职位信息", 0);
  3469. }
  3470. return Result::success($result);
  3471. }
  3472. /**
  3473. * c端 - 验证路由
  3474. * @param array $data
  3475. * @return array
  3476. */
  3477. /**
  3478. * c端 - 验证路由
  3479. * @param array $data
  3480. * @return array
  3481. */
  3482. public function checkWebsiteRoute(array $data): array
  3483. {
  3484. // 测试001111111222
  3485. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name', 'status']);
  3486. if (empty($web)) {
  3487. return Result::error("该网站不存在", 0);
  3488. } elseif ($web['status'] != 1) {
  3489. return Result::error("网站已经关闭", 0);
  3490. }
  3491. if (isset($data['other_route']) && !empty($data['other_route'])) {
  3492. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  3493. // 验证路由是否存在
  3494. if (empty($whiteRouterInfo)) {
  3495. $whiteRouterInfo = WhiteRouter::where("router_type", 1)->where('router_url', $data['other_route'])->first();
  3496. }
  3497. if (!empty($whiteRouterInfo)) {
  3498. return Result::success($whiteRouterInfo->toArray());
  3499. }
  3500. }
  3501. // 验证栏目路由
  3502. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  3503. ->where('path', $data['all_route'])
  3504. ->get()->all();
  3505. if (count($last_category) == 0) {
  3506. return Result::error("该栏目不存在", 0);
  3507. }
  3508. if(count($last_category) > 1){
  3509. return Result::error("该栏目路由存在多个,路由验证失败!", 0);
  3510. }
  3511. if (count($last_category) == 1) {
  3512. $last_category = $last_category[0];
  3513. }
  3514. // return Result::success($last_category);
  3515. if (isset($data['id']) && !empty($data['id'])) {
  3516. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  3517. switch ($last_category['type']) {
  3518. case 1:
  3519. // 文章
  3520. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  3521. $article = Article::where('status', 1)
  3522. ->where('id', $data['id'])
  3523. ->where(function ($query) use ($data) {
  3524. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  3525. ->orWhereNull("ignore_ids");
  3526. })
  3527. ->first(['catid']);
  3528. if (empty($article)) {
  3529. return Result::error("该文章不存在", 0);
  3530. }
  3531. // return Result::success($article);
  3532. break;
  3533. case 2:
  3534. // 商品
  3535. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3536. $article = Good::where('website_id', $data['website_id'])
  3537. ->where('status', 2)
  3538. ->where('id', $data['id'])
  3539. ->first(['cat_arr_id']);
  3540. if (empty($article)) {
  3541. return Result::error("该商品不存在", 0);
  3542. }
  3543. break;
  3544. case 3:
  3545. // 书刊信息
  3546. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3547. $article = Book::where('website_id', $data['website_id'])
  3548. ->where('status', 2)
  3549. ->where('id', $data['id'])
  3550. ->first(['id', 'cat_arr_id']);
  3551. if (empty($article)) {
  3552. return Result::error("该书刊不存在", 0);
  3553. }
  3554. break;
  3555. case 4:
  3556. // 招聘
  3557. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核通过;(只有企业会员需要审核)',
  3558. $article = JobRecruiting::where('website_id', $data['website_id'])
  3559. ->where('status', 1)
  3560. ->where('id', $data['id'])
  3561. ->first(['cat_arr_id']);
  3562. if (empty($article)) {
  3563. return Result::error("该招聘不存在", 0);
  3564. }
  3565. break;
  3566. case 5:
  3567. // 求职
  3568. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3569. $article = JobHunting::where('website_id', $data['website_id'])
  3570. ->where('status', 2)
  3571. ->where('id', $data['id'])
  3572. ->first(['cat_arr_id']);
  3573. if (empty($article)) {
  3574. return Result::error("该求职不存在", 0);
  3575. }
  3576. break;
  3577. case 6:
  3578. // 企业
  3579. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3580. $article = Company::
  3581. // where('website_id', $data['website_id'])
  3582. // ->
  3583. where('status', 1)
  3584. ->where('id', $data['id'])
  3585. ->first(['cat_arr_id']);
  3586. if (empty($article)) {
  3587. return Result::error("该企业不存在", 0);
  3588. }
  3589. break;
  3590. case 7:
  3591. // 项目
  3592. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3593. $article = Project::where('website_id', $data['website_id'])
  3594. ->where('status', 1)
  3595. ->where('id', $data['id'])
  3596. ->first(['cat_arr_id']);
  3597. if (empty($article)) {
  3598. return Result::error("该项目不存在", 0);
  3599. }
  3600. break;
  3601. default:
  3602. return Result::error("该数据不存在", 0);
  3603. break;
  3604. }
  3605. // return Result::success($article);
  3606. // $catid =0 ;
  3607. if(!isset($article['cat_arr_id'])){
  3608. $catid = isset($article['catid']) ? $article['catid'] : (isset($article['category_id']) ? $article['category_id'] : null);
  3609. }else{
  3610. $catidArray = json_decode($article['cat_arr_id'], true);
  3611. $catid = !empty($catidArray) ? end($catidArray) : null;
  3612. }
  3613. // return Result::success($catid);
  3614. // // return Result::success($article['cat_arr_id']);
  3615. if (empty($catid)) {
  3616. return Result::error("该栏目路径不存在", 0);
  3617. }
  3618. $path = WebsiteCategory::where('website_id', $data['website_id'])
  3619. ->where('category_id',$catid)
  3620. ->first('path');
  3621. }
  3622. // else{
  3623. // // if ($last_category['pid'] != 0) {
  3624. // $cat_arr = json_decode($last_category['category_arr_id'], true);
  3625. // $catid = !empty($cat_arr) && is_array($cat_arr) ? end($cat_arr) : null;
  3626. // $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3627. // ->where('category_id',$catid)
  3628. // ->where('path',$data['all_route'])
  3629. // ->first('path');
  3630. // // } else {
  3631. // // $pinyin[0] = $last_category['aLIas_pinyin'];
  3632. // // }
  3633. // }
  3634. // return Result::success($path);
  3635. if (!empty($path) && $path['path'] != $data['all_route']) {
  3636. return Result::error('非法路径!');
  3637. } else {
  3638. return Result::success( $last_category['path']);
  3639. }
  3640. }
  3641. /**
  3642. * 招工招聘 - 获取推荐职位
  3643. * @param array $data
  3644. * @return array
  3645. */
  3646. public function getWebsiteLevelJob(array $data): array
  3647. {
  3648. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3649. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  3650. ->where('job_recruiting.status', 1)
  3651. ->where('job_level', $data['job_level'])
  3652. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3653. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  3654. ->orderBy('job_recruiting.updated_at', 'desc')
  3655. ->limit($data['pageSize'])
  3656. ->get();
  3657. $web = ['website_id' => $data['website_id']];
  3658. if (!empty($job)) {
  3659. $result = $this->processJob($job, $web);
  3660. }
  3661. if (empty($result)) {
  3662. return Result::error("暂无相关职位信息", 0);
  3663. }
  3664. return Result::success($result);
  3665. }
  3666. /**
  3667. * 验证导航名称是否重复
  3668. * @return void
  3669. */
  3670. //20250226 产品列表
  3671. public function getGoodList(array $data): array
  3672. {
  3673. var_dump($data, '---------1-2--');
  3674. $type_id = isset($data['user_type_id']) ? $data['user_type_id'] : '';
  3675. unset($data['user_type_id']);
  3676. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3677. $where = [];
  3678. if ($type_id != '10000') {
  3679. $where = [
  3680. 'good.user_id' => $user_id,
  3681. ];
  3682. }
  3683. //类型
  3684. if (isset($data['type_id']) && $data['type_id']) {
  3685. $where['good.type_id'] = $data['type_id'];
  3686. }
  3687. //名称
  3688. if (isset($data['name']) && $data['name']) {
  3689. $where[] = ['good.name', 'like', '%' . $data['name'] . '%'];
  3690. }
  3691. //status
  3692. if (isset($data['status']) && $data['status'] != '') {
  3693. $where['good.status'] = $data['status'];
  3694. }
  3695. //status1
  3696. // if (isset($data['status1']) && $data['status1'] == 1) {
  3697. // $status1 = 1;
  3698. // }
  3699. $where1 = [];
  3700. //website_id
  3701. // if (isset($data['website_id']) && $data['website_id']) {
  3702. // $where1 = [
  3703. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  3704. // ];
  3705. // }
  3706. // website_name
  3707. if (isset($data['website_name']) && $data['website_name']) {
  3708. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  3709. }
  3710. // catid
  3711. if (isset($data['category_name']) && $data['category_name']) {
  3712. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  3713. }
  3714. // $result = Good::where($where)
  3715. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  3716. var_dump($where, '---------1---');
  3717. $result = Good::where($where)
  3718. ->when(!empty($where1), function ($query) use ($where1) {
  3719. return $query->where($where1);
  3720. })
  3721. //status 1待审核2已审核3已拒绝
  3722. ->when(isset($data['status1']), function ($query) {
  3723. return $query->whereIn('good.status', [1, 3]);
  3724. })
  3725. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3726. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3727. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3728. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3729. ->orderBy("updated_at", "desc")
  3730. ->limit($data['page_size'])
  3731. ->offset(($data['page'] - 1) * $data['page_size'])
  3732. ->get();
  3733. $count = Good::where($where)
  3734. ->when(!empty($where1), function ($query) use ($where1) {
  3735. return $query->where($where1);
  3736. })
  3737. //status 1待审核2已审核3已拒绝
  3738. ->when(isset($data['status1']), function ($query) {
  3739. return $query->whereIn('good.status', [1, 3]);
  3740. })
  3741. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3742. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3743. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3744. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3745. ->orderBy("updated_at", "desc")->count();
  3746. $data = [
  3747. 'rows' => $result->toArray(),
  3748. 'count' => $count,
  3749. ];
  3750. if (empty($result)) {
  3751. return Result::error("此栏目暂无相关产品", 0);
  3752. }
  3753. return Result::success($data);
  3754. }
  3755. public function getGoodInfo(array $data): array
  3756. {
  3757. $result = Good::where('id', $data['id'])->first();
  3758. if (empty($result)) {
  3759. return Result::error("此产品不存在", 0);
  3760. }
  3761. return Result::success($result);
  3762. }
  3763. public function addGood(array $data): array
  3764. {
  3765. // unset($data['city_arr_id']);
  3766. // unset($data['cat_arr_id']);
  3767. $data['city_id'] = end($data['city_arr_id']);
  3768. $data['catid'] = end($data['cat_arr_id']);
  3769. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3770. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3771. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3772. unset($data['imgUrl']); //大小写
  3773. if (isset($data['price']) && $data['price'] == '') {
  3774. $data['price'] = 0;
  3775. }
  3776. if ($data['imgurl'] == '') {
  3777. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  3778. preg_match_all($reg, $data['detail'], $matches);
  3779. if (isset($matches[1][0])) {
  3780. //截取varchar240
  3781. $data['imgurl'] = substr($matches[1][0], 0, 240);
  3782. }
  3783. }
  3784. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  3785. //提取标题+内容中的关键词
  3786. $data['keyword'] = $data['name'];
  3787. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  3788. Jieba::init(); // 初始化 jieba-php
  3789. Finalseg::init();
  3790. $segList = Jieba::cut($data['keyword']);
  3791. $segList1 = array_slice($segList, 0, 8);
  3792. $data['keyword'] = implode(',', $segList1);
  3793. }
  3794. if ($data['description'] == '') {
  3795. //提取内容中的描述
  3796. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  3797. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  3798. // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  3799. }
  3800. if ($data['status'] == 1) {
  3801. $this->sendMessage([
  3802. 'talk_type' => 200,
  3803. 'title' => $data['name'],
  3804. 'content' => '提交了审核',
  3805. 'messageType' => 3,
  3806. ]);
  3807. }
  3808. $result = Good::insert($data);
  3809. if (empty($result)) {
  3810. return Result::error("添加失败", 0);
  3811. }
  3812. return Result::success($result);
  3813. }
  3814. public function updateGood(array $data): array
  3815. {
  3816. $data['city_id'] = end($data['city_arr_id']);
  3817. $data['catid'] = end($data['cat_arr_id']);
  3818. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3819. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3820. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3821. //设置东八区
  3822. date_default_timezone_set('Asia/Shanghai');
  3823. $data['updated_at'] = date('Y-m-d H:i:s');
  3824. if (isset($data['price']) && $data['price'] == '') {
  3825. $data['price'] = 0;
  3826. }
  3827. if ($data['imgurl'] == '') {
  3828. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  3829. preg_match_all($reg, $data['detail'], $matches);
  3830. if (isset($matches[1][0])) {
  3831. //截取varchar240
  3832. $data['imgurl'] = substr($matches[1][0], 0, 240);
  3833. }
  3834. }
  3835. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  3836. //提取标题+内容中的关键词
  3837. $data['keyword'] = $data['name'];
  3838. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  3839. Jieba::init(); // 初始化 jieba-php
  3840. Finalseg::init();
  3841. $segList = Jieba::cut($data['keyword']);
  3842. $segList1 = array_slice($segList, 0, 8);
  3843. $data['keyword'] = implode(',', $segList1);
  3844. }
  3845. if ($data['description'] == '') {
  3846. //提取内容中的描述
  3847. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  3848. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  3849. }
  3850. if ($data['status'] == 1) {
  3851. $this->sendMessage([
  3852. 'talk_type' => 200,
  3853. 'title' => $data['name'],
  3854. 'content' => '提交了审核',
  3855. 'messageType' => 3,
  3856. ]);
  3857. }
  3858. $result = Good::where('id', $data['id'])->update($data);
  3859. if (empty($result)) {
  3860. return Result::error("更新失败", 0);
  3861. }
  3862. return Result::success($result);
  3863. }
  3864. public function delGood(array $data): array
  3865. {
  3866. $result = Good::where('id', $data['id'])->delete();
  3867. if (empty($result)) {
  3868. return Result::error("删除失败", 0);
  3869. }
  3870. return Result::success($result);
  3871. }
  3872. //20250226 产品列表
  3873. //20250306 求职信息
  3874. public function getJobHuntingList(array $data): array
  3875. {
  3876. $where = [];
  3877. if (isset($data['username']) && !empty($data['username'])) {
  3878. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3879. }
  3880. //status 1待审核2已审核3已拒绝
  3881. if (isset($data['status']) && $data['status'] != '') {
  3882. $where = [
  3883. 'job_hunting.status' => $data['status'],
  3884. ];
  3885. }
  3886. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3887. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3888. unset($data['type_id']);
  3889. if ($type_id != '10000') {
  3890. $where[] = ['job_hunting.user_id', '=', $user_id];
  3891. }
  3892. $result = JobHunting::where($where)
  3893. ->when(!empty($data['status1']), function ($query) use ($data) {
  3894. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3895. })
  3896. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3897. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3898. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  3899. ->orderBy("updated_at", "desc")
  3900. ->limit($data['page_size'])
  3901. ->offset(($data['page'] - 1) * $data['page_size'])
  3902. ->get();
  3903. if (empty($result)) {
  3904. return Result::error("查询失败", 0);
  3905. }
  3906. $count = JobHunting::where($where)
  3907. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3908. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3909. ->count();
  3910. $data = [
  3911. 'rows' => $result->toArray(),
  3912. 'count' => $count,
  3913. ];
  3914. return Result::success($data);
  3915. }
  3916. public function getJobHuntingApply(array $data): array
  3917. {
  3918. var_dump($data, '-----------------test--------1-');
  3919. $where = [];
  3920. if (isset($data['username']) && !empty($data['username'])) {
  3921. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3922. }
  3923. if (isset($data['salary']) && !empty($data['salary'])) {
  3924. $where[] = [
  3925. 'job_hunting.salary',
  3926. '=',
  3927. $data['salary'],
  3928. ];
  3929. }
  3930. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3931. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3932. unset($data['type_id']);
  3933. if ($type_id != '10000') {
  3934. $where[] = ['job_apply.receiver_id', '=', $user_id];
  3935. }
  3936. var_dump($where, '-----------------test---------');
  3937. $result = jobApply::where($where)
  3938. // ->when(!empty($data['status1']), function ($query) use ($data) {
  3939. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3940. // })
  3941. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  3942. ->where('job_enum.egroup', '=', 'income')
  3943. ->where('job_hunting.status', 2) //已审核
  3944. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3945. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3946. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3947. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3948. //职位----是申请职位
  3949. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3950. ->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')
  3951. ->orderBy("job_hunting.updated_at", "desc")
  3952. ->limit($data['page_size'])
  3953. ->offset(($data['page'] - 1) * $data['page_size'])
  3954. ->get();
  3955. if (empty($result)) {
  3956. return Result::error("查询失败", 0);
  3957. }
  3958. $count = jobApply::where($where)
  3959. ->where('job_enum.egroup', '=', 'income')
  3960. ->where('job_hunting.status', 2) //已审核
  3961. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3962. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3963. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3964. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3965. //职位----是申请职位
  3966. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3967. ->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')
  3968. ->count();
  3969. $data = [
  3970. 'rows' => $result->toArray(),
  3971. 'count' => $count,
  3972. ];
  3973. return Result::success($data);
  3974. }
  3975. public function addJobHunting(array $data): array
  3976. {
  3977. date_default_timezone_set('Asia/Shanghai');
  3978. unset($data['company_name']);
  3979. unset($data['job_industry']);
  3980. unset($data['job_name']);
  3981. unset($data['department']);
  3982. unset($data['job_timeList']);
  3983. unset($data['job_content']);
  3984. unset($data['job_typename']); //不知道这是啥,
  3985. $data['created_at'] = date('Y-m-d H:i:s');
  3986. $data['updated_at'] = date('Y-m-d H:i:s');
  3987. //根据用户 user_id 只能添加一次
  3988. $result = JobHunting::where('user_id', $data['user_id'])->first();
  3989. if (!empty($result)) {
  3990. return Result::error("您已添加过求职信息", 0);
  3991. }
  3992. var_dump($result, '-----------------test---------');
  3993. if (isset($data['city_arr_id']) && !empty($data['city_arr_id'])) {
  3994. if (is_string($data['city_arr_id'])) {
  3995. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  3996. $cityArr = json_decode($data['city_arr_id'], true);
  3997. // 确保 $cityArr 是数组
  3998. if (is_array($cityArr)) {
  3999. $data['city_id'] = end($cityArr);
  4000. }
  4001. } else {
  4002. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4003. if (is_array($data['city_arr_id'])) {
  4004. $data['city_id'] = end($data['city_arr_id']);
  4005. }
  4006. }
  4007. }
  4008. // 处理求职所绑定栏目
  4009. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id'])) {
  4010. if (is_string($data['cat_arr_id'])) {
  4011. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4012. // 先清理可能存在的无效 JSON 字符
  4013. $cleanedCatArrStr = trim($data['cat_arr_id']);
  4014. $catArr = json_decode($cleanedCatArrStr, true);
  4015. // 检查 JSON 解码是否成功且结果是数组
  4016. if (json_last_error() === JSON_ERROR_NONE && is_array($catArr)) {
  4017. $data['catid'] = end($catArr);
  4018. }
  4019. } else {
  4020. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4021. if (is_array($data['cat_arr_id'])) {
  4022. $data['catid'] = end($data['cat_arr_id']);
  4023. }
  4024. }
  4025. }
  4026. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4027. $this->sendMessage([
  4028. 'talk_type' => 600,
  4029. 'title' => $data['name'],
  4030. 'content' => '提交了审核',
  4031. 'messageType' => 11,
  4032. ]);
  4033. }
  4034. $result = JobHunting::create($data);
  4035. if (empty($result)) {
  4036. return Result::error("添加失败", 0);
  4037. }
  4038. return Result::success($result);
  4039. }
  4040. public function delJobHunting(array $data): array
  4041. {
  4042. $result = JobHunting::where('id', $data['id'])->delete();
  4043. if (empty($result)) {
  4044. return Result::error("删除失败", 0);
  4045. }
  4046. return Result::success($result);
  4047. }
  4048. public function updateJobHunting(array $data): array
  4049. {
  4050. //设置东八区
  4051. date_default_timezone_set('Asia/Shanghai');
  4052. unset($data['company_name']);
  4053. unset($data['job_industry']);
  4054. unset($data['job_name']);
  4055. unset($data['department']);
  4056. unset($data['job_timeList']);
  4057. unset($data['job_content']);
  4058. unset($data['job_typename']); //不知道这是啥,
  4059. $data['created_at'] = date('Y-m-d H:i:s');
  4060. $data['updated_at'] = date('Y-m-d H:i:s');
  4061. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  4062. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4063. $cityArr = json_decode($data['city_arr_id'], true);
  4064. $data['city_id'] = end($cityArr);
  4065. } else {
  4066. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4067. $data['city_id'] = end($data['city_arr_id']);
  4068. }
  4069. // 处理求职所绑定栏目
  4070. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_string($data['cat_arr_id'])) {
  4071. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4072. $catArr = json_decode($data['cat_arr_id'], true);
  4073. $data['catid'] = end($catArr);
  4074. } else {
  4075. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4076. $data['catid'] = end($data['cat_arr_id']);
  4077. }
  4078. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4079. $this->sendMessage([
  4080. 'talk_type' => 600,
  4081. 'title' => $data['name'],
  4082. 'content' => '提交了审核',
  4083. 'messageType' => 11,
  4084. ]);
  4085. }
  4086. $result = JobHunting::where('id', $data['id'])->update($data);
  4087. if (empty($result)) {
  4088. return Result::error("更新失败", 0);
  4089. }
  4090. return Result::success($result);
  4091. }
  4092. public function getJobHuntingInfo(array $data): array
  4093. {
  4094. $result = JobHunting::where('id', $data['id'])->first();
  4095. if (empty($result)) {
  4096. return Result::error("查询失败", 0);
  4097. }
  4098. return Result::success($result);
  4099. }
  4100. public function getJobHuntingData(array $data): array
  4101. {
  4102. $jobEnum = JobEnum::get();
  4103. $jobIndustry = JobIndustry::get();
  4104. $jobNature = JobNature::get();
  4105. $jobPosition = JobPosition::get();
  4106. $data = [
  4107. 'jobEnum' => $jobEnum,
  4108. 'jobIndustry' => $jobIndustry,
  4109. 'jobNature' => $jobNature,
  4110. 'jobPosition' => $jobPosition,
  4111. ];
  4112. return Result::success($data);
  4113. }
  4114. public function delJobHuntingInfo(array $data): array
  4115. {
  4116. $result = JobHunting::where('id', $data['id'])->delete();
  4117. return Result::success();
  4118. }
  4119. //20250324 通知,公告,消息
  4120. public function delNotice(array $data): array
  4121. {
  4122. $result = Notice::where('id', $data['id'])->delete();
  4123. if ($result) {
  4124. return Result::success();
  4125. } else {
  4126. return Result::error("删除失败", 0);
  4127. }
  4128. }
  4129. public function getNoticeInfo(array $data): array
  4130. {
  4131. $result = Notice::where('id', $data['id'])->first();
  4132. // var_dump($result['re_user_ids'], '--------------------');
  4133. if (empty($result)) {
  4134. return Result::error("查询失败", 0);
  4135. }
  4136. return Result::success($result);
  4137. }
  4138. public function readNotice(array $data): array
  4139. {
  4140. $result = Notice::where('id', $data['id'])->first();
  4141. // var_dump($result['re_user_ids'], '--------------------');
  4142. if (empty($result)) {
  4143. return Result::error("查询失败", 0);
  4144. }
  4145. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4146. $re_user_ids = json_decode($result['re_user_ids'], true);
  4147. var_dump($re_user_ids, '--------------1---test---------');
  4148. var_dump($data, '--------------1---test---------');
  4149. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4150. //如果已经存在,就不再添加
  4151. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4152. $read_id = json_decode($result['read_id'], true);
  4153. if (!is_array($read_id)) {
  4154. $read_id = [];
  4155. }
  4156. if (!in_array($data['user_id'], $read_id)) {
  4157. $read_id[] = $data['user_id'];
  4158. $result['read_id'] = json_encode($read_id);
  4159. Notice::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4160. }
  4161. } else {
  4162. //如果不存在,就添加
  4163. $result['read_id'] = json_encode([$data['user_id']]);
  4164. Notice::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4165. }
  4166. }
  4167. return Result::success($result);
  4168. }
  4169. public function addNotice(array $data): array
  4170. {
  4171. date_default_timezone_set('Asia/Shanghai');
  4172. $data['created_at'] = date('Y-m-d H:i:s');
  4173. $data['updated_at'] = date('Y-m-d H:i:s');
  4174. $user_id = UserInfo::
  4175. //city_id不是null
  4176. whereNotNull('city_id')
  4177. ->whereNotNull('department_id')
  4178. ->where(function ($query) use ($data) {
  4179. $query->where(function ($subQuery) use ($data) {
  4180. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4181. });
  4182. })
  4183. ->where(function ($query) use ($data) {
  4184. $query->where(function ($subQuery) use ($data) {
  4185. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4186. });
  4187. })
  4188. ->pluck('user_id')->toArray();
  4189. $user_id = array_unique($user_id);
  4190. $chat_ids = $user_id;
  4191. $user_id = json_encode($user_id);
  4192. $data['re_user_ids'] = $user_id;
  4193. $this->sendMessage([
  4194. 'talk_type' => 700,
  4195. 'title' => $data['title'],
  4196. 'content' => '提交了审核',
  4197. 'messageType' => 5,
  4198. ]);
  4199. $result = Notice::insertGetId($data);
  4200. if (empty($result)) {
  4201. return Result::error("添加失败", 0);
  4202. }
  4203. return Result::success($result);
  4204. }
  4205. public function updateNotice(array $data): array
  4206. {
  4207. date_default_timezone_set('Asia/Shanghai');
  4208. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  4209. $user_id = UserInfo::
  4210. //city_id不是null
  4211. whereNotNull('city_id')
  4212. ->whereNotNull('department_id')
  4213. ->where(function ($query) use ($data) {
  4214. $query->where(function ($subQuery) use ($data) {
  4215. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4216. });
  4217. })
  4218. ->where(function ($query) use ($data) {
  4219. $query->where(function ($subQuery) use ($data) {
  4220. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4221. });
  4222. })
  4223. ->pluck('user_id')->toArray();
  4224. $user_id = array_unique($user_id);
  4225. $user_id = json_encode($user_id);
  4226. $data['re_user_ids'] = $user_id;
  4227. $data['updated_at'] = date('Y-m-d H:i:s');
  4228. $this->sendMessage([
  4229. 'talk_type' => 700,
  4230. 'title' => $data['title'],
  4231. 'content' => '提交了审核',
  4232. 'messageType' => 5,
  4233. ]);
  4234. $result = Notice::where('id', $data['id'])->update($data);
  4235. return Result::success($result);
  4236. }
  4237. public function getNoticeList(array $data): array
  4238. {
  4239. $where = [];
  4240. //title
  4241. if (isset($data['title']) && !empty($data['title'])) {
  4242. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4243. }
  4244. //level
  4245. if (isset($data['level']) && !empty($data['level'])) {
  4246. $where[] = ['notice.level', '=', $data['level']];
  4247. }
  4248. //status
  4249. if (isset($data['status']) && !empty($data['status'])) {
  4250. $where[] = ['notice.status', '=', $data['status']];
  4251. }
  4252. //type
  4253. if (isset($data['type']) && !empty($data['type'])) {
  4254. $where[] = ['notice.type', '=', $data['type']];
  4255. }
  4256. var_dump($data, '------------11111-2----test---------');
  4257. if ($data['type_id'] == 10000) {
  4258. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4259. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4260. })
  4261. ->where($where)
  4262. ->orderBy('updated_at', 'desc')
  4263. ->limit($data['page_size'])
  4264. ->offset(($data['page'] - 1) * $data['page_size'])
  4265. ->get();
  4266. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4267. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4268. })
  4269. ->where($where)
  4270. ->orderBy('updated_at', 'desc')
  4271. ->count();
  4272. } else {
  4273. $result = Notice::where($where)
  4274. // ->where('user_id', $data['user_id'])
  4275. ->Where(function ($query) use ($data) {
  4276. $query->Where(function ($q) use ($data) {
  4277. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4278. ->orWhere('notice.user_id', $data['user_id']);
  4279. });
  4280. })
  4281. ->when(!empty($data['status1']), function ($query) use ($data) {
  4282. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4283. })
  4284. ->orderBy('updated_at', 'desc')
  4285. ->limit($data['page_size'])
  4286. ->offset(($data['page'] - 1) * $data['page_size'])
  4287. ->get();
  4288. $total = Notice::where($where)
  4289. ->when(!empty($data['status1']), function ($query) use ($data) {
  4290. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4291. })
  4292. // ->where('user_id', $data['user_id'])
  4293. ->Where(function ($query) use ($data) {
  4294. $query->Where(function ($q) use ($data) {
  4295. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4296. ->orWhere('notice.user_id', $data['user_id']);
  4297. });
  4298. })
  4299. ->count();
  4300. }
  4301. if (empty($result)) {
  4302. return Result::error("查询失败", 0);
  4303. }
  4304. $data = [
  4305. 'rows' => $result,
  4306. 'count' => $total,
  4307. ];
  4308. return Result::success($data);
  4309. }
  4310. public function noticeList(array $data): array
  4311. {
  4312. $where = [];
  4313. //title
  4314. if (isset($data['title']) && !empty($data['title'])) {
  4315. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4316. }
  4317. //level
  4318. if (isset($data['level']) && !empty($data['level'])) {
  4319. $where[] = ['notice.level', '=', $data['level']];
  4320. }
  4321. //status
  4322. if (isset($data['status']) && !empty($data['status'])) {
  4323. $where[] = ['notice.status', '=', $data['status']];
  4324. }
  4325. //type
  4326. if (isset($data['type']) && !empty($data['type'])) {
  4327. $where[] = ['notice.type', '=', $data['type']];
  4328. }
  4329. var_dump($data, '------------11111-2----test---------');
  4330. if ($data['type_id'] == 10000) {
  4331. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4332. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4333. })
  4334. ->where($where)
  4335. ->orderBy('updated_at', 'desc')
  4336. ->limit($data['page_size'])
  4337. ->offset(($data['page'] - 1) * $data['page_size'])
  4338. ->get();
  4339. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4340. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4341. })
  4342. ->where($where)
  4343. ->orderBy('updated_at', 'desc')
  4344. ->count();
  4345. } else {
  4346. $result = Notice::where($where)
  4347. // ->where('user_id', $data['user_id'])
  4348. ->Where(function ($query) use ($data) {
  4349. $query->Where(function ($q) use ($data) {
  4350. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4351. ->orWhere('notice.user_id', $data['user_id']);
  4352. });
  4353. })
  4354. ->when(!empty($data['status1']), function ($query) use ($data) {
  4355. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4356. })
  4357. ->orderBy('updated_at', 'desc')
  4358. ->limit($data['page_size'])
  4359. ->offset(($data['page'] - 1) * $data['page_size'])
  4360. ->get();
  4361. $total = Notice::where($where)
  4362. ->when(!empty($data['status1']), function ($query) use ($data) {
  4363. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4364. })
  4365. // ->where('user_id', $data['user_id'])
  4366. ->Where(function ($query) use ($data) {
  4367. $query->Where(function ($q) use ($data) {
  4368. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4369. ->orWhere('notice.user_id', $data['user_id']);
  4370. });
  4371. })
  4372. ->count();
  4373. }
  4374. if (empty($result)) {
  4375. return Result::error("查询失败", 0);
  4376. }
  4377. $data = [
  4378. 'rows' => $result,
  4379. 'count' => $total,
  4380. ];
  4381. return Result::success($data);
  4382. }
  4383. public function getNoticeDetail(array $data): array
  4384. {
  4385. $result = Notice::where('id', $data['id'])->first();
  4386. if (empty($result)) {
  4387. return Result::error("查询失败", 0);
  4388. }
  4389. return Result::success($result);
  4390. }
  4391. public function deleteNotice(array $data): array
  4392. {
  4393. $notice = Notice::where('id', $data['id'])->first();
  4394. if (empty($notice)) {
  4395. return Result::error("删除失败", 0);
  4396. }
  4397. $chat_group_id = $notice->group_id;
  4398. if ($chat_group_id) {
  4399. //删除群聊
  4400. ChatGroups::where('id', $chat_group_id)->delete();
  4401. //删除群成员
  4402. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  4403. //删除群聊记录
  4404. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  4405. }
  4406. $result = Notice::where('id', $data['id'])->delete();
  4407. return Result::success($result);
  4408. }
  4409. public function complaintList(array $data): array
  4410. {
  4411. var_dump($data, '---------1---------');
  4412. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4413. unset($data['type_id']);
  4414. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4415. $where = [];
  4416. if ($type_id != 10000 && empty($data['deal_user'])) {
  4417. // $where['complaint.user_id'] = $user_id;
  4418. }
  4419. if (!empty($data['title'])) {
  4420. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4421. }
  4422. if (!empty($data['department_id'])) {
  4423. $where['complaint.department_id'] = $data['department_id'];
  4424. }
  4425. if (!empty($data['deal'])) {
  4426. $where['complaint.deal'] = $data['deal'];
  4427. }
  4428. if (!empty($data['status'])) {
  4429. $where['complaint.status'] = $data['status'];
  4430. }
  4431. var_dump(!empty($data['deal_user']), '----------1');
  4432. var_dump($where, '----------2');
  4433. $result = Complaint::where($where)
  4434. ->when(!empty($data['status1']), function ($query) use ($data) {
  4435. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4436. })
  4437. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4438. //json re_user_ids data[user_id]是不是在里面
  4439. $query->Where(function ($q) use ($data) {
  4440. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4441. ->where('complaint.status', 2);
  4442. });
  4443. })
  4444. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4445. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4446. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4447. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4448. ->orderBy('updated_at', 'desc')
  4449. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4450. //sql输出
  4451. if (empty($result)) {
  4452. return Result::error("暂无投诉信息", 0);
  4453. }
  4454. // 取出数据
  4455. $rows = $result->items();
  4456. $count = $result->total();
  4457. $responseData = [
  4458. 'rows' => $rows,
  4459. 'count' => $count,
  4460. ];
  4461. return Result::success($responseData);
  4462. }
  4463. public function getComplaintList(array $data): array
  4464. {
  4465. var_dump($data, '00000001000000000000');
  4466. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4467. unset($data['type_id']);
  4468. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4469. $where = [];
  4470. if ($type_id != 10000 && empty($data['deal_user'])) {
  4471. $where['complaint.user_id'] = $user_id;
  4472. }
  4473. if (!empty($data['title'])) {
  4474. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4475. }
  4476. if (!empty($data['department_id'])) {
  4477. $where['complaint.department_id'] = $data['department_id'];
  4478. }
  4479. if (!empty($data['deal'])) {
  4480. $where['complaint.deal'] = $data['deal'];
  4481. }
  4482. if (!empty($data['status'])) {
  4483. $where['complaint.status'] = $data['status'];
  4484. }
  4485. var_dump(!empty($data['deal_user']), '----------1');
  4486. var_dump($where, '----------2');
  4487. $result = Complaint::where($where)
  4488. ->when(!empty($data['status1']), function ($query) use ($data) {
  4489. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4490. })
  4491. // ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4492. // //json re_user_ids data[user_id]是不是在里面
  4493. // $query->Where(function ($q) use ($data) {
  4494. // $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4495. // ->where('complaint.status', 2);
  4496. // });
  4497. // })
  4498. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4499. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4500. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4501. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4502. ->orderBy('updated_at', 'desc')
  4503. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4504. //sql输出
  4505. if (empty($result)) {
  4506. return Result::error("暂无投诉信息", 0);
  4507. }
  4508. // 取出数据
  4509. $rows = $result->items();
  4510. $count = $result->total();
  4511. $responseData = [
  4512. 'rows' => $rows,
  4513. 'count' => $count,
  4514. ];
  4515. return Result::success($responseData);
  4516. }
  4517. public function getComplaintInfo(array $data): array
  4518. {
  4519. $result = Complaint::where('id', $data['id'])->first();
  4520. if (empty($result)) {
  4521. return Result::error("查询失败", 0);
  4522. }
  4523. return Result::success($result);
  4524. }
  4525. public function readComplaint(array $data): array
  4526. {
  4527. $result = Complaint::where('id', $data['id'])->first();
  4528. if (empty($result)) {
  4529. return Result::error("查询失败", 0);
  4530. }
  4531. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4532. $re_user_ids = json_decode($result['re_user_ids'], true);
  4533. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4534. //如果已经存在,就不再添加
  4535. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4536. $read_id = json_decode($result['read_id'], true);
  4537. if (!is_array($read_id)) {
  4538. $read_id = [];
  4539. }
  4540. if (!in_array($data['user_id'], $read_id)) {
  4541. $read_id[] = $data['user_id'];
  4542. $result['read_id'] = json_encode($read_id);
  4543. Complaint::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4544. }
  4545. } else {
  4546. //如果不存在,就添加
  4547. $result['read_id'] = json_encode([$data['user_id']]);
  4548. Complaint::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4549. }
  4550. }
  4551. return Result::success($result);
  4552. }
  4553. public function addComplaint(array $data): array
  4554. {
  4555. date_default_timezone_set('Asia/Shanghai');
  4556. $data['created_at'] = date('Y-m-d H:i:s');
  4557. $data['updated_at'] = date('Y-m-d H:i:s');
  4558. $this->sendMessage([
  4559. 'talk_type' => 800,
  4560. 'title' => $data['title'],
  4561. 'content' => '提交了审核',
  4562. 'messageType' => 6,
  4563. ]);
  4564. $result = Complaint::create($data);
  4565. return Result::success($result);
  4566. }
  4567. public function updateComplaint(array $data): array
  4568. {
  4569. date_default_timezone_set('Asia/Shanghai');
  4570. $data['updated_at'] = date('Y-m-d H:i:s');
  4571. $user_id = $data['user_id'] ?? 0;
  4572. $type_id = $data['type_id'] ?? 0;
  4573. unset($data['user_id']);
  4574. unset($data['type_id']);
  4575. $this->sendMessage([
  4576. 'talk_type' => 800,
  4577. 'title' => $data['title'],
  4578. 'content' => '提交了审核',
  4579. 'messageType' => 6,
  4580. ]);
  4581. $result = Complaint::where('id', $data['id'])->update($data);
  4582. return Result::success($result);
  4583. }
  4584. public function deleteComplaint(array $data): array
  4585. {
  4586. $result = Complaint::where('id', $data['id'])->delete();
  4587. return Result::success($result);
  4588. }
  4589. public function getComplainInfo(array $data): array
  4590. {
  4591. $result = Complaint::where('id', $data['id'])->first();
  4592. if (empty($result)) {
  4593. return Result::error("查询失败", 0);
  4594. }
  4595. return Result::success($result);
  4596. }
  4597. public function updateComplaintStatus(array $data): array
  4598. {
  4599. date_default_timezone_set('Asia/Shanghai');
  4600. $data['updated_at'] = date('Y-m-d H:i:s');
  4601. $user_id = $data['user_id'] ?? 0;
  4602. $type_id = $data['type_id'] ?? 0;
  4603. unset($data['user_id']);
  4604. unset($data['type_id']);
  4605. //处理, 写入处理人
  4606. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  4607. $data['real_deal_user'] = $user_id;
  4608. }
  4609. //如果是deal 23,则判断是不是处理人
  4610. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  4611. $complaintInof = Complaint::where('id', $data['id'])
  4612. ->where('real_deal_user', $user_id)
  4613. ->first();
  4614. if (empty($complaintInof)) {
  4615. return Result::error("处理人错误", 0);
  4616. }
  4617. }
  4618. $complaintInfo = Complaint::where('id', $data['id'])->first();
  4619. if ($data['status'] == 1) {
  4620. $this->sendMessage([
  4621. 'talk_type' => 800,
  4622. 'title' => $complaintInfo['title'],
  4623. 'content' => '提交了审核',
  4624. 'messageType' => 6,
  4625. ]);
  4626. }
  4627. if ($data['status'] == 2 && !isset($data['deal'])) {
  4628. $this->sendMessage([
  4629. 'talk_type' => 801,
  4630. 'title' => $complaintInfo['title'],
  4631. 'content' => '审核通过',
  4632. 'messageType' => 6,
  4633. 'user_id' => $complaintInfo['user_id'],
  4634. ]);
  4635. $this->sendMessage([
  4636. 'talk_type' => 802,
  4637. 'title' => $complaintInfo['title'],
  4638. 'content' => '待处理',
  4639. 'messageType' => 6,
  4640. 'user_id' => $complaintInfo['re_user_ids'],
  4641. ]);
  4642. }
  4643. if ($data['status'] == 3 && !isset($data['deal'])) {
  4644. $this->sendMessage([
  4645. 'talk_type' => 801,
  4646. 'title' => $complaintInfo['title'],
  4647. 'content' => '审核拒绝',
  4648. 'messageType' => 6,
  4649. 'user_id' => $complaintInfo['user_id'],
  4650. ]);
  4651. }
  4652. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 2) {
  4653. $this->sendMessage([
  4654. 'talk_type' => 802,
  4655. 'title' => $complaintInfo['title'],
  4656. 'content' => '处理中',
  4657. 'messageType' => 6,
  4658. 'user_id' => $complaintInfo['re_user_ids'],
  4659. ]);
  4660. }
  4661. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 4) {
  4662. $this->sendMessage([
  4663. 'talk_type' => 802,
  4664. 'title' => $complaintInfo['title'],
  4665. 'content' => '不予处理',
  4666. 'messageType' => 6,
  4667. 'user_id' => $complaintInfo['re_user_ids'],
  4668. ]);
  4669. }
  4670. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 3) {
  4671. $this->sendMessage([
  4672. 'talk_type' => 802,
  4673. 'title' => $complaintInfo['title'],
  4674. 'content' => '已完结',
  4675. 'messageType' => 6,
  4676. 'user_id' => $complaintInfo['re_user_ids'],
  4677. ]);
  4678. }
  4679. $result = complaint::where('id', $data['id'])->update($data);
  4680. return Result::success($result);
  4681. }
  4682. public function updateGoodStatus(array $data): array
  4683. {
  4684. $user_id = $data['user_id'] ?? 0;
  4685. $type_id = $data['type_id'] ?? 0;
  4686. unset($data['user_id']);
  4687. unset($data['type_id']);
  4688. $goodInfo = Good::where('id', $data['id'])->first();
  4689. if ($data['status'] == 2) {
  4690. $this->sendMessage([
  4691. 'talk_type' => 201,
  4692. 'title' => $goodInfo['name'],
  4693. 'content' => '审核通过',
  4694. 'messageType' => 3,
  4695. 'user_id' => $goodInfo['user_id'],
  4696. ]);
  4697. }
  4698. if ($data['status'] == 3) {
  4699. $this->sendMessage([
  4700. 'talk_type' => 201,
  4701. 'title' => $goodInfo['name'],
  4702. 'content' => '审核拒绝',
  4703. 'messageType' => 3,
  4704. 'user_id' => $goodInfo['user_id'],
  4705. ]);
  4706. }
  4707. if ($data['status'] == 1) {
  4708. $this->sendMessage([
  4709. 'talk_type' => 200,
  4710. 'title' => $goodInfo['name'],
  4711. 'content' => '提交了审核',
  4712. 'messageType' => 3,
  4713. ]);
  4714. }
  4715. $result = Good::where('id', $data['id'])->update($data);
  4716. return Result::success($result);
  4717. }
  4718. public function updateJobHuntingStatus(array $data): array
  4719. {
  4720. $user_id = $data['user_id'] ?? 0;
  4721. $type_id = $data['type_id'] ?? 0;
  4722. unset($data['user_id']);
  4723. unset($data['type_id']);
  4724. $jogHuntingInfo = JobHunting::where('id', $data['id'])->first();
  4725. if ($data['status'] == 2) {
  4726. $this->sendMessage([
  4727. 'talk_type' => 601,
  4728. 'title' => $jogHuntingInfo['name'],
  4729. 'content' => '审核通过',
  4730. 'messageType' => 11,
  4731. 'user_id' => $jogHuntingInfo['user_id'],
  4732. ]);
  4733. }
  4734. if ($data['status'] == 3) {
  4735. $this->sendMessage([
  4736. 'talk_type' => 601,
  4737. 'title' => $jogHuntingInfo['name'],
  4738. 'content' => '审核拒绝',
  4739. 'messageType' => 11,
  4740. 'user_id' => $jogHuntingInfo['user_id'],
  4741. ]);
  4742. }
  4743. if ($data['status'] == 1) {
  4744. $this->sendMessage([
  4745. 'talk_type' => 600,
  4746. 'title' => $jogHuntingInfo['name'],
  4747. 'content' => '提交了审核',
  4748. 'messageType' => 11,
  4749. ]);
  4750. }
  4751. $result = JobHunting::where('id', $data['id'])->update($data);
  4752. return Result::success($result);
  4753. }
  4754. public function updateNoticeStatus(array $data): array
  4755. {
  4756. $user_id = $data['user_id'] ?? 0;
  4757. $type_id = $data['type_id'] ?? 0;
  4758. unset($data['user_id']);
  4759. unset($data['type_id']);
  4760. //查询公告
  4761. $notice = Notice::where('id', $data['id'])->first();
  4762. if (empty($notice)) {
  4763. return Result::error("公告不存在", 0);
  4764. }
  4765. //$chat_ids 去除掉$data['user_id']
  4766. $chat_ids = json_decode($notice['re_user_ids'], true);
  4767. $chat_ids = array_diff($chat_ids, [$notice['user_id']]);
  4768. //如果公告的状态是2,且是群聊公告,且状态是1,则创建群聊,第一次审核通过的时候处理成群聊
  4769. if ($data['status'] == 2 && $notice['is_group'] == 1 && ($notice['status'] == 1 || $notice['status'] == 3) && empty($notice['group_id'])) {
  4770. //chat_group
  4771. $group_id = PublicData::uuid();
  4772. $groupData = [
  4773. 'id' => $group_id,
  4774. 'creator_id' => $notice['user_id'],
  4775. 'group_name' => $notice['group_name'] ?? '',
  4776. 'profile' => $notice['profile'] ?? 0,
  4777. ];
  4778. var_dump($groupData, '-----------------groupData-------');
  4779. $groupResult = ChatGroups::insertGetId($groupData);
  4780. var_dump($groupResult, '-----------------groupid-------');
  4781. $groupMemberData = [
  4782. 'id' => PublicData::uuid(),
  4783. 'user_id' => $notice['user_id'],
  4784. 'group_id' => $group_id,
  4785. 'leader' => 2,
  4786. ];
  4787. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  4788. //插入群成员表
  4789. $groupMemberDataUser = [];
  4790. $chatData = [];
  4791. foreach ($chat_ids as $key => $value) {
  4792. $groupMemberDataUser[] = [
  4793. 'id' => PublicData::uuid(),
  4794. 'user_id' => $value,
  4795. 'group_id' => $group_id,
  4796. 'leader' => 1,
  4797. ];
  4798. $chatData[] = [
  4799. 'user_id' => $value,
  4800. 'msg_type' => 1,
  4801. 'receiver_id' => $group_id,
  4802. 'content' => '通过通知创建群聊',
  4803. 'group_receiver_id' => $notice['user_id'],
  4804. 'action' => 'recieved',
  4805. 'created_at' => date('Y-m-d H:i:s'),
  4806. ];
  4807. }
  4808. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  4809. ChatGroupsMember::insert($groupMemberDataUser);
  4810. //插入一条管理员聊天记录
  4811. $chatData[] = [
  4812. 'user_id' => $notice['user_id'],
  4813. 'msg_type' => 1,
  4814. 'receiver_id' => $group_id,
  4815. 'content' => '通过通知创建群聊',
  4816. 'group_receiver_id' => $notice['user_id'],
  4817. 'action' => 'said',
  4818. 'created_at' => date('Y-m-d H:i:s'),
  4819. ];
  4820. var_dump($chatData, '-----------------chatData-------');
  4821. $chatResult = ChatRecords::insert($chatData);
  4822. //处理imp
  4823. $group = [
  4824. 'type' => 1,
  4825. 'name' => $notice['group_name'] ?? '',
  4826. 'profile' => '',
  4827. 'avatar' => '',
  4828. 'creator_id' => $notice['user_id'],
  4829. ];
  4830. $groupResult = GroupImp::insertGetId($group);
  4831. var_dump($groupResult, '获取imp group_id');
  4832. $groupMember = [
  4833. 'user_id' => $notice['user_id'],
  4834. 'group_id' => $groupResult,
  4835. 'leader' => 1,
  4836. 'join_time' => Date('Y-m-d H:i:s')
  4837. ];
  4838. $groupMemberResult = GroupMemberImp::insertGetId($groupMember);
  4839. $talk_session = [
  4840. 'user_id' => $notice['user_id'],
  4841. 'to_from_id' => $groupResult,
  4842. 'talk_mode' => 2,
  4843. 'created_at' => Date('Y-m-d H:i:s'),
  4844. 'updated_at' => Date('Y-m-d H:i:s'),
  4845. ];
  4846. $talk_session_result = GroupTalkImp::insertGetId($talk_session);
  4847. //被通知人员处理
  4848. foreach ($chat_ids as $key => $value) {
  4849. $groupMemberdata[] = [
  4850. 'user_id' => $value,
  4851. 'group_id' => $groupResult,
  4852. 'leader' => 3,
  4853. 'join_time' => Date('Y-m-d H:i:s')
  4854. ];
  4855. $talk_sessionData[] = [
  4856. 'user_id' => $value,
  4857. 'to_from_id' => $groupResult,
  4858. 'talk_mode' => 2,
  4859. 'created_at' => Date('Y-m-d H:i:s'),
  4860. 'updated_at' => Date('Y-m-d H:i:s'),
  4861. ];
  4862. }
  4863. $groupResult1 = GroupMemberImp::insert($groupMemberdata);
  4864. $talk_sessionResult = GroupTalkImp::insert($talk_sessionData);
  4865. $group_id = $groupResult;
  4866. //更新result的 group_id
  4867. $data['group_id'] = $group_id;
  4868. Notice::where(['id' => $data['id']])->update($data);
  4869. }
  4870. if (($data['status'] == 1 || $data['status'] == 3) && $notice['is_group'] == 1 && $notice['status'] == 2 && !empty($notice['group_id'])) {
  4871. //删除掉信息
  4872. GroupImp::where('id', $notice['group_id'])->delete();
  4873. GroupMemberImp::where('group_id', $notice['group_id'])->delete();
  4874. GroupTalkImp::where('to_from_id', $notice['group_id'])->delete();
  4875. foreach ($chat_ids as $key => $value) {
  4876. }
  4877. //聊天记录删除
  4878. //如果是群聊公告,且已经有群聊id,则更新公告的group_id
  4879. $data['group_id'] = null;
  4880. Notice::where(['id' => $data['id']])->update($data);
  4881. }
  4882. $result = Notice::where('id', $data['id'])->update($data);
  4883. $noticeInfo = Notice::where('id', $data['id'])->first();
  4884. if ($data['status'] == 2) {
  4885. $this->sendMessage([
  4886. 'talk_type' => 701,
  4887. 'title' => $noticeInfo['title'],
  4888. 'content' => '审核通过',
  4889. 'messageType' => 3,
  4890. 'user_id' => $noticeInfo['user_id'],
  4891. ]);
  4892. }
  4893. if ($data['status'] == 3) {
  4894. $this->sendMessage([
  4895. 'talk_type' => 701,
  4896. 'title' => $noticeInfo['title'],
  4897. 'content' => '审核拒绝',
  4898. 'messageType' => 3,
  4899. 'user_id' => $noticeInfo['user_id'],
  4900. ]);
  4901. }
  4902. if ($data['status'] == 1) {
  4903. $this->sendMessage([
  4904. 'talk_type' => 700,
  4905. 'title' => $noticeInfo['title'],
  4906. 'content' => '提交了审核',
  4907. 'messageType' => 3,
  4908. ]);
  4909. }
  4910. return Result::success($result);
  4911. }
  4912. public function getDUser(array $data): array
  4913. {
  4914. if (!empty($data['ids'])) {
  4915. $user = User::whereIn('id', $data['ids'])->getall();
  4916. if (empty($user)) {
  4917. return Result::error('无数据', 0);
  4918. }
  4919. return Result::success($user);
  4920. }
  4921. $where = [];
  4922. if (!empty($data['department_id'])) {
  4923. $where['department_id'] = $data['department_id'];
  4924. }
  4925. if (!empty($data['city_id'])) {
  4926. $where['city_id'] = $data['city_id'];
  4927. }
  4928. $result = User::where('type_id', 2)
  4929. ->where('status', 1)
  4930. ->where($where)
  4931. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  4932. ->get();
  4933. if (empty($result)) {
  4934. return Result::error("查询失败", 0);
  4935. }
  4936. return Result::success($result);
  4937. }
  4938. /**
  4939. * 验证导航名称是否重复
  4940. * @return void
  4941. */
  4942. public function checkCategoryName(array $data): array
  4943. {
  4944. $result = Category::when($data, function ($query) use ($data) {
  4945. if (isset($data['name']) && $data['name']) {
  4946. $query->where("name", $data['name']);
  4947. }
  4948. if (isset($data['id']) && $data['id']) {
  4949. $query->where("id", "!=", $data['id']);
  4950. }
  4951. })->first();
  4952. if ($result) {
  4953. return Result::error("已存在");
  4954. } else {
  4955. return Result::success();
  4956. }
  4957. }
  4958. //20250226 产品列表
  4959. // 20250306 -------招聘--------fr
  4960. /*
  4961. * 招聘列表
  4962. * */
  4963. public function getJobRecruitingList(array $data): array
  4964. {
  4965. $where = [];
  4966. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  4967. if ($data['checkout'] == 0) {
  4968. $job_status = [0, 2];
  4969. } else {
  4970. $job_status = [1];
  4971. }
  4972. if (isset($data['keyword']) && !empty($data['keyword'])) {
  4973. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  4974. }
  4975. $user = User::where('id', $data['user_id'])->first();
  4976. if (empty($user)) {
  4977. return Result::error("用户不存在", 0);
  4978. }
  4979. // 3:企业会员
  4980. if ($user['type_id'] == 3) {
  4981. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  4982. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  4983. }
  4984. // 如果 $where 为空,则不添加 where 条件
  4985. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4986. return $query->where($where);
  4987. })
  4988. ->whereIn('job_recruiting.status', $job_status)
  4989. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4990. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  4991. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  4992. ->orderBy("updated_at", "desc")
  4993. ->offset(($data['page'] - 1) * $data['page_size'])
  4994. ->limit($data['page_size'])
  4995. ->get()
  4996. ->all();
  4997. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4998. return $query->where($where);
  4999. })
  5000. ->whereIn('job_recruiting.status', $job_status)
  5001. ->count();
  5002. if (empty($result)) {
  5003. return Result::error("暂无招聘信息", 0);
  5004. }
  5005. return Result::success($result);
  5006. }
  5007. /*
  5008. * 招聘信息添加
  5009. * */
  5010. public function addJobRecruiting(array $data): array
  5011. {
  5012. // var_dump('添加招聘进入news------data',$data);
  5013. // return Result::success($data);
  5014. $user = User::where('user.id', $data['user_id'])
  5015. ->where('user.status', 1)
  5016. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5017. ->select(
  5018. 'user.type_id',
  5019. 'user.mobile',
  5020. 'user.email',
  5021. 'user_info.business_name',
  5022. 'user_info.company_hy_id',
  5023. 'user_info.company_nature',
  5024. 'user_info.company_size',
  5025. 'user_info.introduction',
  5026. 'user_info.real_name',
  5027. 'user_info.company_url',
  5028. 'user_info.address_arr_id',
  5029. 'user_info.address'
  5030. )
  5031. ->first();
  5032. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5033. return Result::error("用户不存在", 0);
  5034. }
  5035. $web = Website::where('id', $data['website_id'])->first();
  5036. if (empty($web)) {
  5037. return Result::error("网站不存在", 0);
  5038. }
  5039. // var_dump('添加招聘进入news---user---user',$user);
  5040. // 处理招聘关键词
  5041. if(isset($data['keyword']) && !empty($data['keyword'])){
  5042. $data['keyword'] = str_replace(',',',',$data['keyword']);
  5043. }else{
  5044. Jieba::init(); // 初始化 jieba-php
  5045. Finalseg::init();
  5046. $segList = Jieba::cut($data['title']);
  5047. $segList1 = array_slice($segList, 0, 8);
  5048. $data['keyword'] = implode(',', $segList1);
  5049. }
  5050. // return Result::success($user);
  5051. $data['action_id'] = $data['user_id'] ?? null;
  5052. $data['user_type'] = $user['type_id'] ?? null;
  5053. $data['cat_arr_id'] = isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) ? array_values(array_unique($data['cat_arr_id'])) : [];
  5054. if(isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])){
  5055. $data['catid'] = end($data['cat_arr_id']);
  5056. }else{
  5057. $data['catid'] = 0;
  5058. }
  5059. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? array_values(array_unique($data['city_arr_id'])) : [];
  5060. $data['cat_arr_id'] = isset($data['cat_arr_id']) && $data['cat_arr_id'] != [] ? json_encode(array_map('intval', $data['cat_arr_id'])) : '[]';
  5061. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '[]';
  5062. // 公司地址 管理员必填
  5063. $data['address_arr_id'] = isset($data['address_arr_id']) && !empty($data['address_arr_id']) ? array_values(array_unique($data['address_arr_id'])) : [];
  5064. $data['address_arr_id'] = isset($data['address_arr_id']) && $data['address_arr_id'] != [] ? json_encode(array_map('intval', $data['address_arr_id'])) : '[]';
  5065. // 管理员-企业相关信息
  5066. $company = [
  5067. // 'user_id' => $data['user_id']?? null,
  5068. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5069. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5070. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5071. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5072. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5073. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5074. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5075. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5076. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5077. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5078. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5079. ];
  5080. //去掉相关企业信息
  5081. $job = array_diff_key($data, array_flip(array_keys($company)));
  5082. // var_dump('添加招聘进入news---job---user',$job);
  5083. Db::beginTransaction();
  5084. try {
  5085. // // 先添加职位相关信息
  5086. if ($user['type_id'] == 10000) {
  5087. $job['status'] = 1;
  5088. }
  5089. $job['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5090. $job['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5091. $job['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5092. $job['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5093. $job['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5094. $job['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5095. $job['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5096. // return Result::success($job);
  5097. $jobId = JobRecruiting::insertGetId($job);
  5098. if (empty($jobId)) {
  5099. Db::rollBack();
  5100. return Result::error("添加失败");
  5101. }
  5102. // 添加公司信息
  5103. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5104. $company['job_id'] = $jobId;
  5105. $company['user_type'] = isset($user['type_id']) && $user['type_id'] !== '' ? $user['type_id'] : null;
  5106. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5107. if ($user['type_id'] == 10000) {
  5108. // 管理员添加企业信息
  5109. $companyId = JobCompany::insertGetId($company);
  5110. if (empty($companyId)) {
  5111. Db::rollBack();
  5112. return Result::error("添加失败");
  5113. }
  5114. } else {
  5115. // 企业会员添加企业信息
  5116. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5117. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5118. $company['user_type'] = isset($data['user_type']) && $data['user_type'] !== '' ? $data['user_type'] : null;
  5119. $company['job_id'] = $jobId;
  5120. $companyId = JobCompany::insertGetId($company);
  5121. if (empty($companyId)) {
  5122. Db::rollBack();
  5123. return Result::error("添加失败");
  5124. }
  5125. }
  5126. Db::commit();
  5127. $result = [
  5128. 'job_id' => $jobId,
  5129. 'company_id' => $companyId,
  5130. ];
  5131. return Result::success($result);
  5132. } catch (\Exception $e) {
  5133. Db::rollBack();
  5134. return Result::error($e->getMessage(), 0);
  5135. }
  5136. // return Result::success($result);
  5137. }
  5138. /*
  5139. * 获取招聘信息详情
  5140. * */
  5141. public function getJobRecruitingInfo(array $data): array
  5142. {
  5143. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  5144. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5145. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5146. ->select(
  5147. 'job_recruiting.*',
  5148. 'website.website_name as website_name',
  5149. 'job_company.business_name',
  5150. 'job_company.company_hy_id',
  5151. 'job_company.company_size',
  5152. 'job_company.company_nature',
  5153. 'job_company.introduction',
  5154. 'job_company.real_name',
  5155. 'job_company.mobile',
  5156. 'job_company.company_url',
  5157. 'job_company.address_arr_id',
  5158. 'job_company.address',
  5159. 'job_company.email'
  5160. )
  5161. ->first();
  5162. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  5163. if (!empty($cityId)) {
  5164. if (isset($cityId[1]) && $cityId[1] != null) {
  5165. $city = District::where('id', $cityId[1])->first(['name']);
  5166. } else {
  5167. $city = District::where('id', $cityId[0])->first(['name']);
  5168. }
  5169. $result['city'] = $city['name'] ?? '';
  5170. }
  5171. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  5172. if (is_array($addressId) && !empty($addressId)) {
  5173. $address = District::whereIn('id', $addressId)
  5174. ->orderBy('level', 'asc')
  5175. ->get(['name'])
  5176. ->pluck('name')
  5177. ->implode('');
  5178. // $job->address_name = $address ?? '';
  5179. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  5180. }
  5181. if (empty($result)) {
  5182. return Result::error("招聘信息不存在", 0);
  5183. }
  5184. // return Result::success($job);
  5185. return Result::success($result);
  5186. }
  5187. /*
  5188. * 修改招聘信息
  5189. * */
  5190. public function upJobRecruiting(array $data): array
  5191. {
  5192. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  5193. // return Result::success($job);
  5194. if (empty($job)) {
  5195. return Result::error("招聘信息不存在", 0);
  5196. }
  5197. $user = User::where('id', $data['user_id'])->first();
  5198. // return Result::success($user);
  5199. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5200. return Result::error("用户不存在", 0);
  5201. }
  5202. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5203. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5204. }
  5205. // 处理招聘关键词
  5206. if(isset($data['keyword']) && !empty($data['keyword'])){
  5207. $data['keyword'] = str_replace(',',',',$data['keyword']);
  5208. }else{
  5209. Jieba::init(); // 初始化 jieba-php
  5210. Finalseg::init();
  5211. $segList = Jieba::cut($data['title']);
  5212. $segList1 = array_slice($segList, 0, 8);
  5213. $data['keyword'] = implode(',', $segList1);
  5214. }
  5215. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  5216. if(isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])){
  5217. $data['catid'] = end($data['cat_arr_id']);
  5218. }else{
  5219. }
  5220. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  5221. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  5222. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  5223. // 公司地址 管理员必填
  5224. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  5225. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5226. // 管理员-企业相关信息
  5227. $company = [
  5228. // 'user_id' => $data['user_id']?? null,
  5229. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5230. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5231. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5232. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5233. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5234. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5235. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5236. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5237. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5238. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5239. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5240. ];
  5241. //去掉相关企业信息
  5242. $data = array_diff_key($data, array_flip(array_keys($company)));
  5243. $jobId = $data['id'];
  5244. $web = $data['website_id'];
  5245. $data['action_id'] = $data['user_id'];
  5246. unset($data['user_id']);
  5247. unset($data['user_type']);
  5248. unset($data['id']);
  5249. unset($data['website_id']);
  5250. // return Result::success($data);
  5251. Db::beginTransaction();
  5252. try {
  5253. // 管理员修改招聘信息
  5254. if ($user['type_id'] == 10000) {
  5255. $data['website_id'] = $web;
  5256. $company['website_id'] = $data['website_id'];
  5257. $data['status'] = 1;
  5258. } else {
  5259. $data['status'] = 0;
  5260. }
  5261. $data['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5262. $data['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5263. $data['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5264. $data['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5265. $data['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5266. $data['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5267. $data['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5268. // return Result::success($job);
  5269. // Db::rollBack();
  5270. // return Result::success($company);
  5271. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  5272. $this->sendMessage([
  5273. 'talk_type' => 500,
  5274. 'title' => $data['title'],
  5275. 'content' => '提交了审核',
  5276. 'messageType' => 10,
  5277. ]);
  5278. }
  5279. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  5280. if (empty($result['job'])) {
  5281. Db::rollBack();
  5282. return Result::error("修改招聘信息失败");
  5283. }
  5284. // 管理员修改企业相关信息
  5285. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  5286. if (empty($result['company'])) {
  5287. Db::rollBack();
  5288. return Result::error("修改企业相关信息失败");
  5289. }
  5290. Db::commit();
  5291. // return Result::success($result);
  5292. } catch (\Exception $e) {
  5293. Db::rollBack();
  5294. return Result::error($e->getMessage(), 0);
  5295. }
  5296. return Result::success($result);
  5297. }
  5298. /*
  5299. * 招聘信息删除
  5300. * */
  5301. public function delJobRecruiting(array $data): array
  5302. {
  5303. $user = User::where('id', $data['user_id'])->first();
  5304. if (empty($user)) {
  5305. return Result::error("用户不存在", 0);
  5306. }
  5307. $job = JobRecruiting::where('id', $data['id'])->first();
  5308. if (empty($job)) {
  5309. return Result::error("招聘信息不存在", 0);
  5310. }
  5311. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5312. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5313. }
  5314. Db::beginTransaction();
  5315. try {
  5316. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  5317. if (empty($result['job'])) {
  5318. Db::rollBack();
  5319. return Result::error("删除招聘信息失败");
  5320. }
  5321. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  5322. if (empty($result['company'])) {
  5323. Db::rollBack();
  5324. return Result::error("删除企业相关信息失败");
  5325. }
  5326. Db::commit();
  5327. } catch (\Exception $e) {
  5328. Db::rollBack();
  5329. return Result::error($e->getMessage(), 0);
  5330. }
  5331. return Result::success($result);
  5332. }
  5333. /*
  5334. * 获取公司信息
  5335. * */
  5336. public function getJobCompany(array $data): array
  5337. {
  5338. $user = User::where('user.id', $data['user_id'])
  5339. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5340. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  5341. ->first();
  5342. // return Result::success($user);
  5343. if (empty($user)) {
  5344. return Result::error("用户不存在", 0);
  5345. }
  5346. if ($user['type_id'] == 3) {
  5347. $result = [
  5348. // 'id' => 0,
  5349. 'user_id' => $data['user_id'],
  5350. 'website_id' => $data['website_id'],
  5351. 'business_name' => $user['business_name'], // 企业名称
  5352. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  5353. 'company_nature' => $user['company_nature'], // 公司性质
  5354. 'company_size' => $user['company_size'], // 公司规模
  5355. 'introduction' => $user['introduction'], // 公司简介
  5356. 'real_name' => $user['real_name'], // 企业联系人
  5357. 'mobile' => $user['mobile'], // 企业联系电话
  5358. 'company_url' => $user['company_url'], // 企业网址
  5359. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  5360. 'address' => $user['address'], // 企业地址
  5361. 'email' => $user['email'], // 企业邮箱
  5362. ];
  5363. } else {
  5364. return Result::error("用户类型错误", 0);
  5365. }
  5366. if (empty($result)) {
  5367. return Result::error("公司信息不存在", 0);
  5368. }
  5369. return Result::success($result);
  5370. }
  5371. /*
  5372. * 修改公司信息
  5373. * */
  5374. public function upJobCompany(array $data): array
  5375. {
  5376. // return Result::success($data);
  5377. $user = User::where('user.id', $data['user_id'])
  5378. ->where('user.status', 1)
  5379. ->select('user.user_name', 'user.type_id')
  5380. ->first();
  5381. if (empty($user)) {
  5382. return Result::error("用户不存在", 0);
  5383. }
  5384. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5385. $job_company = JobCompany::where('user_id', $data['user_id'])->first();
  5386. $company = [
  5387. 'business_name' => $data['business_name'], // 企业名称
  5388. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5389. 'company_nature' => $data['company_nature'], // 公司性质
  5390. 'company_size' => $data['company_size'], // 公司规模
  5391. 'introduction' => $data['introduction'], // 公司简介
  5392. // 'real_name' => $data['real_name'], // 企业联系人
  5393. 'company_url' => $data['company_url'], // 企业网址
  5394. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5395. 'address' => $data['address'], // 企业详细地址
  5396. // 'email' => $data['email'], // 企业邮箱
  5397. ];
  5398. if ($user['type_id'] == 3) {
  5399. Db::beginTransaction();
  5400. try {
  5401. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  5402. 'business_name' => $data['business_name'], // 企业名称
  5403. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5404. 'company_nature' => $data['company_nature'], // 公司性质
  5405. 'company_size' => $data['company_size'], // 公司规模
  5406. 'introduction' => $data['introduction'], // 公司简介
  5407. // 'real_name' => $data['real_name'], // 企业联系人
  5408. 'company_url' => $data['company_url'], // 企业网址
  5409. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5410. 'address' => $data['address'], // 企业详细地址
  5411. ]);
  5412. if (empty($result['userinfo'])) {
  5413. Db::rollBack();
  5414. return Result::error('修改企业会员信息失败!');
  5415. }
  5416. $result['user'] = User::where('id', $data['user_id'])->update([
  5417. 'email' => $data['email'], // 企业邮箱
  5418. ]);
  5419. if (empty($result['user'])) {
  5420. Db::rollBack();
  5421. return Result::error('修改个人中心信息失败!');
  5422. }
  5423. // 该企业会员若是未发布招聘信息则暂无该企业会员的企业信息
  5424. if (!empty($job_company)) {
  5425. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  5426. if (empty($result['job_company'])) {
  5427. Db::rollBack();
  5428. return Result::error('修改企业会员信息失败!');
  5429. }
  5430. }
  5431. Db::commit();
  5432. return Result::success($result);
  5433. } catch (\Exception $e) {
  5434. Db::rollBack();
  5435. return Result::error($e->getMessage(), 0);
  5436. }
  5437. } else {
  5438. return Result::error("用户类型错误", 0);
  5439. }
  5440. }
  5441. /*
  5442. * 获取省-市
  5443. * */
  5444. public function getJobRecruitingArea(array $data): array
  5445. {
  5446. if (isset($data['pid']) && $data['pid'] != null) {
  5447. $result = District::where('pid', $data['pid'])->get()->all();
  5448. } else {
  5449. $result = District::where('level', 1)->get()->all();
  5450. }
  5451. if (empty($result)) {
  5452. return Result::error("暂无此省市", 0);
  5453. }
  5454. return Result::success($result);
  5455. }
  5456. /*
  5457. * 获取行业分类
  5458. * */
  5459. public function getIndustry(array $data): array
  5460. {
  5461. $result = JobIndustry::get()->all();
  5462. if (empty($result)) {
  5463. return Result::error("暂无行业分类", 0);
  5464. }
  5465. return Result::success($result);
  5466. }
  5467. /*
  5468. * 获取职位
  5469. * */
  5470. public function getPositionList(array $data): array
  5471. {
  5472. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  5473. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  5474. } else {
  5475. $result = JobPosition::where('zwpid', 0)->get()->all();
  5476. }
  5477. if (empty($result)) {
  5478. return Result::error("暂无此职位", 0);
  5479. }
  5480. return Result::success($result);
  5481. }
  5482. /*
  5483. * 获取工作性质-菜单
  5484. * */
  5485. public function getJobNature(array $data): array
  5486. {
  5487. $result = JobEnum::where('egroup', 'nature')->get()->all();
  5488. if (empty($result)) {
  5489. return Result::error("暂无工作性质", 0);
  5490. }
  5491. return Result::success($result);
  5492. }
  5493. /*
  5494. * 获取工作经验-菜单
  5495. * */
  5496. public function getExperience(array $data): array
  5497. {
  5498. $result = JobEnum::where('egroup', 'years')->get()->all();
  5499. if (empty($result)) {
  5500. return Result::error("暂无工作经验", 0);
  5501. }
  5502. return Result::success($result);
  5503. }
  5504. /*
  5505. * 获取学历-菜单
  5506. * */
  5507. public function getEducation(array $data): array
  5508. {
  5509. $result = JobEnum::where('egroup', 'education')->get()->all();
  5510. if (empty($result)) {
  5511. return Result::error("暂无学历", 0);
  5512. }
  5513. return Result::success($result);
  5514. }
  5515. /*
  5516. * 获取薪资-菜单
  5517. * */
  5518. public function getSalary(array $data): array
  5519. {
  5520. $result = JobEnum::where('egroup', 'income')->get()->all();
  5521. if (empty($result)) {
  5522. return Result::error("暂无薪资", 0);
  5523. }
  5524. return Result::success($result);
  5525. }
  5526. /*
  5527. * 获取语言-菜单
  5528. * */
  5529. public function getLanguage(array $data): array
  5530. {
  5531. $result = JobEnum::where('egroup', 'language')->get()->all();
  5532. if (empty($result)) {
  5533. return Result::error("暂无语言", 0);
  5534. }
  5535. return Result::success($result);
  5536. }
  5537. /*
  5538. * 获取掌握程度-菜单
  5539. * */
  5540. public function getLevel(array $data): array
  5541. {
  5542. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  5543. if (empty($result)) {
  5544. return Result::error("暂无工作性质", 0);
  5545. }
  5546. return Result::success($result);
  5547. }
  5548. // 公司信息
  5549. /*
  5550. * 获取公司性质-菜单
  5551. * */
  5552. public function getCompanyNature(array $data): array
  5553. {
  5554. $result = JobNature::get()->all();
  5555. if (empty($result)) {
  5556. return Result::error("暂无公司性质", 0);
  5557. }
  5558. return Result::success($result);
  5559. }
  5560. /*
  5561. * 获取公司规模-菜单
  5562. * */
  5563. public function getCompanySize(array $data): array
  5564. {
  5565. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  5566. if (empty($result)) {
  5567. return Result::error("暂无公司规模", 0);
  5568. }
  5569. return Result::success($result);
  5570. }
  5571. /*
  5572. * 招聘信息审核
  5573. * */
  5574. public function checkJobRecruiting(array $data): array
  5575. {
  5576. $user = User::where('id', $data['user_id'])->first();
  5577. if (empty($user)) {
  5578. return Result::error("用户不存在", 0);
  5579. }
  5580. $job = JobRecruiting::where('id', $data['id'])->first();
  5581. if (empty($job)) {
  5582. return Result::error("招聘信息不存在", 0);
  5583. }
  5584. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  5585. if ($user['type_id'] != 10000) {
  5586. return Result::error("用户暂无权限审核此招聘信息!", 0);
  5587. }
  5588. // 驳回原因
  5589. if ($data['status'] == 2) {
  5590. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  5591. }
  5592. $data['action_id'] = $data['user_id'];
  5593. unset($data['user_id']);
  5594. if ($data['status'] == 1) {
  5595. $this->sendMessage([
  5596. 'talk_type' => 501,
  5597. 'title' => $job['title'],
  5598. 'content' => '审核通过',
  5599. 'messageType' => 10,
  5600. 'user_id' => $job['user_id'],
  5601. ]);
  5602. }
  5603. if ($data['status'] == 2) {
  5604. $this->sendMessage([
  5605. 'talk_type' => 501,
  5606. 'title' => $job['title'],
  5607. 'content' => '审核拒绝',
  5608. 'messageType' => 10,
  5609. 'user_id' => $job['user_id'],
  5610. ]);
  5611. }
  5612. if ($data['status'] == 0) {
  5613. $this->sendMessage([
  5614. 'talk_type' => 500,
  5615. 'title' => $job['title'],
  5616. 'content' => '提交了审核',
  5617. 'messageType' => 10,
  5618. ]);
  5619. }
  5620. $result = JobRecruiting::where('id', $data['id'])->update($data);
  5621. if (empty($result)) {
  5622. return Result::error("审核失败", 0);
  5623. }
  5624. return Result::success($result);
  5625. }
  5626. public function myApplyList(array $data): array
  5627. {
  5628. var_dump($data, '------参数');
  5629. $user = User::where('id', $data['user_id'])->first();
  5630. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5631. return Result::error("用户不存在", 0);
  5632. }
  5633. // 1:个人会员 职场机会
  5634. if ($user['type_id'] == 1) {
  5635. $where['user_id'] = $user['id'];
  5636. }
  5637. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  5638. $query->where('user_id', $user['id']);
  5639. })
  5640. ->pluck('recruit_id');
  5641. $where = [];
  5642. if (isset($data['salary']) && $data['salary'] != null) {
  5643. $where['job_recruiting.salary'] = $data['salary'];
  5644. }
  5645. if (isset($data['experience']) && $data['experience'] != null) {
  5646. $where['job_recruiting.experience'] = $data['experience'];
  5647. }
  5648. if (isset($data['business_name']) && $data['business_name'] != null) {
  5649. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  5650. }
  5651. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  5652. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5653. ->where($where);
  5654. // ->count();
  5655. $count = $query->count();
  5656. $query = clone $query;
  5657. $job = $query
  5658. ->leftJoin('job_enum as income_enum', function ($join) {
  5659. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  5660. ->where('income_enum.egroup', 'income');
  5661. })
  5662. ->leftJoin('job_enum as years_enum', function ($join) {
  5663. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  5664. ->where('years_enum.egroup', 'years');
  5665. })
  5666. // ->where($where)
  5667. ->orderBy('job_recruiting.updated_at', 'desc')
  5668. ->select(
  5669. 'job_recruiting.id',
  5670. 'job_recruiting.title',
  5671. 'job_company.business_name',
  5672. 'income_enum.evalue as salary_evalue',
  5673. 'income_enum.ename as salary_ename',
  5674. 'years_enum.evalue as experience_evalue',
  5675. 'years_enum.ename as experience_ename',
  5676. 'job_recruiting.updated_at'
  5677. )
  5678. ->offset(($data['page'] - 1) * $data['pageSize'])
  5679. ->limit($data['pageSize'])
  5680. ->get()
  5681. ->all();
  5682. if (empty($job)) {
  5683. return Result::error("暂无招聘信息", 0);
  5684. }
  5685. $result = [
  5686. 'row' => $job,
  5687. 'count' => $count,
  5688. ];
  5689. return Result::success($result);
  5690. }
  5691. public function readJobApply(array $data): array
  5692. {
  5693. $result = JobApply::where('id', $data['id'])->first();
  5694. if (empty($result)) {
  5695. return Result::error("查询失败", 0);
  5696. }
  5697. $result = JobApply::where('id', $data['id'])->update([
  5698. 'status' => 2,
  5699. ]);
  5700. return Result::success($result);
  5701. }
  5702. /*
  5703. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  5704. * */
  5705. public function getRecruitingList(array $data): array
  5706. {
  5707. $user = User::where('id', $data['user_id'])->first();
  5708. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5709. return Result::error("用户不存在", 0);
  5710. }
  5711. // 1:个人会员 职场机会
  5712. if ($user['type_id'] == 1) {
  5713. $where['user_id'] = $user['id'];
  5714. }
  5715. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  5716. $query->where('receiver_id', $user['id']);
  5717. })
  5718. ->pluck('recruit_id');
  5719. // return Result::success($recruitingId);
  5720. $where = [];
  5721. if (isset($data['salary']) && $data['salary'] != null) {
  5722. $where['job_recruiting.salary'] = $data['salary'];
  5723. }
  5724. if (isset($data['experience']) && $data['experience'] != null) {
  5725. $where['job_recruiting.experience'] = $data['experience'];
  5726. }
  5727. if (isset($data['business_name']) && $data['business_name'] != null) {
  5728. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  5729. }
  5730. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  5731. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5732. ->where($where);
  5733. // ->count();
  5734. $count = $query->count();
  5735. $query = clone $query;
  5736. $job = $query
  5737. ->leftJoin('job_enum as income_enum', function ($join) {
  5738. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  5739. ->where('income_enum.egroup', 'income');
  5740. })
  5741. ->leftJoin('job_enum as years_enum', function ($join) {
  5742. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  5743. ->where('years_enum.egroup', 'years');
  5744. })
  5745. // ->where($where)
  5746. ->orderBy('job_recruiting.updated_at', 'desc')
  5747. ->select(
  5748. 'job_recruiting.id',
  5749. 'job_recruiting.title',
  5750. 'job_company.business_name',
  5751. 'income_enum.evalue as salary_evalue',
  5752. 'income_enum.ename as salary_ename',
  5753. 'years_enum.evalue as experience_evalue',
  5754. 'years_enum.ename as experience_ename',
  5755. 'job_recruiting.updated_at'
  5756. )
  5757. ->offset(($data['page'] - 1) * $data['pageSize'])
  5758. ->limit($data['pageSize'])
  5759. ->get()
  5760. ->all();
  5761. if (empty($job)) {
  5762. return Result::error("暂无招聘信息", 0);
  5763. }
  5764. $result = [
  5765. 'row' => $job,
  5766. 'count' => $count,
  5767. ];
  5768. return Result::success($result);
  5769. }
  5770. /*
  5771. * 获取企业会员-招聘信息列表
  5772. * */
  5773. public function getRecruitingInfo(array $data): array
  5774. {
  5775. $user = User::where('id', $data['user_id'])->first();
  5776. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5777. return Result::error("用户不存在", 0);
  5778. }
  5779. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  5780. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5781. ->select(
  5782. 'job_recruiting.*',
  5783. 'job_company.business_name',
  5784. 'job_company.company_hy_id',
  5785. 'job_company.company_size',
  5786. 'job_company.company_nature',
  5787. 'job_company.introduction',
  5788. 'job_company.real_name',
  5789. 'job_company.mobile',
  5790. 'job_company.company_url',
  5791. 'job_company.address_arr_id',
  5792. 'job_company.address',
  5793. 'job_company.email'
  5794. )
  5795. ->get();
  5796. if (empty($recruiting)) {
  5797. return Result::error("暂无招聘信息", 0);
  5798. }
  5799. return Result::success($recruiting);
  5800. }
  5801. /*
  5802. * 获取企业会员-我的沟通
  5803. * */
  5804. public function getJobResumeList(array $data): array
  5805. {
  5806. $user = User::where('id', $data['user_id'])->first();
  5807. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  5808. return Result::error("用户不存在", 0);
  5809. }
  5810. $where = [];
  5811. if (isset($data['salary']) && $data['salary'] != null) {
  5812. $where['job_hunting.salary'] = $data['salary'];
  5813. }
  5814. if (isset($data['user_name']) && $data['user_name'] != null) {
  5815. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  5816. }
  5817. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  5818. $query->where('job_resume.user_id', $user['id']);
  5819. })
  5820. ->when(!empty($where), function ($query) use ($where) {
  5821. $query->where($where);
  5822. })
  5823. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  5824. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  5825. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  5826. ->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');
  5827. $count = $job->count();
  5828. if ($count == 0) {
  5829. return Result::error("暂无沟通记录", 0);
  5830. }
  5831. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  5832. ->offset(($data['page'] - 1) * $data['pageSize'])
  5833. ->limit($data['pageSize'])
  5834. ->get();
  5835. if (empty($jobs)) {
  5836. return Result::error("暂无沟通记录", 0);
  5837. }
  5838. $result['row'] = $this->processJob($jobs, '');
  5839. $result['count'] = $count;
  5840. return Result::success($result);
  5841. }
  5842. public function readJobResume(array $data): array
  5843. {
  5844. $result = JobResume::where('id', $data['id'])->first();
  5845. if (empty($result)) {
  5846. return Result::error("查询失败", 0);
  5847. }
  5848. $result = JobResume::where('id', $data['id'])->update([
  5849. 'status' => 2,
  5850. ]);
  5851. return Result::success($result);
  5852. }
  5853. // 20250306 招聘
  5854. //20250422 书刊音像
  5855. public function addBook(array $data): array
  5856. {
  5857. $user_id = $data['user_id'] ?? 0;
  5858. $type_id = $data['type_id'] ?? 0;
  5859. // $website_id = $data['website_id'] ?? 0;
  5860. // unset($data['user_id']);
  5861. unset($data['type_id']);
  5862. // unset($data['website_id']);
  5863. //处理数组
  5864. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  5865. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  5866. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  5867. if ($data['img_url'] == '') {
  5868. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5869. preg_match_all($reg, $data['detail'], $matches);
  5870. if (isset($matches[1][0])) {
  5871. //截取varchar240
  5872. $data['img_url'] = substr($matches[1][0], 0, 240);
  5873. }
  5874. }
  5875. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  5876. //提取标题+内容中的关键词
  5877. $data['keyword'] = $data['title'];
  5878. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5879. Jieba::init(); // 初始化 jieba-php
  5880. Finalseg::init();
  5881. $segList = Jieba::cut($data['keyword']);
  5882. $segList1 = array_slice($segList, 0, 8);
  5883. $data['keyword'] = implode(',', $segList1);
  5884. }
  5885. if ($data['description'] == '') {
  5886. //提取内容中的描述
  5887. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  5888. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  5889. }
  5890. var_dump($data, '--');
  5891. if ($data['status'] == 1) {
  5892. $this->sendMessage([
  5893. 'talk_type' => 400,
  5894. 'title' => $data['title'],
  5895. 'content' => '提交了审核',
  5896. 'messageType' => 7,
  5897. ]);
  5898. }
  5899. $result = Book::insertGetId($data);
  5900. if (empty($result)) {
  5901. return Result::error("添加失败", 0);
  5902. }
  5903. return Result::success($result);
  5904. }
  5905. public function getBookList(array $data): array
  5906. {
  5907. $where = [];
  5908. if (!empty($data["title"])) {
  5909. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  5910. }
  5911. if (!empty($data['website_name'])) {
  5912. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  5913. }
  5914. if (!empty($data['status'])) {
  5915. $where[] = ['book.status', '=', $data['status']];
  5916. }
  5917. $user_id = $data['user_id'];
  5918. $type_id = $data['type_id'];
  5919. // $type_id = 4;
  5920. var_dump($type_id, '------1--------');
  5921. if ($type_id != 10000) {
  5922. $where[] = ['book.user_id', '=', $user_id];
  5923. }
  5924. var_dump(!empty($data['status1']), '=-===1');
  5925. $result = Book::where($where)
  5926. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  5927. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  5928. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  5929. ->when(isset($data['status1']), function ($query) use ($data) {
  5930. $query->whereIn('book.status', [1, 3]);
  5931. })
  5932. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  5933. ->orderBy("updated_at", "desc")
  5934. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  5935. if (empty($result)) {
  5936. return Result::error("暂无数据", 0);
  5937. }
  5938. // 取出数据
  5939. $rows = $result->items();
  5940. $count = $result->total();
  5941. $responseData = [
  5942. 'rows' => $rows,
  5943. 'count' => $count,
  5944. ];
  5945. return Result::success($responseData);
  5946. }
  5947. public function deleteBook(array $data): array
  5948. {
  5949. $result = Book::where('id', $data['id'])->delete();
  5950. if (empty($result)) {
  5951. return Result::error("删除失败", 0);
  5952. }
  5953. return Result::success($result);
  5954. }
  5955. public function updateBook(array $data): array
  5956. {
  5957. // $user_id = $data['user_id'] ?? 0;
  5958. $type_id = $data['type_id'] ?? 0;
  5959. // $website_id = $data['website_id'] ?? 0;
  5960. unset($data['user_id']);
  5961. unset($data['type_id']);
  5962. // unset($data['website_id']);
  5963. //处理数组
  5964. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  5965. if ($data['img_url'] == '') {
  5966. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5967. preg_match_all($reg, $data['detail'], $matches);
  5968. if (isset($matches[1][0])) {
  5969. //截取varchar240
  5970. $data['img_url'] = substr($matches[1][0], 0, 240);
  5971. }
  5972. }
  5973. if ($data['keyword'] == '') {
  5974. //提取标题+内容中的关键词
  5975. $data['keyword'] = $data['title'];
  5976. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5977. Jieba::init(); // 初始化 jieba-php
  5978. Finalseg::init();
  5979. $segList = Jieba::cut($data['keyword']);
  5980. $segList1 = array_slice($segList, 0, 8);
  5981. $data['keyword'] = implode(',', $segList1);
  5982. }
  5983. if ($data['description'] == '') {
  5984. //提取内容中的描述
  5985. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  5986. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  5987. }
  5988. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  5989. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  5990. if ($data['status'] == 1) {
  5991. $this->sendMessage([
  5992. 'talk_type' => 400,
  5993. 'title' => $data['title'],
  5994. 'content' => '提交了审核',
  5995. 'messageType' => 7,
  5996. ]);
  5997. }
  5998. $result = Book::where("id", $data["id"])->update($data);
  5999. if (empty($result)) {
  6000. return Result::error("更新失败", 0);
  6001. }
  6002. return Result::success($result);
  6003. }
  6004. public function getBookInfo(array $data): array
  6005. {
  6006. $result = Book::where("id", $data["id"])->first();
  6007. if (empty($result)) {
  6008. return Result::error("获取失败", 0);
  6009. }
  6010. return Result::success($result);
  6011. }
  6012. public function updateBookStatus(array $data): array
  6013. {
  6014. //审核
  6015. unset($data['user_id']);
  6016. $bookInfo = Book::where("id", $data["id"])->first();
  6017. var_dump($bookInfo, '----');
  6018. if ($data['status'] == 2) {
  6019. $this->sendMessage([
  6020. 'talk_type' => 401,
  6021. 'title' => $bookInfo['title'],
  6022. 'content' => '审核通过',
  6023. 'messageType' => 7,
  6024. 'user_id' => $bookInfo['user_id'],
  6025. ]);
  6026. }
  6027. if ($data['status'] == 3) {
  6028. $this->sendMessage([
  6029. 'talk_type' => 401,
  6030. 'title' => $bookInfo['title'],
  6031. 'content' => '审核拒绝',
  6032. 'messageType' => 7,
  6033. 'user_id' => $bookInfo['user_id'],
  6034. ]);
  6035. }
  6036. if ($data['status'] == 1) {
  6037. $this->sendMessage([
  6038. 'talk_type' => 400,
  6039. 'title' => $bookInfo['title'],
  6040. 'content' => '提交了审核',
  6041. 'messageType' => 7,
  6042. // 'user_id'=>$bookInfo['user_id'],
  6043. ]);
  6044. }
  6045. $result = Book::where("id", $data["id"])->update($data);
  6046. if (empty($result)) {
  6047. return Result::error("更新失败", 0);
  6048. }
  6049. return Result::success($result);
  6050. }
  6051. //20250422 书刊音像
  6052. /**
  6053. * 贴身宝贝
  6054. * @param array $data
  6055. * @return array
  6056. */
  6057. public function getWebsiteTsbb(array $data): array
  6058. {
  6059. $month = $data['month'] ?? date('m');
  6060. $day = $data['day'] ?? date('d');
  6061. // 使用缓存键
  6062. $cacheKey = "tsbb_data_{$month}_{$day}";
  6063. // 尝试从缓存获取数据
  6064. $container = \Hyperf\Context\ApplicationContext::getContainer();
  6065. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  6066. if ($cachedData = $cache->get($cacheKey)) {
  6067. return Result::success(unserialize($cachedData));
  6068. }
  6069. //查询老黄历
  6070. try {
  6071. $date = date('Y-m-d');
  6072. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  6073. // 使用 curl 替代 file_get_contents
  6074. $ch = curl_init();
  6075. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  6076. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  6077. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  6078. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  6079. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  6080. 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');
  6081. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  6082. 'Accept: application/json',
  6083. 'Content-Type: application/json',
  6084. 'Referer: https://www.36jxs.com/'
  6085. ]);
  6086. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  6087. curl_setopt($ch, CURLOPT_ENCODING, '');
  6088. $almanacResponse = curl_exec($ch);
  6089. var_dump("====:", $almanacResponse);
  6090. if (curl_errno($ch)) {
  6091. var_dump('Curl error:', curl_error($ch));
  6092. throw new \Exception('Curl error: ' . curl_error($ch));
  6093. }
  6094. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  6095. curl_close($ch);
  6096. if ($almanacResponse === false) {
  6097. throw new \Exception('Failed to fetch almanac data');
  6098. }
  6099. $almanacData = json_decode($almanacResponse, true);
  6100. if (json_last_error() !== JSON_ERROR_NONE) {
  6101. throw new \Exception('Failed to parse almanac data');
  6102. }
  6103. $almanacInfo = $almanacData['data'] ?? [];
  6104. } catch (\Exception $e) {
  6105. var_dump('Exception:', $e->getMessage());
  6106. $almanacInfo = [];
  6107. }
  6108. // 获取历史上的今天数据
  6109. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6110. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  6111. ->orderBy('year', 'asc')
  6112. ->select("title", "id", "year", DB::raw('1 as type'))
  6113. ->limit(16)
  6114. ->get();
  6115. // 获取节日数据 - 从今天开始获取未来4条
  6116. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  6117. ->orderBy('showtime', 'asc')
  6118. ->select("title", "id", "showtime", DB::raw('2 as type'))
  6119. ->limit(16)
  6120. ->get();
  6121. //说文解字
  6122. $chartacterList = Character::orderBy('updated_at', 'desc')
  6123. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  6124. ->limit(6)
  6125. ->get();
  6126. //谜语沙龙
  6127. $riddletList = Riddle::orderBy('updated_at', 'desc')
  6128. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  6129. ->limit(4)
  6130. ->get();
  6131. //成语欣赏
  6132. $idiomList = Idiom::orderBy('updated_at', 'desc')
  6133. ->select("id", "title", "duyin", DB::raw('5 as type'))
  6134. ->limit(32)
  6135. ->get();
  6136. //名联赏析
  6137. $coupletList = Couplet::orderBy('updated_at', 'desc')
  6138. ->select("id", "first", "second", DB::raw('6 as type'))
  6139. ->limit(6)
  6140. ->get();
  6141. // 获取分类文章数据
  6142. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  6143. ->pluck('category_id')
  6144. ->toArray();
  6145. $articlesList = [];
  6146. foreach ($categoryIds as $catid) {
  6147. // 先查有图片的
  6148. $withImg = DB::table('article')
  6149. ->where('status', 1)
  6150. ->where('catid', $catid)
  6151. ->whereNotNull('imgurl')
  6152. ->where('imgurl', '!=', '')
  6153. ->orderBy('updated_at', 'desc')
  6154. ->limit(6)
  6155. ->get();
  6156. $count = $withImg->count();
  6157. if ($count < 6) {
  6158. // 不足6条再查无图片的补足
  6159. $withoutImg = DB::table('article')
  6160. ->where('status', 1)
  6161. ->where('catid', $catid)
  6162. ->where(function ($q) {
  6163. $q->whereNull('imgurl')->orWhere('imgurl', '');
  6164. })
  6165. ->orderBy('updated_at', 'desc')
  6166. ->limit(6 - $count)
  6167. ->get();
  6168. $articles = $withImg->concat($withoutImg);
  6169. } else {
  6170. $articles = $withImg;
  6171. }
  6172. // 组装
  6173. $category = \App\Model\Category::find($catid);
  6174. $websiteCategory = WebsiteCategory::where('category_id', $catid)->first();
  6175. $articlesList[] = [
  6176. 'category_name' => $category ? $category->name : '',
  6177. 'catid' => $catid,
  6178. 'pinyin' => $websiteCategory ? $websiteCategory->aLIas_pinyin : '',
  6179. 'type' => 100,
  6180. 'list' => $articles->map(function ($item) {
  6181. return [
  6182. 'id' => $item->id,
  6183. 'title' => $item->title,
  6184. 'imgurl' => $item->imgurl,
  6185. 'created_at' => $item->created_at
  6186. ];
  6187. })->values()
  6188. ];
  6189. }
  6190. $result = [
  6191. 'almanac' => $almanacInfo,
  6192. 'historyTodayList' => [
  6193. 'category_name' => '历史上的今天',
  6194. 'list' => $historyTodayList,
  6195. 'type' => 1
  6196. ],
  6197. 'festivalList' => [
  6198. 'category_name' => '节日预告',
  6199. 'list' => $festivalList,
  6200. 'type' => 2
  6201. ],
  6202. 'chartacterList' => [
  6203. 'category_name' => '说文解字',
  6204. 'list' => $chartacterList,
  6205. 'type' => 3
  6206. ],
  6207. 'coupletList' => [
  6208. 'category_name' => '名联赏析',
  6209. 'list' => $coupletList,
  6210. 'type' => 6
  6211. ],
  6212. 'riddletList' => [
  6213. 'category_name' => '谜语沙龙',
  6214. 'list' => $riddletList,
  6215. 'type' => 4
  6216. ],
  6217. 'idiomList' => [
  6218. 'category_name' => '成语欣赏',
  6219. 'list' => $idiomList,
  6220. 'type' => 5
  6221. ],
  6222. 'articlesList' => $articlesList
  6223. ];
  6224. // 缓存结果,设置1小时过期
  6225. $cache->set($cacheKey, serialize($result), 3600);
  6226. return Result::success($result);
  6227. }
  6228. /**
  6229. * 获取资讯列表
  6230. */
  6231. public function getWebsiteTsbbList(array $data): array
  6232. {
  6233. $page = $data['page'] ?? 1;
  6234. $pageSize = $data['pageSize'] ?? 10;
  6235. // 如果没有传入月份和日期,则使用今天的日期
  6236. $month = $data['month'] ?? date('m');
  6237. $day = $data['day'] ?? date('d');
  6238. $total = 0;
  6239. $result = [];
  6240. $data['type'] = intval($data['type']);
  6241. var_dump("接收参数:", $data);
  6242. switch ($data['type']) {
  6243. case 1:
  6244. $query = HistoryToday::where(function ($q) use ($month, $day) {
  6245. // 当前月份之后的数据
  6246. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  6247. // 或者当前月份且日期大于等于当前日期的数据
  6248. ->orWhere(function ($q) use ($month, $day) {
  6249. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6250. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  6251. });
  6252. })
  6253. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  6254. $total = $query->count();
  6255. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  6256. ->offset(($page - 1) * $pageSize)
  6257. ->limit($pageSize)
  6258. ->get();
  6259. break;
  6260. case 2:
  6261. $query = Festival::where(function ($q) use ($month, $day) {
  6262. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  6263. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  6264. ->orWhere(function ($q) use ($month, $day) {
  6265. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  6266. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  6267. });
  6268. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  6269. $total = $query->count();
  6270. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  6271. ->offset(($page - 1) * $pageSize)
  6272. ->limit($pageSize)
  6273. ->get();
  6274. break;
  6275. case 3:
  6276. $query = Character::orderBy("updated_at", "desc");
  6277. $total = $query->count();
  6278. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  6279. ->offset(($page - 1) * $pageSize)
  6280. ->limit($pageSize)
  6281. ->get();
  6282. break;
  6283. case 4:
  6284. $query = Riddle::orderBy("updated_at", "desc");
  6285. $total = $query->count();
  6286. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  6287. ->offset(($page - 1) * $pageSize)
  6288. ->limit($pageSize)
  6289. ->get();
  6290. break;
  6291. case 5:
  6292. $query = Idiom::orderBy("updated_at", "desc");
  6293. $total = $query->count();
  6294. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  6295. ->offset(($page - 1) * $pageSize)
  6296. ->limit($pageSize)
  6297. ->get();
  6298. break;
  6299. case 6:
  6300. $query = Couplet::orderBy("updated_at", "desc");
  6301. $total = $query->count();
  6302. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  6303. ->offset(($page - 1) * $pageSize)
  6304. ->limit($pageSize)
  6305. ->get();
  6306. break;
  6307. default:
  6308. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  6309. $total = $query->count();
  6310. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  6311. ->offset(($page - 1) * $pageSize)
  6312. ->limit($pageSize)
  6313. ->get();
  6314. }
  6315. return Result::success([
  6316. 'list' => $result,
  6317. 'total' => $total,
  6318. 'page' => (int)$page,
  6319. 'pageSize' => (int)$pageSize,
  6320. 'month' => $month,
  6321. 'day' => $day
  6322. ]);
  6323. }
  6324. /**
  6325. * 1:历史上的今天
  6326. * 2:节日
  6327. * 3:文章
  6328. *
  6329. * 资讯详情信息
  6330. */
  6331. public function getWebsiteTsbbDetail(array $data): array
  6332. {
  6333. $data['type'] = intval($data['type']);
  6334. switch ($data['type']) {
  6335. case 1:
  6336. $result = HistoryToday::where("id", $data['id'])->first();
  6337. break;
  6338. case 2:
  6339. $result = Festival::where("id", $data['id'])->first();
  6340. break;
  6341. case 3:
  6342. $result = Character::where("id", $data['id'])->first();
  6343. break;
  6344. case 4:
  6345. $result = Riddle::where("id", $data['id'])->first();
  6346. break;
  6347. case 5:
  6348. $result = Idiom::where("id", $data['id'])->first();
  6349. break;
  6350. case 6:
  6351. $result = Couplet::where("id", $data['id'])->first();
  6352. break;
  6353. default:
  6354. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  6355. break;
  6356. }
  6357. return Result::success($result);
  6358. }
  6359. /**
  6360. * 农网导航首页数据
  6361. */
  6362. public function getWebsiteNwHomeList(array $data): array
  6363. {
  6364. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  6365. ->pluck('category_id')
  6366. ->toArray();
  6367. // 使用子查询优化
  6368. $articlesList = DB::table('article')
  6369. ->select([
  6370. 'article.id',
  6371. 'article.title',
  6372. 'article.imgurl',
  6373. 'article.created_at',
  6374. 'category.name as category_name',
  6375. 'category.id as category_id',
  6376. 'website_category.aLIas_pinyin as pinyin',
  6377. 'parent_wc.aLIas_pinyin as parent_pinyin',
  6378. DB::raw('100 as type')
  6379. ])
  6380. ->join('category', 'article.catid', '=', 'category.id')
  6381. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  6382. ->leftJoin('website_category as parent_wc', function ($join) {
  6383. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  6384. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  6385. })
  6386. ->where('website_category.website_id', $data['website_id'])
  6387. ->where('article.status', 1)
  6388. ->whereIn('category.id', $categoryIds)
  6389. ->orderBy('article.created_at', 'desc')
  6390. ->get()
  6391. ->groupBy('category_id')
  6392. ->map(function ($group) {
  6393. // 确保第一条数据有图片
  6394. $firstWithImage = $group->first(function ($item) {
  6395. return !empty($item->imgurl);
  6396. });
  6397. if ($firstWithImage) {
  6398. // 如果有带图片的文章,将其放在第一位
  6399. $group = $group->filter(function ($item) use ($firstWithImage) {
  6400. return $item->id !== $firstWithImage->id;
  6401. })->prepend($firstWithImage);
  6402. }
  6403. return [
  6404. 'category_name' => $group->first()->category_name,
  6405. 'catid' => $group->first()->category_id,
  6406. 'pinyin' => $group->first()->pinyin,
  6407. 'parent_pinyin' => $group->first()->parent_pinyin,
  6408. 'list' => $group->take(4)->map(function ($item) {
  6409. return [
  6410. 'id' => $item->id,
  6411. 'title' => $item->title,
  6412. ];
  6413. })->values()
  6414. ];
  6415. })
  6416. ->values()
  6417. ->toArray();
  6418. return Result::success($articlesList);
  6419. }
  6420. /**
  6421. * 企业管理
  6422. * @param array $data
  6423. * @return array
  6424. */
  6425. public function getCompanyList(array $data): array
  6426. {
  6427. // return Result::success($data);
  6428. $where = [];
  6429. $user = User::where('id', $data['user_id'])->first();
  6430. if (empty($user)) {
  6431. return Result::error('用户不存在!');
  6432. }
  6433. if ($user['type_id'] != 10000) {
  6434. $where['user_id'] = $data['user_id'];
  6435. }
  6436. if (isset($data['title']) && !empty($data['title'])) {
  6437. array_push($where, ['company.title', 'like', '%' . $data['title'] . '%']);
  6438. }
  6439. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6440. array_push($where, ['website.id', $data['website_id']]);
  6441. }
  6442. if (isset($data['ischeck']) && !empty($data['ischeck'])) {
  6443. if ($data['ischeck'] == 1) {
  6444. if (isset($data['status']) && $data['status'] != '') {
  6445. array_push($where, ['company.status', $data['status']]);
  6446. $query = Company::where($where);
  6447. } else {
  6448. $query = Company::whereIn('company.status', [0, 2]);
  6449. }
  6450. } else {
  6451. $query = Company::where('company.status', 1);
  6452. }
  6453. }
  6454. $result = $query->where($where)
  6455. ->leftJoin('website_category', function ($query) {
  6456. $query->on('website_category.category_id', '=', 'company.category_id')
  6457. ->on('website_category.website_id', '=', 'company.website_id');
  6458. })
  6459. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  6460. ->select(
  6461. 'company.id',
  6462. 'company.title',
  6463. 'company.website_id',
  6464. 'company.category_id',
  6465. 'website.website_name',
  6466. 'website_category.alias as category_name',
  6467. 'company.status',
  6468. 'company.updated_at',
  6469. 'company.user_id'
  6470. )
  6471. ->orderBy('company.updated_at', 'desc')
  6472. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  6473. if ($result->isEmpty()) {
  6474. return Result::error("暂无企业", 0);
  6475. }
  6476. return Result::success($result);
  6477. }
  6478. /**
  6479. * 添加企业
  6480. * @param array $data
  6481. * @return array
  6482. */
  6483. public function addCompany(array $data): array
  6484. {
  6485. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  6486. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6487. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6488. $data['cat_arr_id'] = json_encode($car_arr_id);
  6489. } else {
  6490. $data['cat_arr_id'] = '';
  6491. }
  6492. if ($data['imgurl'] == '') {
  6493. //content中提取图片第一个图,正则提取
  6494. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6495. preg_match_all($reg, $data['content'], $matches);
  6496. if (isset($matches[1][0])) {
  6497. //截取varchar240
  6498. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6499. }
  6500. }
  6501. if ($data['keyword'] == '') {
  6502. //提取标题+内容中的关键词
  6503. $data['keyword'] = $data['title'];
  6504. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6505. Jieba::init(); // 初始化 jieba-php
  6506. Finalseg::init();
  6507. $segList = Jieba::cut($data['keyword']);
  6508. $segList1 = array_slice($segList, 0, 8);
  6509. $data['keyword'] = implode(',', $segList1);
  6510. }
  6511. if ($data['introduce'] == '' || empty($data['introduce'])) {
  6512. //提取内容中的描述
  6513. $content = $data['content'];
  6514. // 去除 <style> 和 <script> 标签及其内容
  6515. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6516. // 去除所有 HTML 标签
  6517. $content = strip_tags($content);
  6518. // 去除 HTML 实体
  6519. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6520. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6521. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6522. // 去除多余空白
  6523. $content = preg_replace('/\s+/u', '', $content);
  6524. // 截取 100 个字符
  6525. $data['introduce'] = mb_substr($content, 0, 100);
  6526. }
  6527. $user = User::where('id', $data['user_id'])->first();
  6528. if (empty($user)) {
  6529. return Result::error('用户不存在!');
  6530. }
  6531. if ($user['type_id'] == 10000) {
  6532. $data['status'] = 1;
  6533. }
  6534. if (isset($data['level']) && $data['level'] != null) {
  6535. $data['level'] = intval($data['level']);
  6536. } else {
  6537. $data['level'] = null;
  6538. }
  6539. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  6540. $this->sendMessage([
  6541. 'talk_type' => 900,
  6542. 'title' => $data['title'],
  6543. 'content' => '提交了审核',
  6544. 'messageType' => 8,
  6545. ]);
  6546. }
  6547. $result = Company::insertGetId($data);
  6548. if ($result) {
  6549. return Result::success($result);
  6550. } else {
  6551. return Result::error('添加失败');
  6552. }
  6553. }
  6554. /**
  6555. * 更新企业
  6556. * @param array $data
  6557. * @return array
  6558. */
  6559. public function upCompany(array $data): array
  6560. {
  6561. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6562. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6563. $data['cat_arr_id'] = json_encode($car_arr_id);
  6564. $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
  6565. } else {
  6566. $data['cat_arr_id'] = '';
  6567. }
  6568. if ($data['imgurl'] == '') {
  6569. //content中提取图片第一个图,正则提取
  6570. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6571. preg_match_all($reg, $data['content'], $matches);
  6572. if (isset($matches[1][0])) {
  6573. //截取varchar
  6574. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6575. }
  6576. }
  6577. if ($data['keyword'] == '') {
  6578. //提取标题+内容中的关键词
  6579. $data['keyword'] = $data['title'];
  6580. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6581. Jieba::init(); // 初始化 jieba-php
  6582. Finalseg::init();
  6583. $segList = Jieba::cut($data['keyword']);
  6584. $segList1 = array_slice($segList, 0, 8);
  6585. $data['keyword'] = implode(',', $segList1);
  6586. }
  6587. if ($data['introduce'] == '') {
  6588. //提取内容中的描述
  6589. $content = $data['content'];
  6590. // 去除 <style> 和 <script> 标签及其内容
  6591. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6592. // 去除所有 HTML 标签
  6593. $content = strip_tags($content);
  6594. // 去除 HTML 实体
  6595. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6596. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6597. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6598. // 去除多余空白
  6599. $content = preg_replace('/\s+/u', '', $content);
  6600. // 截取 100 个字符
  6601. $data['introduce'] = mb_substr($content, 0, 100);
  6602. }
  6603. if (isset($data['level']) && $data['level'] != null) {
  6604. $data['level'] = intval($data['level']);
  6605. } else {
  6606. $data['level'] = null;
  6607. }
  6608. $user = User::where('id', $data['user_id'])->first();
  6609. if (empty($user)) {
  6610. return Result::error('用户不存在!');
  6611. }
  6612. if ($user['type_id'] == 10000) {
  6613. $data['status'] = 1;
  6614. } else {
  6615. $data['status'] = 0;
  6616. }
  6617. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  6618. $this->sendMessage([
  6619. 'talk_type' => 900,
  6620. 'title' => $data['title'],
  6621. 'content' => '提交了审核',
  6622. 'messageType' => 8,
  6623. ]);
  6624. }
  6625. $result = Company::where('id', $data['id'])->update($data);
  6626. if ($result) {
  6627. return Result::success($result);
  6628. } else {
  6629. return Result::error('修改失败');
  6630. }
  6631. }
  6632. /**
  6633. * 删除企业
  6634. * @param array $data
  6635. * @return array
  6636. */
  6637. public function delCompany(array $data): array
  6638. {
  6639. $result = Company::where('id', $data['id'])->delete();
  6640. if ($result) {
  6641. return Result::success($result);
  6642. } else {
  6643. return Result::error('删除失败');
  6644. }
  6645. }
  6646. /**
  6647. * 审核企业
  6648. * @param array $data
  6649. * @return array
  6650. */
  6651. public function checkCompany(array $data): array
  6652. {
  6653. $user = User::where('id', $data['user_id'])->first();
  6654. if (empty($user)) {
  6655. return Result::error('用户不存在!');
  6656. }
  6657. $company = Company::where('id', $data['id'])->first();
  6658. if (empty($company)) {
  6659. return Result::error('企业不存在!');
  6660. }
  6661. // 状态:0:未审核 1:已审核 2:已拒绝
  6662. if ($data['status'] == 2 || $data['status'] == '2') {
  6663. $this->sendMessage([
  6664. 'talk_type' => 901,
  6665. 'title' => $company['title'],
  6666. 'content' => '审核拒绝',
  6667. 'messageType' => 8,
  6668. 'user_id' => $company['user_id'],
  6669. ]);
  6670. $result = Company::where('id', $data['id'])->update(['status' => $data['status'], 'reject_reason' => $data['reason']]);
  6671. } else {
  6672. if ($data['status'] == 1) {
  6673. $this->sendMessage([
  6674. 'talk_type' => 901,
  6675. 'title' => $company['title'],
  6676. 'content' => '审核通过',
  6677. 'messageType' => 8,
  6678. 'user_id' => $company['user_id'],
  6679. ]);
  6680. } else if ($data['status'] == 0) {
  6681. $this->sendMessage([
  6682. 'talk_type' => 900,
  6683. 'title' => $company['title'],
  6684. 'content' => '提交了审核',
  6685. 'messageType' => 8,
  6686. ]);
  6687. }
  6688. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  6689. }
  6690. if (empty($result)) {
  6691. return Result::error('审核失败!');
  6692. } else {
  6693. return Result::success($result);
  6694. }
  6695. }
  6696. /**
  6697. * 获取企业信息
  6698. * @param array $data
  6699. * @return array
  6700. */
  6701. public function getCompanyInfo(array $data): array
  6702. {
  6703. $result = Company::where('id', $data['id'])->first();
  6704. $city_arr = json_decode($result['city_arr_id']);
  6705. $result['city_name'] = District::whereIn('id', $city_arr)
  6706. ->pluck('name')
  6707. ->implode('-');
  6708. if (empty($result)) {
  6709. return Result::error('企业不存在!');
  6710. } else {
  6711. return Result::success($result);
  6712. }
  6713. }
  6714. /**
  6715. * @param array $data
  6716. * @return array
  6717. */
  6718. public function getWebsiteCompany(array $data): array
  6719. {
  6720. $categorys = json_decode($data['id'], true);
  6721. $category_arr = $this->processArticlePro($data['website_id']);
  6722. $cat_1st_arr = $category_arr['cat_1st_arr'];
  6723. $catiall = $category_arr['catiall'];
  6724. $categoryIds = $category_arr['categoryIds'];
  6725. // return Result::success($category_arr);
  6726. foreach ($categorys as $key => $value) {
  6727. if (array_key_exists('level', $value)) {
  6728. $parts = explode(',', $value['level']);
  6729. $level = $parts[0] ?? null;
  6730. $imgnum = $parts[1] ?? null;
  6731. $textnum = $parts[2] ?? null;
  6732. if (!empty($textnum) && $textnum > 0) {
  6733. $text_num = Company::where('level', $level)
  6734. ->whereIn('category_id', $categoryIds)
  6735. ->where('status', 1)
  6736. ->select(
  6737. 'company.id',
  6738. 'company.title',
  6739. 'company.description',
  6740. 'company.updated_at',
  6741. 'company.category_id',
  6742. 'company.cat_arr_id'
  6743. )
  6744. ->orderBy('updated_at', 'desc')
  6745. ->limit($textnum)
  6746. ->get()->all();
  6747. }
  6748. if (!empty($imgnum) && $imgnum > 0) {
  6749. $img_num = Company::where('level', $level)
  6750. ->whereIn('category_id', $categoryIds)
  6751. ->where('status', 1)
  6752. ->where('imgurl', '!=', '')
  6753. ->whereNotNull('imgurl')
  6754. ->select(
  6755. 'company.id',
  6756. 'company.title',
  6757. 'company.description',
  6758. 'company.updated_at',
  6759. 'company.imgurl as imgs',
  6760. 'company.category_id',
  6761. 'company.cat_arr_id'
  6762. )
  6763. ->orderBy('updated_at', 'desc')
  6764. ->limit($imgnum)
  6765. ->get()->all();
  6766. }
  6767. }
  6768. if (array_key_exists('id', $value)) {
  6769. $parts = explode(',', $value['id']);
  6770. $category_id = $parts[0] ?? null;
  6771. $imgnum = $parts[1] ?? null;
  6772. $textnum = $parts[2] ?? null;
  6773. $category_arr = array_merge([$category_id], $cat_1st_arr[$category_id] ?? [0]);
  6774. if (!empty($textnum) && $textnum > 0) {
  6775. $text_num = Company::whereIn('category_id', $category_arr)
  6776. // ->where('website_id', $data['website_id'])
  6777. ->where('status', 1)
  6778. ->select(
  6779. 'company.id',
  6780. 'company.title',
  6781. 'company.description',
  6782. 'company.updated_at',
  6783. 'company.category_id',
  6784. 'company.cat_arr_id'
  6785. )
  6786. ->orderBy('updated_at', 'desc')
  6787. ->limit($textnum)
  6788. ->get()->all();
  6789. }
  6790. if (!empty($imgnum) && $imgnum > 0) {
  6791. $img_num = Company::whereIn('category_id', $category_arr)
  6792. // ->where('website_id', $data['website_id'])
  6793. ->where('status', 1)
  6794. ->where('imgurl', '!=', '')
  6795. ->whereNotNull('imgurl')
  6796. ->select(
  6797. 'company.id',
  6798. 'company.title',
  6799. 'company.description',
  6800. 'company.updated_at',
  6801. 'company.imgurl as imgs',
  6802. 'company.category_id',
  6803. 'company.cat_arr_id'
  6804. )
  6805. ->orderBy('updated_at', 'desc')
  6806. ->limit($imgnum)
  6807. ->get()->all();
  6808. }
  6809. }
  6810. if (!empty($text_num)) {
  6811. foreach ($text_num as $k => $v) {
  6812. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  6813. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  6814. }
  6815. }
  6816. if (!empty($img_num)) {
  6817. foreach ($img_num as $k => $v) {
  6818. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  6819. $imgurl = json_decode($v['imgs'], true);
  6820. if (!empty($imgurl)) {
  6821. $img_num[$k]->imgurl = $imgurl[0];
  6822. }
  6823. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  6824. }
  6825. }
  6826. $company[$key]['img_num'] = $img_num ?? [];
  6827. $company[$key]['text_num'] = $text_num ?? [];
  6828. }
  6829. if (empty($company)) {
  6830. return Result::error("暂无相关企业信息", 0);
  6831. }
  6832. return Result::success($company);
  6833. }
  6834. /**
  6835. * @param array $data
  6836. * @return array
  6837. */
  6838. public function getWebsiteCompanyList(array $data): array
  6839. {
  6840. $where['website_id'] = $data['website_id'];
  6841. $where['status'] = 1;
  6842. $categoryIds = [];
  6843. if (isset($data['category_id']) && !empty($data['category_id'])) {
  6844. $category_id = $data['category_id'];
  6845. }
  6846. $category_arr = $this->processArticlePro($data['website_id']);
  6847. $categoryIds = $category_arr['categoryIds'];
  6848. // return Result::success($cat_1st_arr);
  6849. $company = Company::when(isset($data['keyword']) && !empty($data['keyword']), function ($query) use ($data) {
  6850. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  6851. })
  6852. ->when(!isset($category_id) || empty($category_id), function ($query) use ($categoryIds) {
  6853. $query->whereIn('category_id', $categoryIds);
  6854. })
  6855. ->when(isset($data['category_id']) && !empty($data['category_id']), function ($query) use ($category_id) {
  6856. $query->where('category_id', $category_id);
  6857. })
  6858. ->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id', 'updated_at')
  6859. ->orderBy('updated_at', 'desc')
  6860. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  6861. if (empty($company)) {
  6862. return Result::error("暂无相关公司信息", 0);
  6863. }
  6864. $result = [
  6865. 'count' => $company->total(),
  6866. 'data' => $company->items(), // 使用 items() 方法替代不存在的 data() 方法
  6867. ];
  6868. return Result::success($result);
  6869. }
  6870. /**
  6871. * 获取项目列表
  6872. * @param array $data
  6873. * @return array
  6874. */
  6875. public function getProjectList(array $data): array
  6876. {
  6877. $where = [];
  6878. $user = User::where('id', $data['user_id'])->first();
  6879. if (empty($user)) {
  6880. return Result::error('用户不存在!');
  6881. }
  6882. if ($user->type_id != 10000) {
  6883. array_push($where, ['project.user_id', $data['user_id']]);
  6884. }
  6885. $query = Project::query();
  6886. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6887. array_push($where, ['project.website_id', $data['website_id']]);
  6888. }
  6889. if (isset($data['title']) && !empty($data['title'])) {
  6890. array_push($where, ['project.title', 'like', '%' . $data['title'] . '%']);
  6891. }
  6892. if ($data['status'] != 3) {
  6893. array_push($where, ['project.status', $data['status']]);
  6894. }
  6895. $query = Project::where($where)
  6896. ->when($data['status'] == 3, function ($query) {
  6897. $query->whereIn('project.status', [0, 2]);
  6898. });
  6899. $count = $query->clone()
  6900. ->count();
  6901. $rows = $query->clone()
  6902. ->leftJoin('website', 'project.website_id', 'website.id')
  6903. ->leftJoin('website_category', function ($join) {
  6904. $join->on('project.website_id', '=', 'website_category.website_id')
  6905. ->on('project.category_id', '=', 'website_category.category_id');
  6906. })
  6907. ->select(
  6908. 'project.id',
  6909. 'project.title',
  6910. 'project.updated_at',
  6911. 'project.status',
  6912. 'website.website_name',
  6913. 'website_category.alias as category_name',
  6914. 'project.website_id',
  6915. 'project.user_id'
  6916. )
  6917. ->orderBy('project.updated_at', 'desc')
  6918. ->offset(($data['page'] - 1) * $data['pageSize'])
  6919. ->limit($data['pageSize'])
  6920. ->get();
  6921. if ($rows->isEmpty()) {
  6922. return Result::error("暂无相关项目信息", 0);
  6923. }
  6924. $result = [
  6925. 'count' => $count,
  6926. 'rows' => $rows,
  6927. ];
  6928. return Result::success($result);
  6929. }
  6930. /**
  6931. * 添加项目
  6932. * @param array $data
  6933. * @return array
  6934. */
  6935. public function addProject(array $data): array
  6936. {
  6937. $user = User::where('id', $data['user_id'])->first();
  6938. if (empty($user)) {
  6939. return Result::error("暂无相关用户信息", 0);
  6940. }
  6941. if ($user->type_id == 10000) {
  6942. $data['status'] = 1;
  6943. } else {
  6944. $data['status'] = 0;
  6945. }
  6946. if ($data['keyword'] == '') {
  6947. //提取标题+内容中的关键词
  6948. $data['keyword'] = $data['title'];
  6949. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6950. Jieba::init(); // 初始化 jieba-php
  6951. Finalseg::init();
  6952. $segList = Jieba::cut($data['keyword']);
  6953. $segList1 = array_slice($segList, 0, 8);
  6954. $data['keyword'] = implode(',', $segList1);
  6955. }
  6956. if ($data['description'] == '') {
  6957. //提取内容中的描述
  6958. // var_dump(11111);
  6959. //提取内容中的描述
  6960. $content = $data['introduce'];
  6961. // 去除 <style> 和 <script> 标签及其内容
  6962. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6963. // 去除所有 HTML 标签
  6964. $content = strip_tags($content);
  6965. // 去除 HTML 实体
  6966. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6967. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6968. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6969. // 去除多余空白
  6970. $content = preg_replace('/\s+/u', '', $content);
  6971. // 截取 100 个字符
  6972. $data['description'] = mb_substr($content, 0, 100);
  6973. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  6974. }
  6975. if ($data['status'] == 0) {
  6976. $this->sendMessage([
  6977. 'talk_type' => 1000,
  6978. 'title' => $data['title'],
  6979. 'content' => '提交了审核',
  6980. 'messageType' => 9,
  6981. ]);
  6982. }
  6983. $project = Project::insertGetId($data);
  6984. if (empty($project)) {
  6985. return Result::error("暂无相关项目信息", 0);
  6986. }
  6987. return Result::success($project);
  6988. }
  6989. /**
  6990. * 更新项目
  6991. * @param array $data
  6992. * @return array
  6993. */
  6994. public function upProject(array $data): array
  6995. {
  6996. $project = Project::where('id', $data['id'])->first();
  6997. if (empty($project)) {
  6998. return Result::error("暂无相关项目信息", 0);
  6999. }
  7000. $id = $data['id'];
  7001. unset($data['id']);
  7002. $user = User::where('id', $data['user_id'])->first();
  7003. if (empty($user)) {
  7004. return Result::error("暂无相关用户信息", 0);
  7005. }
  7006. if ($user->type_id == 10000) {
  7007. $data['status'] = 1;
  7008. } else {
  7009. $data['status'] = 0;
  7010. }
  7011. unset($data['user_id']);
  7012. if ($data['keyword'] == '') {
  7013. //提取标题+内容中的关键词
  7014. $data['keyword'] = $data['title'];
  7015. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7016. Jieba::init(); // 初始化 jieba-php
  7017. Finalseg::init();
  7018. $segList = Jieba::cut($data['keyword']);
  7019. $segList1 = array_slice($segList, 0, 8);
  7020. $data['keyword'] = implode(',', $segList1);
  7021. }
  7022. if ($data['description'] == '') {
  7023. //提取内容中的描述
  7024. // var_dump(11111);
  7025. //提取内容中的描述
  7026. $content = $data['introduce'];
  7027. // 去除 <style> 和 <script> 标签及其内容
  7028. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7029. // 去除所有 HTML 标签
  7030. $content = strip_tags($content);
  7031. // 去除 HTML 实体
  7032. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7033. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7034. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7035. // 去除多余空白
  7036. $content = preg_replace('/\s+/u', '', $content);
  7037. // 截取 100 个字符
  7038. $data['description'] = mb_substr($content, 0, 100);
  7039. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7040. }
  7041. if ($data['status'] == 0) {
  7042. $this->sendMessage([
  7043. 'talk_type' => 1000,
  7044. 'title' => $data['title'],
  7045. 'content' => '提交了审核',
  7046. 'messageType' => 9,
  7047. ]);
  7048. }
  7049. $result = Project::where('id', $id)->update($data);
  7050. if (empty($result)) {
  7051. return Result::error("更新失败", 0);
  7052. }
  7053. return Result::success($result);
  7054. }
  7055. /**
  7056. * 删除项目
  7057. * @param array $data
  7058. * @return array
  7059. */
  7060. public function delProject(array $data): array
  7061. {
  7062. $user = User::where('id', $data['user_id'])->first();
  7063. if (empty($user)) {
  7064. return Result::error("暂无相关用户信息", 0);
  7065. }
  7066. $project = Project::where('id', $data['id'])->first();
  7067. if (empty($project)) {
  7068. return Result::error("暂无相关项目信息", 0);
  7069. }
  7070. $result = Project::where('id', $data['id'])->delete();
  7071. if (empty($result)) {
  7072. return Result::error("删除失败", 0);
  7073. }
  7074. return Result::success($result);
  7075. }
  7076. /**
  7077. * 审核项目
  7078. * @param array $data
  7079. * @return array
  7080. */
  7081. public function checkProject(array $data): array
  7082. {
  7083. $user = User::where('id', $data['user_id'])->first();
  7084. if (empty($user)) {
  7085. return Result::error("暂无相关用户信息", 0);
  7086. }
  7087. // 0:未审核; 1:已审核; 2:已拒绝;
  7088. if ($user->type_id != 10000) {
  7089. if ($data['status'] == 1 || $data['status'] == 2) {
  7090. return Result::error("此用户权限不足", 0);
  7091. }
  7092. }
  7093. $project = Project::where('id', $data['id'])->first();
  7094. if (empty($project)) {
  7095. return Result::error("暂无相关项目信息", 0);
  7096. }
  7097. if ($data['status'] == 2) {
  7098. $this->sendMessage([
  7099. 'talk_type' => 1001,
  7100. 'title' => $project['title'],
  7101. 'content' => '审核拒绝',
  7102. 'messageType' => 9,
  7103. 'user_id' => $project['user_id'],
  7104. ]);
  7105. $result = Project::where('id', $data['id'])->update(['status' => $data['status'], 'refuse_reason' => $data['refuse_reason']]);
  7106. } else {
  7107. if ($data['status'] == 1) {
  7108. $this->sendMessage([
  7109. 'talk_type' => 1001,
  7110. 'title' => $project['title'],
  7111. 'content' => '审核通过',
  7112. 'messageType' => 9,
  7113. 'user_id' => $project['user_id'],
  7114. ]);
  7115. } else if ($data['status'] == 0) {
  7116. $this->sendMessage([
  7117. 'talk_type' => 1000,
  7118. 'title' => $project['title'],
  7119. 'content' => '提交了审核',
  7120. 'messageType' => 9,
  7121. ]);
  7122. }
  7123. $result = Project::where('id', $data['id'])->update(['status' => $data['status']]);
  7124. }
  7125. if (empty($result)) {
  7126. return Result::error("审核失败", 0);
  7127. }
  7128. return Result::success($result);
  7129. }
  7130. /**
  7131. * 获取项目详情
  7132. * @param array $data
  7133. * @return array
  7134. */
  7135. public function getProjectInfo(array $data): array
  7136. {
  7137. $project = Project::where('id', $data['id'])->first();
  7138. if (empty($project)) {
  7139. return Result::error("暂无相关项目信息", 0);
  7140. }
  7141. return Result::success($project);
  7142. }
  7143. public function getWebsiteCompanyInfo(array $data): array
  7144. {
  7145. $company = Company::where('id', $data['id'])
  7146. ->leftJoin('job_industry', 'job_industry.hyid', 'company.hy_id')
  7147. ->where('status', 1)
  7148. // ->where('website_id', $data['website_id'])
  7149. ->select('company.*', 'job_industry.hyname as hy_name')
  7150. ->first();
  7151. // 企业性质:0:市场监管;1:信访纪检;2:公检法司;3:高关注机构
  7152. switch ($company->jobnature_id) {
  7153. case null:
  7154. $company->jobnature_name = '';
  7155. break;
  7156. case 0:
  7157. $company->jobnature_name = '市场监督';
  7158. break;
  7159. case 1:
  7160. $company->jobnature_name = '信访纪检';
  7161. break;
  7162. case 2:
  7163. $company->jobnature_name = '公检法司';
  7164. break;
  7165. case 3:
  7166. $company->jobnature_name = '高关注机构';
  7167. break;
  7168. default:
  7169. $company->jobnature_name = '';
  7170. break;
  7171. }
  7172. $city_arr = $company->city_arr_id;
  7173. if (!empty($city_arr)) {
  7174. $city_arr = json_decode($city_arr, true);
  7175. $cityNames = District::whereIn('id', $city_arr)
  7176. ->pluck('name')
  7177. ->implode('-');
  7178. $company->city_name = $cityNames;
  7179. } else {
  7180. $company->city_name = '';
  7181. }
  7182. if (empty($company)) {
  7183. return Result::error("暂无相关公司信息", 0);
  7184. }
  7185. return Result::success($company);
  7186. }
  7187. public function getMSG(array $data): array
  7188. {
  7189. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  7190. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  7191. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  7192. $result = [];
  7193. if ($type_id == 1 or $type_id == 2 or $type_id == 3 or $type_id == 4) {
  7194. //最近的5篇已审的文章
  7195. $apply_articale = Article::where('status', 1)
  7196. ->where('admin_user_id', $user_id)
  7197. ->orderBy('updated_at', 'desc')
  7198. // ->limit(5)
  7199. ->get();
  7200. //获取5条用户的已审核商品
  7201. $good = Good::where('status', 2)
  7202. ->where('user_id', $user_id)
  7203. ->orderBy('updated_at', 'desc')
  7204. // ->limit(5)
  7205. ->get();
  7206. //获取5条用户待审核的公告
  7207. $notice = Notice::where('status', 2)
  7208. ->where('user_id', $user_id)
  7209. ->orderBy('updated_at', 'desc')
  7210. ->limit(5)->get();
  7211. //获取5条用户的待审核投诉
  7212. $complaint = Complaint::where('status', 2)
  7213. ->where('user_id', $user_id)
  7214. ->orderBy('updated_at', 'desc')
  7215. // ->limit(5)
  7216. ->get();
  7217. //获取5条用户的book
  7218. $book = Book::where('status', 2)
  7219. ->where('user_id', $user_id)
  7220. ->orderBy('updated_at', 'desc')
  7221. // ->limit(5)
  7222. ->get();
  7223. //获取5条用户的求职
  7224. //获取5条用户的求职 1
  7225. $job_hunting = JobHunting::where('job_hunting.status', 2)
  7226. ->where('job_hunting.user_id', $user_id)
  7227. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7228. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7229. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7230. ->orderBy('updated_at', 'desc')
  7231. // ->limit(5)
  7232. ->get();
  7233. //获取5条用户的求职 2
  7234. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  7235. ->where('job_recruiting.user_id', $user_id)
  7236. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7237. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7238. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7239. ->orderBy('updated_at', 'desc')
  7240. // ->limit(5)
  7241. ->get();
  7242. //人才库 1
  7243. $job_apply = JobApply::where('job_apply.status', 1)
  7244. ->where('job_apply.receiver_id', $user_id)
  7245. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7246. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7247. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7248. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7249. ->select('job_recruiting', 'job_recruiting.', '', '')
  7250. ->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')
  7251. ->orderBy('updated_at', 'desc')
  7252. // ->limit(5)
  7253. ->get();
  7254. // 职场机会 2
  7255. $job_resume = JobResume::where('job_resume.status', 1)
  7256. ->where('job_resume.receiver_id', $user_id)
  7257. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7258. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7259. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7260. ->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')
  7261. ->orderBy('updated_at', 'desc')
  7262. // ->limit(5)
  7263. ->get();
  7264. //获取5条用户待处理的投诉
  7265. $complaint_deal = Complaint::where('status', 2)
  7266. ->where('deal', 1)
  7267. ->whereJsonContains('re_user_ids', $user_id)
  7268. ->orderBy('updated_at', 'desc')
  7269. // ->limit(5)
  7270. ->get();
  7271. //获取 被通知者未读信息
  7272. $notice_unread = Notice::where('status', 2)
  7273. ->whereJsonContains('re_user_ids', $user_id)
  7274. //未读消息
  7275. ->where(function ($query) use ($user_id) {
  7276. $query->whereJsonDoesntContain('read_id', $user_id)
  7277. ->orWhereNull('read_id');
  7278. })
  7279. ->orderBy('updated_at', 'desc')
  7280. ->get();
  7281. $complaint_unread = Complaint::where('status', 2)
  7282. ->whereJsonContains('re_user_ids', $user_id)
  7283. //未读消息
  7284. ->where(function ($query) use ($user_id) {
  7285. $query->whereJsonDoesntContain('read_id', $user_id)
  7286. ->orWhereNull('read_id');
  7287. })
  7288. ->orderBy('updated_at', 'desc')
  7289. ->get();
  7290. //获取5条用户的yijing审核公司 :0:未审核;1:已审核;2:已拒绝
  7291. $complany = Company::where('status', 1)
  7292. ->where('user_id', $user_id)
  7293. ->orderBy('updated_at', 'desc')
  7294. // ->limit(5)
  7295. ->get();
  7296. //获取5条单聊未读聊天消息
  7297. // $chat = ChatRecords::where('is_read', 0)
  7298. // ->where('user_id', $user_id)
  7299. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7300. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7301. // ->where('action', 'recieved')
  7302. // ->where('talk_type', 1)
  7303. // ->orderBy('created_at', 'desc')
  7304. // // ->limit(5)
  7305. // ->get();
  7306. //获取5条未读群聊信息
  7307. // $chat_group = ChatRecords::where('is_read', 0)
  7308. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7309. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7310. // ->where('user_id', $user_id)
  7311. // ->where('talk_type', 2)
  7312. // ->orderBy('created_at', 'desc')
  7313. // // ->limit(5)
  7314. // ->get();
  7315. //获取5条用户的待审核项目
  7316. $project = Project::where('status', 1)
  7317. ->where('user_id', $user_id)
  7318. ->orderBy('updated_at', 'desc')
  7319. // ->limit(5)
  7320. ->get();
  7321. // count($chat) + count($chat_group) +
  7322. $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)
  7323. + count($complany)
  7324. + count($project)
  7325. + count($notice_unread)
  7326. + count($complaint_unread)
  7327. // + count($chat) + count($chat_group)
  7328. ;
  7329. $result = [
  7330. 'apply_articale' => $apply_articale,
  7331. // 'chat' => $chat,
  7332. // 'chat_group' => $chat_group,
  7333. 'good' => $good,
  7334. 'notice' => $notice,
  7335. 'complaint' => $complaint,
  7336. 'book' => $book,
  7337. 'job_hunting' => $job_hunting,
  7338. 'job_recruiting' => $job_recruiting,
  7339. 'job_apply' => $job_apply,
  7340. 'job_resume' => $job_resume,
  7341. 'complaint_deal' => $complaint_deal,
  7342. 'complany' => $complany,
  7343. 'project' => $project,
  7344. 'notice_unread' => $notice_unread,
  7345. 'complaint_unread' => $complaint_unread,
  7346. 'count' => $count,
  7347. ];
  7348. } elseif ($type_id == 12) {
  7349. //最近的5篇已审的文章
  7350. $apply_articale = Article::where('status', 1)
  7351. ->where('admin_user_id', $user_id)
  7352. ->limit(5)->get();
  7353. //获取5条单聊未读聊天消息
  7354. $chat = ChatRecords::where('is_read', 0)
  7355. ->where('user_id', $user_id)
  7356. ->where('talk_type', 1)
  7357. ->orderBy('created_at', 'desc')
  7358. ->limit(5)->get();
  7359. //获取5条未读群聊信息
  7360. $chat_group = ChatRecords::where('is_read', 0)
  7361. ->where('user_id', $user_id)
  7362. ->where('talk_type', 2)
  7363. ->orderBy('created_at', 'desc')
  7364. ->limit(5)->get();
  7365. //获取5条用户的已审核商品
  7366. $good = Good::where('status', 2)
  7367. ->where('user_id', $user_id)
  7368. ->orderBy('updated_at', 'desc')
  7369. ->limit(5)->get();
  7370. //获取5条用户的book
  7371. $book = Book::where('status', 2)
  7372. ->where('user_id', $user_id)
  7373. ->orderBy('updated_at', 'desc')
  7374. ->limit(5)->get();
  7375. //获取5条用户的求职
  7376. //获取5条用户的求职 1
  7377. //count($chat) + count($chat_group)
  7378. $count = count($apply_articale) + count($good);
  7379. $result = [
  7380. 'apply_articale' => $apply_articale,
  7381. 'chat' => $chat,
  7382. 'chat_group' => $chat_group,
  7383. 'good' => $good,
  7384. 'book' => $book,
  7385. 'count' => $count,
  7386. ];
  7387. } elseif ($type_id == 13) {
  7388. //最近的5篇已审的文章
  7389. $apply_articale = Article::where('status', 1)
  7390. ->where('admin_user_id', $user_id)
  7391. ->limit(5)->get();
  7392. //获取5条单聊未读聊天消息
  7393. $chat = ChatRecords::where('is_read', 0)
  7394. ->where('user_id', $user_id)
  7395. ->where('talk_type', 1)
  7396. ->orderBy('created_at', 'desc')
  7397. ->limit(5)->get();
  7398. //获取5条未读群聊信息
  7399. $chat_group = ChatRecords::where('is_read', 0)
  7400. ->where('user_id', $user_id)
  7401. ->where('talk_type', 2)
  7402. ->orderBy('created_at', 'desc')
  7403. ->limit(5)->get();
  7404. //获取5条用户的已审核商品
  7405. $good = Good::where('status', 2)
  7406. ->where('user_id', $user_id)
  7407. ->orderBy('updated_at', 'desc')
  7408. ->limit(5)->get();
  7409. //count($chat) + count($chat_group) +
  7410. $count = count($apply_articale) + count($good);
  7411. $result = [
  7412. 'apply_articale' => $apply_articale,
  7413. 'chat' => $chat,
  7414. 'chat_group' => $chat_group,
  7415. 'good' => $good,
  7416. 'count' => $count,
  7417. ];
  7418. } elseif ($type_id == 14) {
  7419. //最近的5篇已审的文章
  7420. $apply_articale = Article::where('status', 1)
  7421. ->where('admin_user_id', $user_id)
  7422. // ->limit(5)
  7423. ->get();
  7424. //获取5条用户的已审核商品
  7425. $good = Good::where('status', 2)
  7426. ->where('user_id', $user_id)
  7427. ->orderBy('updated_at', 'desc')
  7428. // ->limit(5)
  7429. ->get();
  7430. $count = count($apply_articale) + count($good);
  7431. $result = [
  7432. 'apply_articale' => $apply_articale,
  7433. 'chat' => '',
  7434. 'chat_group' => '',
  7435. 'good' => $good,
  7436. 'count' => $count,
  7437. ];
  7438. } elseif ($type_id == 10000) {
  7439. //获取未审核的5篇文章
  7440. $apply_articale = Article::where('status', 0)
  7441. ->orderBy('updated_at', 'desc')
  7442. // ->limit(5)
  7443. ->get();
  7444. //获取5条单聊未读聊天消息
  7445. //获取5条单聊未读聊天消息
  7446. // $chat = ChatRecords::where('is_read', 0)
  7447. // ->where('user_id', $user_id)
  7448. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7449. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7450. // ->where('action', 'recieved')
  7451. // ->where('talk_type', 1)
  7452. // ->orderBy('created_at', 'desc')
  7453. // // ->limit(5)
  7454. // ->get();
  7455. // //获取5条未读群聊信息
  7456. // $chat_group = ChatRecords::where('is_read', 0)
  7457. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7458. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7459. // ->where('user_id', $user_id)
  7460. // ->where('talk_type', 2)
  7461. // ->orderBy('created_at', 'desc')
  7462. // // ->limit(5)
  7463. // ->get();
  7464. //获取5条用户的已审核商品
  7465. $good = Good::where('status', 1)
  7466. // ->where('user_id', $user_id)
  7467. ->orderBy('updated_at', 'desc')
  7468. // ->limit(5)
  7469. ->get();
  7470. //获取5条用户待审核的公告
  7471. $notice = Notice::where('status', 1)
  7472. ->orderBy('updated_at', 'desc')
  7473. // ->limit(5)
  7474. ->get();
  7475. //获取5条用户的待审核投诉
  7476. $complaint = Complaint::where('status', 1)
  7477. ->orderBy('updated_at', 'desc')
  7478. // ->limit(5)
  7479. ->get();
  7480. //获取5条用户的book
  7481. $book = Book::where('status', 1)
  7482. ->orderBy('updated_at', 'desc')
  7483. // ->limit(5)
  7484. ->get();
  7485. //获取5条用户的求职 1
  7486. $job_hunting = JobHunting::where('job_hunting.status', 1)
  7487. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7488. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7489. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7490. ->orderBy('updated_at', 'desc')
  7491. // ->limit(5)
  7492. ->get();
  7493. //获取5条用户的求职 2
  7494. $job_recruiting = JobRecruiting::where('job_recruiting.status', 0)
  7495. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7496. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7497. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7498. ->orderBy('updated_at', 'desc')
  7499. // ->limit(5)
  7500. ->get();
  7501. //人才库 1
  7502. $job_apply = JobApply::where('job_apply.status', 1)
  7503. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7504. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7505. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7506. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7507. ->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')
  7508. ->orderBy('updated_at', 'desc')
  7509. // ->limit(5)
  7510. ->get();
  7511. // 职场机会 2
  7512. $job_resume = JobResume::where('job_resume.status', 1)
  7513. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7514. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7515. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7516. ->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')
  7517. ->orderBy('updated_at', 'desc')
  7518. // ->limit(5)
  7519. ->get();
  7520. //待审核数据com pro
  7521. $complany = Company::where('status', 0)
  7522. ->orderBy('updated_at', 'desc')
  7523. // ->limit(5)
  7524. ->get();
  7525. $project = Project::where('status', 0)
  7526. ->orderBy('updated_at', 'desc')
  7527. // ->limit(5)
  7528. ->get();
  7529. $count =
  7530. // count($chat) +
  7531. // count($chat_group) +
  7532. count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting)
  7533. // + count($job_apply)
  7534. // + count($job_resume)
  7535. + count($complany)
  7536. + count($project);
  7537. $result = [
  7538. 'apply_articale' => $apply_articale,
  7539. // 'chat' => $chat,
  7540. // 'chat_group' => $chat_group,
  7541. 'good' => $good,
  7542. 'notice' => $notice,
  7543. 'complaint' => $complaint,
  7544. 'book' => $book,
  7545. 'job_hunting' => $job_hunting,
  7546. 'job_recruiting' => $job_recruiting,
  7547. // 'job_apply' => $job_apply,
  7548. // 'job_resume' => $job_resume,
  7549. 'complany' => $complany,
  7550. 'project' => $project,
  7551. 'count' => $count,
  7552. ];
  7553. } elseif ($type_id == 20000) {
  7554. }
  7555. var_dump($type_id, '-----------------test---------');
  7556. return Result::success($result);
  7557. }
  7558. /**
  7559. * @param array $data
  7560. * @return array
  7561. */
  7562. public function getWebsiteProject(array $data): array
  7563. {
  7564. $categorys = json_decode($data['id'], true);
  7565. if (!empty($categorys)) {
  7566. $category_arr = $this->processArticlePro($data['website_id']);
  7567. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7568. $catiall = $category_arr['catiall'];
  7569. // return Result::success($catiall);
  7570. foreach ($categorys as $key => $val) {
  7571. if (isset($val['level'][0]) && !empty($val['level'][0])) {
  7572. $level = explode(',', $val['level'])[0];
  7573. $imgnum = explode(',', $val['level'])[1] ?? null;
  7574. $textnum = explode(',', $val['level'])[2] ?? null;
  7575. if ($level == 1) {
  7576. if (!empty($textnum) && $textnum > 0) {
  7577. $text_num = Project::where('level', $level)
  7578. ->where('website_id', $data['website_id'])
  7579. ->where('status', 1)
  7580. ->select(
  7581. 'project.id',
  7582. 'project.title',
  7583. 'project.description',
  7584. 'project.updated_at',
  7585. 'project.category_id',
  7586. 'project.cat_arr_id'
  7587. )
  7588. ->orderBy('updated_at', 'desc')
  7589. ->limit($textnum)
  7590. ->get()->all();
  7591. }
  7592. if (!empty($imgnum) && $imgnum > 0) {
  7593. $img_num = Project::where('level', $level)
  7594. ->where('website_id', $data['website_id'])
  7595. ->where('status', 1)
  7596. ->where('imgurl', '!=', '')
  7597. ->whereNotNull('imgurl')
  7598. ->select(
  7599. 'project.id',
  7600. 'project.title',
  7601. 'project.description',
  7602. 'project.updated_at',
  7603. 'project.imgurl as imgs',
  7604. 'project.category_id',
  7605. 'project.cat_arr_id'
  7606. )
  7607. ->orderBy('updated_at', 'desc')
  7608. ->limit($imgnum)
  7609. ->get()->all();
  7610. }
  7611. } else {
  7612. if (!empty($textnum) && $textnum > 0) {
  7613. $text_num = Project::where('website_id', $data['website_id'])
  7614. ->where('status', 1)
  7615. ->select(
  7616. 'project.id',
  7617. 'project.title',
  7618. 'project.description',
  7619. 'project.updated_at',
  7620. 'project.category_id',
  7621. 'project.cat_arr_id',
  7622. 'project.website_id',
  7623. 'project.updated_at',
  7624. 'project.created_at'
  7625. )
  7626. ->orderBy('updated_at', 'desc')
  7627. ->limit($textnum)
  7628. ->get()->all();
  7629. }
  7630. if (!empty($imgnum) && $imgnum > 0) {
  7631. $img_num = Project::where('website_id', $data['website_id'])
  7632. ->where('status', 1)
  7633. ->where('imgurl', '!=', '')
  7634. ->whereNotNull('imgurl')
  7635. ->select(
  7636. 'project.id',
  7637. 'project.title',
  7638. 'project.description',
  7639. 'project.updated_at',
  7640. 'project.imgurl as imgs',
  7641. 'project.category_id',
  7642. 'project.cat_arr_id'
  7643. )
  7644. ->orderBy('updated_at', 'desc')
  7645. ->limit($imgnum)
  7646. ->get()->all();
  7647. }
  7648. }
  7649. }
  7650. if (isset($val['id'][0]) && !empty($val['id'][0])) {
  7651. $category_ids = explode(',', $val['id'])[0];
  7652. $cat_imgnum = explode(',', $val['id'])[1] ?? null;
  7653. $cat_textnum = explode(',', $val['id'])[2] ?? null;
  7654. $category_arr = array_merge([$category_ids], $cat_1st_arr[$category_ids] ?? [0]);
  7655. if (!empty($cat_textnum) && $cat_textnum > 0) {
  7656. $text_num = Project::whereIn('category_id', $category_arr)
  7657. ->where('website_id', $data['website_id'])
  7658. ->where('status', 1)
  7659. ->select(
  7660. 'project.id',
  7661. 'project.title',
  7662. 'project.description',
  7663. 'project.updated_at',
  7664. 'project.category_id',
  7665. 'project.cat_arr_id'
  7666. )
  7667. ->orderBy('updated_at', 'desc')
  7668. ->limit($cat_textnum)
  7669. ->get()->all();
  7670. }
  7671. if (!empty($cat_imgnum) && $cat_imgnum > 0) {
  7672. $img_num = Project::whereIn('category_id', $category_arr)
  7673. ->where('website_id', $data['website_id'])
  7674. ->where('status', 1)
  7675. ->where('imgurl', '!=', '')
  7676. ->whereNotNull('imgurl')
  7677. ->select(
  7678. 'project.id',
  7679. 'project.title',
  7680. 'project.description',
  7681. 'project.updated_at',
  7682. 'project.imgurl as imgs',
  7683. 'project.category_id',
  7684. 'project.cat_arr_id'
  7685. )
  7686. ->orderBy('updated_at', 'desc')
  7687. ->limit($cat_imgnum)
  7688. ->get()->all();
  7689. }
  7690. }
  7691. if (!empty($img_num)) {
  7692. foreach ($img_num as $k => $v) {
  7693. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7694. $imgurl = json_decode($v['imgs'], true);
  7695. if (!empty($imgurl)) {
  7696. $img_num[$k]->imgurl = $imgurl[0];
  7697. }
  7698. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7699. }
  7700. }
  7701. if (!empty($text_num)) {
  7702. foreach ($text_num as $k => $v) {
  7703. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7704. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7705. }
  7706. }
  7707. $project[$key]['img_num'] = $img_num ?? [];
  7708. $project[$key]['text_num'] = $text_num ?? [];
  7709. }
  7710. }
  7711. if (empty($project)) {
  7712. return Result::error("暂无相关项目信息", 0);
  7713. }
  7714. return Result::success($project);
  7715. }
  7716. /**
  7717. * @param array $data
  7718. * @return array
  7719. */
  7720. public function getWebsiteProjectInfo(array $data): array
  7721. {
  7722. $project = Project::where('id', $data['id'])
  7723. ->where('status', 1)
  7724. ->where('website_id', $data['website_id'])
  7725. ->select('project.*')
  7726. ->first();
  7727. if (empty($project)) {
  7728. return Result::error("暂无相关项目信息", 0);
  7729. }
  7730. return Result::success($project);
  7731. }
  7732. /**
  7733. * @param array $data
  7734. * @return array
  7735. */
  7736. public function getWebsiteProjectList(array $data): array
  7737. {
  7738. $where = [];
  7739. if (isset($data['category_id']) && !empty($data['category_id'])) {
  7740. $where['category_id'] = $data['category_id'];
  7741. }
  7742. if (isset($data['keyword']) && !empty($data['keyword'])) {
  7743. $where[] = ['title', 'like', '%' . $data['keyword'] . '%'];
  7744. }
  7745. $query = Project::where($where)
  7746. ->where('status', 1)
  7747. ->where('website_id', $data['website_id'])
  7748. ->select(
  7749. 'project.id',
  7750. 'project.title',
  7751. 'project.description',
  7752. 'project.imgurl as imgs',
  7753. 'project.category_id',
  7754. 'project.cat_arr_id'
  7755. )
  7756. ->orderBy('updated_at', 'desc');
  7757. $count = $query->count();
  7758. $project = $query->clone()
  7759. ->offset(($data['page'] - 1) * $data['pageSize'])
  7760. ->limit($data['pageSize'])
  7761. ->get()->all();
  7762. if (empty($project)) {
  7763. return Result::error("暂无相关项目信息", 0);
  7764. }
  7765. $categorys = $this->processArticlePro($data['website_id']);
  7766. $catiall = $categorys['catiall'];
  7767. foreach ($project as $key => $val) {
  7768. $project[$key]->category_name = $catiall[$val->category_id]['alias'];
  7769. if (!empty($val['imgs'])) {
  7770. $imgurl = json_decode($val['imgs'], true);
  7771. if (!empty($imgurl)) {
  7772. $project[$key]->imgurl = $imgurl[0];
  7773. }
  7774. } else {
  7775. $project[$key]->imgurl = '';
  7776. }
  7777. $project[$key]->pinyin = $catiall[$val->category_id]['pinyin'];
  7778. }
  7779. $result = [
  7780. 'rows' => $project,
  7781. 'count' => $count,
  7782. ];
  7783. return Result::success($result);
  7784. }
  7785. /**
  7786. * @param array $data
  7787. * @return array
  7788. */
  7789. public function getWebsiteCategoryJob(array $data): array
  7790. {
  7791. $categorys = json_decode($data['id'], true);
  7792. if (!empty($categorys)) {
  7793. $category_arr = $this->processArticlePro($data['website_id']);
  7794. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7795. $catiall = $category_arr['catiall'];
  7796. foreach ($categorys as $key => $val) {
  7797. if (isset($val['id']) && !empty($val['id'])) {
  7798. $catid = explode(',', $val['id'])[0] ?? null;
  7799. $type = explode(',', $val['id'])[1] ?? null;
  7800. $textnum = explode(',', $val['id'])[2] ?? null;
  7801. }
  7802. // 4:招聘;5:求职;
  7803. if ($textnum > 0 && $type == 4 && !empty($catid)) {
  7804. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  7805. $job = JobRecruiting::WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($catid) . "') = 1")
  7806. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  7807. ->where('job_recruiting.status', 1)
  7808. ->where('job_recruiting.website_id', $data['website_id'])
  7809. ->select(
  7810. 'job_recruiting.id',
  7811. 'job_recruiting.title',
  7812. 'job_company.business_name',
  7813. 'job_recruiting.updated_at',
  7814. 'job_recruiting.cat_arr_id',
  7815. 'job_recruiting.keyword',
  7816. 'job_recruiting.description'
  7817. )
  7818. ->orderBy('job_recruiting.updated_at', 'desc')
  7819. ->limit($textnum)
  7820. ->get()->all();
  7821. } else if ($textnum > 0 && $type == 5 && !empty($catid)) {
  7822. // 状态 审核状态,1待审核2已审核3已拒绝
  7823. $job = JobHunting::WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($catid) . "') = 1")
  7824. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  7825. ->where('job_hunting.status', 2)
  7826. ->where('job_hunting.website_id', $data['website_id'])
  7827. ->select(
  7828. 'job_hunting.id',
  7829. 'job_hunting.name',
  7830. 'job_hunting.cat_arr_id',
  7831. 'job_position.zwname as job_name',
  7832. 'job_hunting.updated_at',
  7833. 'job_hunting.keyword',
  7834. 'job_hunting.slelf_evaluation'
  7835. )
  7836. ->orderBy('updated_at', 'desc')
  7837. ->limit($textnum)
  7838. ->get()->all();
  7839. } else {
  7840. $job = [];
  7841. }
  7842. // var_dump($catid.'222uuuuuuu'.$key);
  7843. if (!empty($job)) {
  7844. foreach ($job as $k => $value) {
  7845. if (isset($value->cat_arr_id)) {
  7846. $catArr = json_decode($value->cat_arr_id, true);
  7847. $catId = end($catArr);
  7848. } else {
  7849. continue;
  7850. }
  7851. if (isset($catiall[$catId])) {
  7852. $job[$k]->pinyin = $catiall[$catId]['pinyin'];
  7853. }
  7854. }
  7855. }
  7856. // var_dump($catid.'xxxxx'.$key);
  7857. $result[$key] = $job ?? [];
  7858. }
  7859. }
  7860. if (empty($result)) {
  7861. return Result::error("暂无相关分类信息", 0);
  7862. }
  7863. return Result::success($result);
  7864. }
  7865. /**
  7866. * 发送消息
  7867. * @param array $messageData
  7868. * @return void
  7869. */
  7870. public function sendMessage($messageData)
  7871. {
  7872. $msg = [
  7873. 'talk_type' => $messageData['talk_type'],
  7874. 'title' => $messageData['title'],
  7875. 'content' => $messageData['content'],
  7876. 'messageType' => $messageData['messageType'],
  7877. 'user_id' => $messageData['user_id'] ?? '',
  7878. 'time' => microtime(),
  7879. ];
  7880. $message = new MqProducer($msg);
  7881. $producer = ContextApplicationContext::getContainer()->get(Producer::class);
  7882. $producer->produce($message);
  7883. }
  7884. }