NewsService.php 327 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894
  1. <?php
  2. namespace App\JsonRpc;
  3. use App\Model\Article;
  4. use App\Model\ArticleData;
  5. use App\Model\Category;
  6. use App\Model\HistoryToday;
  7. use App\Model\WebsiteCategory;
  8. use App\Model\ArticleSurvey;
  9. use App\Model\District;
  10. use App\Model\Good;
  11. use App\Model\JobCompany;
  12. use App\Model\Website;
  13. use App\Model\JobRecruiting;
  14. use App\Model\JobIndustry;
  15. use App\Model\Book;
  16. use App\Model\JobPosition;
  17. use App\Model\Notice;
  18. use App\Model\JobNature;
  19. use App\Model\JobEnum;
  20. use App\Model\User;
  21. use App\Model\UserRole;
  22. use App\Model\News;
  23. use App\Model\UserInfo;
  24. use App\Model\WebsiteGroup;;
  25. use App\Model\JobResume;
  26. use Hyperf\DbConnection\Db;
  27. use Hyperf\RpcServer\Annotation\RpcService;
  28. use App\Tools\Result;
  29. use Directory;
  30. use Ramsey\Uuid\Uuid;
  31. use Hyperf\Utils\Random;
  32. use Fukuball\Jieba\Jieba;
  33. use Fukuball\Jieba\Finalseg;
  34. use Hyperf\Utils\Collection;
  35. use function Hyperf\Support\retry;
  36. use App\Tools\PublicData;
  37. use App\Model\ChatGroups;
  38. use App\Model\ChatGroupsMember;
  39. use App\Model\ChatRecords;
  40. use App\Model\Complaint;
  41. use Hamcrest\Arrays\IsArray;
  42. use Hyperf\Codec\Json;
  43. use App\Tools\buildMenuTree;
  44. use App\Model\JobApply;
  45. use App\Model\JobHunting;
  46. use App\Model\JobRemuse;
  47. use Hyperf\Redis\Redis;
  48. use Hyperf\Di\Annotation\Inject;
  49. use App\Model\Festival;
  50. use App\Model\Character;
  51. use App\Model\Couplet;
  52. use App\Model\Riddle;
  53. use App\Model\Idiom;
  54. use App\Model\WhiteRouter;
  55. use Illuminate\Support\Facades\Cache;
  56. use App\Model\Company;
  57. use Hyperf\Paginator\Paginator;
  58. use App\Model\Project;
  59. use Hyperf\Context\Context;
  60. use Hyperf\Context\ApplicationContext as ContextApplicationContext;
  61. use Hyperf\Amqp\Producer;
  62. use App\Amqp\Producer\MqProducer;
  63. use App\Model\Web;
  64. use App\Model\GroupMemberImp;
  65. use App\Model\GroupImp;
  66. use App\Model\GroupTalkImp;
  67. use App\Model\GroupTalkMessagerImp;
  68. use App\Model\ArticleIgnore;
  69. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  70. class NewsService implements NewsServiceInterface
  71. {
  72. #[Inject]
  73. protected Redis $redis;
  74. /**
  75. * 获取导航池列表
  76. * @param array $data
  77. * @return array
  78. */
  79. public function getCategoryList(array $data): array
  80. {
  81. $search = $data['name'] ?? '';
  82. $page = (int)($data['page'] ?? 1);
  83. $perPage = (int)($data['pageSize'] ?? 10);
  84. // 1. 查出所有匹配的分类id
  85. if ($search) {
  86. $matchedIds = Category::where('name', 'like', "%{$search}%")->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  87. if (empty($matchedIds)) {
  88. return Result::success(['rows' => [], 'total' => 0]);
  89. }
  90. // 2. 递归查所有父级,直到一级分类
  91. $idsStr = implode(',', $matchedIds);
  92. $sql = "
  93. WITH RECURSIVE parents AS (
  94. SELECT * FROM category WHERE id IN ($idsStr)
  95. UNION ALL
  96. SELECT c.* FROM category c
  97. INNER JOIN parents p ON c.id = p.pid
  98. )
  99. SELECT * FROM parents
  100. ";
  101. $parents = Db::select($sql);
  102. $parentIds = [];
  103. foreach ($parents as $row) {
  104. if ($row->pid == 0) {
  105. $parentIds[] = $row->id;
  106. }
  107. }
  108. $parentIds = array_unique($parentIds);
  109. } else {
  110. // 没有搜索,一级分类就是根
  111. $parentIds = Category::where('pid', 0)->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  112. }
  113. // 3. 一级分类分页
  114. $total = count($parentIds);
  115. $parentIds = array_slice($parentIds, ($page - 1) * $perPage, $perPage);
  116. if (empty($parentIds)) {
  117. return Result::success(['rows' => [], 'total' => $total]);
  118. }
  119. // 4. 递归查所有子孙
  120. $idsStr = implode(',', $parentIds);
  121. $sql = "
  122. WITH RECURSIVE subcategories AS (
  123. SELECT * FROM category WHERE id IN ($idsStr)
  124. UNION ALL
  125. SELECT c.* FROM category c
  126. INNER JOIN subcategories s ON c.pid = s.id
  127. )
  128. SELECT * FROM subcategories ORDER BY updated_at DESC
  129. ";
  130. $allCategories = Db::select($sql);
  131. // 5. 组装树结构
  132. $categoryMap = [];
  133. foreach ($allCategories as $cat) {
  134. $cat = (array)$cat;
  135. $cat['children'] = [];
  136. $categoryMap[$cat['id']] = $cat;
  137. }
  138. foreach ($categoryMap as $id => &$cat) {
  139. if ($cat['pid'] && isset($categoryMap[$cat['pid']])) {
  140. $categoryMap[$cat['pid']]['children'][] = &$cat;
  141. }
  142. }
  143. unset($cat);
  144. $categoryTree = [];
  145. foreach ($parentIds as $id) {
  146. if (isset($categoryMap[$id])) {
  147. $categoryTree[] = $categoryMap[$id];
  148. }
  149. }
  150. return Result::success([
  151. 'rows' => $categoryTree,
  152. 'total' => $total,
  153. ]);
  154. }
  155. private function findMatchedCategories($search)
  156. {
  157. if ($search) {
  158. return Category::where('name', 'like', "%{$search}%")
  159. ->orderBy('updated_at', 'desc')
  160. ->get();
  161. }
  162. return Category::orderBy('updated_at', 'desc') // 按 updated_at 字段倒序排序
  163. ->get();
  164. }
  165. private function findAllParents($categories)
  166. {
  167. $allCategories = [];
  168. foreach ($categories as $category) {
  169. $parentId = $category->pid;
  170. while ($parentId > 0) {
  171. $parent = Category::find($parentId);
  172. if ($parent) {
  173. $allCategories[$parent->id] = $parent;
  174. $parentId = $parent->pid;
  175. } else {
  176. break;
  177. }
  178. }
  179. $allCategories[$category->id] = $category;
  180. }
  181. return array_values($allCategories);
  182. }
  183. private function buildCategoryTree($category, $allRequiredCategories)
  184. {
  185. $categoryData = $category->toArray();
  186. $children = [];
  187. foreach ($allRequiredCategories as $c) {
  188. if ($c->pid === $category->id) {
  189. $children[] = $this->buildCategoryTree($c, $allRequiredCategories);
  190. }
  191. }
  192. if (!empty($children)) {
  193. $categoryData['children'] = $children;
  194. }
  195. return $categoryData;
  196. }
  197. public function myCategoryList(array $data): array
  198. {
  199. $sszq = $data['sszq'] ?? '';
  200. unset($data['sszq']);
  201. //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
  202. $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
  203. $where[] = [
  204. 'pid',
  205. '=',
  206. $data['pid'],
  207. ];
  208. if (isset($data['name'])) {
  209. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  210. }
  211. var_dump($where);
  212. //根据分类id,从category表中取出分类信息
  213. $result = Category::where($where)
  214. ->whereIn('category.id', $catorytids)
  215. ->select('category.*', 'category.id as category_id')->get();
  216. if (empty($result)) {
  217. return Result::error("没有栏目数据");
  218. }
  219. return Result::success($result);
  220. }
  221. /**
  222. * @param array $data
  223. * @return array
  224. */
  225. public function categoryList(array $data): array
  226. {
  227. $where[] = [
  228. 'pid',
  229. '=',
  230. $data['pid']
  231. ];
  232. if (isset($data['name'])) {
  233. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  234. }
  235. var_dump($where);
  236. $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
  237. if (empty($result)) {
  238. return Result::error("没有栏目数据");
  239. }
  240. return Result::success($result);
  241. }
  242. /**
  243. * @param array $data
  244. * @return array
  245. */
  246. public function addCategory(array $data): array
  247. {
  248. if (isset($data['id'])) {
  249. unset($data['id']);
  250. }
  251. $id = Category::insertGetId($data);
  252. if (empty($id)) {
  253. return Result::error("添加失败");
  254. }
  255. return Result::success(['id' => $id]);
  256. }
  257. /**
  258. * @param array $data
  259. * @return array
  260. */
  261. public function delCategory(array $data): array
  262. {
  263. Db::beginTransaction();
  264. try {
  265. $categoryList = Category::where(['pid' => $data['id']])->get();
  266. if ($categoryList->toArray()) {
  267. Db::rollBack();
  268. return Result::error("分类下面有子分类不能删除");
  269. }
  270. $articleList = Article::where(['catid' => $data['id']])->get();
  271. if ($articleList->toArray()) {
  272. Db::rollBack();
  273. return Result::error("分类下面有资讯不能删除");
  274. }
  275. $result = Category::where($data)->delete();
  276. WebsiteCategory::where(['category_id' => $data['id']])->delete();
  277. if (!$result) {
  278. Db::rollBack();
  279. return Result::error("删除失败");
  280. }
  281. Db::commit();
  282. return Result::success($result);
  283. } catch (\Exception $e) {
  284. Db::rollBack();
  285. return Result::error("删除失败" . $e->getMessage());
  286. }
  287. }
  288. /**
  289. * @param array $data
  290. * @return array
  291. */
  292. public function updateCategory(array $data): array
  293. {
  294. $where = [
  295. 'id' => $data['id'],
  296. ];
  297. $result = Category::where($where)->update($data);
  298. if ($result) {
  299. return Result::success($result);
  300. } else {
  301. return Result::error("更新失败");
  302. }
  303. }
  304. /**
  305. * 获取导航池信息
  306. * @param array $data
  307. * @return array
  308. */
  309. public function getCategoryInfo(array $data): array
  310. {
  311. $where = [
  312. 'id' => $data['id'],
  313. ];
  314. $result = Category::where($where)->first();
  315. if ($result) {
  316. return Result::success($result);
  317. } else {
  318. return Result::error("更新失败");
  319. }
  320. }
  321. public function getArticleCommend(array $data): array
  322. {
  323. $where = [
  324. 'website_id' => $data['website_id'],
  325. ];
  326. $ids = WebsiteCategory::where($where)->pluck('category_id')->toArray();
  327. var_dump($ids);
  328. if (empty($ids)) {
  329. return Result::error("没有推荐数据");
  330. }
  331. //id
  332. $whereArticle = [];
  333. if (isset($data['id'])) {
  334. $whereArticle['id'] = $data['id'];
  335. }
  336. //title like
  337. if (isset($data['title'])) {
  338. array_push($whereArticle, ['title', 'like', "%{$data['title']}%"]);
  339. }
  340. $article = Article::whereIn('catid', values: $ids)->where('status', 1)
  341. ->where($whereArticle)
  342. ->orderBy('id', 'desc')
  343. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  344. if ($article) {
  345. $data = [
  346. 'rows' => $article->items(),
  347. 'count' => $article->total(),
  348. ];
  349. return Result::success($data);
  350. } else {
  351. return Result::error("获取失败失败");
  352. }
  353. }
  354. /**
  355. * @param array $data
  356. * @return array
  357. */
  358. public function getArticleList(array $data): array
  359. {
  360. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  361. $type_id = $data['type_id'];
  362. unset($data['type_id']);
  363. $user_id = $data['user_id'];
  364. unset($data['user_id']);
  365. $where = [];
  366. $status1 = [];
  367. if (isset($data['id']) && $data['id']) {
  368. array_push($where, ['article.id', '=', $data['id']]);
  369. }
  370. if (isset($data['title']) && $data['title']) {
  371. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  372. }
  373. if (isset($data['category_name']) && $data['category_name']) {
  374. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  375. }
  376. if (isset($data['catid']) && $data['catid']) {
  377. array_push($where, ['article.catid', '=', $data['catid']]);
  378. }
  379. if (isset($data['author']) && $data['author']) {
  380. array_push($where, ['article.author', '=', $data['author']]);
  381. }
  382. if (isset($data['islink']) && $data['islink'] !== "") {
  383. array_push($where, ['article.islink', '=', $data['islink']]);
  384. }
  385. if (isset($data['status']) && $data['status'] !== "") {
  386. array_push($where, ['article.status', '=', $data['status']]);
  387. }
  388. if (isset($data['status1'])) {
  389. $status1 = json_decode(($data['status1']));
  390. }
  391. //不是管理员展示个人数据;
  392. if ($type_id != 10000) {
  393. $where[] = ['article.admin_user_id', '=', $user_id];
  394. }
  395. $startTime = microtime(true);
  396. $rep = Article::query()
  397. // 预加载相关关联
  398. ->with([
  399. 'category' => function ($query) {
  400. $query->select('id', 'name');
  401. },
  402. 'websiteCategory' => function ($query) {
  403. $query->select('website_id', 'category_id', 'alias');
  404. }
  405. ])
  406. // 构建where条件
  407. ->when(isset($data['id']) && $data['id'], function ($query) use ($data) {
  408. $query->where('article.id', '=', $data['id']);
  409. })
  410. ->when(isset($data['title']) && $data['title'], function ($query) use ($data) {
  411. $query->where('article.title', 'like', '%' . $data['title'] . '%');
  412. })
  413. ->when(isset($data['category_name']) && $data['category_name'], function ($query) use ($data) {
  414. // 使用子查询替代左连接进行模糊搜索
  415. $query->whereHas('category', function ($subQuery) use ($data) {
  416. $subQuery->where('name', 'like', '%' . $data['category_name'] . '%');
  417. });
  418. })
  419. ->when(isset($data['catid']) && $data['catid'], function ($query) use ($data) {
  420. $query->where('article.catid', '=', $data['catid']);
  421. })
  422. ->when(isset($data['author']) && $data['author'], function ($query) use ($data) {
  423. $query->where('article.author', '=', $data['author']);
  424. })
  425. ->when(isset($data['islink']) && $data['islink'] !== "", function ($query) use ($data) {
  426. $query->where('article.islink', '=', $data['islink']);
  427. })
  428. ->when(isset($data['status']) && $data['status'] !== "", function ($query) use ($data) {
  429. $query->where('article.status', '=', $data['status']);
  430. })
  431. ->when(isset($data['status1']) && $data['status1'], function ($query) use ($data) {
  432. // 安全地处理JSON字符串
  433. $status1 = is_array($data['status1']) ? $data['status1'] : json_decode($data['status1'], true) ?? [];
  434. if (!empty($status1)) {
  435. $query->whereIn('article.status', $status1);
  436. }
  437. })
  438. ->select('article.*')
  439. // 非管理员限制
  440. ->when($type_id != 10000, function ($query) use ($user_id) {
  441. // 非管理员只能看自己的文章,同时把 article_ignore 的 c_show_time 一起查出来
  442. $query->where('article.admin_user_id', $user_id)
  443. ->leftJoin('article_ignore', function ($join) {
  444. // 关联条件:article.id = article_ignore.article_id 且 article.web_site_id = article_ignore.website_id
  445. $join->on('article_ignore.article_id', '=', 'article.id')
  446. ->whereColumn('article_ignore.website_id', 'article.web_site_id');
  447. })
  448. ->addSelect('article_ignore.article_id','article_ignore.c_show_time'); // 用 addSelect 追加字段,避免覆盖原有 select
  449. })
  450. // 基础条件
  451. ->whereNotIn('article.status', [404])
  452. // 排序和分页
  453. ->orderBy('article.updated_at', 'desc')
  454. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  455. // 获取结果并格式化
  456. $data = [
  457. 'rows' => $rep->items(),
  458. 'count' => $rep->total(),
  459. ];
  460. // 执行查询
  461. $endTime = microtime(true);
  462. $executionTime = ($endTime - $startTime) * 1000;
  463. echo "查询执行时间: {$executionTime}ms\n";
  464. return Result::success($data);
  465. }
  466. /**
  467. * @param array $data
  468. * @return array
  469. */
  470. public function addArticle(array $data): array
  471. {
  472. var_dump($data, '----------12-----------1');
  473. // ------c_show_time********add***1****
  474. $is_collect = $data['is_collect'] ?? 0;
  475. $user_type = $data['user_type'];
  476. unset($data['is_collect']);
  477. unset($data['user_type']);
  478. // ------c_show_time********add***1****
  479. unset($data['nav_add_pool_id']);
  480. // unset($data['commend_id']);
  481. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  482. Db::beginTransaction();
  483. try {
  484. //处理投票
  485. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  486. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  487. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  488. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  489. unset($data['is_survey']);
  490. unset($data['survey_name']);
  491. unset($data['suvey_array']);
  492. // unset($data['website_id']);
  493. // unset($data['web_site_id']);
  494. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  495. if ($data['hits'] == '') {
  496. $data['hits'] = 0;
  497. }
  498. if ($data['is_original'] == '') {
  499. $data['is_original'] = 0;
  500. }
  501. if ($data['status'] == '') {
  502. $data['status'] = 0;
  503. }
  504. $articleData = $data;
  505. unset($articleData['content']);
  506. //自动处理缩略图、关键字、描述
  507. if ($articleData['imgurl'] == '') {
  508. //如果没有图,设置level=0
  509. $levelArr = json_decode($articleData['level'], true);
  510. var_dump($levelArr, '----------levelArr-----------1');
  511. //content中提取图片第一个图,正则提取
  512. // -------采集器相关优化-----
  513. // 优化正则表达式,仅匹配 src 属性值,避免匹配到多余内容
  514. if ($is_collect == 1) {
  515. $reg = '/<img.*?src=[\'"]?((?!.*\.gif)[^\'" >]+)[\'"]?.*?>/i';
  516. } else {
  517. $reg = '/<img.*?src=[\'"]?([^\'" >]+)[\'"]?.*?>/i';
  518. }
  519. // -------采集器相关优化-----
  520. preg_match_all($reg, $data['content'], $matches);
  521. if (isset($matches[1][0])) {
  522. //截取varchar240
  523. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  524. //如果有图,设置level=3
  525. if (!in_array(3, $levelArr)) {
  526. $levelArr[] = 3;
  527. }
  528. $articleData['level'] = json_encode($levelArr);
  529. } else {
  530. if (!in_array(0, $levelArr)) {
  531. $levelArr[] = 0;
  532. }
  533. $articleData['level'] = json_encode($levelArr);
  534. }
  535. }
  536. var_dump($articleData['level'], '----------$articleData[level]----------1');
  537. if ($articleData['keyword'] == '') {
  538. //提取标题+内容中的关键词
  539. $articleData['keyword'] = $data['title'];
  540. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  541. Jieba::init(); // 初始化 jieba-php
  542. Finalseg::init();
  543. $segList = Jieba::cut($articleData['keyword']);
  544. $segList1 = array_slice($segList, 0, 8);
  545. $articleData['keyword'] = implode(',', $segList1);
  546. }
  547. if ($articleData['introduce'] == '') {
  548. //提取内容中的描述
  549. $content = $data['content'];
  550. // 去除 <style> 和 <script> 标签及其内容
  551. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  552. // 去除所有 HTML 标签
  553. $content = strip_tags($content);
  554. // 去除 HTML 实体
  555. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  556. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  557. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  558. // 去除多余空白
  559. $content = preg_replace('/\s+/u', '', $content);
  560. // 截取 100 个字符
  561. $articleData['introduce'] = mb_substr($content, 0, 100);
  562. }
  563. if ($articleData['status'] == 0) {
  564. $this->sendMessage([
  565. 'talk_type' => 100,
  566. 'title' => $articleData['title'],
  567. 'content' => '提交了审核',
  568. 'messageType' => 2,
  569. ]);
  570. }
  571. $id = Article::insertGetId($articleData);
  572. if (!$id) {
  573. throw new \Exception('文章插入失败');
  574. }
  575. $articleDataContent = [
  576. 'article_id' => $id,
  577. 'content' => $data['content'],
  578. ];
  579. // 采集器中的文章内容,在添加时,去掉div标签
  580. if ($is_collect == 1) {
  581. // 采集来的文章,content中可能包含div标签,需要先移除
  582. $pattern = '/<\/?div\b(?:[^"\'>]|"[^"]*"|\'[^\']*\')*>/is';
  583. $article_data = preg_replace($pattern, '', $data['content']);
  584. $$articleDataContent['content'] = $article_data;
  585. }
  586. $contentInsertId = ArticleData::insertGetId($articleDataContent);
  587. if (!$contentInsertId) {
  588. throw new \Exception('文章内容插入失败');
  589. }
  590. // ------c_show_time********add***2****
  591. // 直接使用当前系统时间,不再强制添加8小时
  592. $now = date('Y-m-d H:i:s');
  593. if ($user_type == 10000 || $is_collect == 1) {
  594. // 管理员添加文章时,核心站c端显示时间就是创建时间;非核心站c端显示时间就是此创建时间往后推二十分钟;
  595. // 非管理员添加文章时,不做操作只有在审核通过时获取c端显示时间
  596. if (!isset($data['catid'])) {
  597. throw new \Exception('缺少必要字段:catid');
  598. }
  599. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  600. $web = WebsiteCategory::where('category_id', $data['catid'])
  601. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  602. ->select(
  603. 'website_id',
  604. Db::raw('CASE WHEN website.id IS NULL THEN 2 WHEN JSON_CONTAINS(website.`website_column_arr_id`, \'3\') THEN 1 ELSE 0 END as is_core')
  605. )
  606. ->get();
  607. // $id = 225; -----测试开启
  608. // 采集来的文章,错开时间在两小时之内发布
  609. if ($user_type == 10000 && $is_collect == 1) {
  610. $web_num = $web->where('is_core', '!=', 2)->count();
  611. $waiting_interval = 10;
  612. if ($web_num > 12) {
  613. // 若网站数量大于12个,则每个网站间隔时间取均值
  614. // 防止除数为 0,虽然这里 $web_num 是 count 结果不会为 0,但做健壮性检查
  615. $waiting_interval = 120 / max(1, $web_num);
  616. }
  617. $time = 0;
  618. } else {
  619. // 非核心站与核心站----显示时间-----间隔
  620. $time = 20;
  621. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  622. $waiting_interval = 5;
  623. }
  624. // 将 Hyperf\Database\Model\Collection 转换为数组
  625. $webArray = $web->toArray();
  626. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $id, $waiting_interval, $is_collect) {
  627. // 检查 $item 对象是否有 is_core 属性
  628. if (!isset($item['is_core'])) {
  629. throw new \Exception('$item 对象缺少 is_core 属性');
  630. }
  631. // 当 is_core 为 2 时,则表示此网站不存在
  632. if ($item['is_core'] == 2) {
  633. return null;
  634. }
  635. if ($is_collect == 1) {
  636. // 采集来的文章,错开时间在两小时之内发布
  637. // $time = 0;
  638. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  639. $time += $waiting_interval;
  640. } else if ($item['is_core'] == 1) {
  641. // 当 is_core 为 1 时,则表示此网站是核心站
  642. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  643. } else {
  644. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  645. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  646. if ($item['is_core'] == 0) {
  647. $time += $waiting_interval;
  648. }
  649. }
  650. return [
  651. 'article_id' => $id,
  652. 'website_id' => $item['website_id'],
  653. 'c_show_time' => $c_show_time,
  654. // 'is_core' => $item['is_core'],
  655. // 'time' => $time
  656. ];
  657. }, array_keys($webArray), $webArray)));
  658. // Db::commit();
  659. // return Result::success($article_ignore);
  660. if (!empty($article_ignore)) {
  661. $article_ignores = ArticleIgnore::insert($article_ignore);
  662. if (!$article_ignores) {
  663. throw new \Exception('c端展示时间插入失败');
  664. }
  665. }
  666. }
  667. // ------c_show_time********add***2****
  668. //处理投票
  669. if ($is_survey == 1) {
  670. //生成年月日时分秒+8位随机数
  671. $uuid = date('YmdHis') . rand(10000000, 99999999);
  672. var_dump($suvey_array, 'suvey_array________');
  673. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  674. var_dump($suveys_array, '---------------------1');
  675. var_dump($suvey_array, '---------------------2');
  676. $suvey_data = [];
  677. foreach ($suveys_array as $key => $value) {
  678. if ($value == '') {
  679. continue;
  680. }
  681. if (is_array($value)) {
  682. $suvey_data[] = [
  683. 'sur_id' => $uuid,
  684. 'art_id' => $id,
  685. 'website_id' => $website_id ?? 2,
  686. 'survey_name' => $survey_name,
  687. 'choice_name' => $value[1],
  688. 'is_other' => 1,
  689. 'other_id' => 0,
  690. 'results' => 0,
  691. ];
  692. } else {
  693. $suvey_data[] = [
  694. 'sur_id' => $uuid,
  695. 'art_id' => $id,
  696. 'website_id' => $website_id ?? 2,
  697. 'survey_name' => $survey_name,
  698. 'choice_name' => $value,
  699. 'is_other' => 0,
  700. 'other_id' => 0,
  701. 'results' => 0,
  702. ];
  703. }
  704. if (empty($suvey_data)) {
  705. throw new \Exception("投票数据为空");
  706. }
  707. }
  708. $result = ArticleSurvey::insert($suvey_data);
  709. if (!$result) {
  710. throw new \Exception("投票失败,ArticleSurvey插入失败");
  711. }
  712. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  713. if (!$result) {
  714. throw new \Exception("投票失败,更新主表失败");
  715. }
  716. }
  717. Db::commit();
  718. return Result::success(['id' => $id]);
  719. } catch (\Throwable $ex) {
  720. Db::rollBack();
  721. var_dump($ex->getMessage());
  722. return Result::error("创建失败", 0);
  723. }
  724. }
  725. /**
  726. * @param array $data
  727. * @return array
  728. */
  729. public function delArticle(array $data): array
  730. {
  731. // ------c_show_time********del*******
  732. Db::beginTransaction();
  733. try {
  734. $article = Article::where(['id' => $data['id']])->delete();
  735. // 若文章删除失败,抛出异常,后续 SQL 语句不会执行
  736. if (!$article) {
  737. throw new \Exception("删除失败,文章删除失败");
  738. }
  739. //survey投票删除
  740. ArticleSurvey::where(['art_id' => $data['id']])->delete(); // 修正类名大小写
  741. $articleIgnore = ArticleIgnore::where(['article_id' => $data['id']])->delete();
  742. $article_data = ArticleData::where(['article_id' => $data['id']])->delete();
  743. // 若文章详情删除失败,抛出异常
  744. if (!$article_data) {
  745. throw new \Exception("删除失败,文章详情删除失败");
  746. }
  747. Db::commit(); // 所有操作成功,提交事务
  748. } catch (\Throwable $ex) {
  749. Db::rollBack();
  750. var_dump($ex->getMessage());
  751. return Result::error("删除失败: " . $ex->getMessage(), 0);
  752. }
  753. // ------c_show_time********del*******
  754. if (!$article) {
  755. return Result::error("删除失败");
  756. }
  757. return Result::success($article);
  758. }
  759. /**
  760. * @param array $data
  761. * @return array
  762. */
  763. public function updateArticle(array $data): array
  764. {
  765. var_dump($data, '----------12-----------1');
  766. Db::beginTransaction();
  767. // ------c_show_time********up*******
  768. $user_type = isset($data['user_type']) ? $data['user_type'] : 0;
  769. // 无论是否改变了c端显示时间或者栏目,都需要将未屏蔽的网站显示时间删除记录
  770. // 若是存在交集,则进行修改,若无,则合并(此表中的记录应该包含被屏蔽网站及涉及所有网站的展示时间)
  771. $web = WebsiteCategory::where('category_id', $data['catid'])
  772. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  773. ->select(
  774. 'website_id',
  775. Db::raw('CASE WHEN website.id IS NULL THEN 2 WHEN JSON_CONTAINS(website.`website_column_arr_id`, \'3\') THEN 1 ELSE 0 END as is_core')
  776. )
  777. ->get();
  778. // 根据错误信息,问题在于 $web 可能是一个包含对象的集合,不能直接用于 whereNotIn 方法
  779. // 先从 $web 集合中提取 website_id 字段的值,再进行删除操作
  780. $websiteIds = $web->pluck('website_id')->toArray();
  781. $del_article_ignore = ArticleIgnore::where('article_id', $data['id'])->whereNotIn('website_id', $websiteIds)->delete();
  782. if ($user_type == 0) {
  783. throw new \Exception("用户类型不能为空");
  784. }
  785. if ($user_type == 10000) {
  786. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  787. $web = WebsiteCategory::where('category_id', $data['catid'])
  788. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  789. ->select(
  790. 'website_id',
  791. Db::raw('CASE WHEN website.id IS NULL THEN 2 WHEN JSON_CONTAINS(website.`website_column_arr_id`, \'3\') THEN 1 ELSE 0 END as is_core')
  792. )
  793. ->get();
  794. // 非核心站与核心站----显示时间-----间隔
  795. $time = 20;
  796. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  797. $waiting_interval = 5;
  798. $webArray = $web->toArray();
  799. if (empty($webArray)) {
  800. throw new \Exception('网站分类不存在');
  801. }
  802. // 直接使用当前系统时间,不再强制添加8小时
  803. $now = date('Y-m-d H:i:s');
  804. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  805. // 检查 $item 对象是否有 is_core 属性
  806. if (!isset($item['is_core'])) {
  807. throw new \Exception('$item 对象缺少 is_core 属性');
  808. }
  809. // 当 is_core 为 2 时,则表示此网站不存在
  810. if ($item['is_core'] == 2) {
  811. return null;
  812. } else if ($item['is_core'] == 1) {
  813. // 当 is_core 为 1 时,则表示此网站是核心站
  814. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  815. } else {
  816. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  817. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  818. if ($item['is_core'] == 0) {
  819. $time += $waiting_interval;
  820. }
  821. }
  822. return [
  823. 'article_id' => $data['id'],
  824. 'website_id' => $item['website_id'],
  825. 'c_show_time' => $c_show_time,
  826. ];
  827. }, array_keys($webArray), $webArray)));
  828. if (!empty($article_ignore)) {
  829. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  830. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  831. $article_ignores = ArticleIgnore::upsert(
  832. $article_ignore,
  833. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  834. ['c_show_time'] // 需要更新的字段
  835. );
  836. if (!$article_ignores) {
  837. throw new \Exception('c端展示时间插入失败');
  838. }
  839. }
  840. // Db::commit();
  841. // return Result::success($article_ignore);
  842. }
  843. // ------c_show_time********up*******
  844. unset($data['user_type']);
  845. // unset($data['web_site_id']);
  846. unset($data['nav_add_pool_id']);
  847. try {
  848. //处理投票
  849. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  850. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  851. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  852. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  853. unset($data['is_survey']);
  854. unset($data['survey_name']);
  855. unset($data['suvey_array']);
  856. unset($data['website_id']);
  857. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  858. if ($data['hits'] == '') {
  859. $data['hits'] = 0;
  860. }
  861. if ($data['is_original'] == '') {
  862. $data['is_original'] = 0;
  863. }
  864. if ($data['status'] == '') {
  865. $data['status'] = 0;
  866. }
  867. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  868. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  869. $articleData = $data;
  870. unset($articleData['content']);
  871. unset($articleData['status_name']);
  872. unset($articleData['name']);
  873. unset($articleData['content']);
  874. unset($articleData['pid_arr']);
  875. unset($articleData['pid']);
  876. //自动处理缩略图、关键字、描述
  877. if ($articleData['imgurl'] == '') {
  878. //如果没有图,设置level=0
  879. $levelArr = json_decode($articleData['level'], true);
  880. var_dump($levelArr, '----------levelArr-----------1');
  881. //content中提取图片第一个图,正则提取
  882. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  883. preg_match_all($reg, $data['content'], $matches);
  884. if (isset($matches[1][0])) {
  885. //截取varchar240
  886. // 截取到第一个<
  887. $articleData['imgurl'] = $matches[1][0];
  888. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  889. $pos = strpos($articleData['imgurl'], '"');
  890. if ($pos !== false) {
  891. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  892. }
  893. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  894. //如果有图,设置level=3
  895. if (!in_array(3, $levelArr)) {
  896. $levelArr[] = 3;
  897. }
  898. $articleData['level'] = json_encode($levelArr);
  899. } else {
  900. if (!in_array(0, $levelArr)) {
  901. $levelArr[] = 0;
  902. }
  903. $articleData['level'] = json_encode($levelArr);
  904. }
  905. }
  906. var_dump($articleData['level'], '----------$articleData[level]----------1');
  907. if ($articleData['keyword'] == '') {
  908. //提取标题+内容中的关键词
  909. $articleData['keyword'] = $data['title'];
  910. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  911. Jieba::init(); // 初始化 jieba-php
  912. Finalseg::init();
  913. $segList = Jieba::cut($articleData['keyword']);
  914. $segList1 = array_slice($segList, 0, 8);
  915. $articleData['keyword'] = implode(',', $segList1);
  916. }
  917. if ($articleData['introduce'] == '') {
  918. //提取内容中的描述
  919. $content = $data['content'];
  920. // 去除 <style> 和 <script> 标签及其内容
  921. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  922. // 去除所有 HTML 标签
  923. $content = strip_tags($content);
  924. // 去除 HTML 实体
  925. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  926. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  927. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  928. // 去除多余空白
  929. $content = preg_replace('/\s+/u', '', $content);
  930. // 截取 100 个字符
  931. $articleData['introduce'] = mb_substr($content, 0, 100);
  932. }
  933. if ($articleData['status'] == 0) {
  934. $this->sendMessage([
  935. 'talk_type' => 100,
  936. 'title' => $articleData['title'],
  937. 'content' => '提交了审核',
  938. 'messageType' => 2,
  939. ]);
  940. }
  941. $id = Article::where(['id' => $data['id']])->update($articleData);
  942. // $articleDataContent = [
  943. // 'content' => $data['content'],
  944. // ];
  945. // 采集来的文章,content中可能包含div标签,需要先移除
  946. $pattern = '/<\/?div\b(?:[^"\'>]|"[^"]*"|\'[^\']*\')*>/is';
  947. $article_data = preg_replace($pattern, '', $data['content']);
  948. $articleDataContent['content'] = $article_data;
  949. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  950. //处理投票
  951. $id = $data['id'];
  952. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  953. var_dump($suvey_array, 'suvey_array________delete');
  954. //处理投票
  955. if ($is_survey == 1) {
  956. //生成年月日时分秒+8位随机数
  957. $uuid = date('YmdHis') . rand(10000000, 99999999);
  958. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  959. var_dump($suveys_array, '---------------------1');
  960. $suvey_data = [];
  961. if (is_array($suveys_array)) {
  962. foreach ($suveys_array as $key => $value) {
  963. if ($value == '') {
  964. continue;
  965. }
  966. if (is_array($value)) {
  967. $suvey_data[] = [
  968. 'sur_id' => $uuid,
  969. 'art_id' => $id,
  970. 'website_id' => $website_id ?? 2,
  971. 'survey_name' => $survey_name,
  972. 'choice_name' => $value[1],
  973. 'is_other' => 1,
  974. 'other_id' => 0,
  975. 'results' => 0,
  976. ];
  977. } else {
  978. $suvey_data[] = [
  979. 'sur_id' => $uuid,
  980. 'art_id' => $id,
  981. 'website_id' => $website_id ?? 2,
  982. 'survey_name' => $survey_name,
  983. 'choice_name' => $value,
  984. 'is_other' => 0,
  985. 'other_id' => 0,
  986. 'results' => 0,
  987. ];
  988. }
  989. if (empty($suvey_data)) {
  990. throw new \Exception("投票数据为空");
  991. }
  992. }
  993. }
  994. $result = ArticleSurvey::insert($suvey_data);
  995. if (!$result) {
  996. throw new \Exception("投票失败");
  997. }
  998. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  999. if (!$result) {
  1000. throw new \Exception("投票失败");
  1001. }
  1002. } else {
  1003. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  1004. }
  1005. Db::commit();
  1006. return Result::success([]);
  1007. } catch (\Throwable $ex) {
  1008. Db::rollBack();
  1009. var_dump($ex->getMessage());
  1010. return Result::error("更新失败" . $ex->getMessage(), 0);
  1011. }
  1012. }
  1013. /**
  1014. * 更新资讯状态
  1015. * @param array $data
  1016. * @return array
  1017. */
  1018. public function upArticleStatus(array $data): array
  1019. {
  1020. $articleData = Article::where(['id' => $data['id']])->first();
  1021. //发送10次
  1022. // for ($i = 0; $i < 10; $i++) {
  1023. // $this->sendMessage([
  1024. // 'talk_type' => 100,
  1025. // 'title' => $i . $articleData['title'],
  1026. // 'content' => '审核通过',
  1027. // 'messageType' => 2,
  1028. // 'user_id' => $articleData['admin_user_id'],
  1029. // ]);
  1030. // }
  1031. // var_dump($data['status'], 'status');
  1032. // return Result::success();
  1033. if ($data['status'] == 1) {
  1034. $this->sendMessage([
  1035. 'talk_type' => 101,
  1036. 'title' => $articleData['title'],
  1037. 'content' => '审核通过',
  1038. 'messageType' => 2,
  1039. 'user_id' => $articleData['admin_user_id'],
  1040. ]);
  1041. }
  1042. if ($data['status'] == 2) {
  1043. $this->sendMessage([
  1044. 'talk_type' => 101,
  1045. 'title' => $articleData['title'],
  1046. 'content' => '审核拒绝',
  1047. 'messageType' => 2,
  1048. 'user_id' => $articleData['admin_user_id'],
  1049. ]);
  1050. }
  1051. if ($data['status'] == 0) {
  1052. $this->sendMessage([
  1053. 'talk_type' => 100,
  1054. 'title' => $articleData['title'],
  1055. 'content' => '提交了审核',
  1056. 'messageType' => 2,
  1057. ]);
  1058. }
  1059. $result = Article::where(['id' => $data['id']])->update($data);
  1060. // ------c_show_time********up_status*******
  1061. // 若是审核通过 则更新c_show_time
  1062. if ($data['status'] == 1) {
  1063. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  1064. $web = Article::where('article.id', $data['id'])
  1065. ->leftJoin('website_category', 'article.catid', 'website_category.category_id')
  1066. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  1067. ->select(
  1068. 'website_id',
  1069. Db::raw('CASE WHEN website.id IS NULL THEN 2 WHEN JSON_CONTAINS(website.`website_column_arr_id`, \'3\') THEN 1 ELSE 0 END as is_core')
  1070. )
  1071. ->get();
  1072. // 非核心站与核心站----显示时间-----间隔
  1073. $time = 20;
  1074. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  1075. $waiting_interval = 5;
  1076. $webArray = $web->toArray();
  1077. if (empty($webArray)) {
  1078. throw new \Exception('网站分类不存在');
  1079. }
  1080. // 直接使用当前系统时间,不再强制添加8小时
  1081. $now = date('Y-m-d H:i:s');
  1082. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  1083. if (isset($data['ignore_ids'])) {
  1084. $ignore_website_ids = is_array($data['ignore_ids']) ? $data['ignore_ids'] : json_decode($data['ignore_ids'], true);
  1085. if (in_array($item['website_id'], $ignore_website_ids)) {
  1086. $is_ignore = 1;
  1087. } else {
  1088. $is_ignore = 0;
  1089. }
  1090. return [
  1091. 'article_id' => $data['id'],
  1092. 'website_id' => $item['website_id'],
  1093. 'is_ignore' => $is_ignore,
  1094. ];
  1095. } else {
  1096. // 检查 $item 对象是否有 is_core 属性
  1097. if (!isset($item['is_core'])) {
  1098. throw new \Exception('$item 对象缺少 is_core 属性');
  1099. }
  1100. // 当 is_core 为 2 时,则表示此网站不存在
  1101. if ($item['is_core'] == 2) {
  1102. return null;
  1103. } else if ($item['is_core'] == 1) {
  1104. // 当 is_core 为 1 时,则表示此网站是核心站
  1105. $c_show_time = $now;
  1106. } else {
  1107. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  1108. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  1109. if ($item['is_core'] == 0) {
  1110. $time += $waiting_interval;
  1111. }
  1112. }
  1113. return [
  1114. 'article_id' => $data['id'],
  1115. 'website_id' => $item['website_id'],
  1116. 'c_show_time' => $c_show_time,
  1117. ];
  1118. }
  1119. }, array_keys($webArray), $webArray)));
  1120. if (!empty($article_ignore) && !isset($data['ignore_ids'])) {
  1121. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  1122. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  1123. $websiteIds = $web->pluck('website_id')->toArray();
  1124. $del_article_ignore = ArticleIgnore::where('article_id', $data['id'])->whereNotIn('website_id', $websiteIds)->delete();
  1125. $article_ignores = ArticleIgnore::upsert(
  1126. $article_ignore,
  1127. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  1128. ['c_show_time'] // 需要更新的字段
  1129. );
  1130. if (!$article_ignores) {
  1131. throw new \Exception('c端展示时间插入失败');
  1132. }
  1133. }
  1134. if (!empty($data['ignore_ids'])) {
  1135. // return Result::success($article_ignore);
  1136. // 从数据库中删除 article_id 为 $data['id'] 且 website_id 在 $website_ids 中的记录
  1137. if (!empty($article_ignore)) {
  1138. $article_ignores = ArticleIgnore::upsert(
  1139. $article_ignore,
  1140. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  1141. ['is_ignore'] // 需要更新的字段
  1142. );
  1143. // if(!$article_ignores){
  1144. // throw new \Exception('屏蔽网站更新失败');
  1145. // }
  1146. }
  1147. }
  1148. }
  1149. // ------c_show_time********up_status*******
  1150. if ($result) {
  1151. return Result::success();
  1152. } else {
  1153. return Result::error("更新状态失败", 0);
  1154. }
  1155. }
  1156. /**
  1157. * 获取新闻详情
  1158. * @param array $data
  1159. * @return array
  1160. */
  1161. public function getArticleInfo(array $data): array
  1162. {
  1163. $where = [
  1164. 'article.id' => $data['id'],
  1165. // 'article.status' => 1,
  1166. ];
  1167. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  1168. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  1169. $info = $result;
  1170. // var_dump($info, 'info');
  1171. $info['survey_array'] = $articleSurvey;
  1172. if ($result) {
  1173. return Result::success($info);
  1174. } else {
  1175. return Result::error("查询失败", 0);
  1176. }
  1177. }
  1178. /**
  1179. * 获取头条新闻
  1180. * @param array $data
  1181. * @return array
  1182. */
  1183. public function getWebsiteArticlett(array $data): array
  1184. {
  1185. $website_id = $data['website_id'];
  1186. $website = Website::where('id', $data['website_id'])->first();
  1187. if (empty($website)) {
  1188. return Result::error("网站不存在", 0);
  1189. }
  1190. $categorys = $this->processArticlePro($website_id);
  1191. $catiall = $categorys['catiall'];
  1192. $categoryIds = $categorys['categoryIds'];
  1193. $where = [
  1194. 'status' => 1
  1195. ];
  1196. // $website_column = $website['column'];
  1197. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1198. $website_column = json_decode($website['website_column_arr_id'], true);
  1199. }
  1200. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1201. // return Result::success($diff_pid_categoryIds);
  1202. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1203. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1204. }
  1205. // $website_id = $data['website_id'];
  1206. $month = date("Y-m-d H:i:s", strtotime("-30 day"));
  1207. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  1208. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  1209. switch ($data['level']) {
  1210. case 1:
  1211. case 2:
  1212. case 3:
  1213. case 6: //1.头条资讯;2.轮播图;3.推荐图;6.今日热点
  1214. $query = Article::where($where)
  1215. ->where('level', 'like', '%' . $data['level'] . '%')
  1216. ->orderBy('updated_at', 'desc');
  1217. break;
  1218. case 4: //最新资讯
  1219. $query = Article::where($where)->orderBy('updated_at', 'desc');
  1220. break;
  1221. case 5: //资讯推荐
  1222. $query = Article::where($where)
  1223. ->where('updated_at', '>', $month);
  1224. break;
  1225. case 7: //资讯分类
  1226. if (isset($data['id']) && !empty($data['id'])) {
  1227. $keyword = Article::where('id', $data['id'])->value('keyword');
  1228. $keywordArray = explode(',', $keyword);
  1229. $whereL7 = [];
  1230. foreach ($keywordArray as $k => $v) {
  1231. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1232. }
  1233. $query = Article::where($where)->where($whereL7)->orderBy('updated_at', 'desc');;
  1234. break;
  1235. } else {
  1236. return Result::error("请输入资讯ID", 0);
  1237. break;
  1238. }
  1239. default:
  1240. break;
  1241. }
  1242. // $whereL7 = [];
  1243. // if(isset($data['id']) && !empty($data['id'])){
  1244. // $keyword = Article::where('id', $data['id'])->value('keyword');
  1245. // $keywordArray = explode(',', $keyword);
  1246. // foreach ($keywordArray as $k => $v) {
  1247. // $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1248. // }
  1249. // }
  1250. // $query = Article::where($where)
  1251. // ->when(isset($data['level']) && !empty($data['level']), function ($query) use ($data,$whereL7) {
  1252. // if($data['level'] == 1 || $data['level'] == 2 || $data['level'] == 3 || $data['level'] == 6){
  1253. // $query = $query->where('article.level','like','%'.$data['level'].'%')->orderBy('updated_at','desc');
  1254. // }
  1255. // if($data['level'] == 7){
  1256. // $query = $query->where($whereL7)->orderBy('updated_at','desc');
  1257. // }
  1258. // if($data['level'] == 4){
  1259. // $query = $query->inRandomOrder()
  1260. // ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  1261. // }
  1262. // if($data['level'] == 5){
  1263. // $query = $query->orderBy('updated_at','desc');
  1264. // }
  1265. // });
  1266. if ($data['textnum'] > 0) {
  1267. $query = clone $query;
  1268. $result['text'] = $query
  1269. ->whereIn('catid', $categoryIds)
  1270. ->leftJoinSub(function ($query) use ($website_id) {
  1271. $query->from('article_ignore')
  1272. ->where('website_id', $website_id);
  1273. }, 'article_ignore', function ($join) {
  1274. $join->on('article_ignore.article_id', '=', 'article.id');
  1275. })
  1276. ->where(function ($query) {
  1277. $query->whereNull('article_ignore.article_id')
  1278. ->orWhere(function ($subQuery) {
  1279. $subQuery->whereNotNull('article_ignore.article_id')
  1280. ->where('article_ignore.is_ignore', 0)
  1281. ->where(function ($subSubQuery) {
  1282. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1283. ->orWhereNull('article_ignore.c_show_time');
  1284. });
  1285. });
  1286. })
  1287. // ->where(function ($query) use ($website_id) {
  1288. // $query->whereNull('article_ignore.article_id')
  1289. // ->orWhere('article_ignore.website_id', '!=', $website_id);
  1290. // })
  1291. ->select(
  1292. 'article.id',
  1293. 'article.title',
  1294. 'article.author',
  1295. 'article.updated_at',
  1296. 'article.introduce',
  1297. 'article.islink',
  1298. 'article.linkurl',
  1299. 'article.copyfrom',
  1300. 'article.cat_arr_id',
  1301. 'article.catid',
  1302. 'article.level',
  1303. // 'article_ignore.is_ignore',
  1304. // 'article_ignore.c_show_time',
  1305. )
  1306. ->offset($data['placeid'])
  1307. ->limit($data['textnum'])
  1308. ->get()->all();
  1309. foreach ($result['text'] as $k => $v) {
  1310. $result['text'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1311. $result['text'][$k]->alias = $catiall[$v->catid]['alias'];
  1312. }
  1313. }
  1314. if ($data['imgnum'] > 0) {
  1315. $query = clone $query;
  1316. if ($data['textnum'] == 0) {
  1317. $query = $query->leftJoinSub(function ($query) use ($website_id) {
  1318. $query->from('article_ignore')
  1319. ->where('website_id', $website_id);
  1320. }, 'article_ignore', function ($join) {
  1321. $join->on('article_ignore.article_id', '=', 'article.id');
  1322. })
  1323. ->where(function ($query) {
  1324. $query->whereNull('article_ignore.article_id')
  1325. ->orWhere(function ($subQuery) {
  1326. $subQuery->whereNotNull('article_ignore.article_id')
  1327. ->where('article_ignore.is_ignore', 0)
  1328. ->where(function ($subSubQuery) {
  1329. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1330. ->orWhereNull('article_ignore.c_show_time');
  1331. });
  1332. });
  1333. });
  1334. }
  1335. $result['img'] = $query
  1336. ->whereIn('catid', $categoryIds)
  1337. ->where('article.imgurl', '!=', '')
  1338. ->select(
  1339. 'article.id',
  1340. 'article.title',
  1341. 'article.imgurl',
  1342. 'article.author',
  1343. 'article.updated_at',
  1344. 'article.introduce',
  1345. 'article.islink',
  1346. 'article.linkurl',
  1347. 'article.copyfrom',
  1348. 'article.cat_arr_id',
  1349. 'article.catid',
  1350. 'article.level',
  1351. // 'article_ignore.is_ignore',
  1352. // 'article_ignore.c_show_time',
  1353. )
  1354. ->offset($data['placeid'])
  1355. ->limit($data['imgnum'])
  1356. ->get()->all();
  1357. foreach ($result['img'] as $k => $v) {
  1358. $result['img'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1359. $result['img'][$k]->alias = $catiall[$v->catid]['alias'];
  1360. }
  1361. }
  1362. if (empty($result)) {
  1363. return Result::error("暂无相关资讯", 0);
  1364. }
  1365. return Result::success($result);
  1366. }
  1367. /**
  1368. * 获取模块新闻
  1369. * @param array $data
  1370. * @return array
  1371. */
  1372. public function getWebsiteModelArticles(array $data): array
  1373. {
  1374. $catid = $data['catid'];
  1375. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  1376. $category = $category->toArray();
  1377. if (!empty($category)) {
  1378. $where = [
  1379. 'status' => 1,
  1380. 'catid' => $catid,
  1381. ];
  1382. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  1383. // 1:文字新闻;2:轮播图;3:图文;
  1384. // 级别:0:未分类
  1385. // 3:推荐图片
  1386. if ($data['level'] == 1) {
  1387. $data['level'] = 0;
  1388. }
  1389. $result = Article::where($where)
  1390. ->where(function ($query) use ($data) {
  1391. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  1392. ->orWhereNull("level")
  1393. ->orWhereRaw("level = '[]'");
  1394. })
  1395. ->leftJoinSub(function ($query) use ($data) {
  1396. $query->from('article_ignore')
  1397. ->where('website_id', $data['website_id']);
  1398. }, 'article_ignore', function ($join) {
  1399. $join->on('article_ignore.article_id', '=', 'article.id');
  1400. })
  1401. ->where(function ($query) {
  1402. $query->whereNull('article_ignore.article_id')
  1403. ->orWhere(function ($subQuery) {
  1404. $subQuery->whereNotNull('article_ignore.article_id')
  1405. ->where('article_ignore.is_ignore', 0)
  1406. ->where(function ($subSubQuery) {
  1407. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1408. ->orWhereNull('article_ignore.c_show_time');
  1409. });
  1410. });
  1411. })
  1412. // ->where(function ($query) use ($data) {
  1413. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1414. // ->orWhereNull("ignore_ids");
  1415. // })
  1416. ->orderBy("updated_at", "desc")
  1417. ->offset($placeid)
  1418. ->limit($data['pagesize'])
  1419. ->get();
  1420. if (empty($result)) {
  1421. return Result::error("此栏目暂无相关新闻", 0);
  1422. }
  1423. } else {
  1424. return Result::error("此网站暂无此栏目", 0);
  1425. }
  1426. return Result::success($result);
  1427. }
  1428. /**
  1429. *获取新闻列表
  1430. * @param array $data
  1431. * @return array
  1432. */
  1433. public function getWebsiteArticleList(array $data): array
  1434. {
  1435. // return Result::success($data);
  1436. $where[] = ['status', '=', 1];
  1437. $website_id = $data['website_id'];
  1438. $website = Website::where('id', $data['website_id'])->first();
  1439. if (empty($website)) {
  1440. return Result::error("网站不存在", 0);
  1441. }
  1442. // $website_column = $website['column'];
  1443. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1444. $website_column = json_decode($website['website_column_arr_id'], true);
  1445. }
  1446. $categorys = $this->processArticlePro($website_id);
  1447. $cat_1st_arr = $categorys['cat_1st_arr'];
  1448. $catiall = $categorys['catiall'];
  1449. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1450. // return Result::success($diff_pid_categoryIds);
  1451. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1452. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1453. }
  1454. if (isset($data['catid']) && !empty($data['catid'])) {
  1455. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  1456. if (empty($category)) {
  1457. return Result::error("此网站暂无此栏目", 0);
  1458. }
  1459. array_push($where, ['catid', '=', $data['catid']]);
  1460. }
  1461. // return Result::success($where);
  1462. $query = Article::where($where)
  1463. ->leftJoinSub(function ($query) use ($website_id) {
  1464. $query->from('article_ignore')
  1465. ->where('website_id', $website_id);
  1466. }, 'article_ignore', function ($join) {
  1467. $join->on('article_ignore.article_id', '=', 'article.id');
  1468. })
  1469. ->where(function ($query) {
  1470. $query->whereNull('article_ignore.article_id')
  1471. ->orWhere(function ($subQuery) {
  1472. $subQuery->whereNotNull('article_ignore.article_id')
  1473. ->where('article_ignore.is_ignore', 0)
  1474. ->where(function ($subSubQuery) {
  1475. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1476. ->orWhereNull('article_ignore.c_show_time');
  1477. });
  1478. });
  1479. })
  1480. ->select(
  1481. 'article.id',
  1482. 'article.title',
  1483. 'article.imgurl',
  1484. 'article.author',
  1485. 'article.updated_at',
  1486. 'article.introduce',
  1487. 'article.islink',
  1488. 'article.linkurl',
  1489. 'article.copyfrom',
  1490. 'article.cat_arr_id',
  1491. 'article.catid'
  1492. );
  1493. $count = $query->count();
  1494. $rep = $query->orderBy("updated_at", "desc")
  1495. ->offset(($data['page'] - 1) * $data['pageSize'])
  1496. ->limit($data['pageSize'])
  1497. ->get()->all();
  1498. $categorys = $this->processArticlePro($website_id);
  1499. $cat_1st_arr = $categorys['cat_1st_arr'];
  1500. $catiall = $categorys['catiall'];
  1501. // $web['website_id'] = $data['website_id'];
  1502. foreach ($rep as $k => $v) {
  1503. $rep[$k]->category_name = $catiall[$v->catid]['alias'];
  1504. $rep[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1505. }
  1506. // $rep = $this->processArticles($rep,$web);
  1507. $data = [
  1508. 'rows' => $rep,
  1509. 'count' => $count,
  1510. ];
  1511. if (empty($rep)) {
  1512. return Result::error("没有信息数据");
  1513. }
  1514. return Result::success($data);
  1515. }
  1516. /**
  1517. * 前端-获取新闻详情
  1518. * @param array $data
  1519. * @return array
  1520. */
  1521. public function selectWebsiteArticleInfo(array $data): array
  1522. {
  1523. $where = [
  1524. 'article.id' => $data['id'],
  1525. 'article.status' => 1,
  1526. ];
  1527. $result = Article::where($where)
  1528. ->leftJoin("article_data", "article.id", "article_data.article_id")
  1529. ->leftJoin("article_extend", "article_extend.article_id", "article.id")
  1530. // ->where(function ($query) use ($data) {
  1531. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1532. // ->orWhereNull("ignore_ids");
  1533. // })
  1534. ->leftJoinSub(function ($query) use ($data) {
  1535. $query->from('article_ignore')
  1536. ->where('website_id', $data['website_id']);
  1537. }, 'article_ignore', function ($join) {
  1538. $join->on('article_ignore.article_id', '=', 'article.id');
  1539. })
  1540. ->where(function ($query) {
  1541. $query->whereNull('article_ignore.article_id')
  1542. ->orWhere(function ($subQuery) {
  1543. $subQuery->whereNotNull('article_ignore.article_id')
  1544. ->where('article_ignore.is_ignore', 0)
  1545. ->where(function ($subSubQuery) {
  1546. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1547. ->orWhereNull('article_ignore.c_show_time');
  1548. });
  1549. });
  1550. })
  1551. ->select(
  1552. 'article.*',
  1553. 'article_data.content',
  1554. 'article_data.article_id',
  1555. 'article_extend.website_url',
  1556. 'article_extend.email',
  1557. 'article_extend.contacts',
  1558. 'article_extend.contacts_mobile',
  1559. 'article_extend.contacts_address',
  1560. 'article_extend.zip_code',
  1561. 'article_extend.enterprise_name'
  1562. )
  1563. ->first();
  1564. if (empty($result)) {
  1565. return Result::error("暂无此新闻!", 0);
  1566. }
  1567. if (!empty($result['publiced_at'])) {
  1568. $result['updated_at'] = $result['publiced_at'];
  1569. }
  1570. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  1571. ->select('website_category.*', 'website.website_name', 'website.suffix')
  1572. ->where('website_category.website_id', $data['website_id'])
  1573. ->where(['website_category.category_id' => $result['catid']])
  1574. ->first();
  1575. if (empty($category)) {
  1576. return Result::error("查询失败", 0);
  1577. }
  1578. //手动推荐文章
  1579. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  1580. if (empty($commend_ids)) {
  1581. $commendArticle = [];
  1582. } else {
  1583. //去除不存在的文章ID
  1584. $commendArticle = Article::whereIn('article.id', $commend_ids)
  1585. ->leftjoin('website_category', 'website_category.category_id', '=', 'article.catid')
  1586. ->leftJoinSub(function ($query) use ($data) {
  1587. $query->from('article_ignore')
  1588. ->where('website_id', $data['website_id']);
  1589. }, 'article_ignore', function ($join) {
  1590. $join->on('article_ignore.article_id', '=', 'article.id');
  1591. })
  1592. ->where(function ($query) {
  1593. $query->whereNull('article_ignore.article_id')
  1594. ->orWhere(function ($subQuery) {
  1595. $subQuery->whereNotNull('article_ignore.article_id')
  1596. ->where('article_ignore.is_ignore', 0)
  1597. ->where(function ($subSubQuery) {
  1598. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1599. ->orWhereNull('article_ignore.c_show_time');
  1600. });
  1601. });
  1602. })
  1603. ->where('article.status', 1)
  1604. ->where('website_category.website_id', $data['website_id'])
  1605. ->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')
  1606. ->orderByRaw("FIELD(article.id, " . implode(',', $commend_ids) . ")")
  1607. // ->orderBy('article.updated_at', 'desc')
  1608. ->limit(5)
  1609. ->get();
  1610. //循环数组,取出cat_arr_id中的不重复值,再从website_category取出alias_pinyin,再将cat_arr_id的json转成路径/隔开
  1611. foreach ($commendArticle as $k => $v) {
  1612. $cat_arr_id = json_decode($v->cat_arr_id, true);
  1613. if (!empty($cat_arr_id) && is_array($cat_arr_id)) {
  1614. $cat_arr_id = array_unique($cat_arr_id);
  1615. // 从website_category取出alias_pinyin
  1616. $cat_arr = WebsiteCategory::where('website_id', $data['website_id'])
  1617. ->whereIn('category_id', $cat_arr_id)
  1618. ->pluck('alias_pinyin', 'category_id')
  1619. ->toArray();
  1620. // 将cat_arr_id的json转成路径/隔开
  1621. $path_parts = [];
  1622. foreach ($cat_arr_id as $cat_id) {
  1623. if (isset($cat_arr[$cat_id])) {
  1624. $path_parts[] = $cat_arr[$cat_id];
  1625. }
  1626. }
  1627. $v->alias_pinyin = implode('/', $path_parts);
  1628. } else {
  1629. $v->alias_pinyin = '';
  1630. }
  1631. }
  1632. }
  1633. $result['category_id'] = $category['category_id'];
  1634. $result['cat_name'] = $category['alias'];
  1635. $result['website_name'] = $category['website_name'] ?? "";
  1636. $result['suffix'] = $category['suffix'] ?? "";
  1637. $result['commendArticle'] = $commendArticle;
  1638. $result['commend_ids'] = $commend_ids;
  1639. return Result::success($result);
  1640. }
  1641. /**
  1642. * 前端-获取网站调查问卷
  1643. * @param array $data
  1644. * @return array
  1645. */
  1646. public function getWebsiteSurvey(array $data): array
  1647. {
  1648. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1649. $website = Website::where('id', $data['website_id'])->first();
  1650. if (empty($website)) {
  1651. return Result::error("暂无此网站", 0);
  1652. }
  1653. }
  1654. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1655. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1656. if (empty($article)) {
  1657. return Result::error("暂无此文章", 0);
  1658. }
  1659. // return Result::error($data,0);
  1660. $where['art_id'] = $data['art_id'];
  1661. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1662. } else {
  1663. $survey = Article::where(function ($query) {
  1664. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1665. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1666. })
  1667. ->where('status', 1)
  1668. ->where('is_survey', 1)
  1669. ->select('survey_id')
  1670. ->orderBy('updated_at', 'desc')
  1671. ->first();
  1672. if (empty($survey)) {
  1673. return Result::error("暂无调查问卷", 0);
  1674. }
  1675. $where['sur_id'] = $survey['survey_id'];
  1676. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1677. }
  1678. // return Result::success($where);
  1679. $result = ArticleSurvey::where($where)
  1680. ->where(function ($query) {
  1681. $query->where('is_other', 0)
  1682. ->orWhere(function ($subQuery) {
  1683. $subQuery->where('is_other', 1)
  1684. ->where('other_id', 0);
  1685. });
  1686. })
  1687. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1688. ->select('article_survey.*', 'article.survey_type')
  1689. ->get()->all();
  1690. if (empty($result)) {
  1691. return Result::error("此文章暂无调查问卷", 0);
  1692. }
  1693. return Result::success($result);
  1694. }
  1695. /**
  1696. * 前端-添加网站调查问卷选项
  1697. * @param array $data
  1698. * @return array
  1699. */
  1700. public function addWebsiteSurveyOption(array $data): array
  1701. {
  1702. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1703. $website = Website::where('id', $data['website_id'])->first();
  1704. if (empty($website)) {
  1705. return Result::error("暂无此网站", 0);
  1706. }
  1707. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1708. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1709. if (empty($survey)) {
  1710. return Result::error("此调查问卷不可添加选项", 0);
  1711. }
  1712. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1713. $choice = [
  1714. 'art_id' => $survey['art_id'],
  1715. 'website_id' => $data['website_id'],
  1716. 'survey_name' => $survey['survey_name'],
  1717. 'choice_name' => $data['choice_name'],
  1718. 'sur_id' => $survey['sur_id'],
  1719. 'is_other' => 1,
  1720. 'other_id' => $survey['id'],
  1721. ];
  1722. $result = ArticleSurvey::insertGetId($choice);
  1723. if (empty($result)) {
  1724. return Result::error("添加失败", 0);
  1725. }
  1726. return Result::success($result);
  1727. }
  1728. }
  1729. return Result::error("添加失败", 0);
  1730. }
  1731. return Result::error("添加失败", 0);
  1732. }
  1733. /**
  1734. * 前端-调查问卷投票
  1735. * @param array $data
  1736. * @return array
  1737. */
  1738. public function addWebsiteSurveyVote(array $data): array
  1739. {
  1740. // return Result::success($data);
  1741. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1742. $website = Website::where('id', $data['website_id'])->first();
  1743. if (empty($website)) {
  1744. return Result::error("暂无此网站", 0);
  1745. }
  1746. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1747. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1748. // return Result::success($survey);
  1749. if (empty($is_survey)) {
  1750. return Result::error("此调查问卷不存在", 0);
  1751. }
  1752. // return Result::success($survey);
  1753. // 调查问卷类型
  1754. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1755. //多选 若是json型则转化成数组类型
  1756. if (strpos($data['choice_id'], '[') === 0) {
  1757. $data['choice_id'] = json_decode($data['choice_id'], true);
  1758. } else {
  1759. // 单选 也转换成数组
  1760. $data['choice_id'] = [$data['choice_id']];
  1761. }
  1762. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1763. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1764. // ->where('website_id',$data['website_id'])
  1765. ->where('is_other', 1)
  1766. ->where('other_id', 0)
  1767. ->first();
  1768. if (!empty($other)) {
  1769. return Result::error("请选择已有的选项!", 0);
  1770. }
  1771. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1772. // ->where('website_id',$data['website_id'])
  1773. ->where('is_other', 1)
  1774. ->where('other_id', '!=', 0)
  1775. ->first();
  1776. // return Result::success($choice['other']);
  1777. $choice_id = $data['choice_id'];
  1778. if (!empty($choice['other'])) {
  1779. // array_push($data['choice_id'],$choice['other']['other_id']);
  1780. if (!empty($choice_id)) {
  1781. $key = array_search($choice['other']['id'], $choice_id);
  1782. if ($key !== false) {
  1783. unset($choice_id[$key]);
  1784. $choice_id = array_values($choice_id);
  1785. }
  1786. array_push($choice_id, $choice['other']['other_id']);
  1787. } else {
  1788. $choice_id[0] = $choice['other']['other_id'];
  1789. }
  1790. array_push($data['choice_id'], $choice['other']['other_id']);
  1791. }
  1792. // return Result::success($data);
  1793. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1794. // ->where('website_id',$data['website_id'])
  1795. ->increment('results', 1);
  1796. if (empty($choice)) {
  1797. return Result::error("请选择已有的选项!", 0);
  1798. }
  1799. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1800. // ->where('website_id',$data['website_id'])
  1801. ->where('other_id', 0)
  1802. ->get();
  1803. $survey['choice'] = $choice_id;
  1804. return Result::success($survey);
  1805. }
  1806. return Result::error("参数必填!");
  1807. }
  1808. return Result::error("此调查问卷不存在", 0);
  1809. }
  1810. return Result::error("参数必填!");
  1811. }
  1812. /**
  1813. * 后端-获取网站调查问卷列表
  1814. * @param array $data
  1815. * @return array
  1816. */
  1817. public function getSurveyList(array $data): array
  1818. {
  1819. $where = [];
  1820. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1821. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1822. }
  1823. $survey_type = isset($data['survey_type']) && $data['survey_type'] !== '' ? $data['survey_type'] : null;
  1824. if (!empty($where)) {
  1825. // 修复:先关联 article 再按 survey_type 过滤,避免查不到数据
  1826. $query = ArticleSurvey::select(
  1827. 'art_id as id',
  1828. Db::raw('MAX(id) as surid'),
  1829. Db::raw('MAX(survey_name) as survey_name'),
  1830. Db::raw('MAX(sur_id) as survey_id')
  1831. )
  1832. ->groupBy('art_id')
  1833. ->where($where)
  1834. ->when(!is_null($survey_type), function ($q) use ($survey_type) {
  1835. $q->whereIn('art_id', function ($sub) use ($survey_type) {
  1836. $sub->select('id')
  1837. ->from('article')
  1838. ->where('survey_type', $survey_type);
  1839. });
  1840. })
  1841. ->with(['article' => function ($query) {
  1842. $query->select('id', 'survey_type','created_at','updated_at','created_at');
  1843. }]);
  1844. ;
  1845. }else{
  1846. $query = ArticleSurvey::select(
  1847. 'art_id as id',
  1848. Db::raw('MAX(id) as surid'),
  1849. Db::raw('MAX(survey_name) as survey_name'),
  1850. Db::raw('MAX(sur_id) as survey_id'),
  1851. )
  1852. ->groupBy('art_id')
  1853. ->when(!is_null($survey_type), function ($q) use ($survey_type) {
  1854. $q->whereIn('art_id', function ($sub) use ($survey_type) {
  1855. $sub->select('id')
  1856. ->from('article')
  1857. ->where('survey_type', $survey_type);
  1858. });
  1859. })
  1860. ->with(['article' => function ($query) {
  1861. $query->select('id', 'survey_type','created_at','updated_at','created_at');
  1862. }]);
  1863. }
  1864. $count = $query->get()->count();
  1865. // 简单写法:直接统计分组后的 art_id 数量
  1866. $survey = $query->orderBy('id', 'desc')
  1867. ->limit($data['pageSize'])
  1868. ->offset(($data['page'] - 1) * $data['pageSize'])
  1869. ->get();
  1870. if (empty($survey->toArray())) {
  1871. return Result::error("暂无调查问卷!", 0);
  1872. }
  1873. $survey = array_map(function ($item) {
  1874. $item['survey_type'] = $item['article']['survey_type'];
  1875. $item['created_at'] = $item['article']['created_at'];
  1876. $item['updated_at'] = $item['article']['updated_at'];
  1877. unset($item['article']);
  1878. return $item;
  1879. }, $survey->toArray());
  1880. $result = [
  1881. 'rows' => $survey,
  1882. 'count' => $count,
  1883. ];
  1884. return Result::success($result);
  1885. }
  1886. /**
  1887. * 后端-获取网站调查问卷详情
  1888. * @param array $data
  1889. * @return array
  1890. */
  1891. public function getSurveyInfo(array $data): array
  1892. {
  1893. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1894. $where = ['sur_id' => $data['sur_id']];
  1895. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1896. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1897. ->select('article_survey.*', 'article.survey_type')
  1898. ->get()->all();
  1899. if (empty($choose)) {
  1900. return Result::error("此调查问卷不存在", 0);
  1901. }
  1902. $resultsArray = array_column($choose, 'results');
  1903. $total = array_sum($resultsArray);
  1904. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1905. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1906. // $total = 0;
  1907. if (!empty($other)) {
  1908. $total = $total + $other['results'];
  1909. $other['choice_name'] = '(其他)';
  1910. if (!empty($others)) {
  1911. $other['hasChildren'] = true;
  1912. // array_push($other,['hasChildren','=',true]);
  1913. $other['children'] = $others;
  1914. $other_choices = [$other->toArray()];
  1915. $mer_choice = array_merge($choose, $other_choices);
  1916. $value_choice = array_values($mer_choice);
  1917. } else {
  1918. // return Result::error('1111');
  1919. $other_choices = [$other->toArray()];
  1920. $other_choices = array_merge($choose, $other_choices);
  1921. $value_choice = array_values($other_choices);
  1922. // return Result::success($result);
  1923. }
  1924. } else {
  1925. $value_choice = $choose;
  1926. }
  1927. $result = [
  1928. 'choose' => $value_choice,
  1929. 'total' => $total,
  1930. ];
  1931. }
  1932. return Result::success($result);
  1933. }
  1934. /**
  1935. * 前端-搜索新闻列表
  1936. * @param array $data
  1937. * @return array
  1938. */
  1939. public function selectWebsiteArticle(array $data): array
  1940. {
  1941. $website = Website::where('id', $data['website_id'])->first();
  1942. if (empty($website)) {
  1943. return Result::error("网站不存在", 0);
  1944. }
  1945. // $website_column = $website['column'];
  1946. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1947. $website_column = json_decode($website['website_column_arr_id'], true);
  1948. }
  1949. $website_id = $data['website_id'];
  1950. $categorys = $this->processArticlePro($website_id);
  1951. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1952. // return Result::success($diff_pid_categoryIds);
  1953. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1954. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1955. }
  1956. // return Result::success(reset($diff_pid_categoryIds) == 0);
  1957. // $cat_1st_arr = $categorys['cat_1st_arr'];
  1958. $catiall = $categorys['catiall'];
  1959. $categoryIds = $categorys['categoryIds'];
  1960. // return Result::success($categoryIds);
  1961. $query = Article::where('status', 1)
  1962. ->whereIn('catid', $categoryIds)
  1963. ->leftJoinSub(function ($query) use ($website_id) {
  1964. $query->from('article_ignore')
  1965. ->where('website_id', $website_id);
  1966. }, 'article_ignore', function ($join) {
  1967. $join->on('article_ignore.article_id', '=', 'article.id');
  1968. })
  1969. ->where(function ($query) {
  1970. $query->whereNull('article_ignore.article_id')
  1971. ->orWhere(function ($subQuery) {
  1972. $subQuery->whereNotNull('article_ignore.article_id')
  1973. ->where('article_ignore.is_ignore', 0)
  1974. ->where(function ($subSubQuery) {
  1975. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1976. ->orWhereNull('article_ignore.c_show_time');
  1977. });
  1978. });
  1979. });
  1980. // ->get()->all();
  1981. // return Result::success($query);
  1982. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1983. $query->whereRaw("JSON_CONTAINS(article.city_arr_id, '" . intval($data['cityid']) . "')");
  1984. }
  1985. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1986. $query->whereRaw("JSON_CONTAINS(article.department_arr_id, '" . intval($data['department_id']) . "')");
  1987. }
  1988. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1989. $query->where('article.title', 'like', '%' . $data['keyword'] . '%');
  1990. }
  1991. // 计算总数
  1992. $count = $query->count();
  1993. // return Result::success($count);
  1994. // 分页查询
  1995. $articles = $query
  1996. ->select(
  1997. 'article.id',
  1998. 'article.title',
  1999. 'article.imgurl',
  2000. 'article.author',
  2001. 'article.updated_at',
  2002. 'article.introduce',
  2003. 'article.islink',
  2004. 'article.linkurl',
  2005. 'article.copyfrom',
  2006. 'article.cat_arr_id',
  2007. 'article.catid',
  2008. 'article.department_arr_id',
  2009. 'article.city_arr_id',
  2010. // 'article_ignore.c_show_time',
  2011. // 'article_ignore.is_ignore'
  2012. )
  2013. ->orderBy("updated_at", "desc")
  2014. ->offset(($data['page'] - 1) * $data['pageSize'])
  2015. ->limit($data['pageSize'])
  2016. ->get();
  2017. // return Result::success($articles);
  2018. foreach ($articles as $k => $v) {
  2019. $articles[$k]->category_name = $catiall[$v->catid]['alias'];
  2020. $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2021. }
  2022. if (empty($articles)) {
  2023. return Result::error("没有符合条件的资讯数据");
  2024. }
  2025. $result = [
  2026. 'rows' => $articles,
  2027. 'count' => $count,
  2028. ];
  2029. return Result::success($result);
  2030. }
  2031. /**
  2032. * 模块新闻加强版
  2033. * @param array $data
  2034. * @return array
  2035. */
  2036. public function getWebsiteCatidArticle(array $data): array
  2037. {
  2038. $where = [
  2039. 'website_category.category_id' => $data['catid'],
  2040. 'website_category.website_id' => $data['website_id'],
  2041. ];
  2042. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  2043. $child_catnum = $data['child_catnum'] ?? 1;
  2044. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  2045. $childCategoryIds = array_column($category['child'], 'category_id');
  2046. if (empty($childCategoryIds)) {
  2047. return Result::error("暂无子栏目", 0);
  2048. }
  2049. $imgArticles = [];
  2050. $textArticles = [];
  2051. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  2052. // 初始化子分类图片新闻和文字新闻数组
  2053. // 查询所有子级栏目的图文新闻
  2054. $imgArticles = Article::where('catid', $childCategoryIds[0])
  2055. ->where(function ($query) use ($data) {
  2056. $query->where(function ($subQuery) use ($data) {
  2057. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  2058. })->orWhereNull("ignore_ids");
  2059. })
  2060. ->where('status', 1)
  2061. ->where('imgurl', '!=', '')
  2062. ->select('*')
  2063. ->orderBy('updated_at', 'desc')
  2064. ->limit($data['child_imgnum'])
  2065. ->get();
  2066. }
  2067. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  2068. // 查询所有子级栏目的文字新闻
  2069. $textArticles = Article::where('catid', $childCategoryIds[0])
  2070. ->where('status', 1)
  2071. ->where(function ($query) use ($data) {
  2072. $query->where(function ($subQuery) use ($data) {
  2073. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  2074. })->orWhereNull("ignore_ids");
  2075. })
  2076. ->select('*')
  2077. ->orderBy('updated_at', 'desc')
  2078. ->limit($data['child_textnum'])
  2079. ->get();
  2080. }
  2081. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  2082. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  2083. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  2084. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  2085. return $child;
  2086. }, $category['child']);
  2087. }
  2088. // }
  2089. if (isset($data['img_num']) && !empty($data['img_num'])) {
  2090. $category['img'] = WebsiteCategory::where($where)
  2091. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  2092. ->where('article.status', 1)
  2093. ->where('article.imgurl', '!=', '')
  2094. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  2095. ->orderBy('article.updated_at', 'desc')
  2096. ->limit($data['img_num'])
  2097. ->get();
  2098. }
  2099. if (isset($data['text_num']) && !empty($data['text_num'])) {
  2100. $category['text'] = WebsiteCategory::where($where)
  2101. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  2102. ->where('article.status', 1)
  2103. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  2104. ->orderBy('article.updated_at', 'desc')
  2105. ->limit($data['text_num'])
  2106. ->get();
  2107. }
  2108. // $category = $category->get();
  2109. if (empty($category)) {
  2110. return Result::error("查询失败", 0);
  2111. }
  2112. return Result::success($category);
  2113. }
  2114. /**
  2115. * 模块新闻加强plus版
  2116. * @param array $data
  2117. * @return array
  2118. */
  2119. public function getWebsiteAllArticle(array $data): array
  2120. {
  2121. // return Result::success($data);
  2122. $time1 = microtime(true);
  2123. $wetbsite_id = $data['website_id'] ?? 2;
  2124. $data = json_decode($data['id'], true);
  2125. $website = Website::where('id', $wetbsite_id)->first();
  2126. if (empty($website)) {
  2127. return Result::error("网站不存在", 0);
  2128. }
  2129. // return Result::success($website);
  2130. $website_column = $website['website_column_arr_id'] ?? '[]';
  2131. $website_column = json_decode($website_column, true);
  2132. $categorys = $this->processArticlePro($wetbsite_id);
  2133. $cat_1st_arr = $categorys['cat_1st_arr'];
  2134. $catiall = $categorys['catiall'];
  2135. // return Result::success($catiall);
  2136. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  2137. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2138. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2139. }
  2140. $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
  2141. // return Result::success($categorys);
  2142. $parent_category = array_column($data, 'parent');
  2143. $parent_cat = [];
  2144. $child_category = array_column($data, 'child');
  2145. if (!empty($parent_category)) {
  2146. foreach ($parent_category as $key => $value) {
  2147. $arr = array_map('intval', explode(',', $value));
  2148. $parent_cat[$key] = $arr[0] ?? 0;
  2149. $parent_category = $arr[0] ?? 0;
  2150. $article_imgnum = $arr[1] ?? 0;
  2151. $article_textnum = $arr[2] ?? 0;
  2152. if ($parent_category != 0) {
  2153. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2154. // return Result::success($category_arr);
  2155. if ($article_imgnum != 0) {
  2156. $img_article = Article::whereIn('catid', $category_arr)
  2157. ->where('status', 1)
  2158. ->where('imgurl', '!=', '')
  2159. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2160. $query->from('article_ignore')
  2161. ->where('website_id', $wetbsite_id);
  2162. }, 'article_ignore', function ($join) {
  2163. $join->on('article_ignore.article_id', '=', 'article.id');
  2164. })
  2165. ->where(function ($query) {
  2166. $query->whereNull('article_ignore.article_id')
  2167. ->orWhere(function ($subQuery) {
  2168. $subQuery->whereNotNull('article_ignore.article_id')
  2169. ->where('article_ignore.is_ignore', 0)
  2170. ->where(function ($subSubQuery) {
  2171. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2172. ->orWhereNull('article_ignore.c_show_time');
  2173. });
  2174. });
  2175. })
  2176. ->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')
  2177. ->orderBy('updated_at', 'desc')
  2178. ->limit($article_imgnum)
  2179. ->get()->all();
  2180. foreach ($img_article as $k => $v) {
  2181. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2182. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2183. }
  2184. } else {
  2185. $img_article = [];
  2186. }
  2187. if ($article_textnum != 0) {
  2188. $text_article = Article::whereIn('catid', $category_arr)
  2189. ->where('status', 1)
  2190. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2191. $query->from('article_ignore')
  2192. ->where('website_id', $wetbsite_id);
  2193. }, 'article_ignore', function ($join) {
  2194. $join->on('article_ignore.article_id', '=', 'article.id');
  2195. })
  2196. ->where(function ($query) {
  2197. $query->whereNull('article_ignore.article_id')
  2198. ->orWhere(function ($subQuery) {
  2199. $subQuery->whereNotNull('article_ignore.article_id')
  2200. ->where('article_ignore.is_ignore', 0)
  2201. ->where(function ($subSubQuery) {
  2202. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2203. ->orWhereNull('article_ignore.c_show_time');
  2204. });
  2205. });
  2206. })
  2207. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2208. ->orderBy('updated_at', 'desc')
  2209. ->limit($article_textnum)
  2210. ->get()->all();
  2211. foreach ($text_article as $k => $v) {
  2212. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2213. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2214. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2215. }
  2216. } else {
  2217. $text_article = [];
  2218. }
  2219. $catiall[$parent_category]['imgnum'] = $img_article;
  2220. $catiall[$parent_category]['textnum'] = $text_article;
  2221. $parent[$key] = $catiall[$parent_category];
  2222. } else {
  2223. $parent[$key] = '';
  2224. }
  2225. }
  2226. }
  2227. if (!empty($child_category)) {
  2228. foreach ($child_category as $key => $value) {
  2229. $arr = array_map('intval', explode(',', $value));
  2230. $parent_category = $parent_cat[$key];
  2231. $child_category = $arr[0] ?? 0;
  2232. $article_imgnum = $arr[1] ?? 0;
  2233. $article_textnum = $arr[2] ?? 0;
  2234. if ($child_category != 0) {
  2235. $all_childcat = $cat_1st_arr[$parent_category];
  2236. $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
  2237. // 从 $websiteInfoIndexed 中获取对应的数据
  2238. $info = $websiteInfoIndexed[$v];
  2239. // 返回一个包含所需信息的数组
  2240. return [
  2241. 'alias' => $info->alias,
  2242. 'category_id' => $info->category_id,
  2243. 'aLIas_pinyin' => $info->aLIas_pinyin,
  2244. 'pid' => $info->pid,
  2245. 'type' => $info->type,
  2246. 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
  2247. 'pinyin' => $info->pinyin,
  2248. ];
  2249. }, $all_childcat);
  2250. if ($article_imgnum != 0) {
  2251. $img_article = Article::where('catid', $child_category)
  2252. ->where('status', 1)
  2253. ->where('imgurl', '!=', '')
  2254. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2255. $query->from('article_ignore')
  2256. ->where('website_id', $wetbsite_id);
  2257. }, 'article_ignore', function ($join) {
  2258. $join->on('article_ignore.article_id', '=', 'article.id');
  2259. })
  2260. ->where(function ($query) {
  2261. $query->whereNull('article_ignore.article_id')
  2262. ->orWhere(function ($subQuery) {
  2263. $subQuery->whereNotNull('article_ignore.article_id')
  2264. ->where('article_ignore.is_ignore', 0)
  2265. ->where(function ($subSubQuery) {
  2266. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2267. ->orWhereNull('article_ignore.c_show_time');
  2268. });
  2269. });
  2270. })
  2271. ->select('id', 'title', 'imgurl', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2272. ->orderBy('updated_at', 'desc')
  2273. ->limit($article_imgnum)
  2274. ->get()->all();
  2275. foreach ($img_article as $k => $v) {
  2276. // var_dump($v);
  2277. // var_dump($k);
  2278. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2279. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2280. }
  2281. } else {
  2282. $img_article = [];
  2283. }
  2284. if ($article_textnum != 0) {
  2285. $text_article = Article::where('catid', $child_category)
  2286. ->where('status', 1)
  2287. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2288. $query->from('article_ignore')
  2289. ->where('website_id', $wetbsite_id);
  2290. }, 'article_ignore', function ($join) {
  2291. $join->on('article_ignore.article_id', '=', 'article.id');
  2292. })
  2293. ->where(function ($query) {
  2294. $query->whereNull('article_ignore.article_id')
  2295. ->orWhere(function ($subQuery) {
  2296. $subQuery->whereNotNull('article_ignore.article_id')
  2297. ->where('article_ignore.is_ignore', 0)
  2298. ->where(function ($subSubQuery) {
  2299. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2300. ->orWhereNull('article_ignore.c_show_time');
  2301. });
  2302. });
  2303. })
  2304. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2305. ->orderBy('updated_at', 'desc')
  2306. ->limit($article_textnum)
  2307. ->get()->all();
  2308. foreach ($text_article as $k => $v) {
  2309. // var_dump($v);
  2310. // var_dump($k);
  2311. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2312. // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2313. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2314. }
  2315. } else {
  2316. $text_article = [];
  2317. }
  2318. $catiall[$child_category]['all_childcat'] = $processedChildCat;
  2319. $catiall[$child_category]['imgnum'] = $img_article;
  2320. $catiall[$child_category]['textnum'] = $text_article;
  2321. $child[$key] = $catiall[$child_category];
  2322. // var_dump($pids);
  2323. } else {
  2324. $child[$key] = '';
  2325. }
  2326. }
  2327. }
  2328. foreach ($parent as $key => $value) {
  2329. $result[$key] = $value;
  2330. if (!empty($child[$key])) {
  2331. // var_dump($child[$key]);
  2332. $result[$key]['child'] = $child[$key];
  2333. // $value[$key]['child'] = $child[$key];
  2334. } else {
  2335. $result[$key]['child'] = [
  2336. "alias" => null,
  2337. "category_id" => null,
  2338. "type" => null,
  2339. "pinyin" => null,
  2340. "all_childcat" => [],
  2341. "imgnum" => [],
  2342. "textnum" => []
  2343. ];
  2344. }
  2345. }
  2346. return Result::success($result);
  2347. }
  2348. /**
  2349. * 辅助方法:获取文章列表
  2350. */
  2351. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  2352. {
  2353. sleep(1);
  2354. $query = Article::where('article.status', 1)
  2355. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  2356. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  2357. ->where(function ($query) use ($website) {
  2358. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  2359. })
  2360. ->leftJoin('website_category', function ($join) use ($website) {
  2361. $join->on('article.catid', '=', 'website_category.category_id')
  2362. ->where('website_category.website_id', '=', $website['website_id']);
  2363. })
  2364. ->select(
  2365. 'article.id',
  2366. 'article.title',
  2367. 'article.imgurl',
  2368. 'article.author',
  2369. 'article.updated_at',
  2370. 'article.introduce',
  2371. 'article.islink',
  2372. 'article.linkurl',
  2373. 'article.copyfrom',
  2374. 'article.cat_arr_id',
  2375. 'article.catid',
  2376. 'website_category.alias as category_name'
  2377. )
  2378. ->orderBy('updated_at', 'desc')
  2379. ->limit($limit);
  2380. // 如果是图片文章,添加图片URL条件
  2381. if ($isImageArticle) {
  2382. $query->where('imgurl', '!=', '');
  2383. } else {
  2384. // 文字文章不需要imgurl字段
  2385. $query->addSelect('article.introduce');
  2386. }
  2387. $articles = $query->get();
  2388. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  2389. }
  2390. /**
  2391. * 乡村网-获取特殊新闻模块
  2392. * @param array $data
  2393. * @return array
  2394. */
  2395. public function getWebsiteArticles(array $data): array
  2396. {
  2397. $website_id = $data['website_id'];
  2398. $website = Website::where('id', $website_id)->first();
  2399. if (empty($website)) {
  2400. return Result::error("网站不存在", 0);
  2401. }
  2402. // return Result::success($website);
  2403. $website_column = $website['website_column_arr_id'] ?? '[]';
  2404. $website_column = json_decode($website_column, true);
  2405. $catids = json_decode($data['id'], true);
  2406. $parent_category = array_column($catids, 'parent');
  2407. if (!empty($parent_category) && is_array($parent_category)) {
  2408. $categorys = $this->processArticlePro($website_id);
  2409. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  2410. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2411. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2412. }
  2413. $catiall = $categorys['catiall'];
  2414. $cat_1st_arr = $categorys['cat_1st_arr'];
  2415. // return Result::success($categorys);
  2416. foreach ($parent_category as $key => $value) {
  2417. $arr = array_map('intval', explode(',', $value));
  2418. $parent_category = $arr[0] ?? 0;
  2419. $article_imgnum = $arr[1] ?? 0;
  2420. $article_textnum = $arr[2] ?? 0;
  2421. if ($parent_category != 0) {
  2422. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2423. // return Result::success($category_arr);
  2424. if ($article_imgnum != 0) {
  2425. $img_article = Article::whereIn('article.catid', $category_arr)
  2426. ->where('article.status', 1)
  2427. ->where('article.imgurl', '!=', '')
  2428. ->leftJoinSub(function ($query) use ($website_id) {
  2429. $query->from('article_ignore')
  2430. ->where('website_id', $website_id);
  2431. }, 'article_ignore', function ($join) {
  2432. $join->on('article_ignore.article_id', '=', 'article.id');
  2433. })
  2434. ->where(function ($query) {
  2435. $query->whereNull('article_ignore.article_id')
  2436. ->orWhere(function ($subQuery) {
  2437. $subQuery->whereNotNull('article_ignore.article_id')
  2438. ->where('article_ignore.is_ignore', 0)
  2439. ->where(function ($subSubQuery) {
  2440. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2441. ->orWhereNull('article_ignore.c_show_time');
  2442. });
  2443. });
  2444. })
  2445. ->select(
  2446. 'article.id',
  2447. 'article.title',
  2448. 'article.imgurl',
  2449. 'article.author',
  2450. 'article.updated_at',
  2451. 'article.introduce',
  2452. 'article.islink',
  2453. 'article.linkurl',
  2454. 'article.copyfrom',
  2455. 'article.cat_arr_id',
  2456. 'article.catid as category_id'
  2457. )
  2458. ->orderBy('updated_at', 'desc')
  2459. ->limit($article_imgnum)
  2460. ->get()->all();
  2461. foreach ($img_article as $k => $v) {
  2462. $img_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2463. // return Result::success($v);
  2464. $img_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2465. }
  2466. } else {
  2467. $img_article = [];
  2468. }
  2469. if ($article_textnum != 0) {
  2470. $text_article = Article::whereIn('article.catid', $category_arr)
  2471. ->where('article.status', 1)
  2472. ->leftJoinSub(function ($query) use ($website_id) {
  2473. $query->from('article_ignore')
  2474. ->where('website_id', $website_id);
  2475. }, 'article_ignore', function ($join) {
  2476. $join->on('article_ignore.article_id', '=', 'article.id');
  2477. })
  2478. ->where(function ($query) {
  2479. $query->whereNull('article_ignore.article_id')
  2480. ->orWhere(function ($subQuery) {
  2481. $subQuery->whereNotNull('article_ignore.article_id')
  2482. ->where('article_ignore.is_ignore', 0)
  2483. ->where(function ($subSubQuery) {
  2484. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2485. ->orWhereNull('article_ignore.c_show_time');
  2486. });
  2487. });
  2488. })
  2489. ->select(
  2490. 'article.id',
  2491. 'article.title',
  2492. 'article.author',
  2493. 'article.updated_at',
  2494. 'article.introduce',
  2495. 'article.islink',
  2496. 'article.linkurl',
  2497. 'article.copyfrom',
  2498. 'article.cat_arr_id',
  2499. 'article.catid as category_id'
  2500. )
  2501. ->orderBy('updated_at', 'desc')
  2502. ->limit($article_textnum)
  2503. ->get()->all();
  2504. foreach ($text_article as $k => $v) {
  2505. $text_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2506. $text_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2507. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2508. }
  2509. } else {
  2510. $text_article = [];
  2511. }
  2512. $catiall[$parent_category]['imgnum'] = $img_article ?? [];
  2513. $catiall[$parent_category]['textnum'] = $text_article ?? [];
  2514. $parent[$key] = $catiall[$parent_category];
  2515. } else {
  2516. $parent[$key] = [];
  2517. }
  2518. }
  2519. }
  2520. return Result::success($parent);
  2521. }
  2522. // 封装处理商品的路由问题
  2523. function processGoods($goods, $data)
  2524. {
  2525. return $goods->map(function ($good) use ($data) {
  2526. $catid = $good->catid ?? 0;
  2527. // $pinyin = '';
  2528. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2529. if (!empty($category->pid) && $category->pid != 0) {
  2530. $level = json_decode($category->category_arr_id, true);
  2531. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  2532. ->whereIn('category_id', $level)
  2533. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2534. ->get(['aLIas_pinyin'])
  2535. ->pluck('aLIas_pinyin')
  2536. ->implode('/');
  2537. } else {
  2538. $pinyin = $category->aLIas_pinyin ?? '';
  2539. }
  2540. if (isset($good->city_id) && !empty($good->city_id)) {
  2541. $city = District::where('id', $good->city_id)->first(['name']);
  2542. $good->city_name = $city->name ?? '';
  2543. }
  2544. // 解析imgurl JSON并取第一条数据
  2545. $imgUrls = json_decode($good->imgurl, true);
  2546. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  2547. $good->pinyin = $pinyin;
  2548. return $good;
  2549. });
  2550. }
  2551. /**
  2552. * 获取商城首页-根据栏目id
  2553. * @param array $data
  2554. * @return array
  2555. * */
  2556. function getWebsiteCatidshop(array $data): array
  2557. {
  2558. $input['catid'] = $data['catid'];
  2559. $input['website_id'] = $data['website_id'];
  2560. $data = json_decode($input['catid'] ?? '', true) ?? [];
  2561. $result = array_map(function ($item) use ($input) {
  2562. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  2563. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  2564. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  2565. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  2566. if (empty($category) || $category->type != 2) {
  2567. return Result::error("暂无此栏目", 0);
  2568. } else {
  2569. $website['website_id'] = $input['website_id'];
  2570. $goods = Good::where('good.status', 2)
  2571. ->where('good.website_id', $website['website_id'])
  2572. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  2573. ->select(
  2574. 'good.id',
  2575. 'good.name',
  2576. 'good.imgurl',
  2577. 'good.description',
  2578. 'good.updated_at',
  2579. 'good.catid',
  2580. 'good.type_id',
  2581. 'good.price',
  2582. 'good.com',
  2583. 'good.level',
  2584. 'good.unit'
  2585. )
  2586. ->orderBy('updated_at', 'desc')
  2587. ->offset($goodStart)
  2588. ->limit($goodNum);
  2589. $all_goods = $goods->get();
  2590. $all_goods = $this->processGoods($all_goods, $website);
  2591. }
  2592. return $all_goods ?? [];
  2593. }
  2594. }, $data);
  2595. return Result::success($result);
  2596. }
  2597. /**
  2598. * 获取商品模块
  2599. * @param array $data
  2600. * @return array
  2601. * */
  2602. public function getWebsiteshop(array $data): array
  2603. {
  2604. $input['id'] = $data['id'];
  2605. $input['website_id'] = $data['website_id'];
  2606. $catid = $data['catid'];
  2607. $data = json_decode($input['id'] ?? '', true) ?? [];
  2608. $result['goods'] = array_map(function ($item) use ($input) {
  2609. // 检查parent元素是否存在且不是undefined
  2610. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  2611. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  2612. $website = $input['website_id'];
  2613. $query = Good::where('good.status', 2)
  2614. ->where('good.website_id', $website);
  2615. switch ($Levelid) {
  2616. case 1:
  2617. case 2:
  2618. case 3:
  2619. $goods = $query->where(function ($q) use ($Levelid) {
  2620. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  2621. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  2622. });
  2623. break;
  2624. case 4:
  2625. $goods = $query;
  2626. break;
  2627. case 5:
  2628. $goods = $query->where('type_id', 1);
  2629. break;
  2630. case 6:
  2631. $goods = $query->where('type_id', 2);
  2632. break;
  2633. default:
  2634. return [];
  2635. }
  2636. $all_goods = $goods
  2637. ->select(
  2638. 'good.id',
  2639. 'good.name',
  2640. 'good.imgurl',
  2641. 'good.description',
  2642. 'good.updated_at',
  2643. 'good.catid',
  2644. 'good.type_id',
  2645. 'good.price',
  2646. 'good.level',
  2647. 'good.website_id'
  2648. )
  2649. ->orderBy('updated_at', 'desc')
  2650. ->offset($goodStart)
  2651. ->limit($goodNum)
  2652. ->get();
  2653. $web['website_id'] = $website;
  2654. $all_goods = $this->processGoods($all_goods, $web);
  2655. }
  2656. return $all_goods;
  2657. }, $data);
  2658. $website = $input['website_id'];
  2659. $result['article'] = Article::where(function ($query) use ($website) {
  2660. $query->where(function ($subQuery) use ($website) {
  2661. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  2662. })->orWhereNull("ignore_ids");
  2663. })
  2664. ->where('catid', $catid)
  2665. ->where('article.status', 1)
  2666. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  2667. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  2668. ->orderBy('article.updated_at', 'desc')
  2669. ->first();
  2670. return Result::success($result);
  2671. }
  2672. /**
  2673. * 获取商品分类
  2674. * @param array $data
  2675. * @return array
  2676. * */
  2677. public function getWebsiteshopCat(array $data): array
  2678. {
  2679. $website = $data['website_id'];
  2680. $category = WebsiteCategory::where('website_id', $website)
  2681. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  2682. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  2683. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  2684. ->orderBy('sort')
  2685. ->get();
  2686. $cat = $category->map(function ($item) use ($website) {
  2687. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  2688. $pid = $item->pid ?? 0;
  2689. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  2690. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  2691. ->where('website_id', $website)
  2692. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  2693. ->get(['aLIas_pinyin'])
  2694. ->pluck('aLIas_pinyin')
  2695. ->implode('/');
  2696. } else {
  2697. $pinyin = $item->aLIas_pinyin ?? '';
  2698. }
  2699. $item->pinyin = $pinyin;
  2700. });
  2701. if (empty($category)) {
  2702. return Result::error("栏目查询失败", 0);
  2703. }
  2704. $cat_tree = Result::buildMenuTree($category);
  2705. $web['website_id'] = $website;
  2706. $goods = Good::where('website_id', $website)
  2707. ->where('status', 2)
  2708. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  2709. ->latest('updated_at')
  2710. ->offset(($data['page'] - 1) * $data['pageSize'])
  2711. ->limit($data['pageSize'])
  2712. ->get();
  2713. if (!empty($goods)) {
  2714. if ($goods->count() > 1 && !empty($goods)) {
  2715. $goods = $this->processGoods($goods, $web);
  2716. }
  2717. } else {
  2718. $goods = [];
  2719. }
  2720. $result = [
  2721. 'category' => $cat_tree,
  2722. 'goods' => $goods,
  2723. ];
  2724. // $resul['goods'] = $goods;
  2725. if (empty($result)) {
  2726. return Result::error("查询失败", 0);
  2727. }
  2728. return Result::success($result);
  2729. }
  2730. /*
  2731. * 获取商品列表
  2732. * @param array $data
  2733. * @return array
  2734. * */
  2735. public function getWebsiteshopList(array $data): array
  2736. {
  2737. // return Result::success($data);
  2738. $where = [
  2739. 'status' => 2,
  2740. 'website_id' => $data['website_id'],
  2741. ];
  2742. // if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  2743. // return Result::error("查询失败", 0);
  2744. // }
  2745. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  2746. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  2747. $data['catid'] = $category->category_id ?? 0;
  2748. }
  2749. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2750. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  2751. }
  2752. if (isset($data['type_id']) && !empty($data['type_id'])) {
  2753. array_push($where, ['type_id', $data['type_id']]);
  2754. }
  2755. $query = Good::where($where)
  2756. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2757. $query->where(function ($q) use ($data) {
  2758. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  2759. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  2760. });
  2761. })
  2762. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2763. $query->where(function ($q) use ($data) {
  2764. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  2765. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  2766. });
  2767. })
  2768. ->select(
  2769. 'good.id',
  2770. 'good.name',
  2771. 'good.imgurl',
  2772. 'good.description',
  2773. 'good.updated_at',
  2774. 'good.com',
  2775. 'good.catid',
  2776. 'good.type_id',
  2777. 'good.website_id',
  2778. 'good.cat_arr_id',
  2779. 'good.created_at',
  2780. 'good.city_id'
  2781. )
  2782. ->latest('updated_at');
  2783. if (isset($data['ismix']) && $data['ismix'] == 1) {
  2784. $result['count'] = $query->clone()->count();
  2785. $result['goods'] = $this->processGoods(
  2786. $query->clone()
  2787. ->offset(($data['page'] - 1) * $data['pageSize'])
  2788. ->limit($data['pageSize'])
  2789. ->get(),
  2790. $data
  2791. );
  2792. } else {
  2793. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  2794. // 获取 type_id 为 1 的数据
  2795. $result['type1'] = $this->processGoods(
  2796. $query->clone()
  2797. ->where('type_id', 1)
  2798. ->offset(($data['page'] - 1) * $data['pageSize'])
  2799. ->limit($data['pageSize'])
  2800. ->get(),
  2801. $data
  2802. );
  2803. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2804. // 获取 type_id 为 2 的数据
  2805. $result['type2'] = $this->processGoods(
  2806. $query->clone()
  2807. ->where('type_id', 2)
  2808. ->offset(($data['page'] - 1) * $data['pageSize'])
  2809. ->limit($data['pageSize'])
  2810. ->get(),
  2811. $data
  2812. );
  2813. }
  2814. if (empty($result)) {
  2815. return Result::error("查询失败", 0);
  2816. }
  2817. return Result::success($result);
  2818. }
  2819. /**
  2820. * 获取商品详情
  2821. * @param array $data
  2822. * @return array
  2823. * */
  2824. public function getWebsiteshopInfo(array $data): array
  2825. {
  2826. $where = [
  2827. 'good.status' => 2,
  2828. 'good.website_id' => $data['website_id'],
  2829. 'good.id' => $data['id'],
  2830. ];
  2831. $goods = Good::where($where)
  2832. ->where('good.id', $data['id'])
  2833. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2834. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2835. ->first();
  2836. if (empty($goods)) {
  2837. return Result::error("查询失败", 0);
  2838. }
  2839. $goods->imgurl = json_decode($goods->imgurl, true);
  2840. return Result::success($goods);
  2841. }
  2842. /**
  2843. * plus pro 处理文章路由问题
  2844. */
  2845. function processArticlePro($website_id)
  2846. {
  2847. // $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2848. // // $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2849. // // 取出category_id 对应的aLIas_pinyin
  2850. // $categoryIds = array_column($categorys, 'category_id');
  2851. // $categoryPIds = array_column($categorys, 'pid');
  2852. // $aliasPinyins = array_column($categorys, 'path');
  2853. // $alias = array_column($categorys, 'alias');
  2854. // $cat_arr = array_combine($categoryIds, $aliasPinyins);
  2855. // $cat_alias_arr = array_combine($categoryIds, $categoryPIds);
  2856. // // return Result::success($cat_arr);
  2857. // // $catiall = [];
  2858. // //一级所有子级的记录
  2859. // $cat_alias_arr = array_combine($categoryIds, $alias);
  2860. // return [
  2861. // 'cat_1st_arr' => $cat_alias_arr,
  2862. // 'catiall' => $cat_arr,
  2863. // // 'websiteInfoIndexed' => $websiteInfoIndexed,
  2864. // 'categoryIds' => $categoryIds,
  2865. // ];
  2866. $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2867. $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2868. // 取出category_id 对应的aLIas_pinyin
  2869. $categoryIds = array_column($categorys, 'category_id');
  2870. $categoryPIds = array_values(array_unique(array_filter(array_column($categorys, 'pid'), function ($pid) {
  2871. return $pid != 0;
  2872. })));
  2873. $category_path = array_column($categorys, 'path');
  2874. $cat_arr = array_combine($categoryIds, $category_path);
  2875. // return Result::success(array_diff($categoryIds, $categoryPIds));
  2876. $catiall = [];
  2877. //一级所有子级的记录
  2878. $cat_1st_arr = [];
  2879. foreach ($categorys as $key => $value) {
  2880. // $category_arr_id = json_decode($value->category_arr_id);
  2881. // $pinyin_str = '';
  2882. // // 算出一级 并且算出子级
  2883. if ($value->pid != 0 && in_array($value->pid, $categoryIds)) {
  2884. $cat_1st_arr[$value->pid][] = $value->category_id;
  2885. }
  2886. // foreach ($category_arr_id as $k => $v) {
  2887. // $pinyin_str .= $cat_arr[$v] . '/';
  2888. // }
  2889. // $pinyin_str = rtrim($pinyin_str, '/');
  2890. $catiall[$value->category_id]['alias'] = $value->alias;
  2891. $catiall[$value->category_id]['category_id'] = $value->category_id;
  2892. $catiall[$value->category_id]['type'] = $value->type;
  2893. $catiall[$value->category_id]['pinyin'] = $cat_arr[$value->category_id];
  2894. $websiteInfoIndexed[$value->category_id]->pinyin = $cat_arr[$value->category_id];
  2895. }
  2896. return [
  2897. 'cat_1st_arr' => $cat_1st_arr,
  2898. 'catiall' => $catiall,
  2899. 'websiteInfoIndexed' => $websiteInfoIndexed,
  2900. 'categoryIds' => $categoryIds,
  2901. 'diff_pid_categoryIds' => array_diff($categoryPIds, $categoryIds),
  2902. 'categoryPIds' => $categoryPIds,
  2903. ];
  2904. }
  2905. /**
  2906. * 封装处理文章的路由问题
  2907. * */
  2908. function processArticles($articles, $data)
  2909. {
  2910. // 检查 $articles 是否为数组或可迭代对象
  2911. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  2912. return $articles->map(function ($article) use ($data) {
  2913. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  2914. $catid = $article->cat_arr_id ?? '';
  2915. }
  2916. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  2917. $catid = $article->category_arr_id ?? '';
  2918. }
  2919. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  2920. $level = json_decode($catid, true);
  2921. if (!is_array($level)) {
  2922. return $article;
  2923. } else {
  2924. $level = array_map('intval', $level);
  2925. }
  2926. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2927. ->where($data)
  2928. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2929. ->pluck('aLIas_pinyin')
  2930. ->implode('/');
  2931. $article->pinyin = $pinyin ?? '';
  2932. return $article;
  2933. });
  2934. } else {
  2935. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2936. $catid = $articles->cat_arr_id ?? '';
  2937. $level = json_decode($catid, true);
  2938. if (!is_array($level)) {
  2939. return $articles;
  2940. } else {
  2941. $level = array_map('intval', $level);
  2942. }
  2943. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2944. ->where($data)
  2945. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2946. ->pluck('aLIas_pinyin')
  2947. ->implode('/');
  2948. $articles->pinyin = $pinyin ?? '';
  2949. return $articles;
  2950. }
  2951. }
  2952. // 封装处理由问题
  2953. function processJob($job, $data)
  2954. {
  2955. return $job->map(function ($job) use ($data) {
  2956. $category = $job->cat_arr_id ?? '';
  2957. $cityid = $job->city_arr_id ?? '';
  2958. $city = json_decode($cityid, true);
  2959. $pinyin = '';
  2960. $level = json_decode($category, true);
  2961. // 路由
  2962. if (!empty($level) && is_array($level)) {
  2963. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2964. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2965. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2966. ->get(['aLIas_pinyin'])
  2967. ->pluck('aLIas_pinyin')
  2968. ->implode('/');
  2969. if (empty($pinyin)) {
  2970. $pinyin = $pinyin->aLIas_pinyin ?? '';
  2971. }
  2972. $job->pinyin = $pinyin;
  2973. }
  2974. // 取职位-城市 市??省
  2975. if (!empty($city) && is_array($city)) {
  2976. if (isset($city[1]) && !empty($city[1])) {
  2977. $city = District::where('id', $city[1])->first(['name']);
  2978. $job->city_name = $city->name ?? '';
  2979. } else if (isset($city[0]) && !empty($city[0])) {
  2980. $city = District::where('id', $city[0])->first(['name']);
  2981. $job->city_name = $city->name ?? '';
  2982. } else {
  2983. $job->city_name = '全国';
  2984. }
  2985. }
  2986. // 获取简历最后一级地区
  2987. if (isset($job->city_id) && !empty($job->city_id)) {
  2988. $city = District::where('id', $job->city_id)->first(['name']);
  2989. $job->hunt_cityname = $city->name ?? '';
  2990. }
  2991. // 组合详细地址
  2992. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  2993. $address_id = json_decode($job->address_arr_id, true) ?? [];
  2994. if (is_array($address_id) && !empty($address_id)) {
  2995. $address = District::whereIn('id', $address_id)
  2996. ->orderBy('level', 'asc')
  2997. ->get(['name'])
  2998. ->pluck('name')
  2999. ->implode('');
  3000. // $job->address_name = $address ?? '';
  3001. $job->address_name = ($address ?? '') . ($job->address ?? '');
  3002. }
  3003. }
  3004. // 取行业
  3005. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  3006. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  3007. if (!empty($job->industry)) {
  3008. $query->where('hyid', $job->industry);
  3009. } else if (!empty($job->hy_id)) {
  3010. $query->where('hyid', $job->hy_id);
  3011. } else if (!empty($job->company_hy_id)) {
  3012. $query->where('hyid', $job->company_hy_id);
  3013. } else {
  3014. $query->where('hyid', $job->job_industry);
  3015. }
  3016. })->first(['hyname']);
  3017. $job->hy_name = $hy_name->hyname ?? '';
  3018. }
  3019. // 取职位类别
  3020. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  3021. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  3022. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  3023. $job->zw_name = $zw_name->zwname ?? '';
  3024. }
  3025. // 取具体职位
  3026. 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))) {
  3027. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  3028. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  3029. $job->jtzw_name = $jtzw_name->zwname ?? '';
  3030. }
  3031. // 取工作经验
  3032. if (isset($job->experience) && !empty($job->experience)) {
  3033. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  3034. $job->experience_name = $experience->ename ?? '';
  3035. }
  3036. // 取学历
  3037. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  3038. $education = $job->educational ?? $job->school_education;
  3039. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  3040. $job->education_name = $education->ename ?? '';
  3041. }
  3042. // 语言
  3043. if (isset($job->language) && !empty($job->language)) {
  3044. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  3045. $job->language_name = $language->ename ?? '';
  3046. }
  3047. // 薪资
  3048. if (isset($job->salary) && !empty($job->salary)) {
  3049. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  3050. $job->salary_name = $salary->ename ?? '';
  3051. }
  3052. // 职位性质
  3053. if (isset($job->nature_id) && !empty($job->nature_id)) {
  3054. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  3055. $job->job_nature_name = $job_nature->ename ?? '';
  3056. }
  3057. // 公司规模
  3058. if (isset($job->company_size) && !empty($job->company_size)) {
  3059. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  3060. $job->company_size_name = $company_size->ename ?? '';
  3061. }
  3062. // 公司性质
  3063. if (isset($job->company_nature) && !empty($job->company_nature)) {
  3064. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  3065. $job->company_nature_name = $company_nature->nature_name ?? '';
  3066. }
  3067. // $job->pinyin = $pinyin;
  3068. return $job;
  3069. });
  3070. }
  3071. /**
  3072. * 获取书籍模块
  3073. * @param array $data
  3074. * @return array
  3075. * */
  3076. public function getWebsiteBook(array $data): array
  3077. {
  3078. $input['id'] = $data['id'];
  3079. $input['website_id'] = $data['website_id'];
  3080. // 将 JSON 字符串转换为 PHP 数组
  3081. $data = json_decode($input['id'], true);
  3082. // 使用 array_map 处理每个元素
  3083. $result = array_map(function ($item) use ($input) {
  3084. // 检查parent元素是否存在且不是undefined
  3085. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  3086. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  3087. $website = [
  3088. 'website_id' => $input['website_id'],
  3089. ];
  3090. // 查询栏目名称
  3091. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  3092. if (empty($category)) {
  3093. $parent_alias = '';
  3094. $parent_pinyin = null;
  3095. $imgBooks = [];
  3096. $textBooks = [];
  3097. } else {
  3098. $parent_alias = $category->alias ?? '';
  3099. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  3100. // 查找子分类ID数组
  3101. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  3102. array_push($childCategoryIds, $parentCatId);
  3103. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  3104. if ($parentImgNum != 0) {
  3105. // 查询图片新闻
  3106. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  3107. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  3108. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  3109. })
  3110. ->where('book.status', 2)
  3111. ->where('book.img_url', '!=', '')
  3112. ->where('book.website_id', $website['website_id'])
  3113. ->leftJoin('website_category', function ($join) use ($website) {
  3114. $join->on('book.cat_id', '=', 'website_category.category_id')
  3115. ->where('website_category.website_id', '=', $website['website_id']);
  3116. })
  3117. ->select(
  3118. 'book.id',
  3119. 'book.title',
  3120. 'book.img_url',
  3121. 'book.price',
  3122. 'book.market_price',
  3123. 'book.description',
  3124. 'book.cat_id',
  3125. 'book.description',
  3126. 'book.updated_at',
  3127. 'website_category.alias as category_name',
  3128. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3129. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3130. )
  3131. ->orderBy('updated_at', 'desc')
  3132. ->limit($parentImgNum)
  3133. ->get()->all();
  3134. // 查询文字新闻
  3135. }
  3136. if ($parentTextNum != 0) {
  3137. $textBooks = [];
  3138. $textBooks = Book::where(function ($query) use ($parentCatId) {
  3139. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  3140. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  3141. })
  3142. ->where('book.status', 2)
  3143. ->where('book.website_id', $website['website_id'])
  3144. ->leftJoin('website_category', function ($join) use ($website) {
  3145. $join->on('book.cat_id', '=', 'website_category.category_id')
  3146. ->where('website_category.website_id', '=', $website['website_id']);
  3147. })
  3148. ->select(
  3149. 'book.id',
  3150. 'book.title',
  3151. 'book.img_url',
  3152. 'book.price',
  3153. 'book.market_price',
  3154. 'book.description',
  3155. 'book.cat_id',
  3156. 'book.description',
  3157. 'book.updated_at',
  3158. 'website_category.alias as category_name',
  3159. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3160. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3161. )
  3162. ->orderBy('updated_at', 'desc')
  3163. ->limit($parentTextNum)
  3164. ->get()->all();
  3165. }
  3166. }
  3167. }
  3168. $resultItem = [
  3169. 'alias' => $parent_alias ?? '',
  3170. 'category_id' => $parentCatId ?? 0,
  3171. 'pinyin' => $parent_pinyin ?? null,
  3172. 'imgnum' => $imgBooks ?? [],
  3173. 'textnum' => $textBooks ?? [],
  3174. ];
  3175. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  3176. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  3177. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  3178. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3179. ->get()->all();
  3180. if (!empty($childCategory)) {
  3181. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  3182. // 查询子栏目名称
  3183. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  3184. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3185. ->first();
  3186. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  3187. $childImgArticles = [];
  3188. $childTextArticles = [];
  3189. $resultItem['child'] = [];
  3190. } else {
  3191. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  3192. // 查询子栏目图片新闻
  3193. $childImgArticles = Book::where('cat_id', $childCatId)
  3194. ->where('status', 2)
  3195. ->where('img_url', '!=', '')
  3196. ->where('book.website_id', $website['website_id'])
  3197. ->leftJoin('website_category', function ($join) use ($website) {
  3198. $join->on('book.cat_id', '=', 'website_category.category_id')
  3199. ->where('website_category.website_id', '=', $website['website_id']);
  3200. })
  3201. ->select(
  3202. 'book.id',
  3203. 'book.title',
  3204. 'book.img_url',
  3205. 'book.price',
  3206. 'book.market_price',
  3207. 'book.description',
  3208. 'book.cat_id',
  3209. 'book.description',
  3210. 'book.updated_at',
  3211. DB::raw("'$child_pinyin' as pinyin")
  3212. )
  3213. ->orderBy('updated_at', 'desc')
  3214. ->limit($childImgNum)
  3215. ->get()->all();
  3216. // 查询子栏目文字新闻
  3217. $childTextArticles = Book::where('cat_id', $childCatId)
  3218. ->where('status', 2)
  3219. ->where('book.website_id', $website['website_id'])
  3220. ->leftJoin('website_category', function ($join) use ($website) {
  3221. $join->on('book.cat_id', '=', 'website_category.category_id')
  3222. ->where('website_category.website_id', '=', $website['website_id']);
  3223. })
  3224. ->select(
  3225. 'book.id',
  3226. 'book.title',
  3227. 'book.img_url',
  3228. 'book.price',
  3229. 'book.market_price',
  3230. 'book.description',
  3231. 'book.cat_id',
  3232. 'book.description',
  3233. 'book.updated_at',
  3234. DB::raw("'$child_pinyin' as pinyin")
  3235. )
  3236. ->orderBy('updated_at', 'desc')
  3237. ->limit($childTextNum)
  3238. ->get()->all();
  3239. $resultItem['child'] = [
  3240. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  3241. 'category_id' => $childCatId,
  3242. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  3243. 'all_childcat' => $childCategory,
  3244. 'imgnum' => $childImgArticles,
  3245. 'textnum' => $childTextArticles,
  3246. ];
  3247. }
  3248. }
  3249. } else {
  3250. $resultItem['child'] = [];
  3251. }
  3252. return $resultItem;
  3253. }, $data);
  3254. return Result::success($result);
  3255. }
  3256. /**
  3257. * 获取书刊列表
  3258. * @param array $data
  3259. * @return array
  3260. * */
  3261. public function getWebsiteBookList(array $data): array
  3262. {
  3263. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3264. if (empty($web)) {
  3265. return Result::error("查询失败", 0);
  3266. }
  3267. $catid = $data['id'];
  3268. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  3269. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  3270. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  3271. $category_pinyin = $category ? $category->aLias_pinyin : '';
  3272. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  3273. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  3274. ->where('pid', $category['pid'])
  3275. ->select(
  3276. 'category_id',
  3277. 'alias',
  3278. 'aLIas_pinyin',
  3279. 'pid',
  3280. 'sort',
  3281. 'is_url',
  3282. 'web_url',
  3283. 'seo_title',
  3284. 'seo_keywords',
  3285. 'seo_description',
  3286. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  3287. )
  3288. ->orderBy('sort')
  3289. ->get()->all();
  3290. if (empty($category)) {
  3291. return Result::error("查询失败", 0);
  3292. }
  3293. $query = Book::where('book.status', 2)
  3294. ->where('book.website_id', $data['website_id'])
  3295. ->where('book.cat_id', $catid)
  3296. ->select(
  3297. 'book.id',
  3298. 'book.title',
  3299. 'book.img_url',
  3300. 'book.description',
  3301. 'book.updated_at',
  3302. 'book.cat_id',
  3303. DB::raw("'$pinyin' as pinyin")
  3304. )
  3305. ->orderBy('book.updated_at', 'desc');
  3306. $count = $query->count();
  3307. $query = clone $query;
  3308. $Book = $query
  3309. ->limit($data['pageSize'])
  3310. ->offset(($data['page'] - 1) * $data['pageSize'])
  3311. ->get()->all();
  3312. $result = [
  3313. 'category' => $categorys,
  3314. 'books' => $Book,
  3315. 'count' => $count,
  3316. ];
  3317. // if(empty($result)){
  3318. // return Result::error("查询失败", 0);
  3319. // }
  3320. return Result::success($result);
  3321. }
  3322. /**
  3323. * 获取书刊详情
  3324. * @param array $data
  3325. * @return array
  3326. * */
  3327. public function getWebsiteBookInfo(array $data): array
  3328. {
  3329. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3330. if (empty($web)) {
  3331. return Result::error("查询失败", 0);
  3332. }
  3333. $book = Book::where('status', 2)
  3334. ->where('website_id', $data['website_id'])
  3335. ->where('id', $data['id'])
  3336. ->select(
  3337. 'book.*',
  3338. )
  3339. ->orderBy('updated_at', 'desc')
  3340. ->first();
  3341. if (empty($book)) {
  3342. return Result::error("查询失败", 0);
  3343. }
  3344. // 先查询当前分类的 pid
  3345. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  3346. ->where('category_id', $book['cat_id'])
  3347. ->first(['pid', 'category_id']);
  3348. $query = WebsiteCategory::where('website_id', $data['website_id']);
  3349. if (!empty($carpid)) {
  3350. if ($carpid->pid != 0) {
  3351. $pid = $carpid['pid'];
  3352. // $parent_pinyin = '';
  3353. } else {
  3354. $pid = $carpid['category_id'];
  3355. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  3356. }
  3357. }
  3358. $categorys = $query->where('pid', $pid)
  3359. ->select(
  3360. 'category_id',
  3361. 'alias',
  3362. 'aLIas_pinyin',
  3363. 'pid',
  3364. 'sort',
  3365. 'is_url',
  3366. 'web_url',
  3367. 'category_arr_id as cat_arr_id',
  3368. )
  3369. ->orderBy('sort')
  3370. ->get();
  3371. $category = $this->processArticle($categorys, $data);
  3372. $result = [
  3373. 'category' => $category,
  3374. 'books' => $book,
  3375. ];
  3376. return Result::success($result);
  3377. }
  3378. /**
  3379. * 尝试
  3380. * @param array $data
  3381. * @return array
  3382. * */
  3383. public function test(array $data): array
  3384. {
  3385. $input['id'] = $data['id'];
  3386. $input['website_id'] = $data['website_id'];
  3387. // 将 JSON 字符串转换为 PHP 数组
  3388. $data = json_decode($input['id'], true);
  3389. $result = [];
  3390. $article = $data;
  3391. $result = array_map(function ($item) use ($input) {
  3392. $website = [
  3393. 'website_id' => $input['website_id'],
  3394. ];
  3395. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  3396. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  3397. $parent = [
  3398. 0 => $category['category_id'] ?? [],
  3399. 1 => $parentImgNum ?? [],
  3400. 2 => $parentTextNum ?? [],
  3401. ];
  3402. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  3403. $child = [];
  3404. $resultItem = [
  3405. // 'alias' => $parent_alias ?? '',
  3406. 'category_id' => $parentCatId ?? 0,
  3407. 'pinyin' => $parentImgNum ?? null,
  3408. 'imgnum' => $parentTextNum ?? [],
  3409. // 'textnum' => $textArticles ?? [],
  3410. ];
  3411. return $parent;
  3412. }, $data);
  3413. return Result::success($result);
  3414. // });
  3415. }
  3416. /**
  3417. * 封装处理文章的路由问题
  3418. * */
  3419. function processArticle($article, $data)
  3420. {
  3421. return $article->map(function ($article) use ($data) {
  3422. $catid = $article->cat_arr_id ?? '';
  3423. $level = json_decode($catid, true);
  3424. $pinyin = '';
  3425. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  3426. if (!empty($level) && is_array($level)) {
  3427. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  3428. ->where('website_id', $data['website_id'])
  3429. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  3430. ->get(['aLIas_pinyin'])
  3431. ->pluck('aLIas_pinyin')
  3432. ->implode('/');
  3433. } else {
  3434. $pinyin = '';
  3435. }
  3436. $article->pinyin = $pinyin;
  3437. return $article;
  3438. });
  3439. }
  3440. /**
  3441. * c端-获取招工招聘下拉选框
  3442. * @param array $data
  3443. * @return array
  3444. * */
  3445. public function getWebsiteJobSelect(array $data): array
  3446. {
  3447. $web = Website::where('id', $data['website_id'])->first();
  3448. if (empty($web)) {
  3449. return Result::error("该网站不存在", 0);
  3450. }
  3451. $hy = JobIndustry::get()->all();
  3452. $zw = JobPosition::where('zwpid', 0)->get()->all();
  3453. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  3454. $result = [
  3455. 'hy' => $hy,
  3456. 'zw' => $zw,
  3457. 'jtzw' => $jtzw,
  3458. ];
  3459. if (empty($result)) {
  3460. return Result::error("查询失败", 0);
  3461. }
  3462. return Result::success($result);
  3463. }
  3464. /**
  3465. * c端-获取招工招聘
  3466. * @param array $data
  3467. * @return array
  3468. * */
  3469. public function getWebsiteJob(array $data): array
  3470. {
  3471. $web = Website::where('id', $data['website_id'])->first();
  3472. if (empty($web)) {
  3473. return Result::error("该网站不存在", 0);
  3474. }
  3475. $job_hunting = JobHunting::where('job_hunting.status', 2)
  3476. ->where('job_hunting.website_id', $data['website_id'])
  3477. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3478. $query->where(function ($q) use ($data) {
  3479. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3480. });
  3481. })
  3482. ->select(
  3483. 'job_hunting.id',
  3484. 'job_hunting.catid',
  3485. 'job_hunting.cat_arr_id',
  3486. 'job_hunting.job_name_get',
  3487. 'job_hunting.industry',
  3488. 'job_hunting.name',
  3489. 'job_hunting.sexy',
  3490. 'job_hunting.origin',
  3491. 'job_hunting.city_arr_id',
  3492. 'job_hunting.experience',
  3493. 'job_hunting.updated_at',
  3494. 'job_hunting.salary',
  3495. 'job_hunting.skillList',
  3496. 'job_hunting.slelf_evaluation',
  3497. )
  3498. ->orderBy('updated_at', 'desc')
  3499. ->limit($data['job1_num'])
  3500. ->get();
  3501. $web['website_id'] = $data['website_id'];
  3502. if (empty($job_hunting)) {
  3503. $job_huntings = "未查询到相关简历信息";
  3504. } else {
  3505. $job_huntings = $this->processJob($job_hunting, $web);
  3506. }
  3507. // 0:待审核 1:已通过 2:已拒绝
  3508. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3509. ->where('job_recruiting.website_id', $data['website_id'])
  3510. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3511. $query->where(function ($q) use ($data) {
  3512. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3513. });
  3514. })
  3515. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3516. ->select(
  3517. 'job_recruiting.id',
  3518. 'job_recruiting.catid',
  3519. 'job_recruiting.cat_arr_id',
  3520. 'job_recruiting.title',
  3521. 'job_recruiting.jtzw_id',
  3522. 'job_recruiting.hy_id',
  3523. 'job_recruiting.city_arr_id',
  3524. 'job_recruiting.due_data',
  3525. 'job_recruiting.updated_at',
  3526. 'job_recruiting.experience',
  3527. 'job_recruiting.educational',
  3528. 'job_recruiting.salary',
  3529. 'job_recruiting.zw_id',
  3530. 'job_company.business_name',
  3531. 'job_recruiting.keyword',
  3532. 'job_recruiting.description',
  3533. )
  3534. ->orderBy('updated_at', 'desc')
  3535. ->limit($data['job2_num'])
  3536. ->get();
  3537. if (empty($job_recruiting->toArray())) {
  3538. $job_recruitings = "未查询到相关职位信息";
  3539. } else {
  3540. $job_recruitings = $this->processJob($job_recruiting, $web);
  3541. }
  3542. $result = [
  3543. 'job_hunting' => $job_huntings,
  3544. 'job_recuiting' => $job_recruitings,
  3545. ];
  3546. return Result::success($result);
  3547. }
  3548. /**
  3549. * c端-获取招工招聘列表
  3550. * @param array $data
  3551. * @return array
  3552. * */
  3553. public function getWebsiteJobList(array $data): array
  3554. {
  3555. $recruit_where = [];
  3556. $hunt_where = [];
  3557. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3558. if (empty($web)) {
  3559. return Result::error("此网站不存在", 0);
  3560. }
  3561. $website_id['website_id'] = $data['website_id'];
  3562. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  3563. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3564. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  3565. }
  3566. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3567. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  3568. }
  3569. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3570. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  3571. }
  3572. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3573. array_push($recruit_where, ['title', 'like', '%' . $data['keyword'] . '%']);
  3574. }
  3575. $query = JobRecruiting::where('job_recruiting.status', 1)
  3576. ->where('job_recruiting.website_id', $data['website_id'])
  3577. ->where($recruit_where)
  3578. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3579. $query->where(function ($q) use ($data) {
  3580. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3581. });
  3582. })
  3583. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  3584. $query->where(function ($q) use ($data) {
  3585. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  3586. });
  3587. })
  3588. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3589. ->select(
  3590. 'job_recruiting.id',
  3591. 'job_recruiting.catid',
  3592. 'job_recruiting.hy_id',
  3593. 'job_recruiting.title',
  3594. 'job_recruiting.zw_id',
  3595. 'job_recruiting.educational',
  3596. 'job_recruiting.jtzw_id',
  3597. 'job_recruiting.city_arr_id',
  3598. 'job_recruiting.due_data',
  3599. 'job_recruiting.experience',
  3600. 'job_recruiting.cat_arr_id',
  3601. 'job_recruiting.updated_at',
  3602. 'job_company.business_name',
  3603. 'job_recruiting.keyword',
  3604. 'job_recruiting.description',
  3605. )
  3606. ->orderBy('job_recruiting.updated_at', 'desc');
  3607. $recruit_count = $query->count();
  3608. $query = clone $query;
  3609. $JobRecruiting = $query
  3610. ->offset(($data['page'] - 1) * $data['pageSize'])
  3611. ->limit($data['pageSize'])
  3612. ->get();
  3613. if (empty($JobRecruiting)) {
  3614. $JobRecruiting = "暂无相关职位信息";
  3615. } else {
  3616. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  3617. }
  3618. }
  3619. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  3620. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3621. array_push($hunt_where, ['job_hunting.job', $data['zw_id']]);
  3622. }
  3623. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3624. array_push($hunt_where, ['job_hunting.job_name_get', $data['jtzw_id']]);
  3625. }
  3626. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3627. array_push($hunt_where, ['job_hunting.industry', $data['hy_id']]);
  3628. }
  3629. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3630. array_push($hunt_where, ['job_position.zwname', 'like', '%' . $data['keyword'] . '%']);
  3631. }
  3632. $query = JobHunting::where('job_hunting.status', 2)
  3633. ->where('job_hunting.website_id', $data['website_id'])
  3634. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3635. ->where($hunt_where)
  3636. // ->when(isset($data['keyword']) &&!empty($data['keyword']), function ($query) use ($data) {
  3637. // $query->where('job_position.zwname','like','%'.$data['keyword'].'%');
  3638. // })
  3639. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3640. $query->where(function ($q) use ($data) {
  3641. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3642. });
  3643. })
  3644. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  3645. $query->where(function ($q) use ($data) {
  3646. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  3647. });
  3648. })
  3649. ->select(
  3650. 'job_hunting.id',
  3651. 'job_hunting.catid',
  3652. 'job_hunting.sexy',
  3653. 'job_hunting.experience',
  3654. 'job_hunting.origin',
  3655. 'job_hunting.industry',
  3656. 'job_hunting.name',
  3657. 'job_hunting.job',
  3658. 'job_hunting.job_name_get',
  3659. 'job_hunting.city_arr_id',
  3660. 'job_hunting.cat_arr_id',
  3661. 'job_hunting.created_at',
  3662. 'job_hunting.updated_at',
  3663. 'job_position.zwname as job_name',
  3664. 'job_hunting.skillList',
  3665. 'job_hunting.slelf_evaluation',
  3666. )
  3667. ->orderBy('job_hunting.updated_at', 'desc');
  3668. $hunt_count = $query->count();
  3669. $query = clone $query;
  3670. $JobHunting = $query
  3671. ->offset(($data['page'] - 1) * $data['pageSize'])
  3672. ->limit($data['pageSize'])
  3673. ->get();
  3674. if (empty($JobHunting)) {
  3675. $JobRecruiting = "暂无相关简历信息";
  3676. } else {
  3677. $JobHunting = $this->processJob($JobHunting, $website_id);
  3678. }
  3679. }
  3680. $result = [
  3681. 'JobRecruiting' => $JobRecruiting ?? [],
  3682. 'recruit_count' => $recruit_count ?? 0,
  3683. 'JobHunting' => $JobHunting ?? [],
  3684. 'hunt_count' => $hunt_count ?? 0,
  3685. ];
  3686. return Result::success($result);
  3687. }
  3688. /**
  3689. * c端-获取招工招聘详情
  3690. * @param array $data
  3691. * @return array
  3692. * */
  3693. public function getWebsiteJobInfo(array $data): array
  3694. {
  3695. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3696. if (empty($web)) {
  3697. return Result::error("该网站不存在", 0);
  3698. }
  3699. $webid = [
  3700. 'website_id' => $data['website_id'],
  3701. ];
  3702. // 职位相关信息
  3703. if ($data['type'] == 1) {
  3704. $query = JobRecruiting::where('status', 1)
  3705. ->where('website_id', $data['website_id'])
  3706. ->select('*');
  3707. $job = $query->where('job_recruiting.id', $data['id'])->get();
  3708. $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();
  3709. if (!empty($company)) {
  3710. $result['company'] = $this->processJob($company, $webid);
  3711. }
  3712. $other_job = JobRecruiting::where('status', 1)
  3713. ->where('website_id', $data['website_id'])
  3714. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  3715. ->where('id', '!=', $data['id'])
  3716. ->where('user_id', '=', $job[0]['user_id'])
  3717. ->limit($data['pageSize'])
  3718. ->get();
  3719. if (!empty($other_job)) {
  3720. $result['other_job'] = $this->processJob($other_job, $webid);
  3721. }
  3722. } else {
  3723. // 简历相关信息
  3724. $job = JobHunting::where('job_hunting.status', 2)
  3725. ->where('job_hunting.website_id', $data['website_id'])
  3726. ->where('job_hunting.id', $data['id'])
  3727. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3728. ->select('job_hunting.*', 'user_name')
  3729. ->get();
  3730. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  3731. if (!empty($resume->toArray())) {
  3732. $result['resume'] = 1;
  3733. } else {
  3734. $result['resume'] = 0;
  3735. }
  3736. }
  3737. if (empty($job->toArray())) {
  3738. return Result::error("id参数错误", 0);
  3739. }
  3740. if (!empty($job[0]['job_experience'])) {
  3741. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  3742. if (!empty($job_experience)) {
  3743. // $hy = [];
  3744. foreach ($job_experience as $key => $value) {
  3745. // $id = $value['id'];
  3746. $hy[$key] = $value['job_industry'];
  3747. $zw_id[$key] = $value['job_typename'];
  3748. $jtzw_id[$key] = $value['job_name'];
  3749. }
  3750. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  3751. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  3752. // 先将关联表转换为索引数组,提高查找效率
  3753. $hyLookup = [];
  3754. foreach ($hy_table as $item) {
  3755. $hyLookup[$item['hyid']] = $item['hyname'];
  3756. }
  3757. $zwLookup = [];
  3758. foreach ($zw_table as $item) {
  3759. $zwLookup[$item['zwid']] = $item['zwname'];
  3760. }
  3761. foreach ($job_experience as $key => &$value) {
  3762. // 处理行业名称
  3763. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  3764. $value['hy_name'] = $hyLookup[$hy[$key]];
  3765. }
  3766. // 处理职位名称
  3767. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  3768. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  3769. }
  3770. // 处理具体职位名称
  3771. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  3772. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  3773. }
  3774. }
  3775. // 释放引用,防止意外修改后续代码
  3776. unset($value);
  3777. }
  3778. $result['job_experience'] = $job_experience ?? [];
  3779. }
  3780. if (!empty($job[0]['education_experience'])) {
  3781. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  3782. if (!empty($education_experience)) {
  3783. foreach ($education_experience as $key => $value) {
  3784. // $id = $value['id'];
  3785. $education[$key] = $value['school_education'];
  3786. }
  3787. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  3788. // // 先将关联表转换为索引数组,提高查找效率
  3789. $educationLookup = [];
  3790. foreach ($education_table as $item) {
  3791. $educationLookup[$item['evalue']] = $item['ename'];
  3792. }
  3793. foreach ($education_experience as $key => &$value) {
  3794. // 处理学历名称
  3795. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  3796. $value['education_name'] = $educationLookup[$education[$key]];
  3797. }
  3798. }
  3799. }
  3800. $result['education_experience'] = $job_experience ?? [];
  3801. }
  3802. $result['job'] = $this->processJob($job, $webid);
  3803. // // 返现对应的栏目
  3804. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  3805. $category = WebsiteCategory::where('website_id', $data['website_id'])
  3806. ->whereIn('category_id', $catid)
  3807. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  3808. ->orderBy('pid')->get()->all();
  3809. if (!empty($category)) {
  3810. $result['category'] = $category;
  3811. }
  3812. $result['job'] = $job;
  3813. $result['job_experience'] = $job_experience ?? [];
  3814. $result['education_experience'] = $education_experience ?? [];
  3815. if (empty($result)) {
  3816. return Result::error("参数错误", 0);
  3817. }
  3818. return Result::success($result);
  3819. }
  3820. /**
  3821. * c端-申请职位
  3822. * @param array $data
  3823. * @return array
  3824. * */
  3825. public function getWebsiteJobApply(array $data): array
  3826. {
  3827. // 首先验证网站是否存在
  3828. // return Result::success($data);
  3829. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3830. if (empty($web)) {
  3831. return Result::error("该网站不存在", 0);
  3832. }
  3833. // 验证用户是否存在且为个人会员/管理员
  3834. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3835. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3836. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  3837. return Result::error("用户不存在", 0);
  3838. }
  3839. // 去除重复元素和空元素,并保持原始顺序
  3840. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  3841. return !empty($value);
  3842. }));
  3843. // 验证职位是否存在 1:审核通过
  3844. $recruiting = JobRecruiting::where('status', 1)
  3845. ->where('website_id', $data['website_id'])
  3846. ->whereIn('id', $data['recruit_id'])
  3847. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  3848. if (empty($recruiting)) {
  3849. return Result::error("该职位不存在", 0);
  3850. }
  3851. // 简历是否存在
  3852. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  3853. if (empty($hunt_id)) {
  3854. return Result::error("该简历不存在", 0);
  3855. }
  3856. $data['hunt_id'] = $hunt_id['hunt_id'];
  3857. // // 验证是否已投递过该职位
  3858. $apply = JobApply::where('user_id', $data['user_id'])
  3859. ->where('hunt_id', $data['hunt_id'])
  3860. ->where('website_id', $data['website_id'])
  3861. ->whereIn('recruit_id', $data['recruit_id'])
  3862. ->get(['recruit_id']);
  3863. if (!empty($apply->toArray())) {
  3864. return Result::error("您已投递过该职位!");
  3865. }
  3866. $insertData = array_map(function ($recruiting) use ($data) {
  3867. return [
  3868. 'user_id' => $data['user_id'],
  3869. 'hunt_id' => $data['hunt_id'],
  3870. 'website_id' => $data['website_id'],
  3871. 'recruit_id' => $recruiting['recruit_id'],
  3872. 'receiver_id' => $recruiting['receiver_id'],
  3873. 'status' => 1,
  3874. ];
  3875. }, $recruiting);
  3876. // 批量插入数据
  3877. $result = JobApply::insert($insertData);
  3878. if (empty($result)) {
  3879. return Result::error("投递失败", 0);
  3880. }
  3881. return Result::success($result);
  3882. }
  3883. /**
  3884. * 招工招聘-沟通简历
  3885. * @param array $data
  3886. * @return array
  3887. * */
  3888. public function getWebsiteJobResume(array $data): array
  3889. {
  3890. // 首先验证网站是否存在
  3891. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3892. if (empty($web)) {
  3893. return Result::error("该网站不存在", 0);
  3894. }
  3895. // return Result::success($data);
  3896. // 验证用户是否存在且为企业会员/管理员
  3897. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3898. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3899. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3900. return Result::error("用户不存在", 0);
  3901. }
  3902. // 去除重复元素和空元素,并保持原始顺序
  3903. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  3904. return !empty($value);
  3905. }));
  3906. // 验证简历是否存在
  3907. $hunting = JobHunting::where('status', 2)
  3908. ->where('website_id', $data['website_id'])
  3909. ->whereIn('id', $data['hunt_id'])
  3910. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  3911. if (empty($hunting)) {
  3912. return Result::error("该简历不存在", 0);
  3913. }
  3914. // 验证是否已沟通过该简历
  3915. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3916. ->where('recruit_id', $data['recruit_id'])
  3917. ->where('website_id', $data['website_id'])
  3918. ->whereIn('hunt_id', $data['hunt_id'])
  3919. ->get(['hunt_id']);
  3920. if (!empty($remuse->toArray())) {
  3921. return Result::error("您已沟通过该简历!");
  3922. }
  3923. // 准备要插入的数据数组
  3924. $insertData = array_map(function ($hunting) use ($data) {
  3925. return [
  3926. 'user_id' => $data['user_id'],
  3927. 'recruit_id' => $data['recruit_id'],
  3928. 'website_id' => $data['website_id'],
  3929. 'hunt_id' => $hunting['hunt_id'],
  3930. 'receiver_id' => $hunting['receiver_id'],
  3931. 'status' => 1,
  3932. ];
  3933. }, $hunting);
  3934. // 批量插入数据
  3935. $result = JobRemuse::insert($insertData);
  3936. if (empty($result)) {
  3937. return Result::error("沟通失败", 0);
  3938. }
  3939. return Result::success($result);
  3940. }
  3941. /**
  3942. * 招工招聘 -我的职位(企业会员)
  3943. * @param array $data
  3944. * @return array
  3945. */
  3946. public function getWebsiteJobRecruiting(array $data): array
  3947. {
  3948. $web = Website::where('id', $data['website_id'])->first('id');
  3949. if (empty($web)) {
  3950. return Result::error("该网站不存在", 0);
  3951. }
  3952. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3953. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3954. return Result::error("用户暂无权限!", 0);
  3955. }
  3956. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3957. $result = JobRecruiting::where('website_id', $data['website_id'])
  3958. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  3959. $query->where('user_id', $user['id']);
  3960. })
  3961. ->where('status', 1)
  3962. ->select('id', 'title', 'website_id', 'user_id', 'updated_at', 'keyword', 'catid', 'description')
  3963. ->orderBy('updated_at', 'desc')
  3964. ->limit($data['pageSize'])
  3965. ->get();
  3966. if (empty($result)) {
  3967. return Result::error("暂无相关职位信息", 0);
  3968. }
  3969. return Result::success($result);
  3970. }
  3971. /**
  3972. * c端 - 验证路由
  3973. * @param array $data
  3974. * @return array
  3975. */
  3976. /**
  3977. * c端 - 验证路由
  3978. * @param array $data
  3979. * @return array
  3980. */
  3981. public function checkWebsiteRoute(array $data): array
  3982. {
  3983. // 测试001111111222
  3984. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name', 'status']);
  3985. if (empty($web)) {
  3986. return Result::error("该网站不存在", 0);
  3987. } elseif ($web['status'] != 1) {
  3988. return Result::error("网站已经关闭", 0);
  3989. }
  3990. if (isset($data['other_route']) && !empty($data['other_route'])) {
  3991. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  3992. // 验证路由是否存在
  3993. if (empty($whiteRouterInfo)) {
  3994. $whiteRouterInfo = WhiteRouter::where("router_type", 1)->where('router_url', $data['other_route'])->first();
  3995. }
  3996. if (!empty($whiteRouterInfo)) {
  3997. return Result::success($whiteRouterInfo->toArray());
  3998. }
  3999. }
  4000. // 验证栏目路由
  4001. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  4002. ->where('path', $data['all_route'])
  4003. ->get()->all();
  4004. if (count($last_category) == 0) {
  4005. return Result::error("该栏目不存在", 0);
  4006. }
  4007. if (count($last_category) > 1) {
  4008. return Result::error("该栏目路由存在多个,路由验证失败!", 0);
  4009. }
  4010. if (count($last_category) == 1) {
  4011. $last_category = $last_category[0];
  4012. }
  4013. // return Result::success($last_category);
  4014. if (isset($data['id']) && !empty($data['id'])) {
  4015. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  4016. switch ($last_category['type']) {
  4017. case 1:
  4018. // 文章
  4019. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  4020. $article = Article::where('status', 1)
  4021. ->where('id', $data['id'])
  4022. ->where(function ($query) use ($data) {
  4023. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  4024. ->orWhereNull("ignore_ids");
  4025. })
  4026. ->first(['catid']);
  4027. if (empty($article)) {
  4028. return Result::error("该文章不存在", 0);
  4029. }
  4030. // return Result::success($article);
  4031. break;
  4032. case 2:
  4033. // 商品
  4034. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  4035. $article = Good::where('website_id', $data['website_id'])
  4036. ->where('status', 2)
  4037. ->where('id', $data['id'])
  4038. ->first(['cat_arr_id']);
  4039. if (empty($article)) {
  4040. return Result::error("该商品不存在", 0);
  4041. }
  4042. break;
  4043. case 3:
  4044. // 书刊信息
  4045. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  4046. $article = Book::where('website_id', $data['website_id'])
  4047. ->where('status', 2)
  4048. ->where('id', $data['id'])
  4049. ->first(['id', 'cat_arr_id']);
  4050. if (empty($article)) {
  4051. return Result::error("该书刊不存在", 0);
  4052. }
  4053. break;
  4054. case 4:
  4055. // 招聘
  4056. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核通过;(只有企业会员需要审核)',
  4057. $article = JobRecruiting::where('website_id', $data['website_id'])
  4058. ->where('status', 1)
  4059. ->where('id', $data['id'])
  4060. ->first(['cat_arr_id']);
  4061. if (empty($article)) {
  4062. return Result::error("该招聘不存在", 0);
  4063. }
  4064. break;
  4065. case 5:
  4066. // 求职
  4067. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  4068. $article = JobHunting::where('website_id', $data['website_id'])
  4069. ->where('status', 2)
  4070. ->where('id', $data['id'])
  4071. ->first(['cat_arr_id']);
  4072. if (empty($article)) {
  4073. return Result::error("该求职不存在", 0);
  4074. }
  4075. break;
  4076. case 6:
  4077. // 企业
  4078. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  4079. $article = Company::
  4080. // where('website_id', $data['website_id'])
  4081. // ->
  4082. where('status', 1)
  4083. ->where('id', $data['id'])
  4084. ->first(['cat_arr_id']);
  4085. if (empty($article)) {
  4086. return Result::error("该企业不存在", 0);
  4087. }
  4088. break;
  4089. case 7:
  4090. // 项目
  4091. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  4092. $article = Project::where('website_id', $data['website_id'])
  4093. ->where('status', 1)
  4094. ->where('id', $data['id'])
  4095. ->first(['cat_arr_id']);
  4096. if (empty($article)) {
  4097. return Result::error("该项目不存在", 0);
  4098. }
  4099. break;
  4100. default:
  4101. return Result::error("该数据不存在", 0);
  4102. break;
  4103. }
  4104. // return Result::success($article);
  4105. // $catid =0 ;
  4106. if (!isset($article['cat_arr_id'])) {
  4107. $catid = isset($article['catid']) ? $article['catid'] : (isset($article['category_id']) ? $article['category_id'] : null);
  4108. } else {
  4109. $catidArray = json_decode($article['cat_arr_id'], true);
  4110. $catid = !empty($catidArray) ? end($catidArray) : null;
  4111. }
  4112. // return Result::success($catid);
  4113. // // return Result::success($article['cat_arr_id']);
  4114. if (empty($catid)) {
  4115. return Result::error("该栏目路径不存在", 0);
  4116. }
  4117. $path = WebsiteCategory::where('website_id', $data['website_id'])
  4118. ->where('category_id', $catid)
  4119. ->first('path');
  4120. }
  4121. // else{
  4122. // // if ($last_category['pid'] != 0) {
  4123. // $cat_arr = json_decode($last_category['category_arr_id'], true);
  4124. // $catid = !empty($cat_arr) && is_array($cat_arr) ? end($cat_arr) : null;
  4125. // $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  4126. // ->where('category_id',$catid)
  4127. // ->where('path',$data['all_route'])
  4128. // ->first('path');
  4129. // // } else {
  4130. // // $pinyin[0] = $last_category['aLIas_pinyin'];
  4131. // // }
  4132. // }
  4133. // return Result::success($path);
  4134. if (!empty($path) && $path['path'] != $data['all_route']) {
  4135. return Result::error('非法路径!');
  4136. } else {
  4137. return Result::success($last_category['path']);
  4138. }
  4139. }
  4140. /**
  4141. * 招工招聘 - 获取推荐职位
  4142. * @param array $data
  4143. * @return array
  4144. */
  4145. public function getWebsiteLevelJob(array $data): array
  4146. {
  4147. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  4148. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  4149. ->where('job_recruiting.status', 1)
  4150. ->where('job_level', $data['job_level'])
  4151. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4152. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  4153. ->orderBy('job_recruiting.updated_at', 'desc')
  4154. ->limit($data['pageSize'])
  4155. ->get();
  4156. $web = ['website_id' => $data['website_id']];
  4157. if (!empty($job)) {
  4158. $result = $this->processJob($job, $web);
  4159. }
  4160. if (empty($result)) {
  4161. return Result::error("暂无相关职位信息", 0);
  4162. }
  4163. return Result::success($result);
  4164. }
  4165. /**
  4166. * 验证导航名称是否重复
  4167. * @return void
  4168. */
  4169. //20250226 产品列表
  4170. public function getGoodList(array $data): array
  4171. {
  4172. var_dump($data, '---------1-2--');
  4173. $type_id = isset($data['user_type_id']) ? $data['user_type_id'] : '';
  4174. unset($data['user_type_id']);
  4175. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4176. $where = [];
  4177. if ($type_id != '10000') {
  4178. $where = [
  4179. 'good.user_id' => $user_id,
  4180. ];
  4181. }
  4182. //类型
  4183. if (isset($data['type_id']) && $data['type_id']) {
  4184. $where['good.type_id'] = $data['type_id'];
  4185. }
  4186. //名称
  4187. if (isset($data['name']) && $data['name']) {
  4188. $where[] = ['good.name', 'like', '%' . $data['name'] . '%'];
  4189. }
  4190. //status
  4191. if (isset($data['status']) && $data['status'] != '') {
  4192. $where['good.status'] = $data['status'];
  4193. }
  4194. //status1
  4195. // if (isset($data['status1']) && $data['status1'] == 1) {
  4196. // $status1 = 1;
  4197. // }
  4198. $where1 = [];
  4199. //website_id
  4200. // if (isset($data['website_id']) && $data['website_id']) {
  4201. // $where1 = [
  4202. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  4203. // ];
  4204. // }
  4205. // website_name
  4206. if (isset($data['website_name']) && $data['website_name']) {
  4207. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  4208. }
  4209. // catid
  4210. if (isset($data['category_name']) && $data['category_name']) {
  4211. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  4212. }
  4213. // $result = Good::where($where)
  4214. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  4215. var_dump($where, '---------1---');
  4216. $result = Good::where($where)
  4217. ->when(!empty($where1), function ($query) use ($where1) {
  4218. return $query->where($where1);
  4219. })
  4220. //status 1待审核2已审核3已拒绝
  4221. ->when(isset($data['status1']), function ($query) {
  4222. return $query->whereIn('good.status', [1, 3]);
  4223. })
  4224. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4225. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4226. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4227. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4228. ->orderBy("updated_at", "desc")
  4229. ->limit($data['page_size'])
  4230. ->offset(($data['page'] - 1) * $data['page_size'])
  4231. ->get();
  4232. $count = Good::where($where)
  4233. ->when(!empty($where1), function ($query) use ($where1) {
  4234. return $query->where($where1);
  4235. })
  4236. //status 1待审核2已审核3已拒绝
  4237. ->when(isset($data['status1']), function ($query) {
  4238. return $query->whereIn('good.status', [1, 3]);
  4239. })
  4240. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4241. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4242. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4243. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4244. ->orderBy("updated_at", "desc")->count();
  4245. $data = [
  4246. 'rows' => $result->toArray(),
  4247. 'count' => $count,
  4248. ];
  4249. if (empty($result)) {
  4250. return Result::error("此栏目暂无相关产品", 0);
  4251. }
  4252. return Result::success($data);
  4253. }
  4254. public function getGoodInfo(array $data): array
  4255. {
  4256. $result = Good::where('id', $data['id'])->first();
  4257. if (empty($result)) {
  4258. return Result::error("此产品不存在", 0);
  4259. }
  4260. return Result::success($result);
  4261. }
  4262. public function addGood(array $data): array
  4263. {
  4264. // unset($data['city_arr_id']);
  4265. // unset($data['cat_arr_id']);
  4266. $data['city_id'] = end($data['city_arr_id']);
  4267. $data['catid'] = end($data['cat_arr_id']);
  4268. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4269. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4270. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4271. unset($data['imgUrl']); //大小写
  4272. if (isset($data['price']) && $data['price'] == '') {
  4273. $data['price'] = 0;
  4274. }
  4275. if ($data['imgurl'] == '') {
  4276. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4277. preg_match_all($reg, $data['detail'], $matches);
  4278. if (isset($matches[1][0])) {
  4279. //截取varchar240
  4280. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4281. }
  4282. }
  4283. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4284. //提取标题+内容中的关键词
  4285. $data['keyword'] = $data['name'];
  4286. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4287. Jieba::init(); // 初始化 jieba-php
  4288. Finalseg::init();
  4289. $segList = Jieba::cut($data['keyword']);
  4290. $segList1 = array_slice($segList, 0, 8);
  4291. $data['keyword'] = implode(',', $segList1);
  4292. }
  4293. if ($data['description'] == '') {
  4294. //提取内容中的描述
  4295. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4296. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4297. // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  4298. }
  4299. if ($data['status'] == 1) {
  4300. $this->sendMessage([
  4301. 'talk_type' => 200,
  4302. 'title' => $data['name'],
  4303. 'content' => '提交了审核',
  4304. 'messageType' => 3,
  4305. ]);
  4306. }
  4307. $result = Good::insert($data);
  4308. if (empty($result)) {
  4309. return Result::error("添加失败", 0);
  4310. }
  4311. return Result::success($result);
  4312. }
  4313. public function updateGood(array $data): array
  4314. {
  4315. $data['city_id'] = end($data['city_arr_id']);
  4316. $data['catid'] = end($data['cat_arr_id']);
  4317. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4318. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4319. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4320. //设置东八区
  4321. date_default_timezone_set('Asia/Shanghai');
  4322. $data['updated_at'] = date('Y-m-d H:i:s');
  4323. if (isset($data['price']) && $data['price'] == '') {
  4324. $data['price'] = 0;
  4325. }
  4326. if ($data['imgurl'] == '') {
  4327. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4328. preg_match_all($reg, $data['detail'], $matches);
  4329. if (isset($matches[1][0])) {
  4330. //截取varchar240
  4331. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4332. }
  4333. }
  4334. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4335. //提取标题+内容中的关键词
  4336. $data['keyword'] = $data['name'];
  4337. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4338. Jieba::init(); // 初始化 jieba-php
  4339. Finalseg::init();
  4340. $segList = Jieba::cut($data['keyword']);
  4341. $segList1 = array_slice($segList, 0, 8);
  4342. $data['keyword'] = implode(',', $segList1);
  4343. }
  4344. if ($data['description'] == '') {
  4345. //提取内容中的描述
  4346. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4347. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4348. }
  4349. if ($data['status'] == 1) {
  4350. $this->sendMessage([
  4351. 'talk_type' => 200,
  4352. 'title' => $data['name'],
  4353. 'content' => '提交了审核',
  4354. 'messageType' => 3,
  4355. ]);
  4356. }
  4357. $result = Good::where('id', $data['id'])->update($data);
  4358. if (empty($result)) {
  4359. return Result::error("更新失败", 0);
  4360. }
  4361. return Result::success($result);
  4362. }
  4363. public function delGood(array $data): array
  4364. {
  4365. $result = Good::where('id', $data['id'])->delete();
  4366. if (empty($result)) {
  4367. return Result::error("删除失败", 0);
  4368. }
  4369. return Result::success($result);
  4370. }
  4371. //20250226 产品列表
  4372. //20250306 求职信息
  4373. public function getJobHuntingList(array $data): array
  4374. {
  4375. $where = [];
  4376. if (isset($data['username']) && !empty($data['username'])) {
  4377. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4378. }
  4379. //status 1待审核2已审核3已拒绝
  4380. if (isset($data['status']) && $data['status'] != '') {
  4381. $where = [
  4382. 'job_hunting.status' => $data['status'],
  4383. ];
  4384. }
  4385. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4386. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4387. unset($data['type_id']);
  4388. if ($type_id != '10000') {
  4389. $where[] = ['job_hunting.user_id', '=', $user_id];
  4390. }
  4391. $result = JobHunting::where($where)
  4392. ->when(!empty($data['status1']), function ($query) use ($data) {
  4393. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4394. })
  4395. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4396. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4397. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  4398. ->orderBy("updated_at", "desc")
  4399. ->limit($data['page_size'])
  4400. ->offset(($data['page'] - 1) * $data['page_size'])
  4401. ->get();
  4402. if (empty($result)) {
  4403. return Result::error("查询失败", 0);
  4404. }
  4405. $count = JobHunting::where($where)
  4406. ->when(!empty($data['status1']), function ($query) use ($data) {
  4407. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4408. })
  4409. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4410. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4411. ->count();
  4412. $data = [
  4413. 'rows' => $result->toArray(),
  4414. 'count' => $count,
  4415. ];
  4416. return Result::success($data);
  4417. }
  4418. public function getJobHuntingApply(array $data): array
  4419. {
  4420. var_dump($data, '-----------------test--------1-');
  4421. $where = [];
  4422. if (isset($data['username']) && !empty($data['username'])) {
  4423. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4424. }
  4425. if (isset($data['salary']) && !empty($data['salary'])) {
  4426. $where[] = [
  4427. 'job_hunting.salary',
  4428. '=',
  4429. $data['salary'],
  4430. ];
  4431. }
  4432. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4433. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4434. unset($data['type_id']);
  4435. if ($type_id != '10000') {
  4436. $where[] = ['job_apply.receiver_id', '=', $user_id];
  4437. }
  4438. var_dump($where, '-----------------test---------');
  4439. $result = jobApply::where($where)
  4440. // ->when(!empty($data['status1']), function ($query) use ($data) {
  4441. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4442. // })
  4443. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  4444. ->where('job_enum.egroup', '=', 'income')
  4445. ->where('job_hunting.status', 2) //已审核
  4446. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4447. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4448. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4449. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4450. //职位----是申请职位
  4451. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4452. ->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')
  4453. ->orderBy("job_hunting.updated_at", "desc")
  4454. ->limit($data['page_size'])
  4455. ->offset(($data['page'] - 1) * $data['page_size'])
  4456. ->get();
  4457. if (empty($result)) {
  4458. return Result::error("查询失败", 0);
  4459. }
  4460. $count = jobApply::where($where)
  4461. ->where('job_enum.egroup', '=', 'income')
  4462. ->where('job_hunting.status', 2) //已审核
  4463. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4464. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4465. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4466. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4467. //职位----是申请职位
  4468. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4469. ->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')
  4470. ->count();
  4471. $data = [
  4472. 'rows' => $result->toArray(),
  4473. 'count' => $count,
  4474. ];
  4475. return Result::success($data);
  4476. }
  4477. public function addJobHunting(array $data): array
  4478. {
  4479. date_default_timezone_set('Asia/Shanghai');
  4480. unset($data['company_name']);
  4481. unset($data['job_industry']);
  4482. unset($data['job_name']);
  4483. unset($data['department']);
  4484. unset($data['job_timeList']);
  4485. unset($data['job_content']);
  4486. unset($data['job_typename']); //不知道这是啥,
  4487. $data['created_at'] = date('Y-m-d H:i:s');
  4488. $data['updated_at'] = date('Y-m-d H:i:s');
  4489. //根据用户 user_id 只能添加一次
  4490. $result = JobHunting::where('user_id', $data['user_id'])->first();
  4491. if (!empty($result)) {
  4492. return Result::error("您已添加过求职信息", 0);
  4493. }
  4494. var_dump($result, '-----------------test---------');
  4495. if (isset($data['city_arr_id']) && !empty($data['city_arr_id'])) {
  4496. if (is_string($data['city_arr_id'])) {
  4497. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4498. $cityArr = json_decode($data['city_arr_id'], true);
  4499. // 确保 $cityArr 是数组
  4500. if (is_array($cityArr)) {
  4501. $data['city_id'] = end($cityArr);
  4502. }
  4503. } else {
  4504. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4505. if (is_array($data['city_arr_id'])) {
  4506. $data['city_id'] = end($data['city_arr_id']);
  4507. }
  4508. }
  4509. }
  4510. // 处理求职所绑定栏目
  4511. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id'])) {
  4512. if (is_string($data['cat_arr_id'])) {
  4513. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4514. // 先清理可能存在的无效 JSON 字符
  4515. $cleanedCatArrStr = trim($data['cat_arr_id']);
  4516. $catArr = json_decode($cleanedCatArrStr, true);
  4517. // 检查 JSON 解码是否成功且结果是数组
  4518. if (json_last_error() === JSON_ERROR_NONE && is_array($catArr)) {
  4519. $data['catid'] = end($catArr);
  4520. }
  4521. } else {
  4522. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4523. if (is_array($data['cat_arr_id'])) {
  4524. $data['catid'] = end($data['cat_arr_id']);
  4525. }
  4526. }
  4527. }
  4528. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4529. $this->sendMessage([
  4530. 'talk_type' => 600,
  4531. 'title' => $data['name'],
  4532. 'content' => '提交了审核',
  4533. 'messageType' => 11,
  4534. ]);
  4535. }
  4536. $result = JobHunting::create($data);
  4537. if (empty($result)) {
  4538. return Result::error("添加失败", 0);
  4539. }
  4540. return Result::success($result);
  4541. }
  4542. public function delJobHunting(array $data): array
  4543. {
  4544. $result = JobHunting::where('id', $data['id'])->delete();
  4545. if (empty($result)) {
  4546. return Result::error("删除失败", 0);
  4547. }
  4548. return Result::success($result);
  4549. }
  4550. public function updateJobHunting(array $data): array
  4551. {
  4552. //设置东八区
  4553. date_default_timezone_set('Asia/Shanghai');
  4554. unset($data['company_name']);
  4555. unset($data['job_industry']);
  4556. unset($data['job_name']);
  4557. unset($data['department']);
  4558. unset($data['job_timeList']);
  4559. unset($data['job_content']);
  4560. unset($data['job_typename']); //不知道这是啥,
  4561. $data['created_at'] = date('Y-m-d H:i:s');
  4562. $data['updated_at'] = date('Y-m-d H:i:s');
  4563. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  4564. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4565. $cityArr = json_decode($data['city_arr_id'], true);
  4566. $data['city_id'] = end($cityArr);
  4567. } else {
  4568. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4569. $data['city_id'] = end($data['city_arr_id']);
  4570. }
  4571. // 处理求职所绑定栏目
  4572. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_string($data['cat_arr_id'])) {
  4573. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4574. $catArr = json_decode($data['cat_arr_id'], true);
  4575. $data['catid'] = end($catArr);
  4576. } else {
  4577. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4578. $data['catid'] = end($data['cat_arr_id']);
  4579. }
  4580. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4581. $this->sendMessage([
  4582. 'talk_type' => 600,
  4583. 'title' => $data['name'],
  4584. 'content' => '提交了审核',
  4585. 'messageType' => 11,
  4586. ]);
  4587. }
  4588. $result = JobHunting::where('id', $data['id'])->update($data);
  4589. if (empty($result)) {
  4590. return Result::error("更新失败", 0);
  4591. }
  4592. return Result::success($result);
  4593. }
  4594. public function getJobHuntingInfo(array $data): array
  4595. {
  4596. $result = JobHunting::where('id', $data['id'])->first();
  4597. if (empty($result)) {
  4598. return Result::error("查询失败", 0);
  4599. }
  4600. return Result::success($result);
  4601. }
  4602. public function getJobHuntingData(array $data): array
  4603. {
  4604. $jobEnum = JobEnum::get();
  4605. $jobIndustry = JobIndustry::get();
  4606. $jobNature = JobNature::get();
  4607. $jobPosition = JobPosition::get();
  4608. $data = [
  4609. 'jobEnum' => $jobEnum,
  4610. 'jobIndustry' => $jobIndustry,
  4611. 'jobNature' => $jobNature,
  4612. 'jobPosition' => $jobPosition,
  4613. ];
  4614. return Result::success($data);
  4615. }
  4616. public function delJobHuntingInfo(array $data): array
  4617. {
  4618. $result = JobHunting::where('id', $data['id'])->delete();
  4619. return Result::success();
  4620. }
  4621. //20250324 通知,公告,消息
  4622. public function delNotice(array $data): array
  4623. {
  4624. $result = Notice::where('id', $data['id'])->delete();
  4625. if ($result) {
  4626. return Result::success();
  4627. } else {
  4628. return Result::error("删除失败", 0);
  4629. }
  4630. }
  4631. public function getNoticeInfo(array $data): array
  4632. {
  4633. $result = Notice::where('id', $data['id'])->first();
  4634. // var_dump($result['re_user_ids'], '--------------------');
  4635. if (empty($result)) {
  4636. return Result::error("查询失败", 0);
  4637. }
  4638. return Result::success($result);
  4639. }
  4640. public function readNotice(array $data): array
  4641. {
  4642. $result = Notice::where('id', $data['id'])->first();
  4643. // var_dump($result['re_user_ids'], '--------------------');
  4644. if (empty($result)) {
  4645. return Result::error("查询失败", 0);
  4646. }
  4647. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4648. $re_user_ids = json_decode($result['re_user_ids'], true);
  4649. var_dump($re_user_ids, '--------------1---test---------');
  4650. var_dump($data, '--------------1---test---------');
  4651. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4652. //如果已经存在,就不再添加
  4653. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4654. $read_id = json_decode($result['read_id'], true);
  4655. if (!is_array($read_id)) {
  4656. $read_id = [];
  4657. }
  4658. if (!in_array($data['user_id'], $read_id)) {
  4659. $read_id[] = $data['user_id'];
  4660. $result['read_id'] = json_encode($read_id);
  4661. Notice::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4662. }
  4663. } else {
  4664. //如果不存在,就添加
  4665. $result['read_id'] = json_encode([$data['user_id']]);
  4666. Notice::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4667. }
  4668. }
  4669. return Result::success($result);
  4670. }
  4671. public function addNotice(array $data): array
  4672. {
  4673. date_default_timezone_set('Asia/Shanghai');
  4674. $data['created_at'] = date('Y-m-d H:i:s');
  4675. $data['updated_at'] = date('Y-m-d H:i:s');
  4676. // $data['level'] = "1,2,3,4,5";
  4677. $level = json_decode($data['level'], true);
  4678. $user_id = UserInfo::
  4679. //city_id不是null
  4680. whereNotNull('city_id')
  4681. ->whereNotNull('department_id')
  4682. ->where(function ($query) use ($data) {
  4683. $query->where(function ($subQuery) use ($data) {
  4684. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4685. });
  4686. })
  4687. ->where(function ($query) use ($data) {
  4688. $query->where(function ($subQuery) use ($data) {
  4689. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4690. });
  4691. })
  4692. ->when(isset($level) && is_array($level), function ($query) use ($level) {
  4693. $query->whereIn('level', $level);
  4694. })
  4695. ->pluck('user_id')->toArray();
  4696. $user_id = array_unique($user_id);
  4697. $chat_ids = $user_id;
  4698. $user_id = json_encode($user_id);
  4699. $data['re_user_ids'] = $user_id;
  4700. $this->sendMessage([
  4701. 'talk_type' => 700,
  4702. 'title' => $data['title'],
  4703. 'content' => '提交了审核',
  4704. 'messageType' => 5,
  4705. ]);
  4706. $result = Notice::insertGetId($data);
  4707. if (empty($result)) {
  4708. return Result::error("添加失败", 0);
  4709. }
  4710. return Result::success($result);
  4711. }
  4712. public function updateNotice(array $data): array
  4713. {
  4714. date_default_timezone_set('Asia/Shanghai');
  4715. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  4716. $user_id = UserInfo::
  4717. //city_id不是null
  4718. whereNotNull('city_id')
  4719. ->whereNotNull('department_id')
  4720. ->where(function ($query) use ($data) {
  4721. $query->where(function ($subQuery) use ($data) {
  4722. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4723. });
  4724. })
  4725. ->where(function ($query) use ($data) {
  4726. $query->where(function ($subQuery) use ($data) {
  4727. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4728. });
  4729. })
  4730. ->pluck('user_id')->toArray();
  4731. $user_id = array_unique($user_id);
  4732. $user_id = json_encode($user_id);
  4733. $data['re_user_ids'] = $user_id;
  4734. $data['updated_at'] = date('Y-m-d H:i:s');
  4735. $this->sendMessage([
  4736. 'talk_type' => 700,
  4737. 'title' => $data['title'],
  4738. 'content' => '提交了审核',
  4739. 'messageType' => 5,
  4740. ]);
  4741. $result = Notice::where('id', $data['id'])->update($data);
  4742. return Result::success($result);
  4743. }
  4744. public function getNoticeList(array $data): array
  4745. {
  4746. $where = [];
  4747. //title
  4748. if (isset($data['title']) && !empty($data['title'])) {
  4749. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4750. }
  4751. //level
  4752. if (isset($data['level']) && !empty($data['level'])) {
  4753. $where[] = ['notice.level', '=', $data['level']];
  4754. }
  4755. //status
  4756. if (isset($data['status']) && !empty($data['status'])) {
  4757. $where[] = ['notice.status', '=', $data['status']];
  4758. }
  4759. //type
  4760. if (isset($data['type']) && !empty($data['type'])) {
  4761. $where[] = ['notice.type', '=', $data['type']];
  4762. }
  4763. var_dump($data, '------------11111-2----test---------');
  4764. if ($data['type_id'] == 10000) {
  4765. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4766. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4767. })
  4768. ->where($where)
  4769. ->orderBy('updated_at', 'desc')
  4770. ->limit($data['page_size'])
  4771. ->offset(($data['page'] - 1) * $data['page_size'])
  4772. ->get();
  4773. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4774. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4775. })
  4776. ->where($where)
  4777. ->orderBy('updated_at', 'desc')
  4778. ->count();
  4779. } else {
  4780. $result = Notice::where($where)
  4781. // ->where('user_id', $data['user_id'])
  4782. ->Where(function ($query) use ($data) {
  4783. $query->Where(function ($q) use ($data) {
  4784. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4785. ->orWhere('notice.user_id', $data['user_id']);
  4786. });
  4787. })
  4788. ->when(!empty($data['status1']), function ($query) use ($data) {
  4789. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4790. })
  4791. ->orderBy('updated_at', 'desc')
  4792. ->limit($data['page_size'])
  4793. ->offset(($data['page'] - 1) * $data['page_size'])
  4794. ->get();
  4795. $total = Notice::where($where)
  4796. ->when(!empty($data['status1']), function ($query) use ($data) {
  4797. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4798. })
  4799. // ->where('user_id', $data['user_id'])
  4800. ->Where(function ($query) use ($data) {
  4801. $query->Where(function ($q) use ($data) {
  4802. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4803. ->orWhere('notice.user_id', $data['user_id']);
  4804. });
  4805. })
  4806. ->count();
  4807. }
  4808. if (empty($result)) {
  4809. return Result::error("查询失败", 0);
  4810. }
  4811. $data = [
  4812. 'rows' => $result,
  4813. 'count' => $total,
  4814. ];
  4815. return Result::success($data);
  4816. }
  4817. public function noticeList(array $data): array
  4818. {
  4819. $where = [];
  4820. //title
  4821. if (isset($data['title']) && !empty($data['title'])) {
  4822. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4823. }
  4824. //level
  4825. if (isset($data['level']) && !empty($data['level'])) {
  4826. $where[] = ['notice.level', '=', $data['level']];
  4827. }
  4828. //status
  4829. if (isset($data['status']) && !empty($data['status'])) {
  4830. $where[] = ['notice.status', '=', $data['status']];
  4831. }
  4832. //type
  4833. if (isset($data['type']) && !empty($data['type'])) {
  4834. $where[] = ['notice.type', '=', $data['type']];
  4835. }
  4836. var_dump($data, '------------11111-2----test---------');
  4837. if ($data['type_id'] == 10000) {
  4838. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4839. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4840. })
  4841. ->where($where)
  4842. ->orderBy('updated_at', 'desc')
  4843. ->limit($data['page_size'])
  4844. ->offset(($data['page'] - 1) * $data['page_size'])
  4845. ->get();
  4846. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4847. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4848. })
  4849. ->where($where)
  4850. ->orderBy('updated_at', 'desc')
  4851. ->count();
  4852. } else {
  4853. $result = Notice::where($where)
  4854. // ->where('user_id', $data['user_id'])
  4855. ->Where(function ($query) use ($data) {
  4856. $query->Where(function ($q) use ($data) {
  4857. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4858. ->orWhere('notice.user_id', $data['user_id']);
  4859. });
  4860. })
  4861. ->when(!empty($data['status1']), function ($query) use ($data) {
  4862. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4863. })
  4864. ->orderBy('updated_at', 'desc')
  4865. ->limit($data['page_size'])
  4866. ->offset(($data['page'] - 1) * $data['page_size'])
  4867. ->get();
  4868. $total = Notice::where($where)
  4869. ->when(!empty($data['status1']), function ($query) use ($data) {
  4870. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4871. })
  4872. // ->where('user_id', $data['user_id'])
  4873. ->Where(function ($query) use ($data) {
  4874. $query->Where(function ($q) use ($data) {
  4875. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4876. ->orWhere('notice.user_id', $data['user_id']);
  4877. });
  4878. })
  4879. ->count();
  4880. }
  4881. if (empty($result)) {
  4882. return Result::error("查询失败", 0);
  4883. }
  4884. $data = [
  4885. 'rows' => $result,
  4886. 'count' => $total,
  4887. ];
  4888. return Result::success($data);
  4889. }
  4890. public function getNoticeDetail(array $data): array
  4891. {
  4892. $result = Notice::where('id', $data['id'])->first();
  4893. if (empty($result)) {
  4894. return Result::error("查询失败", 0);
  4895. }
  4896. return Result::success($result);
  4897. }
  4898. public function deleteNotice(array $data): array
  4899. {
  4900. $notice = Notice::where('id', $data['id'])->first();
  4901. if (empty($notice)) {
  4902. return Result::error("删除失败", 0);
  4903. }
  4904. $chat_group_id = $notice->group_id;
  4905. if ($chat_group_id) {
  4906. //删除群聊
  4907. ChatGroups::where('id', $chat_group_id)->delete();
  4908. //删除群成员
  4909. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  4910. //删除群聊记录
  4911. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  4912. }
  4913. $result = Notice::where('id', $data['id'])->delete();
  4914. return Result::success($result);
  4915. }
  4916. public function complaintList(array $data): array
  4917. {
  4918. var_dump($data, '---------1---------');
  4919. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4920. unset($data['type_id']);
  4921. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4922. $where = [];
  4923. if ($type_id != 10000 && empty($data['deal_user'])) {
  4924. // $where['complaint.user_id'] = $user_id;
  4925. }
  4926. if (!empty($data['title'])) {
  4927. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4928. }
  4929. if (!empty($data['department_id'])) {
  4930. $where['complaint.department_id'] = $data['department_id'];
  4931. }
  4932. if (!empty($data['deal'])) {
  4933. $where['complaint.deal'] = $data['deal'];
  4934. }
  4935. if (!empty($data['status'])) {
  4936. $where['complaint.status'] = $data['status'];
  4937. }
  4938. var_dump(!empty($data['deal_user']), '----------1');
  4939. var_dump($where, '----------2');
  4940. $result = Complaint::where($where)
  4941. ->when(!empty($data['status1']), function ($query) use ($data) {
  4942. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4943. })
  4944. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4945. //json re_user_ids data[user_id]是不是在里面
  4946. $query->Where(function ($q) use ($data) {
  4947. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4948. ->where('complaint.status', 2);
  4949. });
  4950. })
  4951. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4952. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4953. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4954. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4955. ->orderBy('updated_at', 'desc')
  4956. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4957. //sql输出
  4958. if (empty($result)) {
  4959. return Result::error("暂无投诉信息", 0);
  4960. }
  4961. // 取出数据
  4962. $rows = $result->items();
  4963. $count = $result->total();
  4964. $responseData = [
  4965. 'rows' => $rows,
  4966. 'count' => $count,
  4967. ];
  4968. return Result::success($responseData);
  4969. }
  4970. public function getComplaintList(array $data): array
  4971. {
  4972. var_dump($data, '00000001000000000000');
  4973. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4974. unset($data['type_id']);
  4975. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4976. $where = [];
  4977. if ($type_id != 10000 && empty($data['deal_user'])) {
  4978. $where['complaint.user_id'] = $user_id;
  4979. }
  4980. if (!empty($data['title'])) {
  4981. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4982. }
  4983. if (!empty($data['department_id'])) {
  4984. $where['complaint.department_id'] = $data['department_id'];
  4985. }
  4986. if (!empty($data['deal'])) {
  4987. $where['complaint.deal'] = $data['deal'];
  4988. }
  4989. if (!empty($data['status'])) {
  4990. $where['complaint.status'] = $data['status'];
  4991. }
  4992. var_dump(!empty($data['deal_user']), '----------1');
  4993. var_dump($where, '----------2');
  4994. $result = Complaint::where($where)
  4995. ->when(!empty($data['status1']), function ($query) use ($data) {
  4996. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4997. })
  4998. // ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4999. // //json re_user_ids data[user_id]是不是在里面
  5000. // $query->Where(function ($q) use ($data) {
  5001. // $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  5002. // ->where('complaint.status', 2);
  5003. // });
  5004. // })
  5005. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  5006. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  5007. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  5008. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  5009. ->orderBy('updated_at', 'desc')
  5010. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  5011. //sql输出
  5012. if (empty($result)) {
  5013. return Result::error("暂无投诉信息", 0);
  5014. }
  5015. // 取出数据
  5016. $rows = $result->items();
  5017. $count = $result->total();
  5018. $responseData = [
  5019. 'rows' => $rows,
  5020. 'count' => $count,
  5021. ];
  5022. return Result::success($responseData);
  5023. }
  5024. public function getComplaintInfo(array $data): array
  5025. {
  5026. $result = Complaint::where('id', $data['id'])->first();
  5027. if (empty($result)) {
  5028. return Result::error("查询失败", 0);
  5029. }
  5030. return Result::success($result);
  5031. }
  5032. public function readComplaint(array $data): array
  5033. {
  5034. $result = Complaint::where('id', $data['id'])->first();
  5035. if (empty($result)) {
  5036. return Result::error("查询失败", 0);
  5037. }
  5038. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  5039. $re_user_ids = json_decode($result['re_user_ids'], true);
  5040. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  5041. //如果已经存在,就不再添加
  5042. if (isset($result['read_id']) && !empty($result['read_id'])) {
  5043. $read_id = json_decode($result['read_id'], true);
  5044. if (!is_array($read_id)) {
  5045. $read_id = [];
  5046. }
  5047. if (!in_array($data['user_id'], $read_id)) {
  5048. $read_id[] = $data['user_id'];
  5049. $result['read_id'] = json_encode($read_id);
  5050. Complaint::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  5051. }
  5052. } else {
  5053. //如果不存在,就添加
  5054. $result['read_id'] = json_encode([$data['user_id']]);
  5055. Complaint::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  5056. }
  5057. }
  5058. return Result::success($result);
  5059. }
  5060. public function addComplaint(array $data): array
  5061. {
  5062. date_default_timezone_set('Asia/Shanghai');
  5063. $data['created_at'] = date('Y-m-d H:i:s');
  5064. $data['updated_at'] = date('Y-m-d H:i:s');
  5065. $this->sendMessage([
  5066. 'talk_type' => 800,
  5067. 'title' => $data['title'],
  5068. 'content' => '提交了审核',
  5069. 'messageType' => 6,
  5070. ]);
  5071. $result = Complaint::create($data);
  5072. return Result::success($result);
  5073. }
  5074. public function updateComplaint(array $data): array
  5075. {
  5076. date_default_timezone_set('Asia/Shanghai');
  5077. $data['updated_at'] = date('Y-m-d H:i:s');
  5078. $user_id = $data['user_id'] ?? 0;
  5079. $type_id = $data['type_id'] ?? 0;
  5080. unset($data['user_id']);
  5081. unset($data['type_id']);
  5082. $this->sendMessage([
  5083. 'talk_type' => 800,
  5084. 'title' => $data['title'],
  5085. 'content' => '提交了审核',
  5086. 'messageType' => 6,
  5087. ]);
  5088. $result = Complaint::where('id', $data['id'])->update($data);
  5089. return Result::success($result);
  5090. }
  5091. public function deleteComplaint(array $data): array
  5092. {
  5093. $result = Complaint::where('id', $data['id'])->delete();
  5094. return Result::success($result);
  5095. }
  5096. public function getComplainInfo(array $data): array
  5097. {
  5098. $result = Complaint::where('id', $data['id'])->first();
  5099. if (empty($result)) {
  5100. return Result::error("查询失败", 0);
  5101. }
  5102. return Result::success($result);
  5103. }
  5104. public function updateComplaintStatus(array $data): array
  5105. {
  5106. date_default_timezone_set('Asia/Shanghai');
  5107. $data['updated_at'] = date('Y-m-d H:i:s');
  5108. $user_id = $data['user_id'] ?? 0;
  5109. $type_id = $data['type_id'] ?? 0;
  5110. unset($data['user_id']);
  5111. unset($data['type_id']);
  5112. //处理, 写入处理人
  5113. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  5114. $data['real_deal_user'] = $user_id;
  5115. }
  5116. //如果是deal 23,则判断是不是处理人
  5117. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  5118. $complaintInof = Complaint::where('id', $data['id'])
  5119. ->where('real_deal_user', $user_id)
  5120. ->first();
  5121. if (empty($complaintInof)) {
  5122. return Result::error("处理人错误", 0);
  5123. }
  5124. }
  5125. $complaintInfo = Complaint::where('id', $data['id'])->first();
  5126. if ($data['status'] == 1) {
  5127. $this->sendMessage([
  5128. 'talk_type' => 800,
  5129. 'title' => $complaintInfo['title'],
  5130. 'content' => '提交了审核',
  5131. 'messageType' => 6,
  5132. ]);
  5133. }
  5134. if ($data['status'] == 2 && !isset($data['deal'])) {
  5135. $this->sendMessage([
  5136. 'talk_type' => 801,
  5137. 'title' => $complaintInfo['title'],
  5138. 'content' => '审核通过',
  5139. 'messageType' => 6,
  5140. 'user_id' => $complaintInfo['user_id'],
  5141. ]);
  5142. $this->sendMessage([
  5143. 'talk_type' => 802,
  5144. 'title' => $complaintInfo['title'],
  5145. 'content' => '待处理',
  5146. 'messageType' => 6,
  5147. 'user_id' => $complaintInfo['re_user_ids'],
  5148. ]);
  5149. }
  5150. if ($data['status'] == 3 && !isset($data['deal'])) {
  5151. $this->sendMessage([
  5152. 'talk_type' => 801,
  5153. 'title' => $complaintInfo['title'],
  5154. 'content' => '审核拒绝',
  5155. 'messageType' => 6,
  5156. 'user_id' => $complaintInfo['user_id'],
  5157. ]);
  5158. }
  5159. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 2) {
  5160. $this->sendMessage([
  5161. 'talk_type' => 802,
  5162. 'title' => $complaintInfo['title'],
  5163. 'content' => '处理中',
  5164. 'messageType' => 6,
  5165. 'user_id' => $complaintInfo['re_user_ids'],
  5166. ]);
  5167. }
  5168. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 4) {
  5169. $this->sendMessage([
  5170. 'talk_type' => 802,
  5171. 'title' => $complaintInfo['title'],
  5172. 'content' => '不予处理',
  5173. 'messageType' => 6,
  5174. 'user_id' => $complaintInfo['re_user_ids'],
  5175. ]);
  5176. }
  5177. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 3) {
  5178. $this->sendMessage([
  5179. 'talk_type' => 802,
  5180. 'title' => $complaintInfo['title'],
  5181. 'content' => '已完结',
  5182. 'messageType' => 6,
  5183. 'user_id' => $complaintInfo['re_user_ids'],
  5184. ]);
  5185. }
  5186. $result = complaint::where('id', $data['id'])->update($data);
  5187. return Result::success($result);
  5188. }
  5189. public function updateGoodStatus(array $data): array
  5190. {
  5191. $user_id = $data['user_id'] ?? 0;
  5192. $type_id = $data['type_id'] ?? 0;
  5193. unset($data['user_id']);
  5194. unset($data['type_id']);
  5195. $goodInfo = Good::where('id', $data['id'])->first();
  5196. if ($data['status'] == 2) {
  5197. $this->sendMessage([
  5198. 'talk_type' => 201,
  5199. 'title' => $goodInfo['name'],
  5200. 'content' => '审核通过',
  5201. 'messageType' => 3,
  5202. 'user_id' => $goodInfo['user_id'],
  5203. ]);
  5204. }
  5205. if ($data['status'] == 3) {
  5206. $this->sendMessage([
  5207. 'talk_type' => 201,
  5208. 'title' => $goodInfo['name'],
  5209. 'content' => '审核拒绝',
  5210. 'messageType' => 3,
  5211. 'user_id' => $goodInfo['user_id'],
  5212. ]);
  5213. }
  5214. if ($data['status'] == 1) {
  5215. $this->sendMessage([
  5216. 'talk_type' => 200,
  5217. 'title' => $goodInfo['name'],
  5218. 'content' => '提交了审核',
  5219. 'messageType' => 3,
  5220. ]);
  5221. }
  5222. $result = Good::where('id', $data['id'])->update($data);
  5223. return Result::success($result);
  5224. }
  5225. public function updateJobHuntingStatus(array $data): array
  5226. {
  5227. $user_id = $data['user_id'] ?? 0;
  5228. $type_id = $data['type_id'] ?? 0;
  5229. unset($data['user_id']);
  5230. unset($data['type_id']);
  5231. $jogHuntingInfo = JobHunting::where('id', $data['id'])->first();
  5232. if ($data['status'] == 2) {
  5233. $this->sendMessage([
  5234. 'talk_type' => 601,
  5235. 'title' => $jogHuntingInfo['name'],
  5236. 'content' => '审核通过',
  5237. 'messageType' => 11,
  5238. 'user_id' => $jogHuntingInfo['user_id'],
  5239. ]);
  5240. }
  5241. if ($data['status'] == 3) {
  5242. $this->sendMessage([
  5243. 'talk_type' => 601,
  5244. 'title' => $jogHuntingInfo['name'],
  5245. 'content' => '审核拒绝',
  5246. 'messageType' => 11,
  5247. 'user_id' => $jogHuntingInfo['user_id'],
  5248. ]);
  5249. }
  5250. if ($data['status'] == 1) {
  5251. $this->sendMessage([
  5252. 'talk_type' => 600,
  5253. 'title' => $jogHuntingInfo['name'],
  5254. 'content' => '提交了审核',
  5255. 'messageType' => 11,
  5256. ]);
  5257. }
  5258. $result = JobHunting::where('id', $data['id'])->update($data);
  5259. return Result::success($result);
  5260. }
  5261. public function updateNoticeStatus(array $data): array
  5262. {
  5263. $user_id = $data['user_id'] ?? 0;
  5264. $type_id = $data['type_id'] ?? 0;
  5265. unset($data['user_id']);
  5266. unset($data['type_id']);
  5267. //查询公告
  5268. $notice = Notice::where('id', $data['id'])->first();
  5269. if (empty($notice)) {
  5270. return Result::error("公告不存在", 0);
  5271. }
  5272. //$chat_ids 去除掉$data['user_id']
  5273. $chat_ids = json_decode($notice['re_user_ids'], true);
  5274. $chat_ids = array_diff($chat_ids, [$notice['user_id']]);
  5275. //如果公告的状态是2,且是群聊公告,且状态是1,则创建群聊,第一次审核通过的时候处理成群聊
  5276. if ($data['status'] == 2 && $notice['is_group'] == 1 && ($notice['status'] == 1 || $notice['status'] == 3) && empty($notice['group_id'])) {
  5277. //chat_group
  5278. $group_id = PublicData::uuid();
  5279. $groupData = [
  5280. 'id' => $group_id,
  5281. 'creator_id' => $notice['user_id'],
  5282. 'group_name' => $notice['group_name'] ?? '',
  5283. 'profile' => $notice['profile'] ?? 0,
  5284. ];
  5285. var_dump($groupData, '-----------------groupData-------');
  5286. $groupResult = ChatGroups::insertGetId($groupData);
  5287. var_dump($groupResult, '-----------------groupid-------');
  5288. $groupMemberData = [
  5289. 'id' => PublicData::uuid(),
  5290. 'user_id' => $notice['user_id'],
  5291. 'group_id' => $group_id,
  5292. 'leader' => 2,
  5293. ];
  5294. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  5295. //插入群成员表
  5296. $groupMemberDataUser = [];
  5297. $chatData = [];
  5298. foreach ($chat_ids as $key => $value) {
  5299. $groupMemberDataUser[] = [
  5300. 'id' => PublicData::uuid(),
  5301. 'user_id' => $value,
  5302. 'group_id' => $group_id,
  5303. 'leader' => 1,
  5304. ];
  5305. $chatData[] = [
  5306. 'user_id' => $value,
  5307. 'msg_type' => 1,
  5308. 'receiver_id' => $group_id,
  5309. 'content' => '通过通知创建群聊',
  5310. 'group_receiver_id' => $notice['user_id'],
  5311. 'action' => 'recieved',
  5312. 'created_at' => date('Y-m-d H:i:s'),
  5313. ];
  5314. }
  5315. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  5316. ChatGroupsMember::insert($groupMemberDataUser);
  5317. //插入一条管理员聊天记录
  5318. $chatData[] = [
  5319. 'user_id' => $notice['user_id'],
  5320. 'msg_type' => 1,
  5321. 'receiver_id' => $group_id,
  5322. 'content' => '通过通知创建群聊',
  5323. 'group_receiver_id' => $notice['user_id'],
  5324. 'action' => 'said',
  5325. 'created_at' => date('Y-m-d H:i:s'),
  5326. ];
  5327. var_dump($chatData, '-----------------chatData-------');
  5328. $chatResult = ChatRecords::insert($chatData);
  5329. //处理imp
  5330. $group = [
  5331. 'type' => 1,
  5332. 'name' => $notice['group_name'] ?? '',
  5333. 'profile' => '',
  5334. 'avatar' => '',
  5335. 'creator_id' => $notice['user_id'],
  5336. ];
  5337. $groupResult = GroupImp::insertGetId($group);
  5338. var_dump($groupResult, '获取imp group_id');
  5339. $groupMember = [
  5340. 'user_id' => $notice['user_id'],
  5341. 'group_id' => $groupResult,
  5342. 'leader' => 1,
  5343. 'join_time' => Date('Y-m-d H:i:s')
  5344. ];
  5345. $groupMemberResult = GroupMemberImp::insertGetId($groupMember);
  5346. $talk_session = [
  5347. 'user_id' => $notice['user_id'],
  5348. 'to_from_id' => $groupResult,
  5349. 'talk_mode' => 2,
  5350. 'created_at' => Date('Y-m-d H:i:s'),
  5351. 'updated_at' => Date('Y-m-d H:i:s'),
  5352. ];
  5353. $talk_session_result = GroupTalkImp::insertGetId($talk_session);
  5354. //被通知人员处理
  5355. foreach ($chat_ids as $key => $value) {
  5356. $groupMemberdata[] = [
  5357. 'user_id' => $value,
  5358. 'group_id' => $groupResult,
  5359. 'leader' => 3,
  5360. 'join_time' => Date('Y-m-d H:i:s')
  5361. ];
  5362. $talk_sessionData[] = [
  5363. 'user_id' => $value,
  5364. 'to_from_id' => $groupResult,
  5365. 'talk_mode' => 2,
  5366. 'created_at' => Date('Y-m-d H:i:s'),
  5367. 'updated_at' => Date('Y-m-d H:i:s'),
  5368. ];
  5369. }
  5370. $groupResult1 = GroupMemberImp::insert($groupMemberdata);
  5371. $talk_sessionResult = GroupTalkImp::insert($talk_sessionData);
  5372. $group_id = $groupResult;
  5373. //更新result的 group_id
  5374. $data['group_id'] = $group_id;
  5375. Notice::where(['id' => $data['id']])->update($data);
  5376. }
  5377. if (($data['status'] == 1 || $data['status'] == 3) && $notice['is_group'] == 1 && $notice['status'] == 2 && !empty($notice['group_id'])) {
  5378. //删除掉信息
  5379. GroupImp::where('id', $notice['group_id'])->delete();
  5380. GroupMemberImp::where('group_id', $notice['group_id'])->delete();
  5381. GroupTalkImp::where('to_from_id', $notice['group_id'])->delete();
  5382. foreach ($chat_ids as $key => $value) {
  5383. }
  5384. //聊天记录删除
  5385. //如果是群聊公告,且已经有群聊id,则更新公告的group_id
  5386. $data['group_id'] = null;
  5387. Notice::where(['id' => $data['id']])->update($data);
  5388. }
  5389. $result = Notice::where('id', $data['id'])->update($data);
  5390. $noticeInfo = Notice::where('id', $data['id'])->first();
  5391. if ($data['status'] == 2) {
  5392. $this->sendMessage([
  5393. 'talk_type' => 701,
  5394. 'title' => $noticeInfo['title'],
  5395. 'content' => '审核通过',
  5396. 'messageType' => 3,
  5397. 'user_id' => $noticeInfo['user_id'],
  5398. ]);
  5399. }
  5400. if ($data['status'] == 3) {
  5401. $this->sendMessage([
  5402. 'talk_type' => 701,
  5403. 'title' => $noticeInfo['title'],
  5404. 'content' => '审核拒绝',
  5405. 'messageType' => 3,
  5406. 'user_id' => $noticeInfo['user_id'],
  5407. ]);
  5408. }
  5409. if ($data['status'] == 1) {
  5410. $this->sendMessage([
  5411. 'talk_type' => 700,
  5412. 'title' => $noticeInfo['title'],
  5413. 'content' => '提交了审核',
  5414. 'messageType' => 3,
  5415. ]);
  5416. }
  5417. return Result::success($result);
  5418. }
  5419. public function getDUser(array $data): array
  5420. {
  5421. if (!empty($data['ids'])) {
  5422. $user = User::whereIn('id', $data['ids'])->getall();
  5423. if (empty($user)) {
  5424. return Result::error('无数据', 0);
  5425. }
  5426. return Result::success($user);
  5427. }
  5428. $where = [];
  5429. if (!empty($data['department_id'])) {
  5430. $where['department_id'] = $data['department_id'];
  5431. }
  5432. if (!empty($data['city_id'])) {
  5433. $where['city_id'] = $data['city_id'];
  5434. }
  5435. $result = User::where('type_id', 2)
  5436. ->where('status', 1)
  5437. ->where($where)
  5438. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  5439. ->get();
  5440. if (empty($result)) {
  5441. return Result::error("查询失败", 0);
  5442. }
  5443. return Result::success($result);
  5444. }
  5445. /**
  5446. * 验证导航名称是否重复
  5447. * @return void
  5448. */
  5449. public function checkCategoryName(array $data): array
  5450. {
  5451. $result = Category::when($data, function ($query) use ($data) {
  5452. if (isset($data['name']) && $data['name']) {
  5453. $query->where("name", $data['name']);
  5454. }
  5455. if (isset($data['id']) && $data['id']) {
  5456. $query->where("id", "!=", $data['id']);
  5457. }
  5458. })->first();
  5459. if ($result) {
  5460. return Result::error("已存在");
  5461. } else {
  5462. return Result::success();
  5463. }
  5464. }
  5465. //20250226 产品列表
  5466. // 20250306 -------招聘--------fr
  5467. /*
  5468. * 招聘列表
  5469. * */
  5470. public function getJobRecruitingList(array $data): array
  5471. {
  5472. $where = [];
  5473. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  5474. if ($data['checkout'] == 0) {
  5475. $job_status = [0, 2];
  5476. } else {
  5477. $job_status = [1];
  5478. }
  5479. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5480. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  5481. }
  5482. $user = User::where('id', $data['user_id'])->first();
  5483. if (empty($user)) {
  5484. return Result::error("用户不存在", 0);
  5485. }
  5486. // 3:企业会员
  5487. if ($user['type_id'] == 3) {
  5488. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  5489. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  5490. }
  5491. // 如果 $where 为空,则不添加 where 条件
  5492. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5493. return $query->where($where);
  5494. })
  5495. ->whereIn('job_recruiting.status', $job_status)
  5496. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5497. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  5498. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  5499. ->orderBy("updated_at", "desc")
  5500. ->offset(($data['page'] - 1) * $data['page_size'])
  5501. ->limit($data['page_size'])
  5502. ->get()
  5503. ->all();
  5504. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5505. return $query->where($where);
  5506. })
  5507. ->whereIn('job_recruiting.status', $job_status)
  5508. ->count();
  5509. if (empty($result)) {
  5510. return Result::error("暂无招聘信息", 0);
  5511. }
  5512. return Result::success($result);
  5513. }
  5514. /*
  5515. * 招聘信息添加
  5516. * */
  5517. public function addJobRecruiting(array $data): array
  5518. {
  5519. // var_dump('添加招聘进入news------data',$data);
  5520. // return Result::success($data);
  5521. $user = User::where('user.id', $data['user_id'])
  5522. ->where('user.status', 1)
  5523. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5524. ->select(
  5525. 'user.type_id',
  5526. 'user.mobile',
  5527. 'user.email',
  5528. 'user_info.business_name',
  5529. 'user_info.company_hy_id',
  5530. 'user_info.company_nature',
  5531. 'user_info.company_size',
  5532. 'user_info.introduction',
  5533. 'user_info.real_name',
  5534. 'user_info.company_url',
  5535. 'user_info.address_arr_id',
  5536. 'user_info.address'
  5537. )
  5538. ->first();
  5539. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5540. return Result::error("用户不存在", 0);
  5541. }
  5542. $web = Website::where('id', $data['website_id'])->first();
  5543. if (empty($web)) {
  5544. return Result::error("网站不存在", 0);
  5545. }
  5546. // var_dump('添加招聘进入news---user---user',$user);
  5547. // 处理招聘关键词
  5548. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5549. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5550. } else {
  5551. Jieba::init(); // 初始化 jieba-php
  5552. Finalseg::init();
  5553. $segList = Jieba::cut($data['title']);
  5554. $segList1 = array_slice($segList, 0, 8);
  5555. $data['keyword'] = implode(',', $segList1);
  5556. }
  5557. if (!isset($data['seo_description']) || empty($data['seo_description'])) {
  5558. $content = $data['description'];
  5559. // 去除 <style> 和 <script> 标签及其内容
  5560. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5561. // 去除所有 HTML 标签
  5562. $content = strip_tags($content);
  5563. // 去除 HTML 实体
  5564. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5565. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5566. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5567. // 去除多余空白
  5568. $content = preg_replace('/\s+/u', '', $content);
  5569. // 截取 100 个字符
  5570. $data['seo_description'] = mb_substr($content, 0, 100);
  5571. }
  5572. // return Result::success($user);
  5573. $data['action_id'] = $data['user_id'] ?? null;
  5574. $data['user_type'] = $user['type_id'] ?? null;
  5575. $data['cat_arr_id'] = isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) ? array_values(array_unique($data['cat_arr_id'])) : [];
  5576. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5577. $data['catid'] = end($data['cat_arr_id']);
  5578. } else {
  5579. $data['catid'] = 0;
  5580. }
  5581. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? array_values(array_unique($data['city_arr_id'])) : [];
  5582. $data['cat_arr_id'] = isset($data['cat_arr_id']) && $data['cat_arr_id'] != [] ? json_encode(array_map('intval', $data['cat_arr_id'])) : '[]';
  5583. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '[]';
  5584. // 公司地址 管理员必填
  5585. $data['address_arr_id'] = isset($data['address_arr_id']) && !empty($data['address_arr_id']) ? array_values(array_unique($data['address_arr_id'])) : [];
  5586. $data['address_arr_id'] = isset($data['address_arr_id']) && $data['address_arr_id'] != [] ? json_encode(array_map('intval', $data['address_arr_id'])) : '[]';
  5587. // 管理员-企业相关信息
  5588. $company = [
  5589. // 'user_id' => $data['user_id']?? null,
  5590. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5591. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5592. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5593. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5594. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5595. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5596. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5597. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5598. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5599. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5600. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5601. ];
  5602. //去掉相关企业信息
  5603. $job = array_diff_key($data, array_flip(array_keys($company)));
  5604. // var_dump('添加招聘进入news---job---user',$job);
  5605. Db::beginTransaction();
  5606. try {
  5607. // // 先添加职位相关信息
  5608. if ($user['type_id'] == 10000) {
  5609. $job['status'] = 1;
  5610. }
  5611. $job['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5612. $job['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5613. $job['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5614. $job['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5615. $job['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5616. $job['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5617. $job['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5618. // return Result::success($job);
  5619. $jobId = JobRecruiting::insertGetId($job);
  5620. if (empty($jobId)) {
  5621. Db::rollBack();
  5622. return Result::error("添加失败");
  5623. }
  5624. // 添加公司信息
  5625. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5626. $company['job_id'] = $jobId;
  5627. $company['user_type'] = isset($user['type_id']) && $user['type_id'] !== '' ? $user['type_id'] : null;
  5628. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5629. if ($user['type_id'] == 10000) {
  5630. // 管理员添加企业信息
  5631. $companyId = JobCompany::insertGetId($company);
  5632. if (empty($companyId)) {
  5633. Db::rollBack();
  5634. return Result::error("添加失败");
  5635. }
  5636. } else {
  5637. // 企业会员添加企业信息
  5638. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5639. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5640. $company['user_type'] = isset($data['user_type']) && $data['user_type'] !== '' ? $data['user_type'] : null;
  5641. $company['job_id'] = $jobId;
  5642. $companyId = JobCompany::insertGetId($company);
  5643. if (empty($companyId)) {
  5644. Db::rollBack();
  5645. return Result::error("添加失败");
  5646. }
  5647. }
  5648. Db::commit();
  5649. $result = [
  5650. 'job_id' => $jobId,
  5651. 'company_id' => $companyId,
  5652. ];
  5653. return Result::success($result);
  5654. } catch (\Exception $e) {
  5655. Db::rollBack();
  5656. return Result::error($e->getMessage(), 0);
  5657. }
  5658. // return Result::success($result);
  5659. }
  5660. /*
  5661. * 获取招聘信息详情
  5662. * */
  5663. public function getJobRecruitingInfo(array $data): array
  5664. {
  5665. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  5666. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5667. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5668. ->select(
  5669. 'job_recruiting.*',
  5670. 'website.website_name as website_name',
  5671. 'job_company.business_name',
  5672. 'job_company.company_hy_id',
  5673. 'job_company.company_size',
  5674. 'job_company.company_nature',
  5675. 'job_company.introduction',
  5676. 'job_company.real_name',
  5677. 'job_company.mobile',
  5678. 'job_company.company_url',
  5679. 'job_company.address_arr_id',
  5680. 'job_company.address',
  5681. 'job_company.email'
  5682. )
  5683. ->first();
  5684. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  5685. if (!empty($cityId)) {
  5686. if (isset($cityId[1]) && $cityId[1] != null) {
  5687. $city = District::where('id', $cityId[1])->first(['name']);
  5688. } else {
  5689. $city = District::where('id', $cityId[0])->first(['name']);
  5690. }
  5691. $result['city'] = $city['name'] ?? '';
  5692. }
  5693. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  5694. if (is_array($addressId) && !empty($addressId)) {
  5695. $address = District::whereIn('id', $addressId)
  5696. ->orderBy('level', 'asc')
  5697. ->get(['name'])
  5698. ->pluck('name')
  5699. ->implode('');
  5700. // $job->address_name = $address ?? '';
  5701. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  5702. }
  5703. if (empty($result)) {
  5704. return Result::error("招聘信息不存在", 0);
  5705. }
  5706. // return Result::success($job);
  5707. return Result::success($result);
  5708. }
  5709. /*
  5710. * 修改招聘信息
  5711. * */
  5712. public function upJobRecruiting(array $data): array
  5713. {
  5714. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  5715. // return Result::success($job);
  5716. if (empty($job)) {
  5717. return Result::error("招聘信息不存在", 0);
  5718. }
  5719. $user = User::where('id', $data['user_id'])->first();
  5720. // return Result::success($user);
  5721. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5722. return Result::error("用户不存在", 0);
  5723. }
  5724. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5725. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5726. }
  5727. // 处理招聘关键词
  5728. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5729. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5730. } else {
  5731. Jieba::init(); // 初始化 jieba-php
  5732. Finalseg::init();
  5733. $segList = Jieba::cut($data['title']);
  5734. $segList1 = array_slice($segList, 0, 8);
  5735. $data['keyword'] = implode(',', $segList1);
  5736. }
  5737. if (!isset($data['seo_description']) || empty($data['seo_description'])) {
  5738. $content = $data['description'];
  5739. // 去除 <style> 和 <script> 标签及其内容
  5740. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5741. // 去除所有 HTML 标签
  5742. $content = strip_tags($content);
  5743. // 去除 HTML 实体
  5744. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5745. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5746. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5747. // 去除多余空白
  5748. $content = preg_replace('/\s+/u', '', $content);
  5749. // 截取 100 个字符
  5750. $data['seo_description'] = mb_substr($content, 0, 100);
  5751. }
  5752. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  5753. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5754. $data['catid'] = end($data['cat_arr_id']);
  5755. } else {
  5756. }
  5757. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  5758. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  5759. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  5760. // 公司地址 管理员必填
  5761. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  5762. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5763. // 管理员-企业相关信息
  5764. $company = [
  5765. // 'user_id' => $data['user_id']?? null,
  5766. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5767. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5768. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5769. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5770. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5771. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5772. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5773. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5774. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5775. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5776. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5777. ];
  5778. //去掉相关企业信息
  5779. $data = array_diff_key($data, array_flip(array_keys($company)));
  5780. $jobId = $data['id'];
  5781. $web = $data['website_id'];
  5782. $data['action_id'] = $data['user_id'];
  5783. unset($data['user_id']);
  5784. unset($data['user_type']);
  5785. unset($data['id']);
  5786. unset($data['website_id']);
  5787. // return Result::success($data);
  5788. Db::beginTransaction();
  5789. try {
  5790. // 管理员修改招聘信息
  5791. if ($user['type_id'] == 10000) {
  5792. $data['website_id'] = $web;
  5793. $company['website_id'] = $data['website_id'];
  5794. $data['status'] = 1;
  5795. } else {
  5796. $data['status'] = 0;
  5797. }
  5798. $data['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5799. $data['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5800. $data['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5801. $data['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5802. $data['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5803. $data['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5804. $data['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5805. // return Result::success($job);
  5806. // Db::rollBack();
  5807. // return Result::success($company);
  5808. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  5809. $this->sendMessage([
  5810. 'talk_type' => 500,
  5811. 'title' => $data['title'],
  5812. 'content' => '提交了审核',
  5813. 'messageType' => 10,
  5814. ]);
  5815. }
  5816. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  5817. if (empty($result['job'])) {
  5818. Db::rollBack();
  5819. return Result::error("修改招聘信息失败");
  5820. }
  5821. // 管理员修改企业相关信息
  5822. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  5823. if (empty($result['company'])) {
  5824. Db::rollBack();
  5825. return Result::error("修改企业相关信息失败");
  5826. }
  5827. Db::commit();
  5828. // return Result::success($result);
  5829. } catch (\Exception $e) {
  5830. Db::rollBack();
  5831. return Result::error($e->getMessage(), 0);
  5832. }
  5833. return Result::success($result);
  5834. }
  5835. /*
  5836. * 招聘信息删除
  5837. * */
  5838. public function delJobRecruiting(array $data): array
  5839. {
  5840. $user = User::where('id', $data['user_id'])->first();
  5841. if (empty($user)) {
  5842. return Result::error("用户不存在", 0);
  5843. }
  5844. $job = JobRecruiting::where('id', $data['id'])->first();
  5845. if (empty($job)) {
  5846. return Result::error("招聘信息不存在", 0);
  5847. }
  5848. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5849. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5850. }
  5851. Db::beginTransaction();
  5852. try {
  5853. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  5854. if (empty($result['job'])) {
  5855. Db::rollBack();
  5856. return Result::error("删除招聘信息失败");
  5857. }
  5858. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  5859. if (empty($result['company'])) {
  5860. Db::rollBack();
  5861. return Result::error("删除企业相关信息失败");
  5862. }
  5863. Db::commit();
  5864. } catch (\Exception $e) {
  5865. Db::rollBack();
  5866. return Result::error($e->getMessage(), 0);
  5867. }
  5868. return Result::success($result);
  5869. }
  5870. /*
  5871. * 获取公司信息
  5872. * */
  5873. public function getJobCompany(array $data): array
  5874. {
  5875. $user = User::where('user.id', $data['user_id'])
  5876. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5877. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  5878. ->first();
  5879. // return Result::success($user);
  5880. if (empty($user)) {
  5881. return Result::error("用户不存在", 0);
  5882. }
  5883. if ($user['type_id'] == 3) {
  5884. $result = [
  5885. // 'id' => 0,
  5886. 'user_id' => $data['user_id'],
  5887. 'website_id' => $data['website_id'],
  5888. 'business_name' => $user['business_name'], // 企业名称
  5889. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  5890. 'company_nature' => $user['company_nature'], // 公司性质
  5891. 'company_size' => $user['company_size'], // 公司规模
  5892. 'introduction' => $user['introduction'], // 公司简介
  5893. 'real_name' => $user['real_name'], // 企业联系人
  5894. 'mobile' => $user['mobile'], // 企业联系电话
  5895. 'company_url' => $user['company_url'], // 企业网址
  5896. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  5897. 'address' => $user['address'], // 企业地址
  5898. 'email' => $user['email'], // 企业邮箱
  5899. ];
  5900. } else {
  5901. return Result::error("用户类型错误", 0);
  5902. }
  5903. if (empty($result)) {
  5904. return Result::error("公司信息不存在", 0);
  5905. }
  5906. return Result::success($result);
  5907. }
  5908. /*
  5909. * 修改公司信息
  5910. * */
  5911. public function upJobCompany(array $data): array
  5912. {
  5913. // return Result::success($data);
  5914. $user = User::where('user.id', $data['user_id'])
  5915. ->where('user.status', 1)
  5916. ->select('user.user_name', 'user.type_id')
  5917. ->first();
  5918. if (empty($user)) {
  5919. return Result::error("用户不存在", 0);
  5920. }
  5921. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5922. $job_company = JobCompany::where('user_id', $data['user_id'])->first();
  5923. $company = [
  5924. 'business_name' => $data['business_name'], // 企业名称
  5925. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5926. 'company_nature' => $data['company_nature'], // 公司性质
  5927. 'company_size' => $data['company_size'], // 公司规模
  5928. 'introduction' => $data['introduction'], // 公司简介
  5929. // 'real_name' => $data['real_name'], // 企业联系人
  5930. 'company_url' => $data['company_url'], // 企业网址
  5931. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5932. 'address' => $data['address'], // 企业详细地址
  5933. // 'email' => $data['email'], // 企业邮箱
  5934. ];
  5935. if ($user['type_id'] == 3) {
  5936. Db::beginTransaction();
  5937. try {
  5938. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  5939. 'business_name' => $data['business_name'], // 企业名称
  5940. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5941. 'company_nature' => $data['company_nature'], // 公司性质
  5942. 'company_size' => $data['company_size'], // 公司规模
  5943. 'introduction' => $data['introduction'], // 公司简介
  5944. // 'real_name' => $data['real_name'], // 企业联系人
  5945. 'company_url' => $data['company_url'], // 企业网址
  5946. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5947. 'address' => $data['address'], // 企业详细地址
  5948. ]);
  5949. if (empty($result['userinfo'])) {
  5950. Db::rollBack();
  5951. return Result::error('修改企业会员信息失败!');
  5952. }
  5953. $result['user'] = User::where('id', $data['user_id'])->update([
  5954. 'email' => $data['email'], // 企业邮箱
  5955. ]);
  5956. if (empty($result['user'])) {
  5957. Db::rollBack();
  5958. return Result::error('修改个人中心信息失败!');
  5959. }
  5960. // 该企业会员若是未发布招聘信息则暂无该企业会员的企业信息
  5961. if (!empty($job_company)) {
  5962. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  5963. if (empty($result['job_company'])) {
  5964. Db::rollBack();
  5965. return Result::error('修改企业会员信息失败!');
  5966. }
  5967. }
  5968. Db::commit();
  5969. return Result::success($result);
  5970. } catch (\Exception $e) {
  5971. Db::rollBack();
  5972. return Result::error($e->getMessage(), 0);
  5973. }
  5974. } else {
  5975. return Result::error("用户类型错误", 0);
  5976. }
  5977. }
  5978. /*
  5979. * 获取省-市
  5980. * */
  5981. public function getJobRecruitingArea(array $data): array
  5982. {
  5983. if (isset($data['pid']) && $data['pid'] != null) {
  5984. $result = District::where('pid', $data['pid'])->get()->all();
  5985. } else {
  5986. $result = District::where('level', 1)->get()->all();
  5987. }
  5988. if (empty($result)) {
  5989. return Result::error("暂无此省市", 0);
  5990. }
  5991. return Result::success($result);
  5992. }
  5993. /*
  5994. * 获取行业分类
  5995. * */
  5996. public function getIndustry(array $data): array
  5997. {
  5998. $result = JobIndustry::get()->all();
  5999. if (empty($result)) {
  6000. return Result::error("暂无行业分类", 0);
  6001. }
  6002. return Result::success($result);
  6003. }
  6004. /*
  6005. * 获取职位
  6006. * */
  6007. public function getPositionList(array $data): array
  6008. {
  6009. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  6010. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  6011. } else {
  6012. $result = JobPosition::where('zwpid', 0)->get()->all();
  6013. }
  6014. if (empty($result)) {
  6015. return Result::error("暂无此职位", 0);
  6016. }
  6017. return Result::success($result);
  6018. }
  6019. /*
  6020. * 获取工作性质-菜单
  6021. * */
  6022. public function getJobNature(array $data): array
  6023. {
  6024. $result = JobEnum::where('egroup', 'nature')->get()->all();
  6025. if (empty($result)) {
  6026. return Result::error("暂无工作性质", 0);
  6027. }
  6028. return Result::success($result);
  6029. }
  6030. /*
  6031. * 获取工作经验-菜单
  6032. * */
  6033. public function getExperience(array $data): array
  6034. {
  6035. $result = JobEnum::where('egroup', 'years')->get()->all();
  6036. if (empty($result)) {
  6037. return Result::error("暂无工作经验", 0);
  6038. }
  6039. return Result::success($result);
  6040. }
  6041. /*
  6042. * 获取学历-菜单
  6043. * */
  6044. public function getEducation(array $data): array
  6045. {
  6046. $result = JobEnum::where('egroup', 'education')->get()->all();
  6047. if (empty($result)) {
  6048. return Result::error("暂无学历", 0);
  6049. }
  6050. return Result::success($result);
  6051. }
  6052. /*
  6053. * 获取薪资-菜单
  6054. * */
  6055. public function getSalary(array $data): array
  6056. {
  6057. $result = JobEnum::where('egroup', 'income')->get()->all();
  6058. if (empty($result)) {
  6059. return Result::error("暂无薪资", 0);
  6060. }
  6061. return Result::success($result);
  6062. }
  6063. /*
  6064. * 获取语言-菜单
  6065. * */
  6066. public function getLanguage(array $data): array
  6067. {
  6068. $result = JobEnum::where('egroup', 'language')->get()->all();
  6069. if (empty($result)) {
  6070. return Result::error("暂无语言", 0);
  6071. }
  6072. return Result::success($result);
  6073. }
  6074. /*
  6075. * 获取掌握程度-菜单
  6076. * */
  6077. public function getLevel(array $data): array
  6078. {
  6079. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  6080. if (empty($result)) {
  6081. return Result::error("暂无工作性质", 0);
  6082. }
  6083. return Result::success($result);
  6084. }
  6085. // 公司信息
  6086. /*
  6087. * 获取公司性质-菜单
  6088. * */
  6089. public function getCompanyNature(array $data): array
  6090. {
  6091. $result = JobNature::get()->all();
  6092. if (empty($result)) {
  6093. return Result::error("暂无公司性质", 0);
  6094. }
  6095. return Result::success($result);
  6096. }
  6097. /*
  6098. * 获取公司规模-菜单
  6099. * */
  6100. public function getCompanySize(array $data): array
  6101. {
  6102. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  6103. if (empty($result)) {
  6104. return Result::error("暂无公司规模", 0);
  6105. }
  6106. return Result::success($result);
  6107. }
  6108. /*
  6109. * 招聘信息审核
  6110. * */
  6111. public function checkJobRecruiting(array $data): array
  6112. {
  6113. $user = User::where('id', $data['user_id'])->first();
  6114. if (empty($user)) {
  6115. return Result::error("用户不存在", 0);
  6116. }
  6117. $job = JobRecruiting::where('id', $data['id'])->first();
  6118. if (empty($job)) {
  6119. return Result::error("招聘信息不存在", 0);
  6120. }
  6121. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  6122. if ($user['type_id'] != 10000) {
  6123. return Result::error("用户暂无权限审核此招聘信息!", 0);
  6124. }
  6125. // 驳回原因
  6126. if ($data['status'] == 2) {
  6127. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  6128. }
  6129. $data['action_id'] = $data['user_id'];
  6130. unset($data['user_id']);
  6131. if ($data['status'] == 1) {
  6132. $this->sendMessage([
  6133. 'talk_type' => 501,
  6134. 'title' => $job['title'],
  6135. 'content' => '审核通过',
  6136. 'messageType' => 10,
  6137. 'user_id' => $job['user_id'],
  6138. ]);
  6139. }
  6140. if ($data['status'] == 2) {
  6141. $this->sendMessage([
  6142. 'talk_type' => 501,
  6143. 'title' => $job['title'],
  6144. 'content' => '审核拒绝',
  6145. 'messageType' => 10,
  6146. 'user_id' => $job['user_id'],
  6147. ]);
  6148. }
  6149. if ($data['status'] == 0) {
  6150. $this->sendMessage([
  6151. 'talk_type' => 500,
  6152. 'title' => $job['title'],
  6153. 'content' => '提交了审核',
  6154. 'messageType' => 10,
  6155. ]);
  6156. }
  6157. $result = JobRecruiting::where('id', $data['id'])->update($data);
  6158. if (empty($result)) {
  6159. return Result::error("审核失败", 0);
  6160. }
  6161. return Result::success($result);
  6162. }
  6163. public function myApplyList(array $data): array
  6164. {
  6165. var_dump($data, '------参数');
  6166. $user = User::where('id', $data['user_id'])->first();
  6167. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6168. return Result::error("用户不存在", 0);
  6169. }
  6170. // 1:个人会员 职场机会
  6171. if ($user['type_id'] == 1) {
  6172. $where['user_id'] = $user['id'];
  6173. }
  6174. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  6175. $query->where('user_id', $user['id']);
  6176. })
  6177. ->pluck('recruit_id');
  6178. $where = [];
  6179. if (isset($data['salary']) && $data['salary'] != null) {
  6180. $where['job_recruiting.salary'] = $data['salary'];
  6181. }
  6182. if (isset($data['experience']) && $data['experience'] != null) {
  6183. $where['job_recruiting.experience'] = $data['experience'];
  6184. }
  6185. if (isset($data['business_name']) && $data['business_name'] != null) {
  6186. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6187. }
  6188. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6189. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6190. ->where($where);
  6191. // ->count();
  6192. $count = $query->count();
  6193. $query = clone $query;
  6194. $job = $query
  6195. ->leftJoin('job_enum as income_enum', function ($join) {
  6196. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6197. ->where('income_enum.egroup', 'income');
  6198. })
  6199. ->leftJoin('job_enum as years_enum', function ($join) {
  6200. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6201. ->where('years_enum.egroup', 'years');
  6202. })
  6203. // ->where($where)
  6204. ->orderBy('job_recruiting.updated_at', 'desc')
  6205. ->select(
  6206. 'job_recruiting.id',
  6207. 'job_recruiting.title',
  6208. 'job_company.business_name',
  6209. 'income_enum.evalue as salary_evalue',
  6210. 'income_enum.ename as salary_ename',
  6211. 'years_enum.evalue as experience_evalue',
  6212. 'years_enum.ename as experience_ename',
  6213. 'job_recruiting.updated_at'
  6214. )
  6215. ->offset(($data['page'] - 1) * $data['pageSize'])
  6216. ->limit($data['pageSize'])
  6217. ->get()
  6218. ->all();
  6219. if (empty($job)) {
  6220. return Result::error("暂无招聘信息", 0);
  6221. }
  6222. $result = [
  6223. 'row' => $job,
  6224. 'count' => $count,
  6225. ];
  6226. return Result::success($result);
  6227. }
  6228. public function readJobApply(array $data): array
  6229. {
  6230. $result = JobApply::where('id', $data['id'])->first();
  6231. if (empty($result)) {
  6232. return Result::error("查询失败", 0);
  6233. }
  6234. $result = JobApply::where('id', $data['id'])->update([
  6235. 'status' => 2,
  6236. ]);
  6237. return Result::success($result);
  6238. }
  6239. /*
  6240. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  6241. * */
  6242. public function getRecruitingList(array $data): array
  6243. {
  6244. $user = User::where('id', $data['user_id'])->first();
  6245. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6246. return Result::error("用户不存在", 0);
  6247. }
  6248. // 1:个人会员 职场机会
  6249. if ($user['type_id'] == 1) {
  6250. $where['user_id'] = $user['id'];
  6251. }
  6252. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  6253. $query->where('receiver_id', $user['id']);
  6254. })
  6255. ->pluck('recruit_id');
  6256. // return Result::success($recruitingId);
  6257. $where = [];
  6258. if (isset($data['salary']) && $data['salary'] != null) {
  6259. $where['job_recruiting.salary'] = $data['salary'];
  6260. }
  6261. if (isset($data['experience']) && $data['experience'] != null) {
  6262. $where['job_recruiting.experience'] = $data['experience'];
  6263. }
  6264. if (isset($data['business_name']) && $data['business_name'] != null) {
  6265. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6266. }
  6267. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6268. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6269. ->where($where);
  6270. // ->count();
  6271. $count = $query->count();
  6272. $query = clone $query;
  6273. $job = $query
  6274. ->leftJoin('job_enum as income_enum', function ($join) {
  6275. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6276. ->where('income_enum.egroup', 'income');
  6277. })
  6278. ->leftJoin('job_enum as years_enum', function ($join) {
  6279. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6280. ->where('years_enum.egroup', 'years');
  6281. })
  6282. // ->where($where)
  6283. ->orderBy('job_recruiting.updated_at', 'desc')
  6284. ->select(
  6285. 'job_recruiting.id',
  6286. 'job_recruiting.title',
  6287. 'job_company.business_name',
  6288. 'income_enum.evalue as salary_evalue',
  6289. 'income_enum.ename as salary_ename',
  6290. 'years_enum.evalue as experience_evalue',
  6291. 'years_enum.ename as experience_ename',
  6292. 'job_recruiting.updated_at'
  6293. )
  6294. ->offset(($data['page'] - 1) * $data['pageSize'])
  6295. ->limit($data['pageSize'])
  6296. ->get()
  6297. ->all();
  6298. if (empty($job)) {
  6299. return Result::error("暂无招聘信息", 0);
  6300. }
  6301. $result = [
  6302. 'row' => $job,
  6303. 'count' => $count,
  6304. ];
  6305. return Result::success($result);
  6306. }
  6307. /*
  6308. * 获取企业会员-招聘信息列表
  6309. * */
  6310. public function getRecruitingInfo(array $data): array
  6311. {
  6312. $user = User::where('id', $data['user_id'])->first();
  6313. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6314. return Result::error("用户不存在", 0);
  6315. }
  6316. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  6317. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6318. ->select(
  6319. 'job_recruiting.*',
  6320. 'job_company.business_name',
  6321. 'job_company.company_hy_id',
  6322. 'job_company.company_size',
  6323. 'job_company.company_nature',
  6324. 'job_company.introduction',
  6325. 'job_company.real_name',
  6326. 'job_company.mobile',
  6327. 'job_company.company_url',
  6328. 'job_company.address_arr_id',
  6329. 'job_company.address',
  6330. 'job_company.email'
  6331. )
  6332. ->get();
  6333. if (empty($recruiting)) {
  6334. return Result::error("暂无招聘信息", 0);
  6335. }
  6336. return Result::success($recruiting);
  6337. }
  6338. /*
  6339. * 获取企业会员-我的沟通
  6340. * */
  6341. public function getJobResumeList(array $data): array
  6342. {
  6343. $user = User::where('id', $data['user_id'])->first();
  6344. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  6345. return Result::error("用户不存在", 0);
  6346. }
  6347. $where = [];
  6348. if (isset($data['salary']) && $data['salary'] != null) {
  6349. $where['job_hunting.salary'] = $data['salary'];
  6350. }
  6351. if (isset($data['user_name']) && $data['user_name'] != null) {
  6352. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  6353. }
  6354. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  6355. $query->where('job_resume.user_id', $user['id']);
  6356. })
  6357. ->when(!empty($where), function ($query) use ($where) {
  6358. $query->where($where);
  6359. })
  6360. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  6361. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  6362. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  6363. ->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');
  6364. $count = $job->count();
  6365. if ($count == 0) {
  6366. return Result::error("暂无沟通记录", 0);
  6367. }
  6368. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  6369. ->offset(($data['page'] - 1) * $data['pageSize'])
  6370. ->limit($data['pageSize'])
  6371. ->get();
  6372. if (empty($jobs)) {
  6373. return Result::error("暂无沟通记录", 0);
  6374. }
  6375. $result['row'] = $this->processJob($jobs, '');
  6376. $result['count'] = $count;
  6377. return Result::success($result);
  6378. }
  6379. public function readJobResume(array $data): array
  6380. {
  6381. $result = JobResume::where('id', $data['id'])->first();
  6382. if (empty($result)) {
  6383. return Result::error("查询失败", 0);
  6384. }
  6385. $result = JobResume::where('id', $data['id'])->update([
  6386. 'status' => 2,
  6387. ]);
  6388. return Result::success($result);
  6389. }
  6390. // 20250306 招聘
  6391. //20250422 书刊音像
  6392. public function addBook(array $data): array
  6393. {
  6394. $user_id = $data['user_id'] ?? 0;
  6395. $type_id = $data['type_id'] ?? 0;
  6396. // $website_id = $data['website_id'] ?? 0;
  6397. // unset($data['user_id']);
  6398. unset($data['type_id']);
  6399. // unset($data['website_id']);
  6400. //处理数组
  6401. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6402. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6403. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6404. if ($data['img_url'] == '') {
  6405. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6406. preg_match_all($reg, $data['detail'], $matches);
  6407. if (isset($matches[1][0])) {
  6408. //截取varchar240
  6409. $data['img_url'] = substr($matches[1][0], 0, 240);
  6410. }
  6411. }
  6412. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  6413. //提取标题+内容中的关键词
  6414. $data['keyword'] = $data['title'];
  6415. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6416. Jieba::init(); // 初始化 jieba-php
  6417. Finalseg::init();
  6418. $segList = Jieba::cut($data['keyword']);
  6419. $segList1 = array_slice($segList, 0, 8);
  6420. $data['keyword'] = implode(',', $segList1);
  6421. }
  6422. if ($data['description'] == '') {
  6423. //提取内容中的描述
  6424. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6425. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6426. }
  6427. var_dump($data, '--');
  6428. if ($data['status'] == 1) {
  6429. $this->sendMessage([
  6430. 'talk_type' => 400,
  6431. 'title' => $data['title'],
  6432. 'content' => '提交了审核',
  6433. 'messageType' => 7,
  6434. ]);
  6435. }
  6436. $result = Book::insertGetId($data);
  6437. if (empty($result)) {
  6438. return Result::error("添加失败", 0);
  6439. }
  6440. return Result::success($result);
  6441. }
  6442. public function getBookList(array $data): array
  6443. {
  6444. $where = [];
  6445. if (!empty($data["title"])) {
  6446. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  6447. }
  6448. if (!empty($data['website_name'])) {
  6449. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  6450. }
  6451. if (!empty($data['status'])) {
  6452. $where[] = ['book.status', '=', $data['status']];
  6453. }
  6454. $user_id = $data['user_id'];
  6455. $type_id = $data['type_id'];
  6456. // $type_id = 4;
  6457. var_dump($type_id, '------1--------');
  6458. if ($type_id != 10000) {
  6459. $where[] = ['book.user_id', '=', $user_id];
  6460. }
  6461. var_dump(!empty($data['status1']), '=-===1');
  6462. $result = Book::where($where)
  6463. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  6464. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  6465. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  6466. ->when(isset($data['status1']), function ($query) use ($data) {
  6467. $query->whereIn('book.status', [1, 3]);
  6468. })
  6469. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  6470. ->orderBy("updated_at", "desc")
  6471. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  6472. if (empty($result)) {
  6473. return Result::error("暂无数据", 0);
  6474. }
  6475. // 取出数据
  6476. $rows = $result->items();
  6477. $count = $result->total();
  6478. $responseData = [
  6479. 'rows' => $rows,
  6480. 'count' => $count,
  6481. ];
  6482. return Result::success($responseData);
  6483. }
  6484. public function deleteBook(array $data): array
  6485. {
  6486. $result = Book::where('id', $data['id'])->delete();
  6487. if (empty($result)) {
  6488. return Result::error("删除失败", 0);
  6489. }
  6490. return Result::success($result);
  6491. }
  6492. public function updateBook(array $data): array
  6493. {
  6494. // $user_id = $data['user_id'] ?? 0;
  6495. $type_id = $data['type_id'] ?? 0;
  6496. // $website_id = $data['website_id'] ?? 0;
  6497. unset($data['user_id']);
  6498. unset($data['type_id']);
  6499. // unset($data['website_id']);
  6500. //处理数组
  6501. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6502. if ($data['img_url'] == '') {
  6503. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6504. preg_match_all($reg, $data['detail'], $matches);
  6505. if (isset($matches[1][0])) {
  6506. //截取varchar240
  6507. $data['img_url'] = substr($matches[1][0], 0, 240);
  6508. }
  6509. }
  6510. if ($data['keyword'] == '') {
  6511. //提取标题+内容中的关键词
  6512. $data['keyword'] = $data['title'];
  6513. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6514. Jieba::init(); // 初始化 jieba-php
  6515. Finalseg::init();
  6516. $segList = Jieba::cut($data['keyword']);
  6517. $segList1 = array_slice($segList, 0, 8);
  6518. $data['keyword'] = implode(',', $segList1);
  6519. }
  6520. if ($data['description'] == '') {
  6521. //提取内容中的描述
  6522. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6523. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6524. }
  6525. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6526. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6527. if ($data['status'] == 1) {
  6528. $this->sendMessage([
  6529. 'talk_type' => 400,
  6530. 'title' => $data['title'],
  6531. 'content' => '提交了审核',
  6532. 'messageType' => 7,
  6533. ]);
  6534. }
  6535. $result = Book::where("id", $data["id"])->update($data);
  6536. if (empty($result)) {
  6537. return Result::error("更新失败", 0);
  6538. }
  6539. return Result::success($result);
  6540. }
  6541. public function getBookInfo(array $data): array
  6542. {
  6543. $result = Book::where("id", $data["id"])->first();
  6544. if (empty($result)) {
  6545. return Result::error("获取失败", 0);
  6546. }
  6547. return Result::success($result);
  6548. }
  6549. public function updateBookStatus(array $data): array
  6550. {
  6551. //审核
  6552. unset($data['user_id']);
  6553. $bookInfo = Book::where("id", $data["id"])->first();
  6554. var_dump($bookInfo, '----');
  6555. if ($data['status'] == 2) {
  6556. $this->sendMessage([
  6557. 'talk_type' => 401,
  6558. 'title' => $bookInfo['title'],
  6559. 'content' => '审核通过',
  6560. 'messageType' => 7,
  6561. 'user_id' => $bookInfo['user_id'],
  6562. ]);
  6563. }
  6564. if ($data['status'] == 3) {
  6565. $this->sendMessage([
  6566. 'talk_type' => 401,
  6567. 'title' => $bookInfo['title'],
  6568. 'content' => '审核拒绝',
  6569. 'messageType' => 7,
  6570. 'user_id' => $bookInfo['user_id'],
  6571. ]);
  6572. }
  6573. if ($data['status'] == 1) {
  6574. $this->sendMessage([
  6575. 'talk_type' => 400,
  6576. 'title' => $bookInfo['title'],
  6577. 'content' => '提交了审核',
  6578. 'messageType' => 7,
  6579. // 'user_id'=>$bookInfo['user_id'],
  6580. ]);
  6581. }
  6582. $result = Book::where("id", $data["id"])->update($data);
  6583. if (empty($result)) {
  6584. return Result::error("更新失败", 0);
  6585. }
  6586. return Result::success($result);
  6587. }
  6588. //20250422 书刊音像
  6589. /**
  6590. * 贴身宝贝
  6591. * @param array $data
  6592. * @return array
  6593. */
  6594. public function getWebsiteTsbb(array $data): array
  6595. {
  6596. $month = $data['month'] ?? date('m');
  6597. $day = $data['day'] ?? date('d');
  6598. // 使用缓存键
  6599. $cacheKey = "tsbb_data_{$month}_{$day}";
  6600. // 尝试从缓存获取数据
  6601. $container = \Hyperf\Context\ApplicationContext::getContainer();
  6602. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  6603. if ($cachedData = $cache->get($cacheKey)) {
  6604. return Result::success(unserialize($cachedData));
  6605. }
  6606. //查询老黄历
  6607. try {
  6608. $date = date('Y-m-d');
  6609. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  6610. // 使用 curl 替代 file_get_contents
  6611. $ch = curl_init();
  6612. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  6613. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  6614. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  6615. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  6616. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  6617. 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');
  6618. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  6619. 'Accept: application/json',
  6620. 'Content-Type: application/json',
  6621. 'Referer: https://www.36jxs.com/'
  6622. ]);
  6623. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  6624. curl_setopt($ch, CURLOPT_ENCODING, '');
  6625. $almanacResponse = curl_exec($ch);
  6626. var_dump("====:", $almanacResponse);
  6627. if (curl_errno($ch)) {
  6628. var_dump('Curl error:', curl_error($ch));
  6629. throw new \Exception('Curl error: ' . curl_error($ch));
  6630. }
  6631. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  6632. curl_close($ch);
  6633. if ($almanacResponse === false) {
  6634. throw new \Exception('Failed to fetch almanac data');
  6635. }
  6636. $almanacData = json_decode($almanacResponse, true);
  6637. if (json_last_error() !== JSON_ERROR_NONE) {
  6638. throw new \Exception('Failed to parse almanac data');
  6639. }
  6640. $almanacInfo = $almanacData['data'] ?? [];
  6641. } catch (\Exception $e) {
  6642. var_dump('Exception:', $e->getMessage());
  6643. $almanacInfo = [];
  6644. }
  6645. // 获取历史上的今天数据
  6646. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6647. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  6648. ->orderBy('year', 'asc')
  6649. ->select("title", "id", "year", DB::raw('1 as type'))
  6650. ->limit(16)
  6651. ->get();
  6652. // 获取节日数据 - 从今天开始获取未来4条
  6653. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  6654. ->orderBy('showtime', 'asc')
  6655. ->select("title", "id", "showtime", DB::raw('2 as type'))
  6656. ->limit(16)
  6657. ->get();
  6658. //说文解字
  6659. $chartacterList = Character::orderBy('updated_at', 'desc')
  6660. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  6661. ->limit(6)
  6662. ->get();
  6663. //谜语沙龙
  6664. $riddletList = Riddle::orderBy('updated_at', 'desc')
  6665. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  6666. ->limit(4)
  6667. ->get();
  6668. //成语欣赏
  6669. $idiomList = Idiom::orderBy('updated_at', 'desc')
  6670. ->select("id", "title", "duyin", DB::raw('5 as type'))
  6671. ->limit(32)
  6672. ->get();
  6673. //名联赏析
  6674. $coupletList = Couplet::orderBy('updated_at', 'desc')
  6675. ->select("id", "first", "second", DB::raw('6 as type'))
  6676. ->limit(6)
  6677. ->get();
  6678. // 获取分类文章数据
  6679. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  6680. ->pluck('category_id')
  6681. ->toArray();
  6682. $articlesList = [];
  6683. foreach ($categoryIds as $catid) {
  6684. // 先查有图片的
  6685. $withImg = DB::table('article')
  6686. ->where('status', 1)
  6687. ->where('catid', $catid)
  6688. ->whereNotNull('imgurl')
  6689. ->where('imgurl', '!=', '')
  6690. ->orderBy('updated_at', 'desc')
  6691. ->limit(6)
  6692. ->get();
  6693. $count = $withImg->count();
  6694. if ($count < 6) {
  6695. // 不足6条再查无图片的补足
  6696. $withoutImg = DB::table('article')
  6697. ->where('status', 1)
  6698. ->where('catid', $catid)
  6699. ->where(function ($q) {
  6700. $q->whereNull('imgurl')->orWhere('imgurl', '');
  6701. })
  6702. ->orderBy('updated_at', 'desc')
  6703. ->limit(6 - $count)
  6704. ->get();
  6705. $articles = $withImg->concat($withoutImg);
  6706. } else {
  6707. $articles = $withImg;
  6708. }
  6709. // 组装
  6710. $category = \App\Model\Category::find($catid);
  6711. $websiteCategory = WebsiteCategory::where('category_id', $catid)->first();
  6712. $articlesList[] = [
  6713. 'category_name' => $category ? $category->name : '',
  6714. 'catid' => $catid,
  6715. 'pinyin' => $websiteCategory ? $websiteCategory->aLIas_pinyin : '',
  6716. 'type' => 100,
  6717. 'list' => $articles->map(function ($item) {
  6718. return [
  6719. 'id' => $item->id,
  6720. 'title' => $item->title,
  6721. 'imgurl' => $item->imgurl,
  6722. 'created_at' => $item->created_at
  6723. ];
  6724. })->values()
  6725. ];
  6726. }
  6727. $result = [
  6728. 'almanac' => $almanacInfo,
  6729. 'historyTodayList' => [
  6730. 'category_name' => '历史上的今天',
  6731. 'list' => $historyTodayList,
  6732. 'type' => 1
  6733. ],
  6734. 'festivalList' => [
  6735. 'category_name' => '节日预告',
  6736. 'list' => $festivalList,
  6737. 'type' => 2
  6738. ],
  6739. 'chartacterList' => [
  6740. 'category_name' => '说文解字',
  6741. 'list' => $chartacterList,
  6742. 'type' => 3
  6743. ],
  6744. 'coupletList' => [
  6745. 'category_name' => '名联赏析',
  6746. 'list' => $coupletList,
  6747. 'type' => 6
  6748. ],
  6749. 'riddletList' => [
  6750. 'category_name' => '谜语沙龙',
  6751. 'list' => $riddletList,
  6752. 'type' => 4
  6753. ],
  6754. 'idiomList' => [
  6755. 'category_name' => '成语欣赏',
  6756. 'list' => $idiomList,
  6757. 'type' => 5
  6758. ],
  6759. 'articlesList' => $articlesList
  6760. ];
  6761. // 缓存结果,设置1小时过期
  6762. $cache->set($cacheKey, serialize($result), 3600);
  6763. return Result::success($result);
  6764. }
  6765. /**
  6766. * 获取资讯列表
  6767. */
  6768. public function getWebsiteTsbbList(array $data): array
  6769. {
  6770. $page = $data['page'] ?? 1;
  6771. $pageSize = $data['pageSize'] ?? 10;
  6772. // 如果没有传入月份和日期,则使用今天的日期
  6773. $month = $data['month'] ?? date('m');
  6774. $day = $data['day'] ?? date('d');
  6775. $total = 0;
  6776. $result = [];
  6777. $data['type'] = intval($data['type']);
  6778. var_dump("接收参数:", $data);
  6779. switch ($data['type']) {
  6780. case 1:
  6781. $query = HistoryToday::where(function ($q) use ($month, $day) {
  6782. // 当前月份之后的数据
  6783. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  6784. // 或者当前月份且日期大于等于当前日期的数据
  6785. ->orWhere(function ($q) use ($month, $day) {
  6786. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6787. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  6788. });
  6789. })
  6790. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  6791. $total = $query->count();
  6792. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  6793. ->offset(($page - 1) * $pageSize)
  6794. ->limit($pageSize)
  6795. ->get();
  6796. break;
  6797. case 2:
  6798. $query = Festival::where(function ($q) use ($month, $day) {
  6799. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  6800. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  6801. ->orWhere(function ($q) use ($month, $day) {
  6802. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  6803. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  6804. });
  6805. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  6806. $total = $query->count();
  6807. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  6808. ->offset(($page - 1) * $pageSize)
  6809. ->limit($pageSize)
  6810. ->get();
  6811. break;
  6812. case 3:
  6813. $query = Character::orderBy("updated_at", "desc");
  6814. $total = $query->count();
  6815. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  6816. ->offset(($page - 1) * $pageSize)
  6817. ->limit($pageSize)
  6818. ->get();
  6819. break;
  6820. case 4:
  6821. $query = Riddle::orderBy("updated_at", "desc");
  6822. $total = $query->count();
  6823. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  6824. ->offset(($page - 1) * $pageSize)
  6825. ->limit($pageSize)
  6826. ->get();
  6827. break;
  6828. case 5:
  6829. $query = Idiom::orderBy("updated_at", "desc");
  6830. $total = $query->count();
  6831. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  6832. ->offset(($page - 1) * $pageSize)
  6833. ->limit($pageSize)
  6834. ->get();
  6835. break;
  6836. case 6:
  6837. $query = Couplet::orderBy("updated_at", "desc");
  6838. $total = $query->count();
  6839. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  6840. ->offset(($page - 1) * $pageSize)
  6841. ->limit($pageSize)
  6842. ->get();
  6843. break;
  6844. default:
  6845. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  6846. $total = $query->count();
  6847. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  6848. ->offset(($page - 1) * $pageSize)
  6849. ->limit($pageSize)
  6850. ->get();
  6851. }
  6852. return Result::success([
  6853. 'list' => $result,
  6854. 'total' => $total,
  6855. 'page' => (int)$page,
  6856. 'pageSize' => (int)$pageSize,
  6857. 'month' => $month,
  6858. 'day' => $day
  6859. ]);
  6860. }
  6861. /**
  6862. * 1:历史上的今天
  6863. * 2:节日
  6864. * 3:文章
  6865. *
  6866. * 资讯详情信息
  6867. */
  6868. public function getWebsiteTsbbDetail(array $data): array
  6869. {
  6870. $data['type'] = intval($data['type']);
  6871. switch ($data['type']) {
  6872. case 1:
  6873. $result = HistoryToday::where("id", $data['id'])->first();
  6874. break;
  6875. case 2:
  6876. $result = Festival::where("id", $data['id'])->first();
  6877. break;
  6878. case 3:
  6879. $result = Character::where("id", $data['id'])->first();
  6880. break;
  6881. case 4:
  6882. $result = Riddle::where("id", $data['id'])->first();
  6883. break;
  6884. case 5:
  6885. $result = Idiom::where("id", $data['id'])->first();
  6886. break;
  6887. case 6:
  6888. $result = Couplet::where("id", $data['id'])->first();
  6889. break;
  6890. default:
  6891. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  6892. break;
  6893. }
  6894. return Result::success($result);
  6895. }
  6896. /**
  6897. * 农网导航首页数据
  6898. */
  6899. public function getWebsiteNwHomeList(array $data): array
  6900. {
  6901. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  6902. ->pluck('category_id')
  6903. ->toArray();
  6904. // 使用子查询优化
  6905. $articlesList = DB::table('article')
  6906. ->select([
  6907. 'article.id',
  6908. 'article.title',
  6909. 'article.imgurl',
  6910. 'article.created_at',
  6911. 'category.name as category_name',
  6912. 'category.id as category_id',
  6913. 'website_category.aLIas_pinyin as pinyin',
  6914. 'parent_wc.aLIas_pinyin as parent_pinyin',
  6915. DB::raw('100 as type')
  6916. ])
  6917. ->join('category', 'article.catid', '=', 'category.id')
  6918. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  6919. ->leftJoin('website_category as parent_wc', function ($join) {
  6920. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  6921. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  6922. })
  6923. ->where('website_category.website_id', $data['website_id'])
  6924. ->where('article.status', 1)
  6925. ->whereIn('category.id', $categoryIds)
  6926. ->orderBy('article.created_at', 'desc')
  6927. ->get()
  6928. ->groupBy('category_id')
  6929. ->map(function ($group) {
  6930. // 确保第一条数据有图片
  6931. $firstWithImage = $group->first(function ($item) {
  6932. return !empty($item->imgurl);
  6933. });
  6934. if ($firstWithImage) {
  6935. // 如果有带图片的文章,将其放在第一位
  6936. $group = $group->filter(function ($item) use ($firstWithImage) {
  6937. return $item->id !== $firstWithImage->id;
  6938. })->prepend($firstWithImage);
  6939. }
  6940. return [
  6941. 'category_name' => $group->first()->category_name,
  6942. 'catid' => $group->first()->category_id,
  6943. 'pinyin' => $group->first()->pinyin,
  6944. 'parent_pinyin' => $group->first()->parent_pinyin,
  6945. 'list' => $group->take(4)->map(function ($item) {
  6946. return [
  6947. 'id' => $item->id,
  6948. 'title' => $item->title,
  6949. ];
  6950. })->values()
  6951. ];
  6952. })
  6953. ->values()
  6954. ->toArray();
  6955. return Result::success($articlesList);
  6956. }
  6957. /**
  6958. * 企业管理
  6959. * @param array $data
  6960. * @return array
  6961. */
  6962. public function getCompanyList(array $data): array
  6963. {
  6964. // return Result::success($data);
  6965. $where = [];
  6966. $user = User::where('id', $data['user_id'])->first();
  6967. if (empty($user)) {
  6968. return Result::error('用户不存在!');
  6969. }
  6970. if ($user['type_id'] != 10000) {
  6971. $where['user_id'] = $data['user_id'];
  6972. }
  6973. if (isset($data['title']) && !empty($data['title'])) {
  6974. array_push($where, ['company.title', 'like', '%' . $data['title'] . '%']);
  6975. }
  6976. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6977. array_push($where, ['website.id', $data['website_id']]);
  6978. }
  6979. if (isset($data['ischeck']) && !empty($data['ischeck'])) {
  6980. if ($data['ischeck'] == 1) {
  6981. if (isset($data['status']) && $data['status'] != '') {
  6982. array_push($where, ['company.status', $data['status']]);
  6983. $query = Company::where($where);
  6984. } else {
  6985. $query = Company::whereIn('company.status', [0, 2]);
  6986. }
  6987. } else {
  6988. $query = Company::where('company.status', 1);
  6989. }
  6990. }
  6991. $result = $query->where($where)
  6992. ->leftJoin('website_category', function ($query) {
  6993. $query->on('website_category.category_id', '=', 'company.category_id')
  6994. ->on('website_category.website_id', '=', 'company.website_id');
  6995. })
  6996. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  6997. ->select(
  6998. 'company.id',
  6999. 'company.title',
  7000. 'company.website_id',
  7001. 'company.category_id',
  7002. 'website.website_name',
  7003. 'website_category.alias as category_name',
  7004. 'company.status',
  7005. 'company.updated_at',
  7006. 'company.user_id'
  7007. )
  7008. ->orderBy('company.updated_at', 'desc')
  7009. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  7010. if ($result->isEmpty()) {
  7011. return Result::error("暂无企业", 0);
  7012. }
  7013. return Result::success($result);
  7014. }
  7015. /**
  7016. * 添加企业
  7017. * @param array $data
  7018. * @return array
  7019. */
  7020. public function addCompany(array $data): array
  7021. {
  7022. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  7023. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  7024. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  7025. $data['cat_arr_id'] = json_encode($car_arr_id);
  7026. } else {
  7027. $data['cat_arr_id'] = '';
  7028. }
  7029. if ($data['imgurl'] == '') {
  7030. //content中提取图片第一个图,正则提取
  7031. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  7032. preg_match_all($reg, $data['content'], $matches);
  7033. if (isset($matches[1][0])) {
  7034. //截取varchar240
  7035. $data['imgurl'] = substr($matches[1][0], 0, 240);
  7036. }
  7037. }
  7038. if ($data['keyword'] == '') {
  7039. //提取标题+内容中的关键词
  7040. $data['keyword'] = $data['title'];
  7041. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7042. Jieba::init(); // 初始化 jieba-php
  7043. Finalseg::init();
  7044. $segList = Jieba::cut($data['keyword']);
  7045. $segList1 = array_slice($segList, 0, 8);
  7046. $data['keyword'] = implode(',', $segList1);
  7047. }
  7048. if ($data['introduce'] == '' || empty($data['introduce'])) {
  7049. //提取内容中的描述
  7050. $content = $data['content'];
  7051. // 去除 <style> 和 <script> 标签及其内容
  7052. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7053. // 去除所有 HTML 标签
  7054. $content = strip_tags($content);
  7055. // 去除 HTML 实体
  7056. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7057. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7058. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7059. // 去除多余空白
  7060. $content = preg_replace('/\s+/u', '', $content);
  7061. // 截取 100 个字符
  7062. $data['introduce'] = mb_substr($content, 0, 100);
  7063. }
  7064. $user = User::where('id', $data['user_id'])->first();
  7065. if (empty($user)) {
  7066. return Result::error('用户不存在!');
  7067. }
  7068. if ($user['type_id'] == 10000) {
  7069. $data['status'] = 1;
  7070. }
  7071. if (isset($data['level']) && $data['level'] != null) {
  7072. $data['level'] = intval($data['level']);
  7073. } else {
  7074. $data['level'] = null;
  7075. }
  7076. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  7077. $this->sendMessage([
  7078. 'talk_type' => 900,
  7079. 'title' => $data['title'],
  7080. 'content' => '提交了审核',
  7081. 'messageType' => 8,
  7082. ]);
  7083. }
  7084. $result = Company::insertGetId($data);
  7085. if ($result) {
  7086. return Result::success($result);
  7087. } else {
  7088. return Result::error('添加失败');
  7089. }
  7090. }
  7091. /**
  7092. * 更新企业
  7093. * @param array $data
  7094. * @return array
  7095. */
  7096. public function upCompany(array $data): array
  7097. {
  7098. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  7099. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  7100. $data['cat_arr_id'] = json_encode($car_arr_id);
  7101. $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
  7102. } else {
  7103. $data['cat_arr_id'] = '';
  7104. }
  7105. if ($data['imgurl'] == '') {
  7106. //content中提取图片第一个图,正则提取
  7107. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  7108. preg_match_all($reg, $data['content'], $matches);
  7109. if (isset($matches[1][0])) {
  7110. //截取varchar
  7111. $data['imgurl'] = substr($matches[1][0], 0, 240);
  7112. }
  7113. }
  7114. if ($data['keyword'] == '') {
  7115. //提取标题+内容中的关键词
  7116. $data['keyword'] = $data['title'];
  7117. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7118. Jieba::init(); // 初始化 jieba-php
  7119. Finalseg::init();
  7120. $segList = Jieba::cut($data['keyword']);
  7121. $segList1 = array_slice($segList, 0, 8);
  7122. $data['keyword'] = implode(',', $segList1);
  7123. }
  7124. if ($data['introduce'] == '') {
  7125. //提取内容中的描述
  7126. $content = $data['content'];
  7127. // 去除 <style> 和 <script> 标签及其内容
  7128. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7129. // 去除所有 HTML 标签
  7130. $content = strip_tags($content);
  7131. // 去除 HTML 实体
  7132. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7133. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7134. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7135. // 去除多余空白
  7136. $content = preg_replace('/\s+/u', '', $content);
  7137. // 截取 100 个字符
  7138. $data['introduce'] = mb_substr($content, 0, 100);
  7139. }
  7140. if (isset($data['level']) && $data['level'] != null) {
  7141. $data['level'] = intval($data['level']);
  7142. } else {
  7143. $data['level'] = null;
  7144. }
  7145. $user = User::where('id', $data['user_id'])->first();
  7146. if (empty($user)) {
  7147. return Result::error('用户不存在!');
  7148. }
  7149. if ($user['type_id'] == 10000) {
  7150. $data['status'] = 1;
  7151. } else {
  7152. $data['status'] = 0;
  7153. }
  7154. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  7155. $this->sendMessage([
  7156. 'talk_type' => 900,
  7157. 'title' => $data['title'],
  7158. 'content' => '提交了审核',
  7159. 'messageType' => 8,
  7160. ]);
  7161. }
  7162. $result = Company::where('id', $data['id'])->update($data);
  7163. if ($result) {
  7164. return Result::success($result);
  7165. } else {
  7166. return Result::error('修改失败');
  7167. }
  7168. }
  7169. /**
  7170. * 删除企业
  7171. * @param array $data
  7172. * @return array
  7173. */
  7174. public function delCompany(array $data): array
  7175. {
  7176. $result = Company::where('id', $data['id'])->delete();
  7177. if ($result) {
  7178. return Result::success($result);
  7179. } else {
  7180. return Result::error('删除失败');
  7181. }
  7182. }
  7183. /**
  7184. * 审核企业
  7185. * @param array $data
  7186. * @return array
  7187. */
  7188. public function checkCompany(array $data): array
  7189. {
  7190. $user = User::where('id', $data['user_id'])->first();
  7191. if (empty($user)) {
  7192. return Result::error('用户不存在!');
  7193. }
  7194. $company = Company::where('id', $data['id'])->first();
  7195. if (empty($company)) {
  7196. return Result::error('企业不存在!');
  7197. }
  7198. // 状态:0:未审核 1:已审核 2:已拒绝
  7199. if ($data['status'] == 2 || $data['status'] == '2') {
  7200. $this->sendMessage([
  7201. 'talk_type' => 901,
  7202. 'title' => $company['title'],
  7203. 'content' => '审核拒绝',
  7204. 'messageType' => 8,
  7205. 'user_id' => $company['user_id'],
  7206. ]);
  7207. $result = Company::where('id', $data['id'])->update(['status' => $data['status'], 'reject_reason' => $data['reason']]);
  7208. } else {
  7209. if ($data['status'] == 1) {
  7210. $this->sendMessage([
  7211. 'talk_type' => 901,
  7212. 'title' => $company['title'],
  7213. 'content' => '审核通过',
  7214. 'messageType' => 8,
  7215. 'user_id' => $company['user_id'],
  7216. ]);
  7217. } else if ($data['status'] == 0) {
  7218. $this->sendMessage([
  7219. 'talk_type' => 900,
  7220. 'title' => $company['title'],
  7221. 'content' => '提交了审核',
  7222. 'messageType' => 8,
  7223. ]);
  7224. }
  7225. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  7226. }
  7227. if (empty($result)) {
  7228. return Result::error('审核失败!');
  7229. } else {
  7230. return Result::success($result);
  7231. }
  7232. }
  7233. /**
  7234. * 获取企业信息
  7235. * @param array $data
  7236. * @return array
  7237. */
  7238. public function getCompanyInfo(array $data): array
  7239. {
  7240. $result = Company::where('id', $data['id'])->first();
  7241. $city_arr = json_decode($result['city_arr_id']);
  7242. $result['city_name'] = District::whereIn('id', $city_arr)
  7243. ->pluck('name')
  7244. ->implode('-');
  7245. if (empty($result)) {
  7246. return Result::error('企业不存在!');
  7247. } else {
  7248. return Result::success($result);
  7249. }
  7250. }
  7251. /**
  7252. * @param array $data
  7253. * @return array
  7254. */
  7255. public function getWebsiteCompany(array $data): array
  7256. {
  7257. $categorys = json_decode($data['id'], true);
  7258. $category_arr = $this->processArticlePro($data['website_id']);
  7259. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7260. $catiall = $category_arr['catiall'];
  7261. $categoryIds = $category_arr['categoryIds'];
  7262. // return Result::success($category_arr);
  7263. foreach ($categorys as $key => $value) {
  7264. if (array_key_exists('level', $value)) {
  7265. $parts = explode(',', $value['level']);
  7266. $level = $parts[0] ?? null;
  7267. $imgnum = $parts[1] ?? null;
  7268. $textnum = $parts[2] ?? null;
  7269. if (!empty($textnum) && $textnum > 0) {
  7270. $text_num = Company::where('level', $level)
  7271. ->whereIn('category_id', $categoryIds)
  7272. ->where('status', 1)
  7273. ->select(
  7274. 'company.id',
  7275. 'company.title',
  7276. 'company.description',
  7277. 'company.updated_at',
  7278. 'company.category_id',
  7279. 'company.cat_arr_id'
  7280. )
  7281. ->orderBy('updated_at', 'desc')
  7282. ->limit($textnum)
  7283. ->get()->all();
  7284. }
  7285. if (!empty($imgnum) && $imgnum > 0) {
  7286. $img_num = Company::where('level', $level)
  7287. ->whereIn('category_id', $categoryIds)
  7288. ->where('status', 1)
  7289. ->where('imgurl', '!=', '')
  7290. ->whereNotNull('imgurl')
  7291. ->select(
  7292. 'company.id',
  7293. 'company.title',
  7294. 'company.description',
  7295. 'company.updated_at',
  7296. 'company.imgurl as imgs',
  7297. 'company.category_id',
  7298. 'company.cat_arr_id'
  7299. )
  7300. ->orderBy('updated_at', 'desc')
  7301. ->limit($imgnum)
  7302. ->get()->all();
  7303. }
  7304. }
  7305. if (array_key_exists('id', $value)) {
  7306. $parts = explode(',', $value['id']);
  7307. $category_id = $parts[0] ?? null;
  7308. $imgnum = $parts[1] ?? null;
  7309. $textnum = $parts[2] ?? null;
  7310. $category_arr = array_merge([$category_id], $cat_1st_arr[$category_id] ?? [0]);
  7311. if (!empty($textnum) && $textnum > 0) {
  7312. $text_num = Company::whereIn('category_id', $category_arr)
  7313. // ->where('website_id', $data['website_id'])
  7314. ->where('status', 1)
  7315. ->select(
  7316. 'company.id',
  7317. 'company.title',
  7318. 'company.description',
  7319. 'company.updated_at',
  7320. 'company.category_id',
  7321. 'company.cat_arr_id'
  7322. )
  7323. ->orderBy('updated_at', 'desc')
  7324. ->limit($textnum)
  7325. ->get()->all();
  7326. }
  7327. if (!empty($imgnum) && $imgnum > 0) {
  7328. $img_num = Company::whereIn('category_id', $category_arr)
  7329. // ->where('website_id', $data['website_id'])
  7330. ->where('status', 1)
  7331. ->where('imgurl', '!=', '')
  7332. ->whereNotNull('imgurl')
  7333. ->select(
  7334. 'company.id',
  7335. 'company.title',
  7336. 'company.description',
  7337. 'company.updated_at',
  7338. 'company.imgurl as imgs',
  7339. 'company.category_id',
  7340. 'company.cat_arr_id'
  7341. )
  7342. ->orderBy('updated_at', 'desc')
  7343. ->limit($imgnum)
  7344. ->get()->all();
  7345. }
  7346. }
  7347. if (!empty($text_num)) {
  7348. foreach ($text_num as $k => $v) {
  7349. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7350. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7351. }
  7352. }
  7353. if (!empty($img_num)) {
  7354. foreach ($img_num as $k => $v) {
  7355. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7356. $imgurl = json_decode($v['imgs'], true);
  7357. if (!empty($imgurl)) {
  7358. $img_num[$k]->imgurl = $imgurl[0];
  7359. }
  7360. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7361. }
  7362. }
  7363. $company[$key]['img_num'] = $img_num ?? [];
  7364. $company[$key]['text_num'] = $text_num ?? [];
  7365. }
  7366. if (empty($company)) {
  7367. return Result::error("暂无相关企业信息", 0);
  7368. }
  7369. return Result::success($company);
  7370. }
  7371. /**
  7372. * @param array $data
  7373. * @return array
  7374. */
  7375. public function getWebsiteCompanyList(array $data): array
  7376. {
  7377. $where['website_id'] = $data['website_id'];
  7378. $where['status'] = 1;
  7379. $categoryIds = [];
  7380. if (isset($data['category_id']) && !empty($data['category_id'])) {
  7381. $category_id = $data['category_id'];
  7382. }
  7383. $category_arr = $this->processArticlePro($data['website_id']);
  7384. $categoryIds = $category_arr['categoryIds'];
  7385. // return Result::success($cat_1st_arr);
  7386. $company = Company::when(isset($data['keyword']) && !empty($data['keyword']), function ($query) use ($data) {
  7387. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  7388. })
  7389. ->when(!isset($category_id) || empty($category_id), function ($query) use ($categoryIds) {
  7390. $query->whereIn('category_id', $categoryIds);
  7391. })
  7392. ->when(isset($data['category_id']) && !empty($data['category_id']), function ($query) use ($category_id) {
  7393. $query->where('category_id', $category_id);
  7394. })
  7395. ->where('status',1)
  7396. ->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id', 'updated_at')
  7397. ->orderBy('updated_at', 'desc')
  7398. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  7399. if (empty($company)) {
  7400. return Result::error("暂无相关公司信息", 0);
  7401. }
  7402. $result = [
  7403. 'count' => $company->total(),
  7404. 'data' => $company->items(), // 使用 items() 方法替代不存在的 data() 方法
  7405. ];
  7406. return Result::success($result);
  7407. }
  7408. /**
  7409. * 获取项目列表
  7410. * @param array $data
  7411. * @return array
  7412. */
  7413. public function getProjectList(array $data): array
  7414. {
  7415. $where = [];
  7416. $user = User::where('id', $data['user_id'])->first();
  7417. if (empty($user)) {
  7418. return Result::error('用户不存在!');
  7419. }
  7420. if ($user->type_id != 10000) {
  7421. array_push($where, ['project.user_id', $data['user_id']]);
  7422. }
  7423. $query = Project::query();
  7424. if (isset($data['website_id']) && !empty($data['website_id'])) {
  7425. array_push($where, ['project.website_id', $data['website_id']]);
  7426. }
  7427. if (isset($data['title']) && !empty($data['title'])) {
  7428. array_push($where, ['project.title', 'like', '%' . $data['title'] . '%']);
  7429. }
  7430. if ($data['status'] != 3) {
  7431. array_push($where, ['project.status', $data['status']]);
  7432. }
  7433. $query = Project::where($where)
  7434. ->when($data['status'] == 3, function ($query) {
  7435. $query->whereIn('project.status', [0, 2]);
  7436. });
  7437. $count = $query->clone()
  7438. ->count();
  7439. $rows = $query->clone()
  7440. ->leftJoin('website', 'project.website_id', 'website.id')
  7441. ->leftJoin('website_category', function ($join) {
  7442. $join->on('project.website_id', '=', 'website_category.website_id')
  7443. ->on('project.category_id', '=', 'website_category.category_id');
  7444. })
  7445. ->select(
  7446. 'project.id',
  7447. 'project.title',
  7448. 'project.updated_at',
  7449. 'project.status',
  7450. 'website.website_name',
  7451. 'website_category.alias as category_name',
  7452. 'project.website_id',
  7453. 'project.user_id'
  7454. )
  7455. ->orderBy('project.updated_at', 'desc')
  7456. ->offset(($data['page'] - 1) * $data['pageSize'])
  7457. ->limit($data['pageSize'])
  7458. ->get();
  7459. if ($rows->isEmpty()) {
  7460. return Result::error("暂无相关项目信息", 0);
  7461. }
  7462. $result = [
  7463. 'count' => $count,
  7464. 'rows' => $rows,
  7465. ];
  7466. return Result::success($result);
  7467. }
  7468. /**
  7469. * 添加项目
  7470. * @param array $data
  7471. * @return array
  7472. */
  7473. public function addProject(array $data): array
  7474. {
  7475. $user = User::where('id', $data['user_id'])->first();
  7476. if (empty($user)) {
  7477. return Result::error("暂无相关用户信息", 0);
  7478. }
  7479. if ($user->type_id == 10000) {
  7480. $data['status'] = 1;
  7481. } else {
  7482. $data['status'] = 0;
  7483. }
  7484. if ($data['keyword'] == '') {
  7485. //提取标题+内容中的关键词
  7486. $data['keyword'] = $data['title'];
  7487. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7488. Jieba::init(); // 初始化 jieba-php
  7489. Finalseg::init();
  7490. $segList = Jieba::cut($data['keyword']);
  7491. $segList1 = array_slice($segList, 0, 8);
  7492. $data['keyword'] = implode(',', $segList1);
  7493. }
  7494. if ($data['description'] == '') {
  7495. //提取内容中的描述
  7496. // var_dump(11111);
  7497. //提取内容中的描述
  7498. $content = $data['introduce'];
  7499. // 去除 <style> 和 <script> 标签及其内容
  7500. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7501. // 去除所有 HTML 标签
  7502. $content = strip_tags($content);
  7503. // 去除 HTML 实体
  7504. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7505. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7506. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7507. // 去除多余空白
  7508. $content = preg_replace('/\s+/u', '', $content);
  7509. // 截取 100 个字符
  7510. $data['description'] = mb_substr($content, 0, 100);
  7511. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7512. }
  7513. if ($data['status'] == 0) {
  7514. $this->sendMessage([
  7515. 'talk_type' => 1000,
  7516. 'title' => $data['title'],
  7517. 'content' => '提交了审核',
  7518. 'messageType' => 9,
  7519. ]);
  7520. }
  7521. $project = Project::insertGetId($data);
  7522. if (empty($project)) {
  7523. return Result::error("暂无相关项目信息", 0);
  7524. }
  7525. return Result::success($project);
  7526. }
  7527. /**
  7528. * 更新项目
  7529. * @param array $data
  7530. * @return array
  7531. */
  7532. public function upProject(array $data): array
  7533. {
  7534. $project = Project::where('id', $data['id'])->first();
  7535. if (empty($project)) {
  7536. return Result::error("暂无相关项目信息", 0);
  7537. }
  7538. $id = $data['id'];
  7539. unset($data['id']);
  7540. $user = User::where('id', $data['user_id'])->first();
  7541. if (empty($user)) {
  7542. return Result::error("暂无相关用户信息", 0);
  7543. }
  7544. if ($user->type_id == 10000) {
  7545. $data['status'] = 1;
  7546. } else {
  7547. $data['status'] = 0;
  7548. }
  7549. unset($data['user_id']);
  7550. if ($data['keyword'] == '') {
  7551. //提取标题+内容中的关键词
  7552. $data['keyword'] = $data['title'];
  7553. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7554. Jieba::init(); // 初始化 jieba-php
  7555. Finalseg::init();
  7556. $segList = Jieba::cut($data['keyword']);
  7557. $segList1 = array_slice($segList, 0, 8);
  7558. $data['keyword'] = implode(',', $segList1);
  7559. }
  7560. if ($data['description'] == '') {
  7561. //提取内容中的描述
  7562. // var_dump(11111);
  7563. //提取内容中的描述
  7564. $content = $data['introduce'];
  7565. // 去除 <style> 和 <script> 标签及其内容
  7566. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7567. // 去除所有 HTML 标签
  7568. $content = strip_tags($content);
  7569. // 去除 HTML 实体
  7570. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7571. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7572. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7573. // 去除多余空白
  7574. $content = preg_replace('/\s+/u', '', $content);
  7575. // 截取 100 个字符
  7576. $data['description'] = mb_substr($content, 0, 100);
  7577. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7578. }
  7579. if ($data['status'] == 0) {
  7580. $this->sendMessage([
  7581. 'talk_type' => 1000,
  7582. 'title' => $data['title'],
  7583. 'content' => '提交了审核',
  7584. 'messageType' => 9,
  7585. ]);
  7586. }
  7587. $result = Project::where('id', $id)->update($data);
  7588. if (empty($result)) {
  7589. return Result::error("更新失败", 0);
  7590. }
  7591. return Result::success($result);
  7592. }
  7593. /**
  7594. * 删除项目
  7595. * @param array $data
  7596. * @return array
  7597. */
  7598. public function delProject(array $data): array
  7599. {
  7600. $user = User::where('id', $data['user_id'])->first();
  7601. if (empty($user)) {
  7602. return Result::error("暂无相关用户信息", 0);
  7603. }
  7604. $project = Project::where('id', $data['id'])->first();
  7605. if (empty($project)) {
  7606. return Result::error("暂无相关项目信息", 0);
  7607. }
  7608. $result = Project::where('id', $data['id'])->delete();
  7609. if (empty($result)) {
  7610. return Result::error("删除失败", 0);
  7611. }
  7612. return Result::success($result);
  7613. }
  7614. /**
  7615. * 审核项目
  7616. * @param array $data
  7617. * @return array
  7618. */
  7619. public function checkProject(array $data): array
  7620. {
  7621. $user = User::where('id', $data['user_id'])->first();
  7622. if (empty($user)) {
  7623. return Result::error("暂无相关用户信息", 0);
  7624. }
  7625. // 0:未审核; 1:已审核; 2:已拒绝;
  7626. if ($user->type_id != 10000) {
  7627. if ($data['status'] == 1 || $data['status'] == 2) {
  7628. return Result::error("此用户权限不足", 0);
  7629. }
  7630. }
  7631. $project = Project::where('id', $data['id'])->first();
  7632. if (empty($project)) {
  7633. return Result::error("暂无相关项目信息", 0);
  7634. }
  7635. if ($data['status'] == 2) {
  7636. $this->sendMessage([
  7637. 'talk_type' => 1001,
  7638. 'title' => $project['title'],
  7639. 'content' => '审核拒绝',
  7640. 'messageType' => 9,
  7641. 'user_id' => $project['user_id'],
  7642. ]);
  7643. $result = Project::where('id', $data['id'])->update(['status' => $data['status'], 'refuse_reason' => $data['refuse_reason']]);
  7644. } else {
  7645. if ($data['status'] == 1) {
  7646. $this->sendMessage([
  7647. 'talk_type' => 1001,
  7648. 'title' => $project['title'],
  7649. 'content' => '审核通过',
  7650. 'messageType' => 9,
  7651. 'user_id' => $project['user_id'],
  7652. ]);
  7653. } else if ($data['status'] == 0) {
  7654. $this->sendMessage([
  7655. 'talk_type' => 1000,
  7656. 'title' => $project['title'],
  7657. 'content' => '提交了审核',
  7658. 'messageType' => 9,
  7659. ]);
  7660. }
  7661. $result = Project::where('id', $data['id'])->update(['status' => $data['status']]);
  7662. }
  7663. if (empty($result)) {
  7664. return Result::error("审核失败", 0);
  7665. }
  7666. return Result::success($result);
  7667. }
  7668. /**
  7669. * 获取项目详情
  7670. * @param array $data
  7671. * @return array
  7672. */
  7673. public function getProjectInfo(array $data): array
  7674. {
  7675. $project = Project::where('id', $data['id'])->first();
  7676. if (empty($project)) {
  7677. return Result::error("暂无相关项目信息", 0);
  7678. }
  7679. return Result::success($project);
  7680. }
  7681. public function getWebsiteCompanyInfo(array $data): array
  7682. {
  7683. $company = Company::where('id', $data['id'])
  7684. ->leftJoin('job_industry', 'job_industry.hyid', 'company.hy_id')
  7685. ->where('status', 1)
  7686. // ->where('website_id', $data['website_id'])
  7687. ->select('company.*', 'job_industry.hyname as hy_name')
  7688. ->first();
  7689. // 企业性质:0:市场监管;1:信访纪检;2:公检法司;3:高关注机构
  7690. $jobnature_id = $company['jobnature_id'] ?? null;
  7691. if ($jobnature_id !== null) {
  7692. switch ($jobnature_id) {
  7693. case 0:
  7694. $company->jobnature_name = '市场监督';
  7695. break;
  7696. case 1:
  7697. $company->jobnature_name = '信访纪检';
  7698. break;
  7699. case 2:
  7700. $company->jobnature_name = '公检法司';
  7701. break;
  7702. case 3:
  7703. $company->jobnature_name = '高关注机构';
  7704. break;
  7705. default:
  7706. $company->jobnature_name = '';
  7707. break;
  7708. }
  7709. } else {
  7710. $company->jobnature_name = '';
  7711. }
  7712. $city_arr = $company->city_arr_id;
  7713. if (!empty($city_arr)) {
  7714. $city_arr = json_decode($city_arr, true);
  7715. $cityNames = District::whereIn('id', $city_arr)
  7716. ->pluck('name')
  7717. ->implode('-');
  7718. $company->city_name = $cityNames;
  7719. } else {
  7720. $company->city_name = '';
  7721. }
  7722. if (empty($company)) {
  7723. return Result::error("暂无相关公司信息", 0);
  7724. }
  7725. return Result::success($company);
  7726. }
  7727. public function getMSG(array $data): array
  7728. {
  7729. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  7730. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  7731. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  7732. $result = [];
  7733. if ($type_id == 1 or $type_id == 2 or $type_id == 3 or $type_id == 4) {
  7734. //最近的5篇已审的文章
  7735. $apply_articale = Article::where('status', 1)
  7736. ->where('admin_user_id', $user_id)
  7737. ->orderBy('updated_at', 'desc')
  7738. // ->limit(5)
  7739. ->get();
  7740. //获取5条用户的已审核商品
  7741. $good = Good::where('status', 2)
  7742. ->where('user_id', $user_id)
  7743. ->orderBy('updated_at', 'desc')
  7744. // ->limit(5)
  7745. ->get();
  7746. //获取5条用户待审核的公告
  7747. $notice = Notice::where('status', 2)
  7748. ->where('user_id', $user_id)
  7749. ->orderBy('updated_at', 'desc')
  7750. ->limit(5)->get();
  7751. //获取5条用户的待审核投诉
  7752. $complaint = Complaint::where('status', 2)
  7753. ->where('user_id', $user_id)
  7754. ->orderBy('updated_at', 'desc')
  7755. // ->limit(5)
  7756. ->get();
  7757. //获取5条用户的book
  7758. $book = Book::where('status', 2)
  7759. ->where('user_id', $user_id)
  7760. ->orderBy('updated_at', 'desc')
  7761. // ->limit(5)
  7762. ->get();
  7763. //获取5条用户的求职
  7764. //获取5条用户的求职 1
  7765. $job_hunting = JobHunting::where('job_hunting.status', 2)
  7766. ->where('job_hunting.user_id', $user_id)
  7767. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7768. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7769. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7770. ->orderBy('updated_at', 'desc')
  7771. // ->limit(5)
  7772. ->get();
  7773. //获取5条用户的求职 2
  7774. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  7775. ->where('job_recruiting.user_id', $user_id)
  7776. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7777. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7778. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7779. ->orderBy('updated_at', 'desc')
  7780. // ->limit(5)
  7781. ->get();
  7782. //人才库 1
  7783. $job_apply = JobApply::where('job_apply.status', 1)
  7784. ->where('job_apply.receiver_id', $user_id)
  7785. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7786. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7787. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7788. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7789. ->select('job_recruiting', 'job_recruiting.', '', '')
  7790. ->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')
  7791. ->orderBy('updated_at', 'desc')
  7792. // ->limit(5)
  7793. ->get();
  7794. // 职场机会 2
  7795. $job_resume = JobResume::where('job_resume.status', 1)
  7796. ->where('job_resume.receiver_id', $user_id)
  7797. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7798. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7799. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7800. ->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')
  7801. ->orderBy('updated_at', 'desc')
  7802. // ->limit(5)
  7803. ->get();
  7804. //获取5条用户待处理的投诉
  7805. $complaint_deal = Complaint::where('status', 2)
  7806. ->where('deal', 1)
  7807. ->whereJsonContains('re_user_ids', $user_id)
  7808. ->orderBy('updated_at', 'desc')
  7809. // ->limit(5)
  7810. ->get();
  7811. //获取 被通知者未读信息
  7812. $notice_unread = Notice::where('status', 2)
  7813. ->whereJsonContains('re_user_ids', $user_id)
  7814. //未读消息
  7815. ->where(function ($query) use ($user_id) {
  7816. $query->whereJsonDoesntContain('read_id', $user_id)
  7817. ->orWhereNull('read_id');
  7818. })
  7819. ->orderBy('updated_at', 'desc')
  7820. ->get();
  7821. $complaint_unread = Complaint::where('status', 2)
  7822. ->whereJsonContains('re_user_ids', $user_id)
  7823. //未读消息
  7824. ->where(function ($query) use ($user_id) {
  7825. $query->whereJsonDoesntContain('read_id', $user_id)
  7826. ->orWhereNull('read_id');
  7827. })
  7828. ->orderBy('updated_at', 'desc')
  7829. ->get();
  7830. //获取5条用户的yijing审核公司 :0:未审核;1:已审核;2:已拒绝
  7831. $complany = Company::where('status', 1)
  7832. ->where('user_id', $user_id)
  7833. ->orderBy('updated_at', 'desc')
  7834. // ->limit(5)
  7835. ->get();
  7836. //获取5条单聊未读聊天消息
  7837. // $chat = ChatRecords::where('is_read', 0)
  7838. // ->where('user_id', $user_id)
  7839. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7840. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7841. // ->where('action', 'recieved')
  7842. // ->where('talk_type', 1)
  7843. // ->orderBy('created_at', 'desc')
  7844. // // ->limit(5)
  7845. // ->get();
  7846. //获取5条未读群聊信息
  7847. // $chat_group = ChatRecords::where('is_read', 0)
  7848. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7849. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7850. // ->where('user_id', $user_id)
  7851. // ->where('talk_type', 2)
  7852. // ->orderBy('created_at', 'desc')
  7853. // // ->limit(5)
  7854. // ->get();
  7855. //获取5条用户的待审核项目
  7856. $project = Project::where('status', 1)
  7857. ->where('user_id', $user_id)
  7858. ->orderBy('updated_at', 'desc')
  7859. // ->limit(5)
  7860. ->get();
  7861. // count($chat) + count($chat_group) +
  7862. $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)
  7863. + count($complany)
  7864. + count($project)
  7865. + count($notice_unread)
  7866. + count($complaint_unread)
  7867. // + count($chat) + count($chat_group)
  7868. ;
  7869. $result = [
  7870. 'apply_articale' => $apply_articale,
  7871. // 'chat' => $chat,
  7872. // 'chat_group' => $chat_group,
  7873. 'good' => $good,
  7874. 'notice' => $notice,
  7875. 'complaint' => $complaint,
  7876. 'book' => $book,
  7877. 'job_hunting' => $job_hunting,
  7878. 'job_recruiting' => $job_recruiting,
  7879. 'job_apply' => $job_apply,
  7880. 'job_resume' => $job_resume,
  7881. 'complaint_deal' => $complaint_deal,
  7882. 'complany' => $complany,
  7883. 'project' => $project,
  7884. 'notice_unread' => $notice_unread,
  7885. 'complaint_unread' => $complaint_unread,
  7886. 'count' => $count,
  7887. ];
  7888. } elseif ($type_id == 12) {
  7889. //最近的5篇已审的文章
  7890. $apply_articale = Article::where('status', 1)
  7891. ->where('admin_user_id', $user_id)
  7892. ->limit(5)->get();
  7893. //获取5条单聊未读聊天消息
  7894. $chat = ChatRecords::where('is_read', 0)
  7895. ->where('user_id', $user_id)
  7896. ->where('talk_type', 1)
  7897. ->orderBy('created_at', 'desc')
  7898. ->limit(5)->get();
  7899. //获取5条未读群聊信息
  7900. $chat_group = ChatRecords::where('is_read', 0)
  7901. ->where('user_id', $user_id)
  7902. ->where('talk_type', 2)
  7903. ->orderBy('created_at', 'desc')
  7904. ->limit(5)->get();
  7905. //获取5条用户的已审核商品
  7906. $good = Good::where('status', 2)
  7907. ->where('user_id', $user_id)
  7908. ->orderBy('updated_at', 'desc')
  7909. ->limit(5)->get();
  7910. //获取5条用户的book
  7911. $book = Book::where('status', 2)
  7912. ->where('user_id', $user_id)
  7913. ->orderBy('updated_at', 'desc')
  7914. ->limit(5)->get();
  7915. //获取5条用户的求职
  7916. //获取5条用户的求职 1
  7917. //count($chat) + count($chat_group)
  7918. $count = count($apply_articale) + count($good);
  7919. $result = [
  7920. 'apply_articale' => $apply_articale,
  7921. 'chat' => $chat,
  7922. 'chat_group' => $chat_group,
  7923. 'good' => $good,
  7924. 'book' => $book,
  7925. 'count' => $count,
  7926. ];
  7927. } elseif ($type_id == 13) {
  7928. //最近的5篇已审的文章
  7929. $apply_articale = Article::where('status', 1)
  7930. ->where('admin_user_id', $user_id)
  7931. ->limit(5)->get();
  7932. //获取5条单聊未读聊天消息
  7933. $chat = ChatRecords::where('is_read', 0)
  7934. ->where('user_id', $user_id)
  7935. ->where('talk_type', 1)
  7936. ->orderBy('created_at', 'desc')
  7937. ->limit(5)->get();
  7938. //获取5条未读群聊信息
  7939. $chat_group = ChatRecords::where('is_read', 0)
  7940. ->where('user_id', $user_id)
  7941. ->where('talk_type', 2)
  7942. ->orderBy('created_at', 'desc')
  7943. ->limit(5)->get();
  7944. //获取5条用户的已审核商品
  7945. $good = Good::where('status', 2)
  7946. ->where('user_id', $user_id)
  7947. ->orderBy('updated_at', 'desc')
  7948. ->limit(5)->get();
  7949. //count($chat) + count($chat_group) +
  7950. $count = count($apply_articale) + count($good);
  7951. $result = [
  7952. 'apply_articale' => $apply_articale,
  7953. 'chat' => $chat,
  7954. 'chat_group' => $chat_group,
  7955. 'good' => $good,
  7956. 'count' => $count,
  7957. ];
  7958. } elseif ($type_id == 14) {
  7959. //最近的5篇已审的文章
  7960. $apply_articale = Article::where('status', 1)
  7961. ->where('admin_user_id', $user_id)
  7962. // ->limit(5)
  7963. ->get();
  7964. //获取5条用户的已审核商品
  7965. $good = Good::where('status', 2)
  7966. ->where('user_id', $user_id)
  7967. ->orderBy('updated_at', 'desc')
  7968. // ->limit(5)
  7969. ->get();
  7970. $count = count($apply_articale) + count($good);
  7971. $result = [
  7972. 'apply_articale' => $apply_articale,
  7973. 'chat' => '',
  7974. 'chat_group' => '',
  7975. 'good' => $good,
  7976. 'count' => $count,
  7977. ];
  7978. } elseif ($type_id == 10000) {
  7979. //获取未审核的5篇文章
  7980. $apply_articale = Article::where('status', 0)
  7981. ->orderBy('updated_at', 'desc')
  7982. // ->limit(5)
  7983. ->get();
  7984. //获取5条单聊未读聊天消息
  7985. //获取5条单聊未读聊天消息
  7986. // $chat = ChatRecords::where('is_read', 0)
  7987. // ->where('user_id', $user_id)
  7988. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7989. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7990. // ->where('action', 'recieved')
  7991. // ->where('talk_type', 1)
  7992. // ->orderBy('created_at', 'desc')
  7993. // // ->limit(5)
  7994. // ->get();
  7995. // //获取5条未读群聊信息
  7996. // $chat_group = ChatRecords::where('is_read', 0)
  7997. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7998. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7999. // ->where('user_id', $user_id)
  8000. // ->where('talk_type', 2)
  8001. // ->orderBy('created_at', 'desc')
  8002. // // ->limit(5)
  8003. // ->get();
  8004. //获取5条用户的已审核商品
  8005. $good = Good::where('status', 1)
  8006. // ->where('user_id', $user_id)
  8007. ->orderBy('updated_at', 'desc')
  8008. // ->limit(5)
  8009. ->get();
  8010. //获取5条用户待审核的公告
  8011. $notice = Notice::where('status', 1)
  8012. ->orderBy('updated_at', 'desc')
  8013. // ->limit(5)
  8014. ->get();
  8015. //获取5条用户的待审核投诉
  8016. $complaint = Complaint::where('status', 1)
  8017. ->orderBy('updated_at', 'desc')
  8018. // ->limit(5)
  8019. ->get();
  8020. //获取5条用户的book
  8021. $book = Book::where('status', 1)
  8022. ->orderBy('updated_at', 'desc')
  8023. // ->limit(5)
  8024. ->get();
  8025. //获取5条用户的求职 1
  8026. $job_hunting = JobHunting::where('job_hunting.status', 1)
  8027. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  8028. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  8029. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  8030. ->orderBy('updated_at', 'desc')
  8031. // ->limit(5)
  8032. ->get();
  8033. //获取5条用户的求职 2
  8034. $job_recruiting = JobRecruiting::where('job_recruiting.status', 0)
  8035. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  8036. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  8037. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  8038. ->orderBy('updated_at', 'desc')
  8039. // ->limit(5)
  8040. ->get();
  8041. //人才库 1
  8042. $job_apply = JobApply::where('job_apply.status', 1)
  8043. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  8044. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  8045. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  8046. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  8047. ->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')
  8048. ->orderBy('updated_at', 'desc')
  8049. // ->limit(5)
  8050. ->get();
  8051. // 职场机会 2
  8052. $job_resume = JobResume::where('job_resume.status', 1)
  8053. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  8054. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  8055. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  8056. ->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')
  8057. ->orderBy('updated_at', 'desc')
  8058. // ->limit(5)
  8059. ->get();
  8060. //待审核数据com pro
  8061. $complany = Company::where('status', 0)
  8062. ->orderBy('updated_at', 'desc')
  8063. // ->limit(5)
  8064. ->get();
  8065. $project = Project::where('status', 0)
  8066. ->orderBy('updated_at', 'desc')
  8067. // ->limit(5)
  8068. ->get();
  8069. $count =
  8070. // count($chat) +
  8071. // count($chat_group) +
  8072. count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting)
  8073. // + count($job_apply)
  8074. // + count($job_resume)
  8075. + count($complany)
  8076. + count($project);
  8077. $result = [
  8078. 'apply_articale' => $apply_articale,
  8079. // 'chat' => $chat,
  8080. // 'chat_group' => $chat_group,
  8081. 'good' => $good,
  8082. 'notice' => $notice,
  8083. 'complaint' => $complaint,
  8084. 'book' => $book,
  8085. 'job_hunting' => $job_hunting,
  8086. 'job_recruiting' => $job_recruiting,
  8087. // 'job_apply' => $job_apply,
  8088. // 'job_resume' => $job_resume,
  8089. 'complany' => $complany,
  8090. 'project' => $project,
  8091. 'count' => $count,
  8092. ];
  8093. } elseif ($type_id == 20000) {
  8094. }
  8095. var_dump($type_id, '-----------------test---------');
  8096. return Result::success($result);
  8097. }
  8098. /**
  8099. * @param array $data
  8100. * @return array
  8101. */
  8102. public function getWebsiteProject(array $data): array
  8103. {
  8104. $categorys = json_decode($data['id'], true);
  8105. if (!empty($categorys)) {
  8106. $category_arr = $this->processArticlePro($data['website_id']);
  8107. $cat_1st_arr = $category_arr['cat_1st_arr'];
  8108. $catiall = $category_arr['catiall'];
  8109. // return Result::success($catiall);
  8110. foreach ($categorys as $key => $val) {
  8111. if (isset($val['level'][0]) && !empty($val['level'][0])) {
  8112. $level = explode(',', $val['level'])[0];
  8113. $imgnum = explode(',', $val['level'])[1] ?? null;
  8114. $textnum = explode(',', $val['level'])[2] ?? null;
  8115. if ($level == 1) {
  8116. if (!empty($textnum) && $textnum > 0) {
  8117. $text_num = Project::where('level', $level)
  8118. ->where('website_id', $data['website_id'])
  8119. ->where('status', 1)
  8120. ->select(
  8121. 'project.id',
  8122. 'project.title',
  8123. 'project.description',
  8124. 'project.updated_at',
  8125. 'project.category_id',
  8126. 'project.cat_arr_id'
  8127. )
  8128. ->orderBy('updated_at', 'desc')
  8129. ->limit($textnum)
  8130. ->get()->all();
  8131. }
  8132. if (!empty($imgnum) && $imgnum > 0) {
  8133. $img_num = Project::where('level', $level)
  8134. ->where('website_id', $data['website_id'])
  8135. ->where('status', 1)
  8136. ->where('imgurl', '!=', '')
  8137. ->whereNotNull('imgurl')
  8138. ->select(
  8139. 'project.id',
  8140. 'project.title',
  8141. 'project.description',
  8142. 'project.updated_at',
  8143. 'project.imgurl as imgs',
  8144. 'project.category_id',
  8145. 'project.cat_arr_id'
  8146. )
  8147. ->orderBy('updated_at', 'desc')
  8148. ->limit($imgnum)
  8149. ->get()->all();
  8150. }
  8151. } else {
  8152. if (!empty($textnum) && $textnum > 0) {
  8153. $text_num = Project::where('website_id', $data['website_id'])
  8154. ->where('status', 1)
  8155. ->select(
  8156. 'project.id',
  8157. 'project.title',
  8158. 'project.description',
  8159. 'project.updated_at',
  8160. 'project.category_id',
  8161. 'project.cat_arr_id',
  8162. 'project.website_id',
  8163. 'project.updated_at',
  8164. 'project.created_at'
  8165. )
  8166. ->orderBy('updated_at', 'desc')
  8167. ->limit($textnum)
  8168. ->get()->all();
  8169. }
  8170. if (!empty($imgnum) && $imgnum > 0) {
  8171. $img_num = Project::where('website_id', $data['website_id'])
  8172. ->where('status', 1)
  8173. ->where('imgurl', '!=', '')
  8174. ->whereNotNull('imgurl')
  8175. ->select(
  8176. 'project.id',
  8177. 'project.title',
  8178. 'project.description',
  8179. 'project.updated_at',
  8180. 'project.imgurl as imgs',
  8181. 'project.category_id',
  8182. 'project.cat_arr_id'
  8183. )
  8184. ->orderBy('updated_at', 'desc')
  8185. ->limit($imgnum)
  8186. ->get()->all();
  8187. }
  8188. }
  8189. }
  8190. if (isset($val['id'][0]) && !empty($val['id'][0])) {
  8191. $category_ids = explode(',', $val['id'])[0];
  8192. $cat_imgnum = explode(',', $val['id'])[1] ?? null;
  8193. $cat_textnum = explode(',', $val['id'])[2] ?? null;
  8194. $category_arr = array_merge([$category_ids], $cat_1st_arr[$category_ids] ?? [0]);
  8195. if (!empty($cat_textnum) && $cat_textnum > 0) {
  8196. $text_num = Project::whereIn('category_id', $category_arr)
  8197. ->where('website_id', $data['website_id'])
  8198. ->where('status', 1)
  8199. ->select(
  8200. 'project.id',
  8201. 'project.title',
  8202. 'project.description',
  8203. 'project.updated_at',
  8204. 'project.category_id',
  8205. 'project.cat_arr_id'
  8206. )
  8207. ->orderBy('updated_at', 'desc')
  8208. ->limit($cat_textnum)
  8209. ->get()->all();
  8210. }
  8211. if (!empty($cat_imgnum) && $cat_imgnum > 0) {
  8212. $img_num = Project::whereIn('category_id', $category_arr)
  8213. ->where('website_id', $data['website_id'])
  8214. ->where('status', 1)
  8215. ->where('imgurl', '!=', '')
  8216. ->whereNotNull('imgurl')
  8217. ->select(
  8218. 'project.id',
  8219. 'project.title',
  8220. 'project.description',
  8221. 'project.updated_at',
  8222. 'project.imgurl as imgs',
  8223. 'project.category_id',
  8224. 'project.cat_arr_id'
  8225. )
  8226. ->orderBy('updated_at', 'desc')
  8227. ->limit($cat_imgnum)
  8228. ->get()->all();
  8229. }
  8230. }
  8231. if (!empty($img_num)) {
  8232. foreach ($img_num as $k => $v) {
  8233. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8234. $imgurl = json_decode($v['imgs'], true);
  8235. if (!empty($imgurl)) {
  8236. $img_num[$k]->imgurl = $imgurl[0];
  8237. }
  8238. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8239. }
  8240. }
  8241. if (!empty($text_num)) {
  8242. foreach ($text_num as $k => $v) {
  8243. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8244. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8245. }
  8246. }
  8247. $project[$key]['img_num'] = $img_num ?? [];
  8248. $project[$key]['text_num'] = $text_num ?? [];
  8249. }
  8250. }
  8251. if (empty($project)) {
  8252. return Result::error("暂无相关项目信息", 0);
  8253. }
  8254. return Result::success($project);
  8255. }
  8256. /**
  8257. * @param array $data
  8258. * @return array
  8259. */
  8260. public function getWebsiteProjectInfo(array $data): array
  8261. {
  8262. $project = Project::where('id', $data['id'])
  8263. ->where('status', 1)
  8264. ->where('website_id', $data['website_id'])
  8265. ->select('project.*')
  8266. ->first();
  8267. if (empty($project)) {
  8268. return Result::error("暂无相关项目信息", 0);
  8269. }
  8270. return Result::success($project);
  8271. }
  8272. /**
  8273. * @param array $data
  8274. * @return array
  8275. */
  8276. public function getWebsiteProjectList(array $data): array
  8277. {
  8278. $where = [];
  8279. if (isset($data['category_id']) && !empty($data['category_id'])) {
  8280. $where['category_id'] = $data['category_id'];
  8281. }
  8282. if (isset($data['keyword']) && !empty($data['keyword'])) {
  8283. $where[] = ['title', 'like', '%' . $data['keyword'] . '%'];
  8284. }
  8285. $query = Project::where($where)
  8286. ->where('status', 1)
  8287. ->where('website_id', $data['website_id'])
  8288. ->select(
  8289. 'project.id',
  8290. 'project.title',
  8291. 'project.description',
  8292. 'project.imgurl as imgs',
  8293. 'project.category_id',
  8294. 'project.cat_arr_id'
  8295. )
  8296. ->orderBy('updated_at', 'desc');
  8297. $count = $query->count();
  8298. $project = $query->clone()
  8299. ->offset(($data['page'] - 1) * $data['pageSize'])
  8300. ->limit($data['pageSize'])
  8301. ->get()->all();
  8302. if (empty($project)) {
  8303. return Result::error("暂无相关项目信息", 0);
  8304. }
  8305. $categorys = $this->processArticlePro($data['website_id']);
  8306. $catiall = $categorys['catiall'];
  8307. foreach ($project as $key => $val) {
  8308. $project[$key]->category_name = $catiall[$val->category_id]['alias'];
  8309. if (!empty($val['imgs'])) {
  8310. $imgurl = json_decode($val['imgs'], true);
  8311. if (!empty($imgurl)) {
  8312. $project[$key]->imgurl = $imgurl[0];
  8313. }
  8314. } else {
  8315. $project[$key]->imgurl = '';
  8316. }
  8317. $project[$key]->pinyin = $catiall[$val->category_id]['pinyin'];
  8318. }
  8319. $result = [
  8320. 'rows' => $project,
  8321. 'count' => $count,
  8322. ];
  8323. return Result::success($result);
  8324. }
  8325. /**
  8326. * @param array $data
  8327. * @return array
  8328. */
  8329. public function getWebsiteCategoryJob(array $data): array
  8330. {
  8331. $categorys = json_decode($data['id'], true);
  8332. if (!empty($categorys)) {
  8333. $category_arr = $this->processArticlePro($data['website_id']);
  8334. $cat_1st_arr = $category_arr['cat_1st_arr'];
  8335. $catiall = $category_arr['catiall'];
  8336. foreach ($categorys as $key => $val) {
  8337. if (isset($val['id']) && !empty($val['id'])) {
  8338. $catid = explode(',', $val['id'])[0] ?? null;
  8339. $type = explode(',', $val['id'])[1] ?? null;
  8340. $textnum = explode(',', $val['id'])[2] ?? null;
  8341. }
  8342. // 4:招聘;5:求职;
  8343. if ($textnum > 0 && $type == 4 && !empty($catid)) {
  8344. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  8345. $job = JobRecruiting::WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($catid) . "') = 1")
  8346. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  8347. ->where('job_recruiting.status', 1)
  8348. ->where('job_recruiting.website_id', $data['website_id'])
  8349. ->select(
  8350. 'job_recruiting.id',
  8351. 'job_recruiting.title',
  8352. 'job_company.business_name',
  8353. 'job_recruiting.updated_at',
  8354. 'job_recruiting.cat_arr_id',
  8355. 'job_recruiting.keyword',
  8356. 'job_recruiting.description'
  8357. )
  8358. ->orderBy('job_recruiting.updated_at', 'desc')
  8359. ->limit($textnum)
  8360. ->get()->all();
  8361. } else if ($textnum > 0 && $type == 5 && !empty($catid)) {
  8362. // 状态 审核状态,1待审核2已审核3已拒绝
  8363. $job = JobHunting::WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($catid) . "') = 1")
  8364. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  8365. ->where('job_hunting.status', 2)
  8366. ->where('job_hunting.website_id', $data['website_id'])
  8367. ->select(
  8368. 'job_hunting.id',
  8369. 'job_hunting.name',
  8370. 'job_hunting.cat_arr_id',
  8371. 'job_position.zwname as job_name',
  8372. 'job_hunting.updated_at',
  8373. // 'job_hunting.keyword',
  8374. 'job_hunting.slelf_evaluation'
  8375. )
  8376. ->orderBy('updated_at', 'desc')
  8377. ->limit($textnum)
  8378. ->get()->all();
  8379. } else {
  8380. $job = [];
  8381. }
  8382. // var_dump($catid.'222uuuuuuu'.$key);
  8383. if (!empty($job)) {
  8384. foreach ($job as $k => $value) {
  8385. if (isset($value->cat_arr_id)) {
  8386. $catArr = json_decode($value->cat_arr_id, true);
  8387. $catId = end($catArr);
  8388. } else {
  8389. continue;
  8390. }
  8391. if (isset($catiall[$catId])) {
  8392. $job[$k]->pinyin = $catiall[$catId]['pinyin'];
  8393. }
  8394. }
  8395. }
  8396. // var_dump($catid.'xxxxx'.$key);
  8397. $result[$key] = $job ?? [];
  8398. }
  8399. }
  8400. if (empty($result)) {
  8401. return Result::error("暂无相关分类信息", 0);
  8402. }
  8403. return Result::success($result);
  8404. }
  8405. /**
  8406. * 发送消息
  8407. * @param array $messageData
  8408. * @return void
  8409. */
  8410. public function sendMessage($messageData)
  8411. {
  8412. $msg = [
  8413. 'talk_type' => $messageData['talk_type'],
  8414. 'title' => $messageData['title'],
  8415. 'content' => $messageData['content'],
  8416. 'messageType' => $messageData['messageType'],
  8417. 'user_id' => $messageData['user_id'] ?? '',
  8418. 'time' => microtime(),
  8419. ];
  8420. $message = new MqProducer($msg);
  8421. $producer = ContextApplicationContext::getContainer()->get(Producer::class);
  8422. $producer->produce($message);
  8423. }
  8424. /**
  8425. * 行业分类管理 ------1121
  8426. * @param array $data
  8427. * @return array
  8428. */
  8429. public function getJobIndustryList(array $data): array
  8430. {
  8431. $page = $data['page'] ?? 1;
  8432. $page_size = $data['page_size'] ?? 10;
  8433. if (isset($data['hyname']) && !empty($data['hyname'])) {
  8434. $where = ['hyname', 'like', '%' . $data['hyname'] . '%'];
  8435. } else {
  8436. $where = [];
  8437. }
  8438. $rs_query = JobIndustry::when(!empty($where), function ($query) use ($where) {
  8439. $query->where([$where]); // 修复:将条件包装成二维数组
  8440. })
  8441. ->orderBy('updated_at', 'desc');
  8442. $count = $rs_query->count();
  8443. $hy = $rs_query->offset(($page - 1) * $page_size)->limit($page_size)->get()->all();
  8444. $result = [
  8445. 'count' => $count,
  8446. 'list' => $hy,
  8447. ];
  8448. if (empty($hy)) {
  8449. return Result::success('暂无数据');
  8450. }
  8451. return Result::success($result);
  8452. }
  8453. /**
  8454. * 添加行业分类
  8455. * @param array $data
  8456. * @return array
  8457. */
  8458. public function addJobIndustry(array $data): array
  8459. {
  8460. $hy_name = JobIndustry::where('hyname', $data['hyname'])->first(['hyid']);
  8461. if (!empty($hy_name)) {
  8462. return Result::error('行业分类已存在');
  8463. }
  8464. $hy = JobIndustry::insertGetId($data);
  8465. if (empty($hy)) {
  8466. return Result::error('添加失败');
  8467. }
  8468. return Result::success($hy);
  8469. }
  8470. /**
  8471. * 更新行业分类
  8472. * @param array $data
  8473. * @return array
  8474. */
  8475. public function upJobIndustry(array $data): array
  8476. {
  8477. $hy_query = JobIndustry::get();
  8478. $hy_ids = $hy_query->pluck('hyid')->toArray();
  8479. $hy_names = $hy_query->pluck('hyname')->toArray();
  8480. if (!in_array($data['hyid'], $hy_ids)) {
  8481. return Result::error('行业分类不存在');
  8482. }
  8483. if (isset($data['hyname']) && !empty($data['hyname'])) {
  8484. $other_key_hy = array_search($data['hyid'], $hy_ids);
  8485. // return Result::success($other_key_hy);
  8486. unset($hy_names[$other_key_hy]);
  8487. if (in_array($data['hyname'], $hy_names)) {
  8488. return Result::error('行业分类名称已存在');
  8489. }
  8490. }
  8491. $hy = JobIndustry::where('hyid', $data['hyid'])->update($data);
  8492. if (empty($hy)) {
  8493. return Result::error('更新失败');
  8494. }
  8495. return Result::success($hy);
  8496. }
  8497. /**
  8498. * 删除行业分类
  8499. * @param array $data
  8500. * @return array
  8501. */
  8502. public function delJobIndustry(array $data): array
  8503. {
  8504. $hy_id = JobIndustry::where('hyid', $data['hyid'])->first(['hyid']);
  8505. if (empty($hy_id)) {
  8506. return Result::error('行业分类不存在');
  8507. }
  8508. $hy = JobIndustry::where('hyid', $data['hyid'])->delete();
  8509. if (empty($hy)) {
  8510. return Result::error('删除失败');
  8511. }
  8512. return Result::success($hy);
  8513. }
  8514. /**
  8515. * 职位分类-列表
  8516. * @param array $data
  8517. * @return array
  8518. */
  8519. public function getJobPositionList(array $data): array
  8520. {
  8521. $page = $data['page'] ?? 1;
  8522. $page_size = $data['page_size'] ?? 10;
  8523. $where = [];
  8524. if (isset($data['zwname']) && !empty($data['zwname'])) {
  8525. $zwids = JobPosition::where('zwpid', 0)
  8526. ->when(!empty($data['zwname']), function ($query) use ($data) {
  8527. $query->where('zwname', 'like', '%' . $data['zwname'] . '%');
  8528. })
  8529. ->orderBy('updated_at', 'desc')
  8530. ->pluck('zwid')
  8531. // ->get()
  8532. ->toArray();
  8533. }
  8534. if (isset($data['childname']) && !empty($data['childname'])) {
  8535. $child_zwids = JobPosition::where('zwpid', '!=', 0)
  8536. ->when(!empty($data['childname']), function ($query) use ($data) {
  8537. $query->where('zwname', 'like', '%' . $data['childname'] . '%');
  8538. })
  8539. ->orderBy('updated_at', 'desc')
  8540. ->pluck('zwpid')
  8541. // ->get()
  8542. ->toArray();
  8543. if (isset($zwids) && is_array($zwids) && is_array($child_zwids)) {
  8544. $child_zwids = array_intersect($zwids, $child_zwids);
  8545. }
  8546. $zwids = array_values(array_unique($child_zwids));
  8547. }
  8548. $zwids = $zwids ?? null;
  8549. $count = JobPosition::when(!empty($zwids), function ($query) use ($zwids) {
  8550. $query->whereIn('zwid', $zwids);
  8551. })
  8552. ->where('zwpid', 0)
  8553. ->count();
  8554. $position = JobPosition::when(!empty($zwids), function ($query) use ($zwids) {
  8555. $query->whereIn('zwid', $zwids);
  8556. })
  8557. ->where('zwpid', 0)
  8558. ->orderBy('updated_at', 'desc')
  8559. ->offset(($page - 1) * $page_size)
  8560. ->limit($page_size)->get()
  8561. ->map(function ($item) use ($data) {
  8562. $item->children = $item->where('zwpid', $item->zwid)
  8563. ->when(!empty($data['childname']), function ($query) use ($data) {
  8564. $query->where('zwname', 'like', '%' . $data['childname'] . '%');
  8565. })
  8566. ->orderBy('updated_at', 'desc')
  8567. ->get();
  8568. return $item;
  8569. })
  8570. ->all();
  8571. $result = [
  8572. 'count' => $count,
  8573. 'list' => $position,
  8574. ];
  8575. if (empty($result)) {
  8576. return Result::success('暂无数据');
  8577. }
  8578. return Result::success($result);
  8579. }
  8580. /**
  8581. * 职位分类-添加
  8582. * @param array $data
  8583. * @return array
  8584. */
  8585. public function addJobPosition(array $data): array
  8586. {
  8587. $zw_name = JobPosition::where('zwpid', $data['zwpid'])
  8588. ->where('zwname', $data['zwname'])->first(['zwid']);
  8589. if (!empty($zw_name)) {
  8590. return Result::error('职位分类已存在');
  8591. }
  8592. $zw = JobPosition::insertGetId($data);
  8593. if(empty($zw)){
  8594. return Result::error('添加失败');
  8595. }
  8596. return Result::success($zw);
  8597. }
  8598. /**
  8599. * 更新职位分类
  8600. * @param array $data
  8601. * @return array
  8602. */
  8603. public function upJobPosition(array $data): array
  8604. {
  8605. $zw_position = JobPosition::get();
  8606. if (!in_array($data['zwid'], $zw_position->pluck('zwid')->toArray())) {
  8607. return Result::error('职位分类不存在');
  8608. }
  8609. $zw_name = $zw_position->where('zwid', '!=', $data['zwid'])
  8610. ->where('zwpid', $data['zwpid'])
  8611. ->where('zwname', $data['zwname'])->first();
  8612. if (!empty($zw_name)) {
  8613. return Result::error('职位分类已存在');
  8614. }
  8615. $result = JobPosition::where('zwid', $data['zwid'])->update($data);
  8616. if (empty($result)) {
  8617. return Result::error('更新失败');
  8618. }
  8619. return Result::success($result);
  8620. }
  8621. /**
  8622. * 删除职位分类
  8623. * @param array $data
  8624. * @return array
  8625. */
  8626. public function delJobPosition(array $data): array
  8627. {
  8628. $zw_jobposition = JobPosition::get();
  8629. $zw_id = $zw_jobposition->where('zwid', $data['zwid'])->first();
  8630. if (empty($zw_id)) {
  8631. return Result::error('职位分类不存在');
  8632. }
  8633. if($zw_id->zwpid == 0){
  8634. $zw_job = JobPosition::where('zwpid', $zw_id->zwid)->first();
  8635. if(!empty($zw_job)){
  8636. return Result::error('请先删除子分类');
  8637. }
  8638. }
  8639. $result = JobPosition::where('zwid', $data['zwid'])->delete();
  8640. if (empty($result)) {
  8641. return Result::error('删除失败');
  8642. }
  8643. return Result::success($result);
  8644. }
  8645. }