NewsService.php 310 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483
  1. <?php
  2. namespace App\JsonRpc;
  3. use App\Model\Article;
  4. use App\Model\ArticleData;
  5. use App\Model\Category;
  6. use App\Model\HistoryToday;
  7. use App\Model\WebsiteCategory;
  8. use App\Model\ArticleSurvey;
  9. use App\Model\District;
  10. use App\Model\Good;
  11. use App\Model\JobCompany;
  12. use App\Model\Website;
  13. use App\Model\JobRecruiting;
  14. use App\Model\JobIndustry;
  15. use App\Model\Book;
  16. use App\Model\JobPosition;
  17. use App\Model\Notice;
  18. use App\Model\JobNature;
  19. use App\Model\JobEnum;
  20. use App\Model\User;
  21. use App\Model\UserRole;
  22. use App\Model\News;
  23. use App\Model\UserInfo;
  24. use App\Model\WebsiteGroup;;
  25. use App\Model\JobResume;
  26. use Hyperf\DbConnection\Db;
  27. use Hyperf\RpcServer\Annotation\RpcService;
  28. use App\Tools\Result;
  29. use Directory;
  30. use Ramsey\Uuid\Uuid;
  31. use Hyperf\Utils\Random;
  32. use Fukuball\Jieba\Jieba;
  33. use Fukuball\Jieba\Finalseg;
  34. use Hyperf\Utils\Collection;
  35. use function Hyperf\Support\retry;
  36. use App\Tools\PublicData;
  37. use App\Model\ChatGroups;
  38. use App\Model\ChatGroupsMember;
  39. use App\Model\ChatRecords;
  40. use App\Model\Complaint;
  41. use Hamcrest\Arrays\IsArray;
  42. use Hyperf\Codec\Json;
  43. use App\Tools\buildMenuTree;
  44. use App\Model\JobApply;
  45. use App\Model\JobHunting;
  46. use App\Model\JobRemuse;
  47. use Hyperf\Redis\Redis;
  48. use Hyperf\Di\Annotation\Inject;
  49. use App\Model\Festival;
  50. use App\Model\Character;
  51. use App\Model\Couplet;
  52. use App\Model\Riddle;
  53. use App\Model\Idiom;
  54. use App\Model\WhiteRouter;
  55. use Illuminate\Support\Facades\Cache;
  56. use App\Model\Company;
  57. use Hyperf\Paginator\Paginator;
  58. use App\Model\Project;
  59. use Hyperf\Context\Context;
  60. use Hyperf\Context\ApplicationContext as ContextApplicationContext;
  61. use Hyperf\Amqp\Producer;
  62. use App\Amqp\Producer\MqProducer;
  63. use App\Model\Web;
  64. use App\Model\GroupMemberImp;
  65. use App\Model\GroupImp;
  66. use App\Model\GroupTalkImp;
  67. use App\Model\GroupTalkMessagerImp;
  68. use App\Model\ArticleIgnore;
  69. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  70. class NewsService implements NewsServiceInterface
  71. {
  72. #[Inject]
  73. protected Redis $redis;
  74. /**
  75. * 获取导航池列表
  76. * @param array $data
  77. * @return array
  78. */
  79. public function getCategoryList(array $data): array
  80. {
  81. $search = $data['name'] ?? '';
  82. $page = (int)($data['page'] ?? 1);
  83. $perPage = (int)($data['pageSize'] ?? 10);
  84. // 1. 查出所有匹配的分类id
  85. if ($search) {
  86. $matchedIds = Category::where('name', 'like', "%{$search}%")->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  87. if (empty($matchedIds)) {
  88. return Result::success(['rows' => [], 'total' => 0]);
  89. }
  90. // 2. 递归查所有父级,直到一级分类
  91. $idsStr = implode(',', $matchedIds);
  92. $sql = "
  93. WITH RECURSIVE parents AS (
  94. SELECT * FROM category WHERE id IN ($idsStr)
  95. UNION ALL
  96. SELECT c.* FROM category c
  97. INNER JOIN parents p ON c.id = p.pid
  98. )
  99. SELECT * FROM parents
  100. ";
  101. $parents = Db::select($sql);
  102. $parentIds = [];
  103. foreach ($parents as $row) {
  104. if ($row->pid == 0) {
  105. $parentIds[] = $row->id;
  106. }
  107. }
  108. $parentIds = array_unique($parentIds);
  109. } else {
  110. // 没有搜索,一级分类就是根
  111. $parentIds = Category::where('pid', 0)->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  112. }
  113. // 3. 一级分类分页
  114. $total = count($parentIds);
  115. $parentIds = array_slice($parentIds, ($page - 1) * $perPage, $perPage);
  116. if (empty($parentIds)) {
  117. return Result::success(['rows' => [], 'total' => $total]);
  118. }
  119. // 4. 递归查所有子孙
  120. $idsStr = implode(',', $parentIds);
  121. $sql = "
  122. WITH RECURSIVE subcategories AS (
  123. SELECT * FROM category WHERE id IN ($idsStr)
  124. UNION ALL
  125. SELECT c.* FROM category c
  126. INNER JOIN subcategories s ON c.pid = s.id
  127. )
  128. SELECT * FROM subcategories ORDER BY updated_at DESC
  129. ";
  130. $allCategories = Db::select($sql);
  131. // 5. 组装树结构
  132. $categoryMap = [];
  133. foreach ($allCategories as $cat) {
  134. $cat = (array)$cat;
  135. $cat['children'] = [];
  136. $categoryMap[$cat['id']] = $cat;
  137. }
  138. foreach ($categoryMap as $id => &$cat) {
  139. if ($cat['pid'] && isset($categoryMap[$cat['pid']])) {
  140. $categoryMap[$cat['pid']]['children'][] = &$cat;
  141. }
  142. }
  143. unset($cat);
  144. $categoryTree = [];
  145. foreach ($parentIds as $id) {
  146. if (isset($categoryMap[$id])) {
  147. $categoryTree[] = $categoryMap[$id];
  148. }
  149. }
  150. return Result::success([
  151. 'rows' => $categoryTree,
  152. 'total' => $total,
  153. ]);
  154. }
  155. private function findMatchedCategories($search)
  156. {
  157. if ($search) {
  158. return Category::where('name', 'like', "%{$search}%")
  159. ->orderBy('updated_at', 'desc')
  160. ->get();
  161. }
  162. return Category::orderBy('updated_at', 'desc') // 按 updated_at 字段倒序排序
  163. ->get();
  164. }
  165. private function findAllParents($categories)
  166. {
  167. $allCategories = [];
  168. foreach ($categories as $category) {
  169. $parentId = $category->pid;
  170. while ($parentId > 0) {
  171. $parent = Category::find($parentId);
  172. if ($parent) {
  173. $allCategories[$parent->id] = $parent;
  174. $parentId = $parent->pid;
  175. } else {
  176. break;
  177. }
  178. }
  179. $allCategories[$category->id] = $category;
  180. }
  181. return array_values($allCategories);
  182. }
  183. private function buildCategoryTree($category, $allRequiredCategories)
  184. {
  185. $categoryData = $category->toArray();
  186. $children = [];
  187. foreach ($allRequiredCategories as $c) {
  188. if ($c->pid === $category->id) {
  189. $children[] = $this->buildCategoryTree($c, $allRequiredCategories);
  190. }
  191. }
  192. if (!empty($children)) {
  193. $categoryData['children'] = $children;
  194. }
  195. return $categoryData;
  196. }
  197. public function myCategoryList(array $data): array
  198. {
  199. $sszq = $data['sszq'] ?? '';
  200. unset($data['sszq']);
  201. //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
  202. $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
  203. $where[] = [
  204. 'pid',
  205. '=',
  206. $data['pid'],
  207. ];
  208. if (isset($data['name'])) {
  209. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  210. }
  211. var_dump($where);
  212. //根据分类id,从category表中取出分类信息
  213. $result = Category::where($where)
  214. ->whereIn('category.id', $catorytids)
  215. ->select('category.*', 'category.id as category_id')->get();
  216. if (empty($result)) {
  217. return Result::error("没有栏目数据");
  218. }
  219. return Result::success($result);
  220. }
  221. /**
  222. * @param array $data
  223. * @return array
  224. */
  225. public function categoryList(array $data): array
  226. {
  227. $where[] = [
  228. 'pid',
  229. '=',
  230. $data['pid']
  231. ];
  232. if (isset($data['name'])) {
  233. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  234. }
  235. var_dump($where);
  236. $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
  237. if (empty($result)) {
  238. return Result::error("没有栏目数据");
  239. }
  240. return Result::success($result);
  241. }
  242. /**
  243. * @param array $data
  244. * @return array
  245. */
  246. public function addCategory(array $data): array
  247. {
  248. if (isset($data['id'])) {
  249. unset($data['id']);
  250. }
  251. $id = Category::insertGetId($data);
  252. if (empty($id)) {
  253. return Result::error("添加失败");
  254. }
  255. return Result::success(['id' => $id]);
  256. }
  257. /**
  258. * @param array $data
  259. * @return array
  260. */
  261. public function delCategory(array $data): array
  262. {
  263. Db::beginTransaction();
  264. try {
  265. $categoryList = Category::where(['pid' => $data['id']])->get();
  266. if ($categoryList->toArray()) {
  267. Db::rollBack();
  268. return Result::error("分类下面有子分类不能删除");
  269. }
  270. $articleList = Article::where(['catid' => $data['id']])->get();
  271. if ($articleList->toArray()) {
  272. Db::rollBack();
  273. return Result::error("分类下面有资讯不能删除");
  274. }
  275. $result = Category::where($data)->delete();
  276. WebsiteCategory::where(['category_id' => $data['id']])->delete();
  277. if (!$result) {
  278. Db::rollBack();
  279. return Result::error("删除失败");
  280. }
  281. Db::commit();
  282. return Result::success($result);
  283. } catch (\Exception $e) {
  284. Db::rollBack();
  285. return Result::error("删除失败" . $e->getMessage());
  286. }
  287. }
  288. /**
  289. * @param array $data
  290. * @return array
  291. */
  292. public function updateCategory(array $data): array
  293. {
  294. $where = [
  295. 'id' => $data['id'],
  296. ];
  297. $result = Category::where($where)->update($data);
  298. if ($result) {
  299. return Result::success($result);
  300. } else {
  301. return Result::error("更新失败");
  302. }
  303. }
  304. /**
  305. * 获取导航池信息
  306. * @param array $data
  307. * @return array
  308. */
  309. public function getCategoryInfo(array $data): array
  310. {
  311. $where = [
  312. 'id' => $data['id'],
  313. ];
  314. $result = Category::where($where)->first();
  315. if ($result) {
  316. return Result::success($result);
  317. } else {
  318. return Result::error("更新失败");
  319. }
  320. }
  321. public function getArticleCommend(array $data): array
  322. {
  323. $where = [
  324. 'website_id' => $data['website_id'],
  325. ];
  326. $ids = WebsiteCategory::where($where)->pluck('category_id')->toArray();
  327. var_dump($ids);
  328. if (empty($ids)) {
  329. return Result::error("没有推荐数据");
  330. }
  331. //id
  332. $whereArticle = [];
  333. if (isset($data['id'])) {
  334. $whereArticle['id'] = $data['id'];
  335. }
  336. //title like
  337. if (isset($data['title'])) {
  338. array_push($whereArticle, ['title', 'like', "%{$data['title']}%"]);
  339. }
  340. $article = Article::whereIn('catid', values: $ids)->where('status', 1)
  341. ->where($whereArticle)
  342. ->orderBy('id', 'desc')
  343. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  344. if ($article) {
  345. $data = [
  346. 'rows' => $article->items(),
  347. 'count' => $article->total(),
  348. ];
  349. return Result::success($data);
  350. } else {
  351. return Result::error("获取失败失败");
  352. }
  353. }
  354. /**
  355. * @param array $data
  356. * @return array
  357. */
  358. public function getArticleList(array $data): array
  359. {
  360. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  361. $type_id = $data['type_id'];
  362. unset($data['type_id']);
  363. $user_id = $data['user_id'];
  364. unset($data['user_id']);
  365. $where = [];
  366. $status1 = [];
  367. if (isset($data['id']) && $data['id']) {
  368. array_push($where, ['article.id', '=', $data['id']]);
  369. }
  370. if (isset($data['title']) && $data['title']) {
  371. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  372. }
  373. if (isset($data['category_name']) && $data['category_name']) {
  374. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  375. }
  376. if (isset($data['catid']) && $data['catid']) {
  377. array_push($where, ['article.catid', '=', $data['catid']]);
  378. }
  379. if (isset($data['author']) && $data['author']) {
  380. array_push($where, ['article.author', '=', $data['author']]);
  381. }
  382. if (isset($data['islink']) && $data['islink'] !== "") {
  383. array_push($where, ['article.islink', '=', $data['islink']]);
  384. }
  385. if (isset($data['status']) && $data['status'] !== "") {
  386. array_push($where, ['article.status', '=', $data['status']]);
  387. }
  388. if (isset($data['status1'])) {
  389. $status1 = json_decode(($data['status1']));
  390. }
  391. //不是管理员展示个人数据;
  392. if ($type_id != 10000) {
  393. $where[] = ['article.admin_user_id', '=', $user_id];
  394. }
  395. $rep = Article::where($where)
  396. ->whereNotIn('article.status', [404])
  397. ->when($status1, function ($query) use ($status1) {
  398. if (isset($status1) && $status1) {
  399. $query->whereIn('article.status', $status1);
  400. }
  401. })
  402. ->leftJoin('category', 'article.catid', 'category.id')
  403. ->leftJoin('website_category', function ($join) {
  404. $join->on('article.web_site_id', '=', 'website_category.website_id')
  405. ->on('article.catid', '=', 'website_category.category_id');
  406. })
  407. ->when($type_id != 10000 && !empty($data['website_id']), function ($query) use ($data) {
  408. $query->leftJoin('article_ignore', function ($join) use ($data) {
  409. $join->on('article.id', '=', 'article_ignore.article_id')
  410. ->where('article_ignore.website_id', $data['website_id']);
  411. });
  412. })
  413. ->select("article.*", "category.name as category_name", "website_category.alias",
  414. Db::raw('IFNULL(article_ignore.c_show_time, "") as c_show_time'))
  415. ->orderBy("article.updated_at", "desc")
  416. ->limit($data['pageSize'])
  417. ->offset(($data['page'] - 1) * $data['pageSize'])->get();
  418. $count = Article::where($where)->whereNotIn('article.status', [404])
  419. ->when($status1, function ($query) use ($status1) {
  420. if (isset($status1) && $status1) {
  421. $query->whereIn('article.status', $status1);
  422. }
  423. })
  424. ->leftJoin('category', 'article.catid', 'category.id')->count();
  425. $data = [
  426. 'rows' => $rep->toArray(),
  427. 'count' => $count,
  428. ];
  429. if (empty($rep)) {
  430. return Result::error("没有信息数据");
  431. }
  432. return Result::success($data);
  433. }
  434. /**
  435. * @param array $data
  436. * @return array
  437. */
  438. public function addArticle(array $data): array
  439. {
  440. var_dump($data, '----------12-----------1');
  441. // ------c_show_time********add***1****
  442. $is_collect = $data['is_collect'] ?? 0;
  443. $user_type = $data['user_type'];
  444. unset($data['is_collect']);
  445. unset($data['user_type']);
  446. // ------c_show_time********add***1****
  447. unset($data['nav_add_pool_id']);
  448. // unset($data['commend_id']);
  449. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  450. Db::beginTransaction();
  451. try {
  452. //处理投票
  453. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  454. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  455. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  456. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  457. unset($data['is_survey']);
  458. unset($data['survey_name']);
  459. unset($data['suvey_array']);
  460. unset($data['website_id']);
  461. unset($data['web_site_id']);
  462. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  463. if ($data['hits'] == '') {
  464. $data['hits'] = 0;
  465. }
  466. if ($data['is_original'] == '') {
  467. $data['is_original'] = 0;
  468. }
  469. if ($data['status'] == '') {
  470. $data['status'] = 0;
  471. }
  472. $articleData = $data;
  473. unset($articleData['content']);
  474. //自动处理缩略图、关键字、描述
  475. if ($articleData['imgurl'] == '') {
  476. //如果没有图,设置level=0
  477. $levelArr = json_decode($articleData['level'], true);
  478. var_dump($levelArr, '----------levelArr-----------1');
  479. //content中提取图片第一个图,正则提取
  480. // -------采集器相关优化-----
  481. // 优化正则表达式,仅匹配 src 属性值,避免匹配到多余内容
  482. if($is_collect == 1){
  483. $reg = '/<img.*?src=[\'"]?((?!.*\.gif)[^\'" >]+)[\'"]?.*?>/i';
  484. }else{
  485. $reg = '/<img.*?src=[\'"]?([^\'" >]+)[\'"]?.*?>/i';
  486. }
  487. // -------采集器相关优化-----
  488. preg_match_all($reg, $data['content'], $matches);
  489. if (isset($matches[1][0])) {
  490. //截取varchar240
  491. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  492. //如果有图,设置level=3
  493. if (!in_array(3, $levelArr)) {
  494. $levelArr[] = 3;
  495. }
  496. $articleData['level'] = json_encode($levelArr);
  497. } else {
  498. if (!in_array(0, $levelArr)) {
  499. $levelArr[] = 0;
  500. }
  501. $articleData['level'] = json_encode($levelArr);
  502. }
  503. }
  504. var_dump($articleData['level'], '----------$articleData[level]----------1');
  505. if ($articleData['keyword'] == '') {
  506. //提取标题+内容中的关键词
  507. $articleData['keyword'] = $data['title'];
  508. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  509. Jieba::init(); // 初始化 jieba-php
  510. Finalseg::init();
  511. $segList = Jieba::cut($articleData['keyword']);
  512. $segList1 = array_slice($segList, 0, 8);
  513. $articleData['keyword'] = implode(',', $segList1);
  514. }
  515. if ($articleData['introduce'] == '') {
  516. //提取内容中的描述
  517. $content = $data['content'];
  518. // 去除 <style> 和 <script> 标签及其内容
  519. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  520. // 去除所有 HTML 标签
  521. $content = strip_tags($content);
  522. // 去除 HTML 实体
  523. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  524. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  525. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  526. // 去除多余空白
  527. $content = preg_replace('/\s+/u', '', $content);
  528. // 截取 100 个字符
  529. $articleData['introduce'] = mb_substr($content, 0, 100);
  530. }
  531. if ($articleData['status'] == 0) {
  532. $this->sendMessage([
  533. 'talk_type' => 100,
  534. 'title' => $articleData['title'],
  535. 'content' => '提交了审核',
  536. 'messageType' => 2,
  537. ]);
  538. }
  539. $id = Article::insertGetId($articleData);
  540. if (!$id) {
  541. throw new \Exception('文章插入失败');
  542. }
  543. $articleDataContent = [
  544. 'article_id' => $id,
  545. 'content' => $data['content'],
  546. ];
  547. $contentInsertId = ArticleData::insertGetId($articleDataContent);
  548. if (!$contentInsertId) {
  549. throw new \Exception('文章内容插入失败');
  550. }
  551. // ------c_show_time********add***2****
  552. // 直接使用当前系统时间,不再强制添加8小时
  553. $now = date('Y-m-d H:i:s');
  554. if($user_type == 10000 || $is_collect == 1){
  555. // 管理员添加文章时,核心站c端显示时间就是创建时间;非核心站c端显示时间就是此创建时间往后推二十分钟;
  556. // 非管理员添加文章时,不做操作只有在审核通过时获取c端显示时间
  557. if (!isset($data['catid'])) {
  558. throw new \Exception('缺少必要字段:catid');
  559. }
  560. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  561. $web = WebsiteCategory::where('category_id', $data['catid'])
  562. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  563. ->select('website_id',
  564. 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'))
  565. ->get();
  566. // $id = 225; -----测试开启
  567. // 采集来的文章,错开时间在两小时之内发布
  568. if($user_type == 10000 && $is_collect == 1){
  569. $web_num = $web->where('is_core', '!=', 2)->count();
  570. $waiting_interval = 10;
  571. if($web_num > 12){
  572. // 若网站数量大于12个,则每个网站间隔时间取均值
  573. // 防止除数为 0,虽然这里 $web_num 是 count 结果不会为 0,但做健壮性检查
  574. $waiting_interval = 120 / max(1, $web_num);
  575. }
  576. $time = 0;
  577. }else{
  578. // 非核心站与核心站----显示时间-----间隔
  579. $time = 20;
  580. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  581. $waiting_interval = 5;
  582. }
  583. // 将 Hyperf\Database\Model\Collection 转换为数组
  584. $webArray = $web->toArray();
  585. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $id, $waiting_interval, $is_collect) {
  586. // 检查 $item 对象是否有 is_core 属性
  587. if (!isset($item['is_core'])) {
  588. throw new \Exception('$item 对象缺少 is_core 属性');
  589. }
  590. // 当 is_core 为 2 时,则表示此网站不存在
  591. if ($item['is_core'] == 2) {
  592. return null;
  593. }
  594. if($is_collect == 1){
  595. // 采集来的文章,错开时间在两小时之内发布
  596. // $time = 0;
  597. $c_show_time = date('Y-m-d H:i:s', strtotime($now)+$time*60);
  598. $time += $waiting_interval;
  599. }else if($item['is_core'] == 1){
  600. // 当 is_core 为 1 时,则表示此网站是核心站
  601. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  602. }else{
  603. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  604. $c_show_time = date('Y-m-d H:i:s', strtotime($now)+$time*60);
  605. if ($item['is_core'] == 0) {
  606. $time += $waiting_interval;
  607. }
  608. }
  609. return [
  610. 'article_id' => $id,
  611. 'website_id' => $item['website_id'],
  612. 'c_show_time' => $c_show_time,
  613. // 'is_core' => $item['is_core'],
  614. // 'time' => $time
  615. ];
  616. }, array_keys($webArray), $webArray)));
  617. // Db::commit();
  618. // return Result::success($article_ignore);
  619. if(!empty($article_ignore)){
  620. $article_ignores = ArticleIgnore::insert($article_ignore);
  621. if(!$article_ignores){
  622. throw new \Exception('c端展示时间插入失败');
  623. }
  624. }
  625. }
  626. // ------c_show_time********add***2****
  627. //处理投票
  628. if ($is_survey == 1) {
  629. //生成年月日时分秒+8位随机数
  630. $uuid = date('YmdHis') . rand(10000000, 99999999);
  631. var_dump($suvey_array, 'suvey_array________');
  632. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  633. var_dump($suveys_array, '---------------------1');
  634. var_dump($suvey_array, '---------------------2');
  635. $suvey_data = [];
  636. foreach ($suveys_array as $key => $value) {
  637. if ($value == '') {
  638. continue;
  639. }
  640. if (is_array($value)) {
  641. $suvey_data[] = [
  642. 'sur_id' => $uuid,
  643. 'art_id' => $id,
  644. 'website_id' => $website_id ?? 2,
  645. 'survey_name' => $survey_name,
  646. 'choice_name' => $value[1],
  647. 'is_other' => 1,
  648. 'other_id' => 0,
  649. 'results' => 0,
  650. ];
  651. } else {
  652. $suvey_data[] = [
  653. 'sur_id' => $uuid,
  654. 'art_id' => $id,
  655. 'website_id' => $website_id ?? 2,
  656. 'survey_name' => $survey_name,
  657. 'choice_name' => $value,
  658. 'is_other' => 0,
  659. 'other_id' => 0,
  660. 'results' => 0,
  661. ];
  662. }
  663. if (empty($suvey_data)) {
  664. throw new \Exception("投票数据为空");
  665. }
  666. }
  667. $result = ArticleSurvey::insert($suvey_data);
  668. if (!$result) {
  669. throw new \Exception("投票失败,ArticleSurvey插入失败");
  670. }
  671. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  672. if (!$result) {
  673. throw new \Exception("投票失败,更新主表失败");
  674. }
  675. }
  676. Db::commit();
  677. return Result::success(['id' => $id]);
  678. } catch (\Throwable $ex) {
  679. Db::rollBack();
  680. var_dump($ex->getMessage());
  681. return Result::error("创建失败", 0);
  682. }
  683. }
  684. /**
  685. * @param array $data
  686. * @return array
  687. */
  688. public function delArticle(array $data): array
  689. {
  690. // ------c_show_time********del*******
  691. Db::beginTransaction();
  692. try{
  693. $article = Article::where(['id' => $data['id']])->delete();
  694. // 若文章删除失败,抛出异常,后续 SQL 语句不会执行
  695. if (!$article) {
  696. throw new \Exception("删除失败,文章删除失败");
  697. }
  698. //survey投票删除
  699. ArticleSurvey::where(['art_id' => $data['id']])->delete(); // 修正类名大小写
  700. $articleIgnore = ArticleIgnore::where(['article_id' => $data['id']])->delete();
  701. $article_data = ArticleData::where(['article_id' => $data['id']])->delete();
  702. // 若文章详情删除失败,抛出异常
  703. if (!$article_data) {
  704. throw new \Exception("删除失败,文章详情删除失败");
  705. }
  706. Db::commit(); // 所有操作成功,提交事务
  707. }catch (\Throwable $ex) {
  708. Db::rollBack();
  709. var_dump($ex->getMessage());
  710. return Result::error("删除失败: " . $ex->getMessage(), 0);
  711. }
  712. // ------c_show_time********del*******
  713. if (!$article) {
  714. return Result::error("删除失败");
  715. }
  716. return Result::success($article);
  717. }
  718. /**
  719. * @param array $data
  720. * @return array
  721. */
  722. public function updateArticle(array $data): array
  723. {
  724. var_dump($data, '----------12-----------1');
  725. Db::beginTransaction();
  726. // ------c_show_time********up*******
  727. $user_type = isset($data['user_type']) ? $data['user_type'] : 0;
  728. // 无论是否改变了c端显示时间或者栏目,都需要将未屏蔽的网站显示时间删除记录
  729. // 若是存在交集,则进行修改,若无,则合并(此表中的记录应该包含被屏蔽网站及涉及所有网站的展示时间)
  730. $web = WebsiteCategory::where('category_id', $data['catid'])
  731. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  732. ->select('website_id',
  733. 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'))
  734. ->get();
  735. // 根据错误信息,问题在于 $web 可能是一个包含对象的集合,不能直接用于 whereNotIn 方法
  736. // 先从 $web 集合中提取 website_id 字段的值,再进行删除操作
  737. $websiteIds = $web->pluck('website_id')->toArray();
  738. $del_article_ignore = ArticleIgnore::where('article_id', $data['id'])->whereNotIn('website_id', $websiteIds)->delete();
  739. if($user_type == 0){
  740. throw new \Exception("用户类型不能为空");
  741. }
  742. if($user_type == 10000 ){
  743. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  744. $web = WebsiteCategory::where('category_id', $data['catid'])
  745. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  746. ->select('website_id',
  747. 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'))
  748. ->get();
  749. // 非核心站与核心站----显示时间-----间隔
  750. $time = 20;
  751. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  752. $waiting_interval = 5;
  753. $webArray = $web->toArray();
  754. if(empty($webArray)){
  755. throw new \Exception('网站分类不存在');
  756. }
  757. // 直接使用当前系统时间,不再强制添加8小时
  758. $now = date('Y-m-d H:i:s');
  759. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  760. // 检查 $item 对象是否有 is_core 属性
  761. if (!isset($item['is_core'])) {
  762. throw new \Exception('$item 对象缺少 is_core 属性');
  763. }
  764. // 当 is_core 为 2 时,则表示此网站不存在
  765. if ($item['is_core'] == 2) {
  766. return null;
  767. }else if($item['is_core'] == 1){
  768. // 当 is_core 为 1 时,则表示此网站是核心站
  769. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  770. }else{
  771. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  772. $c_show_time = date('Y-m-d H:i:s', strtotime($now)+$time*60);
  773. if ($item['is_core'] == 0) {
  774. $time += $waiting_interval;
  775. }
  776. }
  777. return [
  778. 'article_id' => $data['id'],
  779. 'website_id' => $item['website_id'],
  780. 'c_show_time' => $c_show_time,
  781. ];
  782. }, array_keys($webArray), $webArray)));
  783. if(!empty($article_ignore)){
  784. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  785. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  786. $article_ignores = ArticleIgnore::upsert(
  787. $article_ignore,
  788. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  789. ['c_show_time'] // 需要更新的字段
  790. );
  791. if(!$article_ignores){
  792. throw new \Exception('c端展示时间插入失败');
  793. }
  794. }
  795. // Db::commit();
  796. // return Result::success($article_ignore);
  797. }
  798. // ------c_show_time********up*******
  799. unset($data['user_type']);
  800. // unset($data['web_site_id']);
  801. unset($data['nav_add_pool_id']);
  802. try {
  803. //处理投票
  804. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  805. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  806. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  807. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  808. unset($data['is_survey']);
  809. unset($data['survey_name']);
  810. unset($data['suvey_array']);
  811. unset($data['website_id']);
  812. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  813. if ($data['hits'] == '') {
  814. $data['hits'] = 0;
  815. }
  816. if ($data['is_original'] == '') {
  817. $data['is_original'] = 0;
  818. }
  819. if ($data['status'] == '') {
  820. $data['status'] = 0;
  821. }
  822. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  823. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  824. $articleData = $data;
  825. unset($articleData['content']);
  826. unset($articleData['status_name']);
  827. unset($articleData['name']);
  828. unset($articleData['content']);
  829. unset($articleData['pid_arr']);
  830. unset($articleData['pid']);
  831. //自动处理缩略图、关键字、描述
  832. if ($articleData['imgurl'] == '') {
  833. //如果没有图,设置level=0
  834. $levelArr = json_decode($articleData['level'], true);
  835. var_dump($levelArr, '----------levelArr-----------1');
  836. //content中提取图片第一个图,正则提取
  837. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  838. preg_match_all($reg, $data['content'], $matches);
  839. if (isset($matches[1][0])) {
  840. //截取varchar240
  841. // 截取到第一个<
  842. $articleData['imgurl'] = $matches[1][0];
  843. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  844. $pos = strpos($articleData['imgurl'], '"');
  845. if ($pos !== false) {
  846. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  847. }
  848. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  849. //如果有图,设置level=3
  850. if (!in_array(3, $levelArr)) {
  851. $levelArr[] = 3;
  852. }
  853. $articleData['level'] = json_encode($levelArr);
  854. } else {
  855. if (!in_array(0, $levelArr)) {
  856. $levelArr[] = 0;
  857. }
  858. $articleData['level'] = json_encode($levelArr);
  859. }
  860. }
  861. var_dump($articleData['level'], '----------$articleData[level]----------1');
  862. if ($articleData['keyword'] == '') {
  863. //提取标题+内容中的关键词
  864. $articleData['keyword'] = $data['title'];
  865. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  866. Jieba::init(); // 初始化 jieba-php
  867. Finalseg::init();
  868. $segList = Jieba::cut($articleData['keyword']);
  869. $segList1 = array_slice($segList, 0, 8);
  870. $articleData['keyword'] = implode(',', $segList1);
  871. }
  872. if ($articleData['introduce'] == '') {
  873. //提取内容中的描述
  874. $content = $data['content'];
  875. // 去除 <style> 和 <script> 标签及其内容
  876. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  877. // 去除所有 HTML 标签
  878. $content = strip_tags($content);
  879. // 去除 HTML 实体
  880. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  881. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  882. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  883. // 去除多余空白
  884. $content = preg_replace('/\s+/u', '', $content);
  885. // 截取 100 个字符
  886. $articleData['introduce'] = mb_substr($content, 0, 100);
  887. }
  888. if ($articleData['status'] == 0) {
  889. $this->sendMessage([
  890. 'talk_type' => 100,
  891. 'title' => $articleData['title'],
  892. 'content' => '提交了审核',
  893. 'messageType' => 2,
  894. ]);
  895. }
  896. $id = Article::where(['id' => $data['id']])->update($articleData);
  897. $articleDataContent = [
  898. 'content' => $data['content'],
  899. ];
  900. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  901. //处理投票
  902. $id = $data['id'];
  903. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  904. var_dump($suvey_array, 'suvey_array________delete');
  905. //处理投票
  906. if ($is_survey == 1) {
  907. //生成年月日时分秒+8位随机数
  908. $uuid = date('YmdHis') . rand(10000000, 99999999);
  909. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  910. var_dump($suveys_array, '---------------------1');
  911. $suvey_data = [];
  912. if (is_array($suveys_array)) {
  913. foreach ($suveys_array as $key => $value) {
  914. if ($value == '') {
  915. continue;
  916. }
  917. if (is_array($value)) {
  918. $suvey_data[] = [
  919. 'sur_id' => $uuid,
  920. 'art_id' => $id,
  921. 'website_id' => $website_id ?? 2,
  922. 'survey_name' => $survey_name,
  923. 'choice_name' => $value[1],
  924. 'is_other' => 1,
  925. 'other_id' => 0,
  926. 'results' => 0,
  927. ];
  928. } else {
  929. $suvey_data[] = [
  930. 'sur_id' => $uuid,
  931. 'art_id' => $id,
  932. 'website_id' => $website_id ?? 2,
  933. 'survey_name' => $survey_name,
  934. 'choice_name' => $value,
  935. 'is_other' => 0,
  936. 'other_id' => 0,
  937. 'results' => 0,
  938. ];
  939. }
  940. if (empty($suvey_data)) {
  941. throw new \Exception("投票数据为空");
  942. }
  943. }
  944. }
  945. $result = ArticleSurvey::insert($suvey_data);
  946. if (!$result) {
  947. throw new \Exception("投票失败");
  948. }
  949. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  950. if (!$result) {
  951. throw new \Exception("投票失败");
  952. }
  953. } else {
  954. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  955. }
  956. Db::commit();
  957. return Result::success([]);
  958. } catch (\Throwable $ex) {
  959. Db::rollBack();
  960. var_dump($ex->getMessage());
  961. return Result::error("更新失败" . $ex->getMessage(), 0);
  962. }
  963. }
  964. /**
  965. * 更新资讯状态
  966. * @param array $data
  967. * @return array
  968. */
  969. public function upArticleStatus(array $data): array
  970. {
  971. $articleData = Article::where(['id' => $data['id']])->first();
  972. //发送10次
  973. // for ($i = 0; $i < 10; $i++) {
  974. // $this->sendMessage([
  975. // 'talk_type' => 100,
  976. // 'title' => $i . $articleData['title'],
  977. // 'content' => '审核通过',
  978. // 'messageType' => 2,
  979. // 'user_id' => $articleData['admin_user_id'],
  980. // ]);
  981. // }
  982. // var_dump($data['status'], 'status');
  983. // return Result::success();
  984. if ($data['status'] == 1) {
  985. $this->sendMessage([
  986. 'talk_type' => 101,
  987. 'title' => $articleData['title'],
  988. 'content' => '审核通过',
  989. 'messageType' => 2,
  990. 'user_id' => $articleData['admin_user_id'],
  991. ]);
  992. }
  993. if ($data['status'] == 2) {
  994. $this->sendMessage([
  995. 'talk_type' => 101,
  996. 'title' => $articleData['title'],
  997. 'content' => '审核拒绝',
  998. 'messageType' => 2,
  999. 'user_id' => $articleData['admin_user_id'],
  1000. ]);
  1001. }
  1002. if ($data['status'] == 0) {
  1003. $this->sendMessage([
  1004. 'talk_type' => 100,
  1005. 'title' => $articleData['title'],
  1006. 'content' => '提交了审核',
  1007. 'messageType' => 2,
  1008. ]);
  1009. }
  1010. $result = Article::where(['id' => $data['id']])->update($data);
  1011. if (isset($data['ignore_ids']) && !empty($data['ignore_ids'])) {
  1012. //article_ignore 表插入数据 db操作
  1013. //转成数组
  1014. //删掉数据重新写入
  1015. // DB::table('article_ignore')->where('article_id', $data['id'])->delete();
  1016. $website_ids = is_array($data['ignore_ids']) ? $data['ignore_ids'] : json_decode($data['ignore_ids'], true);
  1017. // $insert_data = [];
  1018. // foreach ($website_ids as $key => $value) {
  1019. // $insert_data[] = [
  1020. // 'article_id' => $data['id'],
  1021. // 'website_id' => $value,
  1022. // 'is_ignore' => 1
  1023. // ];
  1024. // }
  1025. DB::table('article_ignore')->where('article_id', $data['id'])->whereIn('website_id',$website_ids)->update(['is_ignore' => 1]);
  1026. }else{
  1027. // ------c_show_time********up_status*******
  1028. // 若是审核通过 则更新c_show_time
  1029. if($data['status'] == 1){
  1030. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  1031. $web = Article::where('article.id',$data['id'])
  1032. ->leftJoin('website_category','article.catid','website_category.category_id')
  1033. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  1034. ->select('website_id',
  1035. 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'))
  1036. ->get();
  1037. // 非核心站与核心站----显示时间-----间隔
  1038. $time = 20;
  1039. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  1040. $waiting_interval = 5;
  1041. $webArray = $web->toArray();
  1042. if(empty($webArray)){
  1043. throw new \Exception('网站分类不存在');
  1044. }
  1045. // 直接使用当前系统时间,不再强制添加8小时
  1046. $now = date('Y-m-d H:i:s');
  1047. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  1048. // 检查 $item 对象是否有 is_core 属性
  1049. if (!isset($item['is_core'])) {
  1050. throw new \Exception('$item 对象缺少 is_core 属性');
  1051. }
  1052. // 当 is_core 为 2 时,则表示此网站不存在
  1053. if ($item['is_core'] == 2) {
  1054. return null;
  1055. }else if($item['is_core'] == 1){
  1056. // 当 is_core 为 1 时,则表示此网站是核心站
  1057. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  1058. }else{
  1059. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  1060. $c_show_time = date('Y-m-d H:i:s', strtotime($now)+$time*60);
  1061. if ($item['is_core'] == 0) {
  1062. $time += $waiting_interval;
  1063. }
  1064. }
  1065. return [
  1066. 'article_id' => $data['id'],
  1067. 'website_id' => $item['website_id'],
  1068. 'c_show_time' => $c_show_time,
  1069. ];
  1070. }, array_keys($webArray), $webArray)));
  1071. if(!empty($article_ignore)){
  1072. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  1073. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  1074. $article_ignores = ArticleIgnore::upsert(
  1075. $article_ignore,
  1076. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  1077. ['c_show_time'] // 需要更新的字段
  1078. );
  1079. if(!$article_ignores){
  1080. throw new \Exception('c端展示时间插入失败');
  1081. }
  1082. }
  1083. }
  1084. // ------c_show_time********up_status*******
  1085. }
  1086. if ($result) {
  1087. return Result::success();
  1088. } else {
  1089. return Result::error("更新状态失败", 0);
  1090. }
  1091. }
  1092. /**
  1093. * 获取新闻详情
  1094. * @param array $data
  1095. * @return array
  1096. */
  1097. public function getArticleInfo(array $data): array
  1098. {
  1099. $where = [
  1100. 'article.id' => $data['id'],
  1101. // 'article.status' => 1,
  1102. ];
  1103. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  1104. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  1105. $info = $result;
  1106. // var_dump($info, 'info');
  1107. $info['survey_array'] = $articleSurvey;
  1108. if ($result) {
  1109. return Result::success($info);
  1110. } else {
  1111. return Result::error("查询失败", 0);
  1112. }
  1113. }
  1114. /**
  1115. * 获取头条新闻
  1116. * @param array $data
  1117. * @return array
  1118. */
  1119. public function getWebsiteArticlett(array $data): array
  1120. {
  1121. $website_id = $data['website_id'];
  1122. $website = Website::where('id', $data['website_id'])->first();
  1123. if (empty($website)) {
  1124. return Result::error("网站不存在", 0);
  1125. }
  1126. $categorys = $this->processArticlePro($website_id);
  1127. $catiall = $categorys['catiall'];
  1128. $categoryIds = $categorys['categoryIds'];
  1129. $where = [
  1130. 'status' => 1
  1131. ];
  1132. // $website_column = $website['column'];
  1133. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1134. $website_column = json_decode($website['website_column_arr_id'], true);
  1135. }
  1136. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1137. // return Result::success($diff_pid_categoryIds);
  1138. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1139. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1140. }
  1141. // $website_id = $data['website_id'];
  1142. $month = date("Y-m-d H:i:s", strtotime("-30 day"));
  1143. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  1144. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  1145. switch ($data['level']) {
  1146. case 1:
  1147. case 2:
  1148. case 3:
  1149. case 6: //1.头条资讯;2.轮播图;3.推荐图;6.今日热点
  1150. $query = Article::where($where)
  1151. ->where('level', 'like', '%' . $data['level'] . '%')
  1152. ->orderBy('updated_at', 'desc');
  1153. break;
  1154. case 4: //最新资讯
  1155. $query = Article::where($where)->orderBy('updated_at', 'desc');
  1156. break;
  1157. case 5: //资讯推荐
  1158. $query = Article::where($where)
  1159. ->where('updated_at', '>', $month);
  1160. break;
  1161. case 7: //资讯分类
  1162. if (isset($data['id']) && !empty($data['id'])) {
  1163. $keyword = Article::where('id', $data['id'])->value('keyword');
  1164. $keywordArray = explode(',', $keyword);
  1165. $whereL7 = [];
  1166. foreach ($keywordArray as $k => $v) {
  1167. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1168. }
  1169. $query = Article::where($where)->where($whereL7)->orderBy('updated_at', 'desc');;
  1170. break;
  1171. } else {
  1172. return Result::error("请输入资讯ID", 0);
  1173. break;
  1174. }
  1175. default:
  1176. break;
  1177. }
  1178. // $whereL7 = [];
  1179. // if(isset($data['id']) && !empty($data['id'])){
  1180. // $keyword = Article::where('id', $data['id'])->value('keyword');
  1181. // $keywordArray = explode(',', $keyword);
  1182. // foreach ($keywordArray as $k => $v) {
  1183. // $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1184. // }
  1185. // }
  1186. // $query = Article::where($where)
  1187. // ->when(isset($data['level']) && !empty($data['level']), function ($query) use ($data,$whereL7) {
  1188. // if($data['level'] == 1 || $data['level'] == 2 || $data['level'] == 3 || $data['level'] == 6){
  1189. // $query = $query->where('article.level','like','%'.$data['level'].'%')->orderBy('updated_at','desc');
  1190. // }
  1191. // if($data['level'] == 7){
  1192. // $query = $query->where($whereL7)->orderBy('updated_at','desc');
  1193. // }
  1194. // if($data['level'] == 4){
  1195. // $query = $query->inRandomOrder()
  1196. // ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  1197. // }
  1198. // if($data['level'] == 5){
  1199. // $query = $query->orderBy('updated_at','desc');
  1200. // }
  1201. // });
  1202. if ($data['textnum'] > 0) {
  1203. $query = clone $query;
  1204. $result['text'] = $query
  1205. ->whereIn('catid', $categoryIds)
  1206. ->leftJoinSub(function ($query) use ($website_id) {
  1207. $query->from('article_ignore')
  1208. ->where('website_id', $website_id);
  1209. }, 'article_ignore', function ($join) {
  1210. $join->on('article_ignore.article_id', '=', 'article.id');
  1211. })
  1212. ->where(function ($query) {
  1213. $query->whereNull('article_ignore.article_id')
  1214. ->orWhere(function ($subQuery) {
  1215. $subQuery->whereNotNull('article_ignore.article_id')
  1216. ->where('article_ignore.is_ignore', 0)
  1217. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  1218. });
  1219. })
  1220. // ->where(function ($query) use ($website_id) {
  1221. // $query->whereNull('article_ignore.article_id')
  1222. // ->orWhere('article_ignore.website_id', '!=', $website_id);
  1223. // })
  1224. ->select(
  1225. 'article.id',
  1226. 'article.title',
  1227. 'article.author',
  1228. 'article.updated_at',
  1229. 'article.introduce',
  1230. 'article.islink',
  1231. 'article.linkurl',
  1232. 'article.copyfrom',
  1233. 'article.cat_arr_id',
  1234. 'article.catid',
  1235. 'article.level',
  1236. // 'article_ignore.is_ignore',
  1237. // 'article_ignore.c_show_time',
  1238. )
  1239. ->offset($data['placeid'])
  1240. ->limit($data['textnum'])
  1241. ->get()->all();
  1242. foreach ($result['text'] as $k => $v) {
  1243. $result['text'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1244. $result['text'][$k]->alias = $catiall[$v->catid]['alias'];
  1245. }
  1246. }
  1247. if ($data['imgnum'] > 0) {
  1248. $query = clone $query;
  1249. $result['img'] = $query
  1250. ->whereIn('catid', $categoryIds)
  1251. ->where('article.imgurl', '!=', '')
  1252. ->select(
  1253. 'article.id',
  1254. 'article.title',
  1255. 'article.imgurl',
  1256. 'article.author',
  1257. 'article.updated_at',
  1258. 'article.introduce',
  1259. 'article.islink',
  1260. 'article.linkurl',
  1261. 'article.copyfrom',
  1262. 'article.cat_arr_id',
  1263. 'article.catid',
  1264. 'article.level',
  1265. // 'article_ignore.is_ignore',
  1266. // 'article_ignore.c_show_time',
  1267. )
  1268. ->offset($data['placeid'])
  1269. ->limit($data['imgnum'])
  1270. ->get()->all();
  1271. foreach ($result['img'] as $k => $v) {
  1272. $result['img'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1273. $result['img'][$k]->alias = $catiall[$v->catid]['alias'];
  1274. }
  1275. }
  1276. if (empty($result)) {
  1277. return Result::error("暂无相关资讯", 0);
  1278. }
  1279. return Result::success($result);
  1280. }
  1281. /**
  1282. * 获取模块新闻
  1283. * @param array $data
  1284. * @return array
  1285. */
  1286. public function getWebsiteModelArticles(array $data): array
  1287. {
  1288. $catid = $data['catid'];
  1289. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  1290. $category = $category->toArray();
  1291. if (!empty($category)) {
  1292. $where = [
  1293. 'status' => 1,
  1294. 'catid' => $catid,
  1295. ];
  1296. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  1297. // 1:文字新闻;2:轮播图;3:图文;
  1298. // 级别:0:未分类
  1299. // 3:推荐图片
  1300. if ($data['level'] == 1) {
  1301. $data['level'] = 0;
  1302. }
  1303. $result = Article::where($where)
  1304. ->where(function ($query) use ($data) {
  1305. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  1306. ->orWhereNull("level")
  1307. ->orWhereRaw("level = '[]'");
  1308. })
  1309. ->leftJoinSub(function ($query) use ($data) {
  1310. $query->from('article_ignore')
  1311. ->where('website_id', $data['website_id']);
  1312. }, 'article_ignore', function ($join) {
  1313. $join->on('article_ignore.article_id', '=', 'article.id');
  1314. })
  1315. ->where(function ($query) {
  1316. $query->whereNull('article_ignore.article_id')
  1317. ->orWhere(function ($subQuery) {
  1318. $subQuery->whereNotNull('article_ignore.article_id')
  1319. ->where('article_ignore.is_ignore', 0)
  1320. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  1321. });
  1322. })
  1323. // ->where(function ($query) use ($data) {
  1324. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1325. // ->orWhereNull("ignore_ids");
  1326. // })
  1327. ->orderBy("updated_at", "desc")
  1328. ->offset($placeid)
  1329. ->limit($data['pagesize'])
  1330. ->get();
  1331. if (empty($result)) {
  1332. return Result::error("此栏目暂无相关新闻", 0);
  1333. }
  1334. } else {
  1335. return Result::error("此网站暂无此栏目", 0);
  1336. }
  1337. return Result::success($result);
  1338. }
  1339. /**
  1340. *获取新闻列表
  1341. * @param array $data
  1342. * @return array
  1343. */
  1344. public function getWebsiteArticleList(array $data): array
  1345. {
  1346. // return Result::success($data);
  1347. $where[] = ['status', '=', 1];
  1348. $website_id = $data['website_id'];
  1349. $website = Website::where('id', $data['website_id'])->first();
  1350. if (empty($website)) {
  1351. return Result::error("网站不存在", 0);
  1352. }
  1353. // $website_column = $website['column'];
  1354. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1355. $website_column = json_decode($website['website_column_arr_id'], true);
  1356. }
  1357. $categorys = $this->processArticlePro($website_id);
  1358. $cat_1st_arr = $categorys['cat_1st_arr'];
  1359. $catiall = $categorys['catiall'];
  1360. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1361. // return Result::success($diff_pid_categoryIds);
  1362. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1363. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1364. }
  1365. if (isset($data['catid']) && !empty($data['catid'])) {
  1366. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  1367. if (empty($category)) {
  1368. return Result::error("此网站暂无此栏目", 0);
  1369. }
  1370. array_push($where, ['catid', '=', $data['catid']]);
  1371. }
  1372. // return Result::success($where);
  1373. $query = Article::where($where)
  1374. ->leftJoinSub(function ($query) use ($website_id) {
  1375. $query->from('article_ignore')
  1376. ->where('website_id', $website_id);
  1377. }, 'article_ignore', function ($join) {
  1378. $join->on('article_ignore.article_id', '=', 'article.id');
  1379. })
  1380. ->where(function ($query) {
  1381. $query->whereNull('article_ignore.article_id')
  1382. ->orWhere(function ($subQuery) {
  1383. $subQuery->whereNotNull('article_ignore.article_id')
  1384. ->where('article_ignore.is_ignore', 0)
  1385. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  1386. });
  1387. })
  1388. ->select(
  1389. 'article.id',
  1390. 'article.title',
  1391. 'article.imgurl',
  1392. 'article.author',
  1393. 'article.updated_at',
  1394. 'article.introduce',
  1395. 'article.islink',
  1396. 'article.linkurl',
  1397. 'article.copyfrom',
  1398. 'article.cat_arr_id',
  1399. 'article.catid'
  1400. );
  1401. $count = $query->count();
  1402. $rep = $query->orderBy("updated_at", "desc")
  1403. ->offset(($data['page'] - 1) * $data['pageSize'])
  1404. ->limit($data['pageSize'])
  1405. ->get()->all();
  1406. $categorys = $this->processArticlePro($website_id);
  1407. $cat_1st_arr = $categorys['cat_1st_arr'];
  1408. $catiall = $categorys['catiall'];
  1409. // $web['website_id'] = $data['website_id'];
  1410. foreach ($rep as $k => $v) {
  1411. $rep[$k]->category_name = $catiall[$v->catid]['alias'];
  1412. $rep[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1413. }
  1414. // $rep = $this->processArticles($rep,$web);
  1415. $data = [
  1416. 'rows' => $rep,
  1417. 'count' => $count,
  1418. ];
  1419. if (empty($rep)) {
  1420. return Result::error("没有信息数据");
  1421. }
  1422. return Result::success($data);
  1423. }
  1424. /**
  1425. * 前端-获取新闻详情
  1426. * @param array $data
  1427. * @return array
  1428. */
  1429. public function selectWebsiteArticleInfo(array $data): array
  1430. {
  1431. $where = [
  1432. 'article.id' => $data['id'],
  1433. 'article.status' => 1,
  1434. ];
  1435. $result = Article::where($where)
  1436. ->leftJoin("article_data", "article.id", "article_data.article_id")
  1437. ->leftJoin("article_extend", "article_extend.article_id", "article.id")
  1438. ->where(function ($query) use ($data) {
  1439. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1440. ->orWhereNull("ignore_ids");
  1441. })
  1442. ->select(
  1443. 'article.*',
  1444. 'article_data.content',
  1445. 'article_data.article_id',
  1446. 'article_extend.website_url',
  1447. 'article_extend.email',
  1448. 'article_extend.contacts',
  1449. 'article_extend.contacts_mobile',
  1450. 'article_extend.contacts_address',
  1451. 'article_extend.zip_code',
  1452. 'article_extend.enterprise_name'
  1453. )
  1454. ->first();
  1455. if (empty($result)) {
  1456. return Result::error("暂无此新闻!", 0);
  1457. }
  1458. if (!empty($result['publiced_at'])) {
  1459. $result['updated_at'] = $result['publiced_at'];
  1460. }
  1461. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  1462. ->select('website_category.*', 'website.website_name', 'website.suffix')
  1463. ->where('website_category.website_id', $data['website_id'])
  1464. ->where(['website_category.category_id' => $result['catid']])
  1465. ->first();
  1466. if (empty($category)) {
  1467. return Result::error("查询失败", 0);
  1468. }
  1469. //手动推荐文章
  1470. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  1471. if (empty($commend_ids)) {
  1472. $commendArticle = [];
  1473. } else {
  1474. //去除不存在的文章ID
  1475. $commendArticle = Article::whereIn('article.id', $commend_ids)
  1476. ->leftjoin('website_category', 'website_category.category_id', '=', 'article.catid')
  1477. ->where('article.status', 1)
  1478. ->where('website_category.website_id', $data['website_id'])
  1479. ->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')
  1480. ->orderByRaw("FIELD(article.id, " . implode(',', $commend_ids) . ")")
  1481. // ->orderBy('article.updated_at', 'desc')
  1482. ->limit(5)
  1483. ->get();
  1484. //循环数组,取出cat_arr_id中的不重复值,再从website_category取出alias_pinyin,再将cat_arr_id的json转成路径/隔开
  1485. foreach ($commendArticle as $k => $v) {
  1486. $cat_arr_id = json_decode($v->cat_arr_id, true);
  1487. if (!empty($cat_arr_id) && is_array($cat_arr_id)) {
  1488. $cat_arr_id = array_unique($cat_arr_id);
  1489. // 从website_category取出alias_pinyin
  1490. $cat_arr = WebsiteCategory::where('website_id', $data['website_id'])
  1491. ->whereIn('category_id', $cat_arr_id)
  1492. ->pluck('alias_pinyin', 'category_id')
  1493. ->toArray();
  1494. // 将cat_arr_id的json转成路径/隔开
  1495. $path_parts = [];
  1496. foreach ($cat_arr_id as $cat_id) {
  1497. if (isset($cat_arr[$cat_id])) {
  1498. $path_parts[] = $cat_arr[$cat_id];
  1499. }
  1500. }
  1501. $v->alias_pinyin = implode('/', $path_parts);
  1502. } else {
  1503. $v->alias_pinyin = '';
  1504. }
  1505. }
  1506. }
  1507. $result['category_id'] = $category['category_id'];
  1508. $result['cat_name'] = $category['alias'];
  1509. $result['website_name'] = $category['website_name'] ?? "";
  1510. $result['suffix'] = $category['suffix'] ?? "";
  1511. $result['commendArticle'] = $commendArticle;
  1512. $result['commend_ids'] = $commend_ids;
  1513. return Result::success($result);
  1514. }
  1515. /**
  1516. * 前端-获取网站调查问卷
  1517. * @param array $data
  1518. * @return array
  1519. */
  1520. public function getWebsiteSurvey(array $data): array
  1521. {
  1522. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1523. $website = Website::where('id', $data['website_id'])->first();
  1524. if (empty($website)) {
  1525. return Result::error("暂无此网站", 0);
  1526. }
  1527. }
  1528. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1529. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1530. if (empty($article)) {
  1531. return Result::error("暂无此文章", 0);
  1532. }
  1533. // return Result::error($data,0);
  1534. $where['art_id'] = $data['art_id'];
  1535. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1536. } else {
  1537. $survey = Article::where(function ($query) {
  1538. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1539. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1540. })
  1541. ->where('status', 1)
  1542. ->where('is_survey', 1)
  1543. ->select('survey_id')
  1544. ->orderBy('updated_at', 'desc')
  1545. ->first();
  1546. if (empty($survey)) {
  1547. return Result::error("暂无调查问卷", 0);
  1548. }
  1549. $where['sur_id'] = $survey['survey_id'];
  1550. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1551. }
  1552. // return Result::success($where);
  1553. $result = ArticleSurvey::where($where)
  1554. ->where(function ($query) {
  1555. $query->where('is_other', 0)
  1556. ->orWhere(function ($subQuery) {
  1557. $subQuery->where('is_other', 1)
  1558. ->where('other_id', 0);
  1559. });
  1560. })
  1561. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1562. ->select('article_survey.*', 'article.survey_type')
  1563. ->get()->all();
  1564. if (empty($result)) {
  1565. return Result::error("此文章暂无调查问卷", 0);
  1566. }
  1567. return Result::success($result);
  1568. }
  1569. /**
  1570. * 前端-添加网站调查问卷选项
  1571. * @param array $data
  1572. * @return array
  1573. */
  1574. public function addWebsiteSurveyOption(array $data): array
  1575. {
  1576. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1577. $website = Website::where('id', $data['website_id'])->first();
  1578. if (empty($website)) {
  1579. return Result::error("暂无此网站", 0);
  1580. }
  1581. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1582. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1583. if (empty($survey)) {
  1584. return Result::error("此调查问卷不可添加选项", 0);
  1585. }
  1586. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1587. $choice = [
  1588. 'art_id' => $survey['art_id'],
  1589. 'website_id' => $data['website_id'],
  1590. 'survey_name' => $survey['survey_name'],
  1591. 'choice_name' => $data['choice_name'],
  1592. 'sur_id' => $survey['sur_id'],
  1593. 'is_other' => 1,
  1594. 'other_id' => $survey['id'],
  1595. ];
  1596. $result = ArticleSurvey::insertGetId($choice);
  1597. if (empty($result)) {
  1598. return Result::error("添加失败", 0);
  1599. }
  1600. return Result::success($result);
  1601. }
  1602. }
  1603. return Result::error("添加失败", 0);
  1604. }
  1605. return Result::error("添加失败", 0);
  1606. }
  1607. /**
  1608. * 前端-调查问卷投票
  1609. * @param array $data
  1610. * @return array
  1611. */
  1612. public function addWebsiteSurveyVote(array $data): array
  1613. {
  1614. // return Result::success($data);
  1615. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1616. $website = Website::where('id', $data['website_id'])->first();
  1617. if (empty($website)) {
  1618. return Result::error("暂无此网站", 0);
  1619. }
  1620. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1621. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1622. // return Result::success($survey);
  1623. if (empty($is_survey)) {
  1624. return Result::error("此调查问卷不存在", 0);
  1625. }
  1626. // return Result::success($survey);
  1627. // 调查问卷类型
  1628. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1629. //多选 若是json型则转化成数组类型
  1630. if (strpos($data['choice_id'], '[') === 0) {
  1631. $data['choice_id'] = json_decode($data['choice_id'], true);
  1632. } else {
  1633. // 单选 也转换成数组
  1634. $data['choice_id'] = [$data['choice_id']];
  1635. }
  1636. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1637. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1638. // ->where('website_id',$data['website_id'])
  1639. ->where('is_other', 1)
  1640. ->where('other_id', 0)
  1641. ->first();
  1642. if (!empty($other)) {
  1643. return Result::error("请选择已有的选项!", 0);
  1644. }
  1645. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1646. // ->where('website_id',$data['website_id'])
  1647. ->where('is_other', 1)
  1648. ->where('other_id', '!=', 0)
  1649. ->first();
  1650. // return Result::success($choice['other']);
  1651. $choice_id = $data['choice_id'];
  1652. if (!empty($choice['other'])) {
  1653. // array_push($data['choice_id'],$choice['other']['other_id']);
  1654. if (!empty($choice_id)) {
  1655. $key = array_search($choice['other']['id'], $choice_id);
  1656. if ($key !== false) {
  1657. unset($choice_id[$key]);
  1658. $choice_id = array_values($choice_id);
  1659. }
  1660. array_push($choice_id, $choice['other']['other_id']);
  1661. } else {
  1662. $choice_id[0] = $choice['other']['other_id'];
  1663. }
  1664. array_push($data['choice_id'], $choice['other']['other_id']);
  1665. }
  1666. // return Result::success($data);
  1667. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1668. // ->where('website_id',$data['website_id'])
  1669. ->increment('results', 1);
  1670. if (empty($choice)) {
  1671. return Result::error("请选择已有的选项!", 0);
  1672. }
  1673. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1674. // ->where('website_id',$data['website_id'])
  1675. ->where('other_id', 0)
  1676. ->get();
  1677. $survey['choice'] = $choice_id;
  1678. return Result::success($survey);
  1679. }
  1680. return Result::error("参数必填!");
  1681. }
  1682. return Result::error("此调查问卷不存在", 0);
  1683. }
  1684. return Result::error("参数必填!");
  1685. }
  1686. /**
  1687. * 后端-获取网站调查问卷列表
  1688. * @param array $data
  1689. * @return array
  1690. */
  1691. public function getSurveyList(array $data): array
  1692. {
  1693. $where = [];
  1694. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1695. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1696. }
  1697. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  1698. array_push($where, ['survey_type', '=', $data['survey_type']]);
  1699. }
  1700. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  1701. array_push($where, ['is_survey', '=', $data['is_survey']]);
  1702. }
  1703. // return Result::success($where);
  1704. if (!empty($where)) {
  1705. $query = Article::where($where)->where(function ($q) {
  1706. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1707. });
  1708. } else {
  1709. $query = Article::where(function ($q) {
  1710. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1711. });
  1712. }
  1713. $count = $query->count();
  1714. $survey = $query->orderByDesc('id')
  1715. ->limit($data['pageSize'])
  1716. ->offset(($data['page'] - 1) * $data['pageSize'])
  1717. ->get();
  1718. if (empty($survey->toArray())) {
  1719. return Result::error("暂无调查问卷!", 0);
  1720. }
  1721. $result = [
  1722. 'rows' => $survey,
  1723. 'count' => $count,
  1724. ];
  1725. return Result::success($result);
  1726. }
  1727. /**
  1728. * 后端-获取网站调查问卷详情
  1729. * @param array $data
  1730. * @return array
  1731. */
  1732. public function getSurveyInfo(array $data): array
  1733. {
  1734. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1735. $where = ['sur_id' => $data['sur_id']];
  1736. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1737. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1738. ->select('article_survey.*', 'article.survey_type')
  1739. ->get()->all();
  1740. if (empty($choose)) {
  1741. return Result::error("此调查问卷不存在", 0);
  1742. }
  1743. $resultsArray = array_column($choose, 'results');
  1744. $total = array_sum($resultsArray);
  1745. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1746. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1747. // $total = 0;
  1748. if (!empty($other)) {
  1749. $total = $total + $other['results'];
  1750. $other['choice_name'] = '(其他)';
  1751. if (!empty($others)) {
  1752. $other['hasChildren'] = true;
  1753. // array_push($other,['hasChildren','=',true]);
  1754. $other['children'] = $others;
  1755. $other_choices = [$other->toArray()];
  1756. $mer_choice = array_merge($choose, $other_choices);
  1757. $value_choice = array_values($mer_choice);
  1758. } else {
  1759. // return Result::error('1111');
  1760. $other_choices = [$other->toArray()];
  1761. $other_choices = array_merge($choose, $other_choices);
  1762. $value_choice = array_values($other_choices);
  1763. // return Result::success($result);
  1764. }
  1765. } else {
  1766. $value_choice = $choose;
  1767. }
  1768. $result = [
  1769. 'choose' => $value_choice,
  1770. 'total' => $total,
  1771. ];
  1772. }
  1773. return Result::success($result);
  1774. }
  1775. /**
  1776. * 前端-搜索新闻列表
  1777. * @param array $data
  1778. * @return array
  1779. */
  1780. public function selectWebsiteArticle(array $data): array
  1781. {
  1782. $website = Website::where('id', $data['website_id'])->first();
  1783. if (empty($website)) {
  1784. return Result::error("网站不存在", 0);
  1785. }
  1786. // $website_column = $website['column'];
  1787. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1788. $website_column = json_decode($website['website_column_arr_id'], true);
  1789. }
  1790. $website_id = $data['website_id'];
  1791. $categorys = $this->processArticlePro($website_id);
  1792. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1793. // return Result::success($diff_pid_categoryIds);
  1794. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1795. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1796. }
  1797. // return Result::success(reset($diff_pid_categoryIds) == 0);
  1798. // $cat_1st_arr = $categorys['cat_1st_arr'];
  1799. $catiall = $categorys['catiall'];
  1800. $categoryIds = $categorys['categoryIds'];
  1801. // return Result::success($categoryIds);
  1802. $query = Article::where('status', 1)
  1803. ->whereIn('catid', $categoryIds)
  1804. ->leftJoinSub(function ($query) use ($website_id) {
  1805. $query->from('article_ignore')
  1806. ->where('website_id', $website_id);
  1807. }, 'article_ignore', function ($join) {
  1808. $join->on('article_ignore.article_id', '=', 'article.id');
  1809. })
  1810. ->where(function ($query) {
  1811. $query->whereNull('article_ignore.article_id')
  1812. ->orWhere(function ($subQuery) {
  1813. $subQuery->whereNotNull('article_ignore.article_id')
  1814. ->where('article_ignore.is_ignore', 0)
  1815. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  1816. });
  1817. });
  1818. // ->get()->all();
  1819. // return Result::success($query);
  1820. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1821. $query->whereRaw("JSON_CONTAINS(article.city_arr_id, '" . intval($data['cityid']) . "')");
  1822. }
  1823. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1824. $query->whereRaw("JSON_CONTAINS(article.department_arr_id, '" . intval($data['department_id']) . "')");
  1825. }
  1826. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1827. $query->where('article.title', 'like', '%' . $data['keyword'] . '%');
  1828. }
  1829. // 计算总数
  1830. $count = $query->count();
  1831. // return Result::success($count);
  1832. // 分页查询
  1833. $articles = $query
  1834. ->select(
  1835. 'article.id',
  1836. 'article.title',
  1837. 'article.imgurl',
  1838. 'article.author',
  1839. 'article.updated_at',
  1840. 'article.introduce',
  1841. 'article.islink',
  1842. 'article.linkurl',
  1843. 'article.copyfrom',
  1844. 'article.cat_arr_id',
  1845. 'article.catid',
  1846. 'article.department_arr_id',
  1847. 'article.city_arr_id',
  1848. // 'article_ignore.c_show_time',
  1849. // 'article_ignore.is_ignore'
  1850. )
  1851. ->orderBy("updated_at", "desc")
  1852. ->offset(($data['page'] - 1) * $data['pageSize'])
  1853. ->limit($data['pageSize'])
  1854. ->get();
  1855. // return Result::success($articles);
  1856. foreach ($articles as $k => $v) {
  1857. $articles[$k]->category_name = $catiall[$v->catid]['alias'];
  1858. $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1859. }
  1860. if (empty($articles)) {
  1861. return Result::error("没有符合条件的资讯数据");
  1862. }
  1863. $result = [
  1864. 'rows' => $articles,
  1865. 'count' => $count,
  1866. ];
  1867. return Result::success($result);
  1868. }
  1869. /**
  1870. * 模块新闻加强版
  1871. * @param array $data
  1872. * @return array
  1873. */
  1874. public function getWebsiteCatidArticle(array $data): array
  1875. {
  1876. $where = [
  1877. 'website_category.category_id' => $data['catid'],
  1878. 'website_category.website_id' => $data['website_id'],
  1879. ];
  1880. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  1881. $child_catnum = $data['child_catnum'] ?? 1;
  1882. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  1883. $childCategoryIds = array_column($category['child'], 'category_id');
  1884. if (empty($childCategoryIds)) {
  1885. return Result::error("暂无子栏目", 0);
  1886. }
  1887. $imgArticles = [];
  1888. $textArticles = [];
  1889. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  1890. // 初始化子分类图片新闻和文字新闻数组
  1891. // 查询所有子级栏目的图文新闻
  1892. $imgArticles = Article::where('catid', $childCategoryIds[0])
  1893. ->where(function ($query) use ($data) {
  1894. $query->where(function ($subQuery) use ($data) {
  1895. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1896. })->orWhereNull("ignore_ids");
  1897. })
  1898. ->where('status', 1)
  1899. ->where('imgurl', '!=', '')
  1900. ->select('*')
  1901. ->orderBy('updated_at', 'desc')
  1902. ->limit($data['child_imgnum'])
  1903. ->get();
  1904. }
  1905. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  1906. // 查询所有子级栏目的文字新闻
  1907. $textArticles = Article::where('catid', $childCategoryIds[0])
  1908. ->where('status', 1)
  1909. ->where(function ($query) use ($data) {
  1910. $query->where(function ($subQuery) use ($data) {
  1911. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1912. })->orWhereNull("ignore_ids");
  1913. })
  1914. ->select('*')
  1915. ->orderBy('updated_at', 'desc')
  1916. ->limit($data['child_textnum'])
  1917. ->get();
  1918. }
  1919. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  1920. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  1921. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  1922. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  1923. return $child;
  1924. }, $category['child']);
  1925. }
  1926. // }
  1927. if (isset($data['img_num']) && !empty($data['img_num'])) {
  1928. $category['img'] = WebsiteCategory::where($where)
  1929. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1930. ->where('article.status', 1)
  1931. ->where('article.imgurl', '!=', '')
  1932. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1933. ->orderBy('article.updated_at', 'desc')
  1934. ->limit($data['img_num'])
  1935. ->get();
  1936. }
  1937. if (isset($data['text_num']) && !empty($data['text_num'])) {
  1938. $category['text'] = WebsiteCategory::where($where)
  1939. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1940. ->where('article.status', 1)
  1941. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1942. ->orderBy('article.updated_at', 'desc')
  1943. ->limit($data['text_num'])
  1944. ->get();
  1945. }
  1946. // $category = $category->get();
  1947. if (empty($category)) {
  1948. return Result::error("查询失败", 0);
  1949. }
  1950. return Result::success($category);
  1951. }
  1952. /**
  1953. * 模块新闻加强plus版
  1954. * @param array $data
  1955. * @return array
  1956. */
  1957. public function getWebsiteAllArticle(array $data): array
  1958. {
  1959. // return Result::success($data);
  1960. $time1 = microtime(true);
  1961. $wetbsite_id = $data['website_id'] ?? 2;
  1962. $data = json_decode($data['id'], true);
  1963. $website = Website::where('id', $wetbsite_id)->first();
  1964. if (empty($website)) {
  1965. return Result::error("网站不存在", 0);
  1966. }
  1967. // return Result::success($website);
  1968. $website_column = $website['website_column_arr_id'] ?? '[]';
  1969. $website_column = json_decode($website_column, true);
  1970. $categorys = $this->processArticlePro($wetbsite_id);
  1971. $cat_1st_arr = $categorys['cat_1st_arr'];
  1972. $catiall = $categorys['catiall'];
  1973. // return Result::success($catiall);
  1974. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  1975. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1976. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1977. }
  1978. $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
  1979. // return Result::success($categorys);
  1980. $parent_category = array_column($data, 'parent');
  1981. $parent_cat = [];
  1982. $child_category = array_column($data, 'child');
  1983. if (!empty($parent_category)) {
  1984. foreach ($parent_category as $key => $value) {
  1985. $arr = array_map('intval', explode(',', $value));
  1986. $parent_cat[$key] = $arr[0] ?? 0;
  1987. $parent_category = $arr[0] ?? 0;
  1988. $article_imgnum = $arr[1] ?? 0;
  1989. $article_textnum = $arr[2] ?? 0;
  1990. if ($parent_category != 0) {
  1991. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  1992. // return Result::success($category_arr);
  1993. if ($article_imgnum != 0) {
  1994. $img_article = Article::whereIn('catid', $category_arr)
  1995. ->where('status', 1)
  1996. ->where('imgurl', '!=', '')
  1997. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1998. $query->from('article_ignore')
  1999. ->where('website_id', $wetbsite_id);
  2000. }, 'article_ignore', function ($join) {
  2001. $join->on('article_ignore.article_id', '=', 'article.id');
  2002. })
  2003. ->where(function ($query) {
  2004. $query->whereNull('article_ignore.article_id')
  2005. ->orWhere(function ($subQuery) {
  2006. $subQuery->whereNotNull('article_ignore.article_id')
  2007. ->where('article_ignore.is_ignore', 0)
  2008. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  2009. });
  2010. })
  2011. ->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')
  2012. ->orderBy('updated_at', 'desc')
  2013. ->limit($article_imgnum)
  2014. ->get()->all();
  2015. foreach ($img_article as $k => $v) {
  2016. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2017. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2018. }
  2019. } else {
  2020. $img_article = [];
  2021. }
  2022. if ($article_textnum != 0) {
  2023. $text_article = Article::whereIn('catid', $category_arr)
  2024. ->where('status', 1)
  2025. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2026. $query->from('article_ignore')
  2027. ->where('website_id', $wetbsite_id);
  2028. }, 'article_ignore', function ($join) {
  2029. $join->on('article_ignore.article_id', '=', 'article.id');
  2030. })
  2031. ->where(function ($query) {
  2032. $query->whereNull('article_ignore.article_id')
  2033. ->orWhere(function ($subQuery) {
  2034. $subQuery->whereNotNull('article_ignore.article_id')
  2035. ->where('article_ignore.is_ignore', 0)
  2036. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  2037. });
  2038. })
  2039. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2040. ->orderBy('updated_at', 'desc')
  2041. ->limit($article_textnum)
  2042. ->get()->all();
  2043. foreach ($text_article as $k => $v) {
  2044. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2045. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2046. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2047. }
  2048. } else {
  2049. $text_article = [];
  2050. }
  2051. $catiall[$parent_category]['imgnum'] = $img_article;
  2052. $catiall[$parent_category]['textnum'] = $text_article;
  2053. $parent[$key] = $catiall[$parent_category];
  2054. } else {
  2055. $parent[$key] = '';
  2056. }
  2057. }
  2058. }
  2059. if (!empty($child_category)) {
  2060. foreach ($child_category as $key => $value) {
  2061. $arr = array_map('intval', explode(',', $value));
  2062. $parent_category = $parent_cat[$key];
  2063. $child_category = $arr[0] ?? 0;
  2064. $article_imgnum = $arr[1] ?? 0;
  2065. $article_textnum = $arr[2] ?? 0;
  2066. if ($child_category != 0) {
  2067. $all_childcat = $cat_1st_arr[$parent_category];
  2068. $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
  2069. // 从 $websiteInfoIndexed 中获取对应的数据
  2070. $info = $websiteInfoIndexed[$v];
  2071. // 返回一个包含所需信息的数组
  2072. return [
  2073. 'alias' => $info->alias,
  2074. 'category_id' => $info->category_id,
  2075. 'aLIas_pinyin' => $info->aLIas_pinyin,
  2076. 'pid' => $info->pid,
  2077. 'type' => $info->type,
  2078. 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
  2079. 'pinyin' => $info->pinyin,
  2080. ];
  2081. }, $all_childcat);
  2082. if ($article_imgnum != 0) {
  2083. $img_article = Article::where('catid', $child_category)
  2084. ->where('status', 1)
  2085. ->where('imgurl', '!=', '')
  2086. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2087. $query->from('article_ignore')
  2088. ->where('website_id', $wetbsite_id);
  2089. }, 'article_ignore', function ($join) {
  2090. $join->on('article_ignore.article_id', '=', 'article.id');
  2091. })
  2092. ->where(function ($query) {
  2093. $query->whereNull('article_ignore.article_id')
  2094. ->orWhere(function ($subQuery) {
  2095. $subQuery->whereNotNull('article_ignore.article_id')
  2096. ->where('article_ignore.is_ignore', 0)
  2097. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  2098. });
  2099. })
  2100. ->select('id', 'title', 'imgurl', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2101. ->orderBy('updated_at', 'desc')
  2102. ->limit($article_imgnum)
  2103. ->get()->all();
  2104. foreach ($img_article as $k => $v) {
  2105. // var_dump($v);
  2106. // var_dump($k);
  2107. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2108. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2109. }
  2110. } else {
  2111. $img_article = [];
  2112. }
  2113. if ($article_textnum != 0) {
  2114. $text_article = Article::where('catid', $child_category)
  2115. ->where('status', 1)
  2116. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2117. $query->from('article_ignore')
  2118. ->where('website_id', $wetbsite_id);
  2119. }, 'article_ignore', function ($join) {
  2120. $join->on('article_ignore.article_id', '=', 'article.id');
  2121. })
  2122. ->where(function ($query) {
  2123. $query->whereNull('article_ignore.article_id')
  2124. ->orWhere(function ($subQuery) {
  2125. $subQuery->whereNotNull('article_ignore.article_id')
  2126. ->where('article_ignore.is_ignore', 0)
  2127. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  2128. });
  2129. })
  2130. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2131. ->orderBy('updated_at', 'desc')
  2132. ->limit($article_textnum)
  2133. ->get()->all();
  2134. foreach ($text_article as $k => $v) {
  2135. // var_dump($v);
  2136. // var_dump($k);
  2137. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2138. // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2139. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2140. }
  2141. } else {
  2142. $text_article = [];
  2143. }
  2144. $catiall[$child_category]['all_childcat'] = $processedChildCat;
  2145. $catiall[$child_category]['imgnum'] = $img_article;
  2146. $catiall[$child_category]['textnum'] = $text_article;
  2147. $child[$key] = $catiall[$child_category];
  2148. // var_dump($pids);
  2149. } else {
  2150. $child[$key] = '';
  2151. }
  2152. }
  2153. }
  2154. foreach ($parent as $key => $value) {
  2155. $result[$key] = $value;
  2156. if (!empty($child[$key])) {
  2157. // var_dump($child[$key]);
  2158. $result[$key]['child'] = $child[$key];
  2159. // $value[$key]['child'] = $child[$key];
  2160. } else {
  2161. $result[$key]['child'] = [
  2162. "alias" => null,
  2163. "category_id" => null,
  2164. "type" => null,
  2165. "pinyin" => null,
  2166. "all_childcat" => [],
  2167. "imgnum" => [],
  2168. "textnum" => []
  2169. ];
  2170. }
  2171. }
  2172. return Result::success($result);
  2173. }
  2174. /**
  2175. * 辅助方法:获取文章列表
  2176. */
  2177. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  2178. {
  2179. sleep(1);
  2180. $query = Article::where('article.status', 1)
  2181. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  2182. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  2183. ->where(function ($query) use ($website) {
  2184. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  2185. })
  2186. ->leftJoin('website_category', function ($join) use ($website) {
  2187. $join->on('article.catid', '=', 'website_category.category_id')
  2188. ->where('website_category.website_id', '=', $website['website_id']);
  2189. })
  2190. ->select(
  2191. 'article.id',
  2192. 'article.title',
  2193. 'article.imgurl',
  2194. 'article.author',
  2195. 'article.updated_at',
  2196. 'article.introduce',
  2197. 'article.islink',
  2198. 'article.linkurl',
  2199. 'article.copyfrom',
  2200. 'article.cat_arr_id',
  2201. 'article.catid',
  2202. 'website_category.alias as category_name'
  2203. )
  2204. ->orderBy('updated_at', 'desc')
  2205. ->limit($limit);
  2206. // 如果是图片文章,添加图片URL条件
  2207. if ($isImageArticle) {
  2208. $query->where('imgurl', '!=', '');
  2209. } else {
  2210. // 文字文章不需要imgurl字段
  2211. $query->addSelect('article.introduce');
  2212. }
  2213. $articles = $query->get();
  2214. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  2215. }
  2216. /**
  2217. * 乡村网-获取特殊新闻模块
  2218. * @param array $data
  2219. * @return array
  2220. */
  2221. public function getWebsiteArticles(array $data): array
  2222. {
  2223. $website_id = $data['website_id'];
  2224. $website = Website::where('id', $website_id)->first();
  2225. if (empty($website)) {
  2226. return Result::error("网站不存在", 0);
  2227. }
  2228. // return Result::success($website);
  2229. $website_column = $website['website_column_arr_id'] ?? '[]';
  2230. $website_column = json_decode($website_column, true);
  2231. $catids = json_decode($data['id'], true);
  2232. $parent_category = array_column($catids, 'parent');
  2233. if (!empty($parent_category) && is_array($parent_category)) {
  2234. $categorys = $this->processArticlePro($website_id);
  2235. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  2236. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2237. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2238. }
  2239. $catiall = $categorys['catiall'];
  2240. $cat_1st_arr = $categorys['cat_1st_arr'];
  2241. // return Result::success($categorys);
  2242. foreach ($parent_category as $key => $value) {
  2243. $arr = array_map('intval', explode(',', $value));
  2244. $parent_category = $arr[0] ?? 0;
  2245. $article_imgnum = $arr[1] ?? 0;
  2246. $article_textnum = $arr[2] ?? 0;
  2247. if ($parent_category != 0) {
  2248. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2249. // return Result::success($category_arr);
  2250. if ($article_imgnum != 0) {
  2251. $img_article = Article::whereIn('article.catid', $category_arr)
  2252. ->where('article.status', 1)
  2253. ->where('article.imgurl', '!=', '')
  2254. ->leftJoinSub(function ($query) use ($website_id) {
  2255. $query->from('article_ignore')
  2256. ->where('website_id', $website_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('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  2266. });
  2267. })
  2268. ->select(
  2269. 'article.id',
  2270. 'article.title',
  2271. 'article.imgurl',
  2272. 'article.author',
  2273. 'article.updated_at',
  2274. 'article.introduce',
  2275. 'article.islink',
  2276. 'article.linkurl',
  2277. 'article.copyfrom',
  2278. 'article.cat_arr_id',
  2279. 'article.catid as category_id'
  2280. )
  2281. ->orderBy('updated_at', 'desc')
  2282. ->limit($article_imgnum)
  2283. ->get()->all();
  2284. foreach ($img_article as $k => $v) {
  2285. $img_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2286. // return Result::success($v);
  2287. $img_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2288. }
  2289. } else {
  2290. $img_article = [];
  2291. }
  2292. if ($article_textnum != 0) {
  2293. $text_article = Article::whereIn('article.catid', $category_arr)
  2294. ->where('article.status', 1)
  2295. ->leftJoinSub(function ($query) use ($website_id) {
  2296. $query->from('article_ignore')
  2297. ->where('website_id', $website_id);
  2298. }, 'article_ignore', function ($join) {
  2299. $join->on('article_ignore.article_id', '=', 'article.id');
  2300. })
  2301. ->where(function ($query) {
  2302. $query->whereNull('article_ignore.article_id')
  2303. ->orWhere(function ($subQuery) {
  2304. $subQuery->whereNotNull('article_ignore.article_id')
  2305. ->where('article_ignore.is_ignore', 0)
  2306. ->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'));
  2307. });
  2308. })
  2309. ->select(
  2310. 'article.id',
  2311. 'article.title',
  2312. 'article.author',
  2313. 'article.updated_at',
  2314. 'article.introduce',
  2315. 'article.islink',
  2316. 'article.linkurl',
  2317. 'article.copyfrom',
  2318. 'article.cat_arr_id',
  2319. 'article.catid as category_id'
  2320. )
  2321. ->orderBy('updated_at', 'desc')
  2322. ->limit($article_textnum)
  2323. ->get()->all();
  2324. foreach ($text_article as $k => $v) {
  2325. $text_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2326. $text_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2327. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2328. }
  2329. } else {
  2330. $text_article = [];
  2331. }
  2332. $catiall[$parent_category]['imgnum'] = $img_article ?? [];
  2333. $catiall[$parent_category]['textnum'] = $text_article ?? [];
  2334. $parent[$key] = $catiall[$parent_category];
  2335. } else {
  2336. $parent[$key] = [];
  2337. }
  2338. }
  2339. }
  2340. return Result::success($parent);
  2341. }
  2342. // 封装处理商品的路由问题
  2343. function processGoods($goods, $data)
  2344. {
  2345. return $goods->map(function ($good) use ($data) {
  2346. $catid = $good->catid ?? 0;
  2347. // $pinyin = '';
  2348. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2349. if (!empty($category->pid) && $category->pid != 0) {
  2350. $level = json_decode($category->category_arr_id, true);
  2351. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  2352. ->whereIn('category_id', $level)
  2353. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2354. ->get(['aLIas_pinyin'])
  2355. ->pluck('aLIas_pinyin')
  2356. ->implode('/');
  2357. } else {
  2358. $pinyin = $category->aLIas_pinyin ?? '';
  2359. }
  2360. if (isset($good->city_id) && !empty($good->city_id)) {
  2361. $city = District::where('id', $good->city_id)->first(['name']);
  2362. $good->city_name = $city->name ?? '';
  2363. }
  2364. // 解析imgurl JSON并取第一条数据
  2365. $imgUrls = json_decode($good->imgurl, true);
  2366. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  2367. $good->pinyin = $pinyin;
  2368. return $good;
  2369. });
  2370. }
  2371. /**
  2372. * 获取商城首页-根据栏目id
  2373. * @param array $data
  2374. * @return array
  2375. * */
  2376. function getWebsiteCatidshop(array $data): array
  2377. {
  2378. $input['catid'] = $data['catid'];
  2379. $input['website_id'] = $data['website_id'];
  2380. $data = json_decode($input['catid'] ?? '', true) ?? [];
  2381. $result = array_map(function ($item) use ($input) {
  2382. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  2383. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  2384. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  2385. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  2386. if (empty($category) || $category->type != 2) {
  2387. return Result::error("暂无此栏目", 0);
  2388. } else {
  2389. $website['website_id'] = $input['website_id'];
  2390. $goods = Good::where('good.status', 2)
  2391. ->where('good.website_id', $website['website_id'])
  2392. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  2393. ->select(
  2394. 'good.id',
  2395. 'good.name',
  2396. 'good.imgurl',
  2397. 'good.description',
  2398. 'good.updated_at',
  2399. 'good.catid',
  2400. 'good.type_id',
  2401. 'good.price',
  2402. 'good.com',
  2403. 'good.level',
  2404. 'good.unit'
  2405. )
  2406. ->orderBy('updated_at', 'desc')
  2407. ->offset($goodStart)
  2408. ->limit($goodNum);
  2409. $all_goods = $goods->get();
  2410. $all_goods = $this->processGoods($all_goods, $website);
  2411. }
  2412. return $all_goods ?? [];
  2413. }
  2414. }, $data);
  2415. return Result::success($result);
  2416. }
  2417. /**
  2418. * 获取商品模块
  2419. * @param array $data
  2420. * @return array
  2421. * */
  2422. public function getWebsiteshop(array $data): array
  2423. {
  2424. $input['id'] = $data['id'];
  2425. $input['website_id'] = $data['website_id'];
  2426. $catid = $data['catid'];
  2427. $data = json_decode($input['id'] ?? '', true) ?? [];
  2428. $result['goods'] = array_map(function ($item) use ($input) {
  2429. // 检查parent元素是否存在且不是undefined
  2430. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  2431. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  2432. $website = $input['website_id'];
  2433. $query = Good::where('good.status', 2)
  2434. ->where('good.website_id', $website);
  2435. switch ($Levelid) {
  2436. case 1:
  2437. case 2:
  2438. case 3:
  2439. $goods = $query->where(function ($q) use ($Levelid) {
  2440. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  2441. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  2442. });
  2443. break;
  2444. case 4:
  2445. $goods = $query;
  2446. break;
  2447. case 5:
  2448. $goods = $query->where('type_id', 1);
  2449. break;
  2450. case 6:
  2451. $goods = $query->where('type_id', 2);
  2452. break;
  2453. default:
  2454. return [];
  2455. }
  2456. $all_goods = $goods
  2457. ->select(
  2458. 'good.id',
  2459. 'good.name',
  2460. 'good.imgurl',
  2461. 'good.description',
  2462. 'good.updated_at',
  2463. 'good.catid',
  2464. 'good.type_id',
  2465. 'good.price',
  2466. 'good.level',
  2467. 'good.website_id'
  2468. )
  2469. ->orderBy('updated_at', 'desc')
  2470. ->offset($goodStart)
  2471. ->limit($goodNum)
  2472. ->get();
  2473. $web['website_id'] = $website;
  2474. $all_goods = $this->processGoods($all_goods, $web);
  2475. }
  2476. return $all_goods;
  2477. }, $data);
  2478. $website = $input['website_id'];
  2479. $result['article'] = Article::where(function ($query) use ($website) {
  2480. $query->where(function ($subQuery) use ($website) {
  2481. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  2482. })->orWhereNull("ignore_ids");
  2483. })
  2484. ->where('catid', $catid)
  2485. ->where('article.status', 1)
  2486. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  2487. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  2488. ->orderBy('article.updated_at', 'desc')
  2489. ->first();
  2490. return Result::success($result);
  2491. }
  2492. /**
  2493. * 获取商品分类
  2494. * @param array $data
  2495. * @return array
  2496. * */
  2497. public function getWebsiteshopCat(array $data): array
  2498. {
  2499. $website = $data['website_id'];
  2500. $category = WebsiteCategory::where('website_id', $website)
  2501. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  2502. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  2503. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  2504. ->orderBy('sort')
  2505. ->get();
  2506. $cat = $category->map(function ($item) use ($website) {
  2507. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  2508. $pid = $item->pid ?? 0;
  2509. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  2510. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  2511. ->where('website_id', $website)
  2512. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  2513. ->get(['aLIas_pinyin'])
  2514. ->pluck('aLIas_pinyin')
  2515. ->implode('/');
  2516. } else {
  2517. $pinyin = $item->aLIas_pinyin ?? '';
  2518. }
  2519. $item->pinyin = $pinyin;
  2520. });
  2521. if (empty($category)) {
  2522. return Result::error("栏目查询失败", 0);
  2523. }
  2524. $cat_tree = Result::buildMenuTree($category);
  2525. $web['website_id'] = $website;
  2526. $goods = Good::where('website_id', $website)
  2527. ->where('status', 2)
  2528. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  2529. ->latest('updated_at')
  2530. ->offset(($data['page'] - 1) * $data['pageSize'])
  2531. ->limit($data['pageSize'])
  2532. ->get();
  2533. if (!empty($goods)) {
  2534. if ($goods->count() > 1 && !empty($goods)) {
  2535. $goods = $this->processGoods($goods, $web);
  2536. }
  2537. } else {
  2538. $goods = [];
  2539. }
  2540. $result = [
  2541. 'category' => $cat_tree,
  2542. 'goods' => $goods,
  2543. ];
  2544. // $resul['goods'] = $goods;
  2545. if (empty($result)) {
  2546. return Result::error("查询失败", 0);
  2547. }
  2548. return Result::success($result);
  2549. }
  2550. /*
  2551. * 获取商品列表
  2552. * @param array $data
  2553. * @return array
  2554. * */
  2555. public function getWebsiteshopList(array $data): array
  2556. {
  2557. // return Result::success($data);
  2558. $where = [
  2559. 'status' => 2,
  2560. 'website_id' => $data['website_id'],
  2561. ];
  2562. // if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  2563. // return Result::error("查询失败", 0);
  2564. // }
  2565. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  2566. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  2567. $data['catid'] = $category->category_id ?? 0;
  2568. }
  2569. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2570. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  2571. }
  2572. if (isset($data['type_id']) && !empty($data['type_id'])) {
  2573. array_push($where, ['type_id', $data['type_id']]);
  2574. }
  2575. $query = Good::where($where)
  2576. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2577. $query->where(function ($q) use ($data) {
  2578. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  2579. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  2580. });
  2581. })
  2582. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2583. $query->where(function ($q) use ($data) {
  2584. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  2585. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  2586. });
  2587. })
  2588. ->select(
  2589. 'good.id',
  2590. 'good.name',
  2591. 'good.imgurl',
  2592. 'good.description',
  2593. 'good.updated_at',
  2594. 'good.com',
  2595. 'good.catid',
  2596. 'good.type_id',
  2597. 'good.website_id',
  2598. 'good.cat_arr_id',
  2599. 'good.created_at',
  2600. 'good.city_id'
  2601. )
  2602. ->latest('updated_at');
  2603. if (isset($data['ismix']) && $data['ismix'] == 1) {
  2604. $result['count'] = $query->clone()->count();
  2605. $result['goods'] = $this->processGoods(
  2606. $query->clone()
  2607. ->offset(($data['page'] - 1) * $data['pageSize'])
  2608. ->limit($data['pageSize'])
  2609. ->get(),
  2610. $data
  2611. );
  2612. } else {
  2613. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  2614. // 获取 type_id 为 1 的数据
  2615. $result['type1'] = $this->processGoods(
  2616. $query->clone()
  2617. ->where('type_id', 1)
  2618. ->offset(($data['page'] - 1) * $data['pageSize'])
  2619. ->limit($data['pageSize'])
  2620. ->get(),
  2621. $data
  2622. );
  2623. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2624. // 获取 type_id 为 2 的数据
  2625. $result['type2'] = $this->processGoods(
  2626. $query->clone()
  2627. ->where('type_id', 2)
  2628. ->offset(($data['page'] - 1) * $data['pageSize'])
  2629. ->limit($data['pageSize'])
  2630. ->get(),
  2631. $data
  2632. );
  2633. }
  2634. if (empty($result)) {
  2635. return Result::error("查询失败", 0);
  2636. }
  2637. return Result::success($result);
  2638. }
  2639. /**
  2640. * 获取商品详情
  2641. * @param array $data
  2642. * @return array
  2643. * */
  2644. public function getWebsiteshopInfo(array $data): array
  2645. {
  2646. $where = [
  2647. 'good.status' => 2,
  2648. 'good.website_id' => $data['website_id'],
  2649. 'good.id' => $data['id'],
  2650. ];
  2651. $goods = Good::where($where)
  2652. ->where('good.id', $data['id'])
  2653. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2654. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2655. ->first();
  2656. if (empty($goods)) {
  2657. return Result::error("查询失败", 0);
  2658. }
  2659. $goods->imgurl = json_decode($goods->imgurl, true);
  2660. return Result::success($goods);
  2661. }
  2662. /**
  2663. * plus pro 处理文章路由问题
  2664. */
  2665. function processArticlePro($website_id)
  2666. {
  2667. // $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2668. // // $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2669. // // 取出category_id 对应的aLIas_pinyin
  2670. // $categoryIds = array_column($categorys, 'category_id');
  2671. // $categoryPIds = array_column($categorys, 'pid');
  2672. // $aliasPinyins = array_column($categorys, 'path');
  2673. // $alias = array_column($categorys, 'alias');
  2674. // $cat_arr = array_combine($categoryIds, $aliasPinyins);
  2675. // $cat_alias_arr = array_combine($categoryIds, $categoryPIds);
  2676. // // return Result::success($cat_arr);
  2677. // // $catiall = [];
  2678. // //一级所有子级的记录
  2679. // $cat_alias_arr = array_combine($categoryIds, $alias);
  2680. // return [
  2681. // 'cat_1st_arr' => $cat_alias_arr,
  2682. // 'catiall' => $cat_arr,
  2683. // // 'websiteInfoIndexed' => $websiteInfoIndexed,
  2684. // 'categoryIds' => $categoryIds,
  2685. // ];
  2686. $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2687. $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2688. // 取出category_id 对应的aLIas_pinyin
  2689. $categoryIds = array_column($categorys, 'category_id');
  2690. $categoryPIds = array_values(array_unique(array_filter(array_column($categorys, 'pid'), function ($pid) {
  2691. return $pid != 0;
  2692. })));
  2693. $category_path = array_column($categorys, 'path');
  2694. $cat_arr = array_combine($categoryIds, $category_path);
  2695. // return Result::success(array_diff($categoryIds, $categoryPIds));
  2696. $catiall = [];
  2697. //一级所有子级的记录
  2698. $cat_1st_arr = [];
  2699. foreach ($categorys as $key => $value) {
  2700. // $category_arr_id = json_decode($value->category_arr_id);
  2701. // $pinyin_str = '';
  2702. // // 算出一级 并且算出子级
  2703. if ($value->pid != 0 && in_array($value->pid, $categoryIds)) {
  2704. $cat_1st_arr[$value->pid][] = $value->category_id;
  2705. }
  2706. // foreach ($category_arr_id as $k => $v) {
  2707. // $pinyin_str .= $cat_arr[$v] . '/';
  2708. // }
  2709. // $pinyin_str = rtrim($pinyin_str, '/');
  2710. $catiall[$value->category_id]['alias'] = $value->alias;
  2711. $catiall[$value->category_id]['category_id'] = $value->category_id;
  2712. $catiall[$value->category_id]['type'] = $value->type;
  2713. $catiall[$value->category_id]['pinyin'] = $cat_arr[$value->category_id];
  2714. $websiteInfoIndexed[$value->category_id]->pinyin = $cat_arr[$value->category_id];
  2715. }
  2716. return [
  2717. 'cat_1st_arr' => $cat_1st_arr,
  2718. 'catiall' => $catiall,
  2719. 'websiteInfoIndexed' => $websiteInfoIndexed,
  2720. 'categoryIds' => $categoryIds,
  2721. 'diff_pid_categoryIds' => array_diff($categoryPIds, $categoryIds),
  2722. 'categoryPIds' => $categoryPIds,
  2723. ];
  2724. }
  2725. /**
  2726. * 封装处理文章的路由问题
  2727. * */
  2728. function processArticles($articles, $data)
  2729. {
  2730. // 检查 $articles 是否为数组或可迭代对象
  2731. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  2732. return $articles->map(function ($article) use ($data) {
  2733. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  2734. $catid = $article->cat_arr_id ?? '';
  2735. }
  2736. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  2737. $catid = $article->category_arr_id ?? '';
  2738. }
  2739. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  2740. $level = json_decode($catid, true);
  2741. if (!is_array($level)) {
  2742. return $article;
  2743. } else {
  2744. $level = array_map('intval', $level);
  2745. }
  2746. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2747. ->where($data)
  2748. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2749. ->pluck('aLIas_pinyin')
  2750. ->implode('/');
  2751. $article->pinyin = $pinyin ?? '';
  2752. return $article;
  2753. });
  2754. } else {
  2755. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2756. $catid = $articles->cat_arr_id ?? '';
  2757. $level = json_decode($catid, true);
  2758. if (!is_array($level)) {
  2759. return $articles;
  2760. } else {
  2761. $level = array_map('intval', $level);
  2762. }
  2763. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2764. ->where($data)
  2765. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2766. ->pluck('aLIas_pinyin')
  2767. ->implode('/');
  2768. $articles->pinyin = $pinyin ?? '';
  2769. return $articles;
  2770. }
  2771. }
  2772. // 封装处理由问题
  2773. function processJob($job, $data)
  2774. {
  2775. return $job->map(function ($job) use ($data) {
  2776. $category = $job->cat_arr_id ?? '';
  2777. $cityid = $job->city_arr_id ?? '';
  2778. $city = json_decode($cityid, true);
  2779. $pinyin = '';
  2780. $level = json_decode($category, true);
  2781. // 路由
  2782. if (!empty($level) && is_array($level)) {
  2783. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2784. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2785. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2786. ->get(['aLIas_pinyin'])
  2787. ->pluck('aLIas_pinyin')
  2788. ->implode('/');
  2789. if (empty($pinyin)) {
  2790. $pinyin = $pinyin->aLIas_pinyin ?? '';
  2791. }
  2792. $job->pinyin = $pinyin;
  2793. }
  2794. // 取职位-城市 市??省
  2795. if (!empty($city) && is_array($city)) {
  2796. if (isset($city[1]) && !empty($city[1])) {
  2797. $city = District::where('id', $city[1])->first(['name']);
  2798. $job->city_name = $city->name ?? '';
  2799. } else if (isset($city[0]) && !empty($city[0])) {
  2800. $city = District::where('id', $city[0])->first(['name']);
  2801. $job->city_name = $city->name ?? '';
  2802. } else {
  2803. $job->city_name = '全国';
  2804. }
  2805. }
  2806. // 获取简历最后一级地区
  2807. if (isset($job->city_id) && !empty($job->city_id)) {
  2808. $city = District::where('id', $job->city_id)->first(['name']);
  2809. $job->hunt_cityname = $city->name ?? '';
  2810. }
  2811. // 组合详细地址
  2812. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  2813. $address_id = json_decode($job->address_arr_id, true) ?? [];
  2814. if (is_array($address_id) && !empty($address_id)) {
  2815. $address = District::whereIn('id', $address_id)
  2816. ->orderBy('level', 'asc')
  2817. ->get(['name'])
  2818. ->pluck('name')
  2819. ->implode('');
  2820. // $job->address_name = $address ?? '';
  2821. $job->address_name = ($address ?? '') . ($job->address ?? '');
  2822. }
  2823. }
  2824. // 取行业
  2825. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  2826. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  2827. if (!empty($job->industry)) {
  2828. $query->where('hyid', $job->industry);
  2829. } else if (!empty($job->hy_id)) {
  2830. $query->where('hyid', $job->hy_id);
  2831. } else if (!empty($job->company_hy_id)) {
  2832. $query->where('hyid', $job->company_hy_id);
  2833. } else {
  2834. $query->where('hyid', $job->job_industry);
  2835. }
  2836. })->first(['hyname']);
  2837. $job->hy_name = $hy_name->hyname ?? '';
  2838. }
  2839. // 取职位类别
  2840. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  2841. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  2842. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  2843. $job->zw_name = $zw_name->zwname ?? '';
  2844. }
  2845. // 取具体职位
  2846. 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))) {
  2847. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  2848. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  2849. $job->jtzw_name = $jtzw_name->zwname ?? '';
  2850. }
  2851. // 取工作经验
  2852. if (isset($job->experience) && !empty($job->experience)) {
  2853. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  2854. $job->experience_name = $experience->ename ?? '';
  2855. }
  2856. // 取学历
  2857. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  2858. $education = $job->educational ?? $job->school_education;
  2859. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  2860. $job->education_name = $education->ename ?? '';
  2861. }
  2862. // 语言
  2863. if (isset($job->language) && !empty($job->language)) {
  2864. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  2865. $job->language_name = $language->ename ?? '';
  2866. }
  2867. // 薪资
  2868. if (isset($job->salary) && !empty($job->salary)) {
  2869. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  2870. $job->salary_name = $salary->ename ?? '';
  2871. }
  2872. // 职位性质
  2873. if (isset($job->nature_id) && !empty($job->nature_id)) {
  2874. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  2875. $job->job_nature_name = $job_nature->ename ?? '';
  2876. }
  2877. // 公司规模
  2878. if (isset($job->company_size) && !empty($job->company_size)) {
  2879. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  2880. $job->company_size_name = $company_size->ename ?? '';
  2881. }
  2882. // 公司性质
  2883. if (isset($job->company_nature) && !empty($job->company_nature)) {
  2884. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  2885. $job->company_nature_name = $company_nature->nature_name ?? '';
  2886. }
  2887. // $job->pinyin = $pinyin;
  2888. return $job;
  2889. });
  2890. }
  2891. /**
  2892. * 获取书籍模块
  2893. * @param array $data
  2894. * @return array
  2895. * */
  2896. public function getWebsiteBook(array $data): array
  2897. {
  2898. $input['id'] = $data['id'];
  2899. $input['website_id'] = $data['website_id'];
  2900. // 将 JSON 字符串转换为 PHP 数组
  2901. $data = json_decode($input['id'], true);
  2902. // 使用 array_map 处理每个元素
  2903. $result = array_map(function ($item) use ($input) {
  2904. // 检查parent元素是否存在且不是undefined
  2905. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  2906. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2907. $website = [
  2908. 'website_id' => $input['website_id'],
  2909. ];
  2910. // 查询栏目名称
  2911. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2912. if (empty($category)) {
  2913. $parent_alias = '';
  2914. $parent_pinyin = null;
  2915. $imgBooks = [];
  2916. $textBooks = [];
  2917. } else {
  2918. $parent_alias = $category->alias ?? '';
  2919. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  2920. // 查找子分类ID数组
  2921. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  2922. array_push($childCategoryIds, $parentCatId);
  2923. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  2924. if ($parentImgNum != 0) {
  2925. // 查询图片新闻
  2926. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  2927. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2928. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2929. })
  2930. ->where('book.status', 2)
  2931. ->where('book.img_url', '!=', '')
  2932. ->where('book.website_id', $website['website_id'])
  2933. ->leftJoin('website_category', function ($join) use ($website) {
  2934. $join->on('book.cat_id', '=', 'website_category.category_id')
  2935. ->where('website_category.website_id', '=', $website['website_id']);
  2936. })
  2937. ->select(
  2938. 'book.id',
  2939. 'book.title',
  2940. 'book.img_url',
  2941. 'book.price',
  2942. 'book.market_price',
  2943. 'book.description',
  2944. 'book.cat_id',
  2945. 'book.description',
  2946. 'book.updated_at',
  2947. 'website_category.alias as category_name',
  2948. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2949. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2950. )
  2951. ->orderBy('updated_at', 'desc')
  2952. ->limit($parentImgNum)
  2953. ->get()->all();
  2954. // 查询文字新闻
  2955. }
  2956. if ($parentTextNum != 0) {
  2957. $textBooks = [];
  2958. $textBooks = Book::where(function ($query) use ($parentCatId) {
  2959. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2960. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2961. })
  2962. ->where('book.status', 2)
  2963. ->where('book.website_id', $website['website_id'])
  2964. ->leftJoin('website_category', function ($join) use ($website) {
  2965. $join->on('book.cat_id', '=', 'website_category.category_id')
  2966. ->where('website_category.website_id', '=', $website['website_id']);
  2967. })
  2968. ->select(
  2969. 'book.id',
  2970. 'book.title',
  2971. 'book.img_url',
  2972. 'book.price',
  2973. 'book.market_price',
  2974. 'book.description',
  2975. 'book.cat_id',
  2976. 'book.description',
  2977. 'book.updated_at',
  2978. 'website_category.alias as category_name',
  2979. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2980. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2981. )
  2982. ->orderBy('updated_at', 'desc')
  2983. ->limit($parentTextNum)
  2984. ->get()->all();
  2985. }
  2986. }
  2987. }
  2988. $resultItem = [
  2989. 'alias' => $parent_alias ?? '',
  2990. 'category_id' => $parentCatId ?? 0,
  2991. 'pinyin' => $parent_pinyin ?? null,
  2992. 'imgnum' => $imgBooks ?? [],
  2993. 'textnum' => $textBooks ?? [],
  2994. ];
  2995. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  2996. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  2997. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  2998. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2999. ->get()->all();
  3000. if (!empty($childCategory)) {
  3001. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  3002. // 查询子栏目名称
  3003. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  3004. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3005. ->first();
  3006. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  3007. $childImgArticles = [];
  3008. $childTextArticles = [];
  3009. $resultItem['child'] = [];
  3010. } else {
  3011. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  3012. // 查询子栏目图片新闻
  3013. $childImgArticles = Book::where('cat_id', $childCatId)
  3014. ->where('status', 2)
  3015. ->where('img_url', '!=', '')
  3016. ->where('book.website_id', $website['website_id'])
  3017. ->leftJoin('website_category', function ($join) use ($website) {
  3018. $join->on('book.cat_id', '=', 'website_category.category_id')
  3019. ->where('website_category.website_id', '=', $website['website_id']);
  3020. })
  3021. ->select(
  3022. 'book.id',
  3023. 'book.title',
  3024. 'book.img_url',
  3025. 'book.price',
  3026. 'book.market_price',
  3027. 'book.description',
  3028. 'book.cat_id',
  3029. 'book.description',
  3030. 'book.updated_at',
  3031. DB::raw("'$child_pinyin' as pinyin")
  3032. )
  3033. ->orderBy('updated_at', 'desc')
  3034. ->limit($childImgNum)
  3035. ->get()->all();
  3036. // 查询子栏目文字新闻
  3037. $childTextArticles = Book::where('cat_id', $childCatId)
  3038. ->where('status', 2)
  3039. ->where('book.website_id', $website['website_id'])
  3040. ->leftJoin('website_category', function ($join) use ($website) {
  3041. $join->on('book.cat_id', '=', 'website_category.category_id')
  3042. ->where('website_category.website_id', '=', $website['website_id']);
  3043. })
  3044. ->select(
  3045. 'book.id',
  3046. 'book.title',
  3047. 'book.img_url',
  3048. 'book.price',
  3049. 'book.market_price',
  3050. 'book.description',
  3051. 'book.cat_id',
  3052. 'book.description',
  3053. 'book.updated_at',
  3054. DB::raw("'$child_pinyin' as pinyin")
  3055. )
  3056. ->orderBy('updated_at', 'desc')
  3057. ->limit($childTextNum)
  3058. ->get()->all();
  3059. $resultItem['child'] = [
  3060. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  3061. 'category_id' => $childCatId,
  3062. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  3063. 'all_childcat' => $childCategory,
  3064. 'imgnum' => $childImgArticles,
  3065. 'textnum' => $childTextArticles,
  3066. ];
  3067. }
  3068. }
  3069. } else {
  3070. $resultItem['child'] = [];
  3071. }
  3072. return $resultItem;
  3073. }, $data);
  3074. return Result::success($result);
  3075. }
  3076. /**
  3077. * 获取书刊列表
  3078. * @param array $data
  3079. * @return array
  3080. * */
  3081. public function getWebsiteBookList(array $data): array
  3082. {
  3083. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3084. if (empty($web)) {
  3085. return Result::error("查询失败", 0);
  3086. }
  3087. $catid = $data['id'];
  3088. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  3089. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  3090. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  3091. $category_pinyin = $category ? $category->aLias_pinyin : '';
  3092. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  3093. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  3094. ->where('pid', $category['pid'])
  3095. ->select(
  3096. 'category_id',
  3097. 'alias',
  3098. 'aLIas_pinyin',
  3099. 'pid',
  3100. 'sort',
  3101. 'is_url',
  3102. 'web_url',
  3103. 'seo_title',
  3104. 'seo_keywords',
  3105. 'seo_description',
  3106. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  3107. )
  3108. ->orderBy('sort')
  3109. ->get()->all();
  3110. if (empty($category)) {
  3111. return Result::error("查询失败", 0);
  3112. }
  3113. $query = Book::where('book.status', 2)
  3114. ->where('book.website_id', $data['website_id'])
  3115. ->where('book.cat_id', $catid)
  3116. ->select(
  3117. 'book.id',
  3118. 'book.title',
  3119. 'book.img_url',
  3120. 'book.description',
  3121. 'book.updated_at',
  3122. 'book.cat_id',
  3123. DB::raw("'$pinyin' as pinyin")
  3124. )
  3125. ->orderBy('book.updated_at', 'desc');
  3126. $count = $query->count();
  3127. $query = clone $query;
  3128. $Book = $query
  3129. ->limit($data['pageSize'])
  3130. ->offset(($data['page'] - 1) * $data['pageSize'])
  3131. ->get()->all();
  3132. $result = [
  3133. 'category' => $categorys,
  3134. 'books' => $Book,
  3135. 'count' => $count,
  3136. ];
  3137. // if(empty($result)){
  3138. // return Result::error("查询失败", 0);
  3139. // }
  3140. return Result::success($result);
  3141. }
  3142. /**
  3143. * 获取书刊详情
  3144. * @param array $data
  3145. * @return array
  3146. * */
  3147. public function getWebsiteBookInfo(array $data): array
  3148. {
  3149. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3150. if (empty($web)) {
  3151. return Result::error("查询失败", 0);
  3152. }
  3153. $book = Book::where('status', 2)
  3154. ->where('website_id', $data['website_id'])
  3155. ->where('id', $data['id'])
  3156. ->select(
  3157. 'book.*',
  3158. )
  3159. ->orderBy('updated_at', 'desc')
  3160. ->first();
  3161. if (empty($book)) {
  3162. return Result::error("查询失败", 0);
  3163. }
  3164. // 先查询当前分类的 pid
  3165. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  3166. ->where('category_id', $book['cat_id'])
  3167. ->first(['pid', 'category_id']);
  3168. $query = WebsiteCategory::where('website_id', $data['website_id']);
  3169. if (!empty($carpid)) {
  3170. if ($carpid->pid != 0) {
  3171. $pid = $carpid['pid'];
  3172. // $parent_pinyin = '';
  3173. } else {
  3174. $pid = $carpid['category_id'];
  3175. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  3176. }
  3177. }
  3178. $categorys = $query->where('pid', $pid)
  3179. ->select(
  3180. 'category_id',
  3181. 'alias',
  3182. 'aLIas_pinyin',
  3183. 'pid',
  3184. 'sort',
  3185. 'is_url',
  3186. 'web_url',
  3187. 'category_arr_id as cat_arr_id',
  3188. )
  3189. ->orderBy('sort')
  3190. ->get();
  3191. $category = $this->processArticle($categorys, $data);
  3192. $result = [
  3193. 'category' => $category,
  3194. 'books' => $book,
  3195. ];
  3196. return Result::success($result);
  3197. }
  3198. /**
  3199. * 尝试
  3200. * @param array $data
  3201. * @return array
  3202. * */
  3203. public function test(array $data): array
  3204. {
  3205. $input['id'] = $data['id'];
  3206. $input['website_id'] = $data['website_id'];
  3207. // 将 JSON 字符串转换为 PHP 数组
  3208. $data = json_decode($input['id'], true);
  3209. $result = [];
  3210. $article = $data;
  3211. $result = array_map(function ($item) use ($input) {
  3212. $website = [
  3213. 'website_id' => $input['website_id'],
  3214. ];
  3215. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  3216. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  3217. $parent = [
  3218. 0 => $category['category_id'] ?? [],
  3219. 1 => $parentImgNum ?? [],
  3220. 2 => $parentTextNum ?? [],
  3221. ];
  3222. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  3223. $child = [];
  3224. $resultItem = [
  3225. // 'alias' => $parent_alias ?? '',
  3226. 'category_id' => $parentCatId ?? 0,
  3227. 'pinyin' => $parentImgNum ?? null,
  3228. 'imgnum' => $parentTextNum ?? [],
  3229. // 'textnum' => $textArticles ?? [],
  3230. ];
  3231. return $parent;
  3232. }, $data);
  3233. return Result::success($result);
  3234. // });
  3235. }
  3236. /**
  3237. * 封装处理文章的路由问题
  3238. * */
  3239. function processArticle($article, $data)
  3240. {
  3241. return $article->map(function ($article) use ($data) {
  3242. $catid = $article->cat_arr_id ?? '';
  3243. $level = json_decode($catid, true);
  3244. $pinyin = '';
  3245. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  3246. if (!empty($level) && is_array($level)) {
  3247. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  3248. ->where('website_id', $data['website_id'])
  3249. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  3250. ->get(['aLIas_pinyin'])
  3251. ->pluck('aLIas_pinyin')
  3252. ->implode('/');
  3253. } else {
  3254. $pinyin = '';
  3255. }
  3256. $article->pinyin = $pinyin;
  3257. return $article;
  3258. });
  3259. }
  3260. /**
  3261. * c端-获取招工招聘下拉选框
  3262. * @param array $data
  3263. * @return array
  3264. * */
  3265. public function getWebsiteJobSelect(array $data): array
  3266. {
  3267. $web = Website::where('id', $data['website_id'])->first();
  3268. if (empty($web)) {
  3269. return Result::error("该网站不存在", 0);
  3270. }
  3271. $hy = JobIndustry::get()->all();
  3272. $zw = JobPosition::where('zwpid', 0)->get()->all();
  3273. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  3274. $result = [
  3275. 'hy' => $hy,
  3276. 'zw' => $zw,
  3277. 'jtzw' => $jtzw,
  3278. ];
  3279. if (empty($result)) {
  3280. return Result::error("查询失败", 0);
  3281. }
  3282. return Result::success($result);
  3283. }
  3284. /**
  3285. * c端-获取招工招聘
  3286. * @param array $data
  3287. * @return array
  3288. * */
  3289. public function getWebsiteJob(array $data): array
  3290. {
  3291. $web = Website::where('id', $data['website_id'])->first();
  3292. if (empty($web)) {
  3293. return Result::error("该网站不存在", 0);
  3294. }
  3295. $job_hunting = JobHunting::where('job_hunting.status', 2)
  3296. ->where('job_hunting.website_id', $data['website_id'])
  3297. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3298. $query->where(function ($q) use ($data) {
  3299. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3300. });
  3301. })
  3302. ->select(
  3303. 'job_hunting.id',
  3304. 'job_hunting.catid',
  3305. 'job_hunting.cat_arr_id',
  3306. 'job_hunting.job_name_get',
  3307. 'job_hunting.industry',
  3308. 'job_hunting.name',
  3309. 'job_hunting.sexy',
  3310. 'job_hunting.origin',
  3311. 'job_hunting.city_arr_id',
  3312. 'job_hunting.experience',
  3313. 'job_hunting.updated_at',
  3314. 'job_hunting.salary',
  3315. 'job_hunting.skillList',
  3316. 'job_hunting.slelf_evaluation',
  3317. )
  3318. ->orderBy('updated_at', 'desc')
  3319. ->limit($data['job1_num'])
  3320. ->get();
  3321. $web['website_id'] = $data['website_id'];
  3322. if (empty($job_hunting)) {
  3323. $job_huntings = "未查询到相关简历信息";
  3324. } else {
  3325. $job_huntings = $this->processJob($job_hunting, $web);
  3326. }
  3327. // 0:待审核 1:已通过 2:已拒绝
  3328. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3329. ->where('job_recruiting.website_id', $data['website_id'])
  3330. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3331. $query->where(function ($q) use ($data) {
  3332. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3333. });
  3334. })
  3335. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3336. ->select(
  3337. 'job_recruiting.id',
  3338. 'job_recruiting.catid',
  3339. 'job_recruiting.cat_arr_id',
  3340. 'job_recruiting.title',
  3341. 'job_recruiting.jtzw_id',
  3342. 'job_recruiting.hy_id',
  3343. 'job_recruiting.city_arr_id',
  3344. 'job_recruiting.due_data',
  3345. 'job_recruiting.updated_at',
  3346. 'job_recruiting.experience',
  3347. 'job_recruiting.educational',
  3348. 'job_recruiting.salary',
  3349. 'job_recruiting.zw_id',
  3350. 'job_company.business_name',
  3351. 'job_recruiting.keyword',
  3352. 'job_recruiting.description',
  3353. )
  3354. ->orderBy('updated_at', 'desc')
  3355. ->limit($data['job2_num'])
  3356. ->get();
  3357. if (empty($job_recruiting->toArray())) {
  3358. $job_recruitings = "未查询到相关职位信息";
  3359. } else {
  3360. $job_recruitings = $this->processJob($job_recruiting, $web);
  3361. }
  3362. $result = [
  3363. 'job_hunting' => $job_huntings,
  3364. 'job_recuiting' => $job_recruitings,
  3365. ];
  3366. return Result::success($result);
  3367. }
  3368. /**
  3369. * c端-获取招工招聘列表
  3370. * @param array $data
  3371. * @return array
  3372. * */
  3373. public function getWebsiteJobList(array $data): array
  3374. {
  3375. $recruit_where = [];
  3376. $hunt_where = [];
  3377. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3378. if (empty($web)) {
  3379. return Result::error("此网站不存在", 0);
  3380. }
  3381. $website_id['website_id'] = $data['website_id'];
  3382. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  3383. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3384. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  3385. }
  3386. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3387. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  3388. }
  3389. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3390. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  3391. }
  3392. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3393. array_push($recruit_where, ['title', 'like', '%' . $data['keyword'] . '%']);
  3394. }
  3395. $query = JobRecruiting::where('job_recruiting.status', 1)
  3396. ->where('job_recruiting.website_id', $data['website_id'])
  3397. ->where($recruit_where)
  3398. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3399. $query->where(function ($q) use ($data) {
  3400. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3401. });
  3402. })
  3403. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  3404. $query->where(function ($q) use ($data) {
  3405. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  3406. });
  3407. })
  3408. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3409. ->select(
  3410. 'job_recruiting.id',
  3411. 'job_recruiting.catid',
  3412. 'job_recruiting.hy_id',
  3413. 'job_recruiting.title',
  3414. 'job_recruiting.zw_id',
  3415. 'job_recruiting.educational',
  3416. 'job_recruiting.jtzw_id',
  3417. 'job_recruiting.city_arr_id',
  3418. 'job_recruiting.due_data',
  3419. 'job_recruiting.experience',
  3420. 'job_recruiting.cat_arr_id',
  3421. 'job_recruiting.updated_at',
  3422. 'job_company.business_name',
  3423. 'job_recruiting.keyword',
  3424. 'job_recruiting.description',
  3425. )
  3426. ->orderBy('job_recruiting.updated_at', 'desc');
  3427. $recruit_count = $query->count();
  3428. $query = clone $query;
  3429. $JobRecruiting = $query
  3430. ->offset(($data['page'] - 1) * $data['pageSize'])
  3431. ->limit($data['pageSize'])
  3432. ->get();
  3433. if (empty($JobRecruiting)) {
  3434. $JobRecruiting = "暂无相关职位信息";
  3435. } else {
  3436. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  3437. }
  3438. }
  3439. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  3440. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3441. array_push($hunt_where, ['job_hunting.job', $data['zw_id']]);
  3442. }
  3443. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3444. array_push($hunt_where, ['job_hunting.job_name_get', $data['jtzw_id']]);
  3445. }
  3446. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3447. array_push($hunt_where, ['job_hunting.industry', $data['hy_id']]);
  3448. }
  3449. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3450. array_push($hunt_where, ['job_position.zwname', 'like', '%' . $data['keyword'] . '%']);
  3451. }
  3452. $query = JobHunting::where('job_hunting.status', 2)
  3453. ->where('job_hunting.website_id', $data['website_id'])
  3454. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3455. ->where($hunt_where)
  3456. // ->when(isset($data['keyword']) &&!empty($data['keyword']), function ($query) use ($data) {
  3457. // $query->where('job_position.zwname','like','%'.$data['keyword'].'%');
  3458. // })
  3459. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3460. $query->where(function ($q) use ($data) {
  3461. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3462. });
  3463. })
  3464. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  3465. $query->where(function ($q) use ($data) {
  3466. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  3467. });
  3468. })
  3469. ->select(
  3470. 'job_hunting.id',
  3471. 'job_hunting.catid',
  3472. 'job_hunting.sexy',
  3473. 'job_hunting.experience',
  3474. 'job_hunting.origin',
  3475. 'job_hunting.industry',
  3476. 'job_hunting.name',
  3477. 'job_hunting.job',
  3478. 'job_hunting.job_name_get',
  3479. 'job_hunting.city_arr_id',
  3480. 'job_hunting.cat_arr_id',
  3481. 'job_hunting.created_at',
  3482. 'job_hunting.updated_at',
  3483. 'job_position.zwname as job_name',
  3484. 'job_hunting.skillList',
  3485. 'job_hunting.slelf_evaluation',
  3486. )
  3487. ->orderBy('job_hunting.updated_at', 'desc');
  3488. $hunt_count = $query->count();
  3489. $query = clone $query;
  3490. $JobHunting = $query
  3491. ->offset(($data['page'] - 1) * $data['pageSize'])
  3492. ->limit($data['pageSize'])
  3493. ->get();
  3494. if (empty($JobHunting)) {
  3495. $JobRecruiting = "暂无相关简历信息";
  3496. } else {
  3497. $JobHunting = $this->processJob($JobHunting, $website_id);
  3498. }
  3499. }
  3500. $result = [
  3501. 'JobRecruiting' => $JobRecruiting ?? [],
  3502. 'recruit_count' => $recruit_count ?? 0,
  3503. 'JobHunting' => $JobHunting ?? [],
  3504. 'hunt_count' => $hunt_count ?? 0,
  3505. ];
  3506. return Result::success($result);
  3507. }
  3508. /**
  3509. * c端-获取招工招聘详情
  3510. * @param array $data
  3511. * @return array
  3512. * */
  3513. public function getWebsiteJobInfo(array $data): array
  3514. {
  3515. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3516. if (empty($web)) {
  3517. return Result::error("该网站不存在", 0);
  3518. }
  3519. $webid = [
  3520. 'website_id' => $data['website_id'],
  3521. ];
  3522. // 职位相关信息
  3523. if ($data['type'] == 1) {
  3524. $query = JobRecruiting::where('status', 1)
  3525. ->where('website_id', $data['website_id'])
  3526. ->select('*');
  3527. $job = $query->where('job_recruiting.id', $data['id'])->get();
  3528. $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();
  3529. if (!empty($company)) {
  3530. $result['company'] = $this->processJob($company, $webid);
  3531. }
  3532. $other_job = JobRecruiting::where('status', 1)
  3533. ->where('website_id', $data['website_id'])
  3534. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  3535. ->where('id', '!=', $data['id'])
  3536. ->where('user_id', '=', $job[0]['user_id'])
  3537. ->limit($data['pageSize'])
  3538. ->get();
  3539. if (!empty($other_job)) {
  3540. $result['other_job'] = $this->processJob($other_job, $webid);
  3541. }
  3542. } else {
  3543. // 简历相关信息
  3544. $job = JobHunting::where('job_hunting.status', 2)
  3545. ->where('job_hunting.website_id', $data['website_id'])
  3546. ->where('job_hunting.id', $data['id'])
  3547. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3548. ->select('job_hunting.*', 'user_name')
  3549. ->get();
  3550. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  3551. if (!empty($resume->toArray())) {
  3552. $result['resume'] = 1;
  3553. } else {
  3554. $result['resume'] = 0;
  3555. }
  3556. }
  3557. if (empty($job->toArray())) {
  3558. return Result::error("id参数错误", 0);
  3559. }
  3560. if (!empty($job[0]['job_experience'])) {
  3561. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  3562. if (!empty($job_experience)) {
  3563. // $hy = [];
  3564. foreach ($job_experience as $key => $value) {
  3565. // $id = $value['id'];
  3566. $hy[$key] = $value['job_industry'];
  3567. $zw_id[$key] = $value['job_typename'];
  3568. $jtzw_id[$key] = $value['job_name'];
  3569. }
  3570. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  3571. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  3572. // 先将关联表转换为索引数组,提高查找效率
  3573. $hyLookup = [];
  3574. foreach ($hy_table as $item) {
  3575. $hyLookup[$item['hyid']] = $item['hyname'];
  3576. }
  3577. $zwLookup = [];
  3578. foreach ($zw_table as $item) {
  3579. $zwLookup[$item['zwid']] = $item['zwname'];
  3580. }
  3581. foreach ($job_experience as $key => &$value) {
  3582. // 处理行业名称
  3583. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  3584. $value['hy_name'] = $hyLookup[$hy[$key]];
  3585. }
  3586. // 处理职位名称
  3587. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  3588. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  3589. }
  3590. // 处理具体职位名称
  3591. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  3592. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  3593. }
  3594. }
  3595. // 释放引用,防止意外修改后续代码
  3596. unset($value);
  3597. }
  3598. $result['job_experience'] = $job_experience ?? [];
  3599. }
  3600. if (!empty($job[0]['education_experience'])) {
  3601. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  3602. if (!empty($education_experience)) {
  3603. foreach ($education_experience as $key => $value) {
  3604. // $id = $value['id'];
  3605. $education[$key] = $value['school_education'];
  3606. }
  3607. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  3608. // // 先将关联表转换为索引数组,提高查找效率
  3609. $educationLookup = [];
  3610. foreach ($education_table as $item) {
  3611. $educationLookup[$item['evalue']] = $item['ename'];
  3612. }
  3613. foreach ($education_experience as $key => &$value) {
  3614. // 处理学历名称
  3615. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  3616. $value['education_name'] = $educationLookup[$education[$key]];
  3617. }
  3618. }
  3619. }
  3620. $result['education_experience'] = $job_experience ?? [];
  3621. }
  3622. $result['job'] = $this->processJob($job, $webid);
  3623. // // 返现对应的栏目
  3624. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  3625. $category = WebsiteCategory::where('website_id', $data['website_id'])
  3626. ->whereIn('category_id', $catid)
  3627. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  3628. ->orderBy('pid')->get()->all();
  3629. if (!empty($category)) {
  3630. $result['category'] = $category;
  3631. }
  3632. $result['job'] = $job;
  3633. $result['job_experience'] = $job_experience ?? [];
  3634. $result['education_experience'] = $education_experience ?? [];
  3635. if (empty($result)) {
  3636. return Result::error("参数错误", 0);
  3637. }
  3638. return Result::success($result);
  3639. }
  3640. /**
  3641. * c端-申请职位
  3642. * @param array $data
  3643. * @return array
  3644. * */
  3645. public function getWebsiteJobApply(array $data): array
  3646. {
  3647. // 首先验证网站是否存在
  3648. // return Result::success($data);
  3649. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3650. if (empty($web)) {
  3651. return Result::error("该网站不存在", 0);
  3652. }
  3653. // 验证用户是否存在且为个人会员/管理员
  3654. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3655. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3656. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  3657. return Result::error("用户不存在", 0);
  3658. }
  3659. // 去除重复元素和空元素,并保持原始顺序
  3660. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  3661. return !empty($value);
  3662. }));
  3663. // 验证职位是否存在 1:审核通过
  3664. $recruiting = JobRecruiting::where('status', 1)
  3665. ->where('website_id', $data['website_id'])
  3666. ->whereIn('id', $data['recruit_id'])
  3667. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  3668. if (empty($recruiting)) {
  3669. return Result::error("该职位不存在", 0);
  3670. }
  3671. // 简历是否存在
  3672. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  3673. if (empty($hunt_id)) {
  3674. return Result::error("该简历不存在", 0);
  3675. }
  3676. $data['hunt_id'] = $hunt_id['hunt_id'];
  3677. // // 验证是否已投递过该职位
  3678. $apply = JobApply::where('user_id', $data['user_id'])
  3679. ->where('hunt_id', $data['hunt_id'])
  3680. ->where('website_id', $data['website_id'])
  3681. ->whereIn('recruit_id', $data['recruit_id'])
  3682. ->get(['recruit_id']);
  3683. if (!empty($apply->toArray())) {
  3684. return Result::error("您已投递过该职位!");
  3685. }
  3686. $insertData = array_map(function ($recruiting) use ($data) {
  3687. return [
  3688. 'user_id' => $data['user_id'],
  3689. 'hunt_id' => $data['hunt_id'],
  3690. 'website_id' => $data['website_id'],
  3691. 'recruit_id' => $recruiting['recruit_id'],
  3692. 'receiver_id' => $recruiting['receiver_id'],
  3693. 'status' => 1,
  3694. ];
  3695. }, $recruiting);
  3696. // 批量插入数据
  3697. $result = JobApply::insert($insertData);
  3698. if (empty($result)) {
  3699. return Result::error("投递失败", 0);
  3700. }
  3701. return Result::success($result);
  3702. }
  3703. /**
  3704. * 招工招聘-沟通简历
  3705. * @param array $data
  3706. * @return array
  3707. * */
  3708. public function getWebsiteJobResume(array $data): array
  3709. {
  3710. // 首先验证网站是否存在
  3711. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3712. if (empty($web)) {
  3713. return Result::error("该网站不存在", 0);
  3714. }
  3715. // return Result::success($data);
  3716. // 验证用户是否存在且为企业会员/管理员
  3717. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3718. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3719. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3720. return Result::error("用户不存在", 0);
  3721. }
  3722. // 去除重复元素和空元素,并保持原始顺序
  3723. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  3724. return !empty($value);
  3725. }));
  3726. // 验证简历是否存在
  3727. $hunting = JobHunting::where('status', 2)
  3728. ->where('website_id', $data['website_id'])
  3729. ->whereIn('id', $data['hunt_id'])
  3730. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  3731. if (empty($hunting)) {
  3732. return Result::error("该简历不存在", 0);
  3733. }
  3734. // 验证是否已沟通过该简历
  3735. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3736. ->where('recruit_id', $data['recruit_id'])
  3737. ->where('website_id', $data['website_id'])
  3738. ->whereIn('hunt_id', $data['hunt_id'])
  3739. ->get(['hunt_id']);
  3740. if (!empty($remuse->toArray())) {
  3741. return Result::error("您已沟通过该简历!");
  3742. }
  3743. // 准备要插入的数据数组
  3744. $insertData = array_map(function ($hunting) use ($data) {
  3745. return [
  3746. 'user_id' => $data['user_id'],
  3747. 'recruit_id' => $data['recruit_id'],
  3748. 'website_id' => $data['website_id'],
  3749. 'hunt_id' => $hunting['hunt_id'],
  3750. 'receiver_id' => $hunting['receiver_id'],
  3751. 'status' => 1,
  3752. ];
  3753. }, $hunting);
  3754. // 批量插入数据
  3755. $result = JobRemuse::insert($insertData);
  3756. if (empty($result)) {
  3757. return Result::error("沟通失败", 0);
  3758. }
  3759. return Result::success($result);
  3760. }
  3761. /**
  3762. * 招工招聘 -我的职位(企业会员)
  3763. * @param array $data
  3764. * @return array
  3765. */
  3766. public function getWebsiteJobRecruiting(array $data): array
  3767. {
  3768. $web = Website::where('id', $data['website_id'])->first('id');
  3769. if (empty($web)) {
  3770. return Result::error("该网站不存在", 0);
  3771. }
  3772. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3773. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3774. return Result::error("用户暂无权限!", 0);
  3775. }
  3776. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3777. $result = JobRecruiting::where('website_id', $data['website_id'])
  3778. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  3779. $query->where('user_id', $user['id']);
  3780. })
  3781. ->where('status', 1)
  3782. ->select('id', 'title', 'website_id', 'user_id', 'updated_at', 'keyword', 'catid', 'description')
  3783. ->orderBy('updated_at', 'desc')
  3784. ->limit($data['pageSize'])
  3785. ->get();
  3786. if (empty($result)) {
  3787. return Result::error("暂无相关职位信息", 0);
  3788. }
  3789. return Result::success($result);
  3790. }
  3791. /**
  3792. * c端 - 验证路由
  3793. * @param array $data
  3794. * @return array
  3795. */
  3796. /**
  3797. * c端 - 验证路由
  3798. * @param array $data
  3799. * @return array
  3800. */
  3801. public function checkWebsiteRoute(array $data): array
  3802. {
  3803. // 测试001111111222
  3804. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name', 'status']);
  3805. if (empty($web)) {
  3806. return Result::error("该网站不存在", 0);
  3807. } elseif ($web['status'] != 1) {
  3808. return Result::error("网站已经关闭", 0);
  3809. }
  3810. if (isset($data['other_route']) && !empty($data['other_route'])) {
  3811. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  3812. // 验证路由是否存在
  3813. if (empty($whiteRouterInfo)) {
  3814. $whiteRouterInfo = WhiteRouter::where("router_type", 1)->where('router_url', $data['other_route'])->first();
  3815. }
  3816. if (!empty($whiteRouterInfo)) {
  3817. return Result::success($whiteRouterInfo->toArray());
  3818. }
  3819. }
  3820. // 验证栏目路由
  3821. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  3822. ->where('path', $data['all_route'])
  3823. ->get()->all();
  3824. if (count($last_category) == 0) {
  3825. return Result::error("该栏目不存在", 0);
  3826. }
  3827. if (count($last_category) > 1) {
  3828. return Result::error("该栏目路由存在多个,路由验证失败!", 0);
  3829. }
  3830. if (count($last_category) == 1) {
  3831. $last_category = $last_category[0];
  3832. }
  3833. // return Result::success($last_category);
  3834. if (isset($data['id']) && !empty($data['id'])) {
  3835. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  3836. switch ($last_category['type']) {
  3837. case 1:
  3838. // 文章
  3839. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  3840. $article = Article::where('status', 1)
  3841. ->where('id', $data['id'])
  3842. ->where(function ($query) use ($data) {
  3843. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  3844. ->orWhereNull("ignore_ids");
  3845. })
  3846. ->first(['catid']);
  3847. if (empty($article)) {
  3848. return Result::error("该文章不存在", 0);
  3849. }
  3850. // return Result::success($article);
  3851. break;
  3852. case 2:
  3853. // 商品
  3854. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3855. $article = Good::where('website_id', $data['website_id'])
  3856. ->where('status', 2)
  3857. ->where('id', $data['id'])
  3858. ->first(['cat_arr_id']);
  3859. if (empty($article)) {
  3860. return Result::error("该商品不存在", 0);
  3861. }
  3862. break;
  3863. case 3:
  3864. // 书刊信息
  3865. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3866. $article = Book::where('website_id', $data['website_id'])
  3867. ->where('status', 2)
  3868. ->where('id', $data['id'])
  3869. ->first(['id', 'cat_arr_id']);
  3870. if (empty($article)) {
  3871. return Result::error("该书刊不存在", 0);
  3872. }
  3873. break;
  3874. case 4:
  3875. // 招聘
  3876. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核通过;(只有企业会员需要审核)',
  3877. $article = JobRecruiting::where('website_id', $data['website_id'])
  3878. ->where('status', 1)
  3879. ->where('id', $data['id'])
  3880. ->first(['cat_arr_id']);
  3881. if (empty($article)) {
  3882. return Result::error("该招聘不存在", 0);
  3883. }
  3884. break;
  3885. case 5:
  3886. // 求职
  3887. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3888. $article = JobHunting::where('website_id', $data['website_id'])
  3889. ->where('status', 2)
  3890. ->where('id', $data['id'])
  3891. ->first(['cat_arr_id']);
  3892. if (empty($article)) {
  3893. return Result::error("该求职不存在", 0);
  3894. }
  3895. break;
  3896. case 6:
  3897. // 企业
  3898. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3899. $article = Company::
  3900. // where('website_id', $data['website_id'])
  3901. // ->
  3902. where('status', 1)
  3903. ->where('id', $data['id'])
  3904. ->first(['cat_arr_id']);
  3905. if (empty($article)) {
  3906. return Result::error("该企业不存在", 0);
  3907. }
  3908. break;
  3909. case 7:
  3910. // 项目
  3911. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3912. $article = Project::where('website_id', $data['website_id'])
  3913. ->where('status', 1)
  3914. ->where('id', $data['id'])
  3915. ->first(['cat_arr_id']);
  3916. if (empty($article)) {
  3917. return Result::error("该项目不存在", 0);
  3918. }
  3919. break;
  3920. default:
  3921. return Result::error("该数据不存在", 0);
  3922. break;
  3923. }
  3924. // return Result::success($article);
  3925. // $catid =0 ;
  3926. if (!isset($article['cat_arr_id'])) {
  3927. $catid = isset($article['catid']) ? $article['catid'] : (isset($article['category_id']) ? $article['category_id'] : null);
  3928. } else {
  3929. $catidArray = json_decode($article['cat_arr_id'], true);
  3930. $catid = !empty($catidArray) ? end($catidArray) : null;
  3931. }
  3932. // return Result::success($catid);
  3933. // // return Result::success($article['cat_arr_id']);
  3934. if (empty($catid)) {
  3935. return Result::error("该栏目路径不存在", 0);
  3936. }
  3937. $path = WebsiteCategory::where('website_id', $data['website_id'])
  3938. ->where('category_id', $catid)
  3939. ->first('path');
  3940. }
  3941. // else{
  3942. // // if ($last_category['pid'] != 0) {
  3943. // $cat_arr = json_decode($last_category['category_arr_id'], true);
  3944. // $catid = !empty($cat_arr) && is_array($cat_arr) ? end($cat_arr) : null;
  3945. // $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3946. // ->where('category_id',$catid)
  3947. // ->where('path',$data['all_route'])
  3948. // ->first('path');
  3949. // // } else {
  3950. // // $pinyin[0] = $last_category['aLIas_pinyin'];
  3951. // // }
  3952. // }
  3953. // return Result::success($path);
  3954. if (!empty($path) && $path['path'] != $data['all_route']) {
  3955. return Result::error('非法路径!');
  3956. } else {
  3957. return Result::success($last_category['path']);
  3958. }
  3959. }
  3960. /**
  3961. * 招工招聘 - 获取推荐职位
  3962. * @param array $data
  3963. * @return array
  3964. */
  3965. public function getWebsiteLevelJob(array $data): array
  3966. {
  3967. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3968. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  3969. ->where('job_recruiting.status', 1)
  3970. ->where('job_level', $data['job_level'])
  3971. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3972. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  3973. ->orderBy('job_recruiting.updated_at', 'desc')
  3974. ->limit($data['pageSize'])
  3975. ->get();
  3976. $web = ['website_id' => $data['website_id']];
  3977. if (!empty($job)) {
  3978. $result = $this->processJob($job, $web);
  3979. }
  3980. if (empty($result)) {
  3981. return Result::error("暂无相关职位信息", 0);
  3982. }
  3983. return Result::success($result);
  3984. }
  3985. /**
  3986. * 验证导航名称是否重复
  3987. * @return void
  3988. */
  3989. //20250226 产品列表
  3990. public function getGoodList(array $data): array
  3991. {
  3992. var_dump($data, '---------1-2--');
  3993. $type_id = isset($data['user_type_id']) ? $data['user_type_id'] : '';
  3994. unset($data['user_type_id']);
  3995. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3996. $where = [];
  3997. if ($type_id != '10000') {
  3998. $where = [
  3999. 'good.user_id' => $user_id,
  4000. ];
  4001. }
  4002. //类型
  4003. if (isset($data['type_id']) && $data['type_id']) {
  4004. $where['good.type_id'] = $data['type_id'];
  4005. }
  4006. //名称
  4007. if (isset($data['name']) && $data['name']) {
  4008. $where[] = ['good.name', 'like', '%' . $data['name'] . '%'];
  4009. }
  4010. //status
  4011. if (isset($data['status']) && $data['status'] != '') {
  4012. $where['good.status'] = $data['status'];
  4013. }
  4014. //status1
  4015. // if (isset($data['status1']) && $data['status1'] == 1) {
  4016. // $status1 = 1;
  4017. // }
  4018. $where1 = [];
  4019. //website_id
  4020. // if (isset($data['website_id']) && $data['website_id']) {
  4021. // $where1 = [
  4022. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  4023. // ];
  4024. // }
  4025. // website_name
  4026. if (isset($data['website_name']) && $data['website_name']) {
  4027. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  4028. }
  4029. // catid
  4030. if (isset($data['category_name']) && $data['category_name']) {
  4031. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  4032. }
  4033. // $result = Good::where($where)
  4034. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  4035. var_dump($where, '---------1---');
  4036. $result = Good::where($where)
  4037. ->when(!empty($where1), function ($query) use ($where1) {
  4038. return $query->where($where1);
  4039. })
  4040. //status 1待审核2已审核3已拒绝
  4041. ->when(isset($data['status1']), function ($query) {
  4042. return $query->whereIn('good.status', [1, 3]);
  4043. })
  4044. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4045. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4046. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4047. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4048. ->orderBy("updated_at", "desc")
  4049. ->limit($data['page_size'])
  4050. ->offset(($data['page'] - 1) * $data['page_size'])
  4051. ->get();
  4052. $count = Good::where($where)
  4053. ->when(!empty($where1), function ($query) use ($where1) {
  4054. return $query->where($where1);
  4055. })
  4056. //status 1待审核2已审核3已拒绝
  4057. ->when(isset($data['status1']), function ($query) {
  4058. return $query->whereIn('good.status', [1, 3]);
  4059. })
  4060. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4061. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4062. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4063. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4064. ->orderBy("updated_at", "desc")->count();
  4065. $data = [
  4066. 'rows' => $result->toArray(),
  4067. 'count' => $count,
  4068. ];
  4069. if (empty($result)) {
  4070. return Result::error("此栏目暂无相关产品", 0);
  4071. }
  4072. return Result::success($data);
  4073. }
  4074. public function getGoodInfo(array $data): array
  4075. {
  4076. $result = Good::where('id', $data['id'])->first();
  4077. if (empty($result)) {
  4078. return Result::error("此产品不存在", 0);
  4079. }
  4080. return Result::success($result);
  4081. }
  4082. public function addGood(array $data): array
  4083. {
  4084. // unset($data['city_arr_id']);
  4085. // unset($data['cat_arr_id']);
  4086. $data['city_id'] = end($data['city_arr_id']);
  4087. $data['catid'] = end($data['cat_arr_id']);
  4088. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4089. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4090. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4091. unset($data['imgUrl']); //大小写
  4092. if (isset($data['price']) && $data['price'] == '') {
  4093. $data['price'] = 0;
  4094. }
  4095. if ($data['imgurl'] == '') {
  4096. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4097. preg_match_all($reg, $data['detail'], $matches);
  4098. if (isset($matches[1][0])) {
  4099. //截取varchar240
  4100. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4101. }
  4102. }
  4103. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4104. //提取标题+内容中的关键词
  4105. $data['keyword'] = $data['name'];
  4106. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4107. Jieba::init(); // 初始化 jieba-php
  4108. Finalseg::init();
  4109. $segList = Jieba::cut($data['keyword']);
  4110. $segList1 = array_slice($segList, 0, 8);
  4111. $data['keyword'] = implode(',', $segList1);
  4112. }
  4113. if ($data['description'] == '') {
  4114. //提取内容中的描述
  4115. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4116. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4117. // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  4118. }
  4119. if ($data['status'] == 1) {
  4120. $this->sendMessage([
  4121. 'talk_type' => 200,
  4122. 'title' => $data['name'],
  4123. 'content' => '提交了审核',
  4124. 'messageType' => 3,
  4125. ]);
  4126. }
  4127. $result = Good::insert($data);
  4128. if (empty($result)) {
  4129. return Result::error("添加失败", 0);
  4130. }
  4131. return Result::success($result);
  4132. }
  4133. public function updateGood(array $data): array
  4134. {
  4135. $data['city_id'] = end($data['city_arr_id']);
  4136. $data['catid'] = end($data['cat_arr_id']);
  4137. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4138. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4139. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4140. //设置东八区
  4141. date_default_timezone_set('Asia/Shanghai');
  4142. $data['updated_at'] = date('Y-m-d H:i:s');
  4143. if (isset($data['price']) && $data['price'] == '') {
  4144. $data['price'] = 0;
  4145. }
  4146. if ($data['imgurl'] == '') {
  4147. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4148. preg_match_all($reg, $data['detail'], $matches);
  4149. if (isset($matches[1][0])) {
  4150. //截取varchar240
  4151. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4152. }
  4153. }
  4154. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4155. //提取标题+内容中的关键词
  4156. $data['keyword'] = $data['name'];
  4157. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4158. Jieba::init(); // 初始化 jieba-php
  4159. Finalseg::init();
  4160. $segList = Jieba::cut($data['keyword']);
  4161. $segList1 = array_slice($segList, 0, 8);
  4162. $data['keyword'] = implode(',', $segList1);
  4163. }
  4164. if ($data['description'] == '') {
  4165. //提取内容中的描述
  4166. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4167. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4168. }
  4169. if ($data['status'] == 1) {
  4170. $this->sendMessage([
  4171. 'talk_type' => 200,
  4172. 'title' => $data['name'],
  4173. 'content' => '提交了审核',
  4174. 'messageType' => 3,
  4175. ]);
  4176. }
  4177. $result = Good::where('id', $data['id'])->update($data);
  4178. if (empty($result)) {
  4179. return Result::error("更新失败", 0);
  4180. }
  4181. return Result::success($result);
  4182. }
  4183. public function delGood(array $data): array
  4184. {
  4185. $result = Good::where('id', $data['id'])->delete();
  4186. if (empty($result)) {
  4187. return Result::error("删除失败", 0);
  4188. }
  4189. return Result::success($result);
  4190. }
  4191. //20250226 产品列表
  4192. //20250306 求职信息
  4193. public function getJobHuntingList(array $data): array
  4194. {
  4195. $where = [];
  4196. if (isset($data['username']) && !empty($data['username'])) {
  4197. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4198. }
  4199. //status 1待审核2已审核3已拒绝
  4200. if (isset($data['status']) && $data['status'] != '') {
  4201. $where = [
  4202. 'job_hunting.status' => $data['status'],
  4203. ];
  4204. }
  4205. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4206. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4207. unset($data['type_id']);
  4208. if ($type_id != '10000') {
  4209. $where[] = ['job_hunting.user_id', '=', $user_id];
  4210. }
  4211. $result = JobHunting::where($where)
  4212. ->when(!empty($data['status1']), function ($query) use ($data) {
  4213. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4214. })
  4215. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4216. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4217. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  4218. ->orderBy("updated_at", "desc")
  4219. ->limit($data['page_size'])
  4220. ->offset(($data['page'] - 1) * $data['page_size'])
  4221. ->get();
  4222. if (empty($result)) {
  4223. return Result::error("查询失败", 0);
  4224. }
  4225. $count = JobHunting::where($where)
  4226. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4227. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4228. ->count();
  4229. $data = [
  4230. 'rows' => $result->toArray(),
  4231. 'count' => $count,
  4232. ];
  4233. return Result::success($data);
  4234. }
  4235. public function getJobHuntingApply(array $data): array
  4236. {
  4237. var_dump($data, '-----------------test--------1-');
  4238. $where = [];
  4239. if (isset($data['username']) && !empty($data['username'])) {
  4240. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4241. }
  4242. if (isset($data['salary']) && !empty($data['salary'])) {
  4243. $where[] = [
  4244. 'job_hunting.salary',
  4245. '=',
  4246. $data['salary'],
  4247. ];
  4248. }
  4249. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4250. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4251. unset($data['type_id']);
  4252. if ($type_id != '10000') {
  4253. $where[] = ['job_apply.receiver_id', '=', $user_id];
  4254. }
  4255. var_dump($where, '-----------------test---------');
  4256. $result = jobApply::where($where)
  4257. // ->when(!empty($data['status1']), function ($query) use ($data) {
  4258. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4259. // })
  4260. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  4261. ->where('job_enum.egroup', '=', 'income')
  4262. ->where('job_hunting.status', 2) //已审核
  4263. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4264. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4265. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4266. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4267. //职位----是申请职位
  4268. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4269. ->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')
  4270. ->orderBy("job_hunting.updated_at", "desc")
  4271. ->limit($data['page_size'])
  4272. ->offset(($data['page'] - 1) * $data['page_size'])
  4273. ->get();
  4274. if (empty($result)) {
  4275. return Result::error("查询失败", 0);
  4276. }
  4277. $count = jobApply::where($where)
  4278. ->where('job_enum.egroup', '=', 'income')
  4279. ->where('job_hunting.status', 2) //已审核
  4280. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4281. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4282. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4283. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4284. //职位----是申请职位
  4285. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4286. ->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')
  4287. ->count();
  4288. $data = [
  4289. 'rows' => $result->toArray(),
  4290. 'count' => $count,
  4291. ];
  4292. return Result::success($data);
  4293. }
  4294. public function addJobHunting(array $data): array
  4295. {
  4296. date_default_timezone_set('Asia/Shanghai');
  4297. unset($data['company_name']);
  4298. unset($data['job_industry']);
  4299. unset($data['job_name']);
  4300. unset($data['department']);
  4301. unset($data['job_timeList']);
  4302. unset($data['job_content']);
  4303. unset($data['job_typename']); //不知道这是啥,
  4304. $data['created_at'] = date('Y-m-d H:i:s');
  4305. $data['updated_at'] = date('Y-m-d H:i:s');
  4306. //根据用户 user_id 只能添加一次
  4307. $result = JobHunting::where('user_id', $data['user_id'])->first();
  4308. if (!empty($result)) {
  4309. return Result::error("您已添加过求职信息", 0);
  4310. }
  4311. var_dump($result, '-----------------test---------');
  4312. if (isset($data['city_arr_id']) && !empty($data['city_arr_id'])) {
  4313. if (is_string($data['city_arr_id'])) {
  4314. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4315. $cityArr = json_decode($data['city_arr_id'], true);
  4316. // 确保 $cityArr 是数组
  4317. if (is_array($cityArr)) {
  4318. $data['city_id'] = end($cityArr);
  4319. }
  4320. } else {
  4321. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4322. if (is_array($data['city_arr_id'])) {
  4323. $data['city_id'] = end($data['city_arr_id']);
  4324. }
  4325. }
  4326. }
  4327. // 处理求职所绑定栏目
  4328. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id'])) {
  4329. if (is_string($data['cat_arr_id'])) {
  4330. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4331. // 先清理可能存在的无效 JSON 字符
  4332. $cleanedCatArrStr = trim($data['cat_arr_id']);
  4333. $catArr = json_decode($cleanedCatArrStr, true);
  4334. // 检查 JSON 解码是否成功且结果是数组
  4335. if (json_last_error() === JSON_ERROR_NONE && is_array($catArr)) {
  4336. $data['catid'] = end($catArr);
  4337. }
  4338. } else {
  4339. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4340. if (is_array($data['cat_arr_id'])) {
  4341. $data['catid'] = end($data['cat_arr_id']);
  4342. }
  4343. }
  4344. }
  4345. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4346. $this->sendMessage([
  4347. 'talk_type' => 600,
  4348. 'title' => $data['name'],
  4349. 'content' => '提交了审核',
  4350. 'messageType' => 11,
  4351. ]);
  4352. }
  4353. $result = JobHunting::create($data);
  4354. if (empty($result)) {
  4355. return Result::error("添加失败", 0);
  4356. }
  4357. return Result::success($result);
  4358. }
  4359. public function delJobHunting(array $data): array
  4360. {
  4361. $result = JobHunting::where('id', $data['id'])->delete();
  4362. if (empty($result)) {
  4363. return Result::error("删除失败", 0);
  4364. }
  4365. return Result::success($result);
  4366. }
  4367. public function updateJobHunting(array $data): array
  4368. {
  4369. //设置东八区
  4370. date_default_timezone_set('Asia/Shanghai');
  4371. unset($data['company_name']);
  4372. unset($data['job_industry']);
  4373. unset($data['job_name']);
  4374. unset($data['department']);
  4375. unset($data['job_timeList']);
  4376. unset($data['job_content']);
  4377. unset($data['job_typename']); //不知道这是啥,
  4378. $data['created_at'] = date('Y-m-d H:i:s');
  4379. $data['updated_at'] = date('Y-m-d H:i:s');
  4380. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  4381. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4382. $cityArr = json_decode($data['city_arr_id'], true);
  4383. $data['city_id'] = end($cityArr);
  4384. } else {
  4385. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4386. $data['city_id'] = end($data['city_arr_id']);
  4387. }
  4388. // 处理求职所绑定栏目
  4389. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_string($data['cat_arr_id'])) {
  4390. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4391. $catArr = json_decode($data['cat_arr_id'], true);
  4392. $data['catid'] = end($catArr);
  4393. } else {
  4394. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4395. $data['catid'] = end($data['cat_arr_id']);
  4396. }
  4397. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4398. $this->sendMessage([
  4399. 'talk_type' => 600,
  4400. 'title' => $data['name'],
  4401. 'content' => '提交了审核',
  4402. 'messageType' => 11,
  4403. ]);
  4404. }
  4405. $result = JobHunting::where('id', $data['id'])->update($data);
  4406. if (empty($result)) {
  4407. return Result::error("更新失败", 0);
  4408. }
  4409. return Result::success($result);
  4410. }
  4411. public function getJobHuntingInfo(array $data): array
  4412. {
  4413. $result = JobHunting::where('id', $data['id'])->first();
  4414. if (empty($result)) {
  4415. return Result::error("查询失败", 0);
  4416. }
  4417. return Result::success($result);
  4418. }
  4419. public function getJobHuntingData(array $data): array
  4420. {
  4421. $jobEnum = JobEnum::get();
  4422. $jobIndustry = JobIndustry::get();
  4423. $jobNature = JobNature::get();
  4424. $jobPosition = JobPosition::get();
  4425. $data = [
  4426. 'jobEnum' => $jobEnum,
  4427. 'jobIndustry' => $jobIndustry,
  4428. 'jobNature' => $jobNature,
  4429. 'jobPosition' => $jobPosition,
  4430. ];
  4431. return Result::success($data);
  4432. }
  4433. public function delJobHuntingInfo(array $data): array
  4434. {
  4435. $result = JobHunting::where('id', $data['id'])->delete();
  4436. return Result::success();
  4437. }
  4438. //20250324 通知,公告,消息
  4439. public function delNotice(array $data): array
  4440. {
  4441. $result = Notice::where('id', $data['id'])->delete();
  4442. if ($result) {
  4443. return Result::success();
  4444. } else {
  4445. return Result::error("删除失败", 0);
  4446. }
  4447. }
  4448. public function getNoticeInfo(array $data): array
  4449. {
  4450. $result = Notice::where('id', $data['id'])->first();
  4451. // var_dump($result['re_user_ids'], '--------------------');
  4452. if (empty($result)) {
  4453. return Result::error("查询失败", 0);
  4454. }
  4455. return Result::success($result);
  4456. }
  4457. public function readNotice(array $data): array
  4458. {
  4459. $result = Notice::where('id', $data['id'])->first();
  4460. // var_dump($result['re_user_ids'], '--------------------');
  4461. if (empty($result)) {
  4462. return Result::error("查询失败", 0);
  4463. }
  4464. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4465. $re_user_ids = json_decode($result['re_user_ids'], true);
  4466. var_dump($re_user_ids, '--------------1---test---------');
  4467. var_dump($data, '--------------1---test---------');
  4468. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4469. //如果已经存在,就不再添加
  4470. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4471. $read_id = json_decode($result['read_id'], true);
  4472. if (!is_array($read_id)) {
  4473. $read_id = [];
  4474. }
  4475. if (!in_array($data['user_id'], $read_id)) {
  4476. $read_id[] = $data['user_id'];
  4477. $result['read_id'] = json_encode($read_id);
  4478. Notice::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4479. }
  4480. } else {
  4481. //如果不存在,就添加
  4482. $result['read_id'] = json_encode([$data['user_id']]);
  4483. Notice::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4484. }
  4485. }
  4486. return Result::success($result);
  4487. }
  4488. public function addNotice(array $data): array
  4489. {
  4490. date_default_timezone_set('Asia/Shanghai');
  4491. $data['created_at'] = date('Y-m-d H:i:s');
  4492. $data['updated_at'] = date('Y-m-d H:i:s');
  4493. $user_id = UserInfo::
  4494. //city_id不是null
  4495. whereNotNull('city_id')
  4496. ->whereNotNull('department_id')
  4497. ->where(function ($query) use ($data) {
  4498. $query->where(function ($subQuery) use ($data) {
  4499. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4500. });
  4501. })
  4502. ->where(function ($query) use ($data) {
  4503. $query->where(function ($subQuery) use ($data) {
  4504. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4505. });
  4506. })
  4507. ->pluck('user_id')->toArray();
  4508. $user_id = array_unique($user_id);
  4509. $chat_ids = $user_id;
  4510. $user_id = json_encode($user_id);
  4511. $data['re_user_ids'] = $user_id;
  4512. $this->sendMessage([
  4513. 'talk_type' => 700,
  4514. 'title' => $data['title'],
  4515. 'content' => '提交了审核',
  4516. 'messageType' => 5,
  4517. ]);
  4518. $result = Notice::insertGetId($data);
  4519. if (empty($result)) {
  4520. return Result::error("添加失败", 0);
  4521. }
  4522. return Result::success($result);
  4523. }
  4524. public function updateNotice(array $data): array
  4525. {
  4526. date_default_timezone_set('Asia/Shanghai');
  4527. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  4528. $user_id = UserInfo::
  4529. //city_id不是null
  4530. whereNotNull('city_id')
  4531. ->whereNotNull('department_id')
  4532. ->where(function ($query) use ($data) {
  4533. $query->where(function ($subQuery) use ($data) {
  4534. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4535. });
  4536. })
  4537. ->where(function ($query) use ($data) {
  4538. $query->where(function ($subQuery) use ($data) {
  4539. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4540. });
  4541. })
  4542. ->pluck('user_id')->toArray();
  4543. $user_id = array_unique($user_id);
  4544. $user_id = json_encode($user_id);
  4545. $data['re_user_ids'] = $user_id;
  4546. $data['updated_at'] = date('Y-m-d H:i:s');
  4547. $this->sendMessage([
  4548. 'talk_type' => 700,
  4549. 'title' => $data['title'],
  4550. 'content' => '提交了审核',
  4551. 'messageType' => 5,
  4552. ]);
  4553. $result = Notice::where('id', $data['id'])->update($data);
  4554. return Result::success($result);
  4555. }
  4556. public function getNoticeList(array $data): array
  4557. {
  4558. $where = [];
  4559. //title
  4560. if (isset($data['title']) && !empty($data['title'])) {
  4561. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4562. }
  4563. //level
  4564. if (isset($data['level']) && !empty($data['level'])) {
  4565. $where[] = ['notice.level', '=', $data['level']];
  4566. }
  4567. //status
  4568. if (isset($data['status']) && !empty($data['status'])) {
  4569. $where[] = ['notice.status', '=', $data['status']];
  4570. }
  4571. //type
  4572. if (isset($data['type']) && !empty($data['type'])) {
  4573. $where[] = ['notice.type', '=', $data['type']];
  4574. }
  4575. var_dump($data, '------------11111-2----test---------');
  4576. if ($data['type_id'] == 10000) {
  4577. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4578. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4579. })
  4580. ->where($where)
  4581. ->orderBy('updated_at', 'desc')
  4582. ->limit($data['page_size'])
  4583. ->offset(($data['page'] - 1) * $data['page_size'])
  4584. ->get();
  4585. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4586. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4587. })
  4588. ->where($where)
  4589. ->orderBy('updated_at', 'desc')
  4590. ->count();
  4591. } else {
  4592. $result = Notice::where($where)
  4593. // ->where('user_id', $data['user_id'])
  4594. ->Where(function ($query) use ($data) {
  4595. $query->Where(function ($q) use ($data) {
  4596. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4597. ->orWhere('notice.user_id', $data['user_id']);
  4598. });
  4599. })
  4600. ->when(!empty($data['status1']), function ($query) use ($data) {
  4601. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4602. })
  4603. ->orderBy('updated_at', 'desc')
  4604. ->limit($data['page_size'])
  4605. ->offset(($data['page'] - 1) * $data['page_size'])
  4606. ->get();
  4607. $total = Notice::where($where)
  4608. ->when(!empty($data['status1']), function ($query) use ($data) {
  4609. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4610. })
  4611. // ->where('user_id', $data['user_id'])
  4612. ->Where(function ($query) use ($data) {
  4613. $query->Where(function ($q) use ($data) {
  4614. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4615. ->orWhere('notice.user_id', $data['user_id']);
  4616. });
  4617. })
  4618. ->count();
  4619. }
  4620. if (empty($result)) {
  4621. return Result::error("查询失败", 0);
  4622. }
  4623. $data = [
  4624. 'rows' => $result,
  4625. 'count' => $total,
  4626. ];
  4627. return Result::success($data);
  4628. }
  4629. public function noticeList(array $data): array
  4630. {
  4631. $where = [];
  4632. //title
  4633. if (isset($data['title']) && !empty($data['title'])) {
  4634. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4635. }
  4636. //level
  4637. if (isset($data['level']) && !empty($data['level'])) {
  4638. $where[] = ['notice.level', '=', $data['level']];
  4639. }
  4640. //status
  4641. if (isset($data['status']) && !empty($data['status'])) {
  4642. $where[] = ['notice.status', '=', $data['status']];
  4643. }
  4644. //type
  4645. if (isset($data['type']) && !empty($data['type'])) {
  4646. $where[] = ['notice.type', '=', $data['type']];
  4647. }
  4648. var_dump($data, '------------11111-2----test---------');
  4649. if ($data['type_id'] == 10000) {
  4650. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4651. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4652. })
  4653. ->where($where)
  4654. ->orderBy('updated_at', 'desc')
  4655. ->limit($data['page_size'])
  4656. ->offset(($data['page'] - 1) * $data['page_size'])
  4657. ->get();
  4658. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4659. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4660. })
  4661. ->where($where)
  4662. ->orderBy('updated_at', 'desc')
  4663. ->count();
  4664. } else {
  4665. $result = Notice::where($where)
  4666. // ->where('user_id', $data['user_id'])
  4667. ->Where(function ($query) use ($data) {
  4668. $query->Where(function ($q) use ($data) {
  4669. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4670. ->orWhere('notice.user_id', $data['user_id']);
  4671. });
  4672. })
  4673. ->when(!empty($data['status1']), function ($query) use ($data) {
  4674. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4675. })
  4676. ->orderBy('updated_at', 'desc')
  4677. ->limit($data['page_size'])
  4678. ->offset(($data['page'] - 1) * $data['page_size'])
  4679. ->get();
  4680. $total = Notice::where($where)
  4681. ->when(!empty($data['status1']), function ($query) use ($data) {
  4682. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4683. })
  4684. // ->where('user_id', $data['user_id'])
  4685. ->Where(function ($query) use ($data) {
  4686. $query->Where(function ($q) use ($data) {
  4687. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4688. ->orWhere('notice.user_id', $data['user_id']);
  4689. });
  4690. })
  4691. ->count();
  4692. }
  4693. if (empty($result)) {
  4694. return Result::error("查询失败", 0);
  4695. }
  4696. $data = [
  4697. 'rows' => $result,
  4698. 'count' => $total,
  4699. ];
  4700. return Result::success($data);
  4701. }
  4702. public function getNoticeDetail(array $data): array
  4703. {
  4704. $result = Notice::where('id', $data['id'])->first();
  4705. if (empty($result)) {
  4706. return Result::error("查询失败", 0);
  4707. }
  4708. return Result::success($result);
  4709. }
  4710. public function deleteNotice(array $data): array
  4711. {
  4712. $notice = Notice::where('id', $data['id'])->first();
  4713. if (empty($notice)) {
  4714. return Result::error("删除失败", 0);
  4715. }
  4716. $chat_group_id = $notice->group_id;
  4717. if ($chat_group_id) {
  4718. //删除群聊
  4719. ChatGroups::where('id', $chat_group_id)->delete();
  4720. //删除群成员
  4721. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  4722. //删除群聊记录
  4723. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  4724. }
  4725. $result = Notice::where('id', $data['id'])->delete();
  4726. return Result::success($result);
  4727. }
  4728. public function complaintList(array $data): array
  4729. {
  4730. var_dump($data, '---------1---------');
  4731. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4732. unset($data['type_id']);
  4733. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4734. $where = [];
  4735. if ($type_id != 10000 && empty($data['deal_user'])) {
  4736. // $where['complaint.user_id'] = $user_id;
  4737. }
  4738. if (!empty($data['title'])) {
  4739. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4740. }
  4741. if (!empty($data['department_id'])) {
  4742. $where['complaint.department_id'] = $data['department_id'];
  4743. }
  4744. if (!empty($data['deal'])) {
  4745. $where['complaint.deal'] = $data['deal'];
  4746. }
  4747. if (!empty($data['status'])) {
  4748. $where['complaint.status'] = $data['status'];
  4749. }
  4750. var_dump(!empty($data['deal_user']), '----------1');
  4751. var_dump($where, '----------2');
  4752. $result = Complaint::where($where)
  4753. ->when(!empty($data['status1']), function ($query) use ($data) {
  4754. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4755. })
  4756. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4757. //json re_user_ids data[user_id]是不是在里面
  4758. $query->Where(function ($q) use ($data) {
  4759. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4760. ->where('complaint.status', 2);
  4761. });
  4762. })
  4763. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4764. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4765. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4766. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4767. ->orderBy('updated_at', 'desc')
  4768. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4769. //sql输出
  4770. if (empty($result)) {
  4771. return Result::error("暂无投诉信息", 0);
  4772. }
  4773. // 取出数据
  4774. $rows = $result->items();
  4775. $count = $result->total();
  4776. $responseData = [
  4777. 'rows' => $rows,
  4778. 'count' => $count,
  4779. ];
  4780. return Result::success($responseData);
  4781. }
  4782. public function getComplaintList(array $data): array
  4783. {
  4784. var_dump($data, '00000001000000000000');
  4785. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4786. unset($data['type_id']);
  4787. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4788. $where = [];
  4789. if ($type_id != 10000 && empty($data['deal_user'])) {
  4790. $where['complaint.user_id'] = $user_id;
  4791. }
  4792. if (!empty($data['title'])) {
  4793. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4794. }
  4795. if (!empty($data['department_id'])) {
  4796. $where['complaint.department_id'] = $data['department_id'];
  4797. }
  4798. if (!empty($data['deal'])) {
  4799. $where['complaint.deal'] = $data['deal'];
  4800. }
  4801. if (!empty($data['status'])) {
  4802. $where['complaint.status'] = $data['status'];
  4803. }
  4804. var_dump(!empty($data['deal_user']), '----------1');
  4805. var_dump($where, '----------2');
  4806. $result = Complaint::where($where)
  4807. ->when(!empty($data['status1']), function ($query) use ($data) {
  4808. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4809. })
  4810. // ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4811. // //json re_user_ids data[user_id]是不是在里面
  4812. // $query->Where(function ($q) use ($data) {
  4813. // $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4814. // ->where('complaint.status', 2);
  4815. // });
  4816. // })
  4817. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4818. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4819. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4820. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4821. ->orderBy('updated_at', 'desc')
  4822. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4823. //sql输出
  4824. if (empty($result)) {
  4825. return Result::error("暂无投诉信息", 0);
  4826. }
  4827. // 取出数据
  4828. $rows = $result->items();
  4829. $count = $result->total();
  4830. $responseData = [
  4831. 'rows' => $rows,
  4832. 'count' => $count,
  4833. ];
  4834. return Result::success($responseData);
  4835. }
  4836. public function getComplaintInfo(array $data): array
  4837. {
  4838. $result = Complaint::where('id', $data['id'])->first();
  4839. if (empty($result)) {
  4840. return Result::error("查询失败", 0);
  4841. }
  4842. return Result::success($result);
  4843. }
  4844. public function readComplaint(array $data): array
  4845. {
  4846. $result = Complaint::where('id', $data['id'])->first();
  4847. if (empty($result)) {
  4848. return Result::error("查询失败", 0);
  4849. }
  4850. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4851. $re_user_ids = json_decode($result['re_user_ids'], true);
  4852. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4853. //如果已经存在,就不再添加
  4854. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4855. $read_id = json_decode($result['read_id'], true);
  4856. if (!is_array($read_id)) {
  4857. $read_id = [];
  4858. }
  4859. if (!in_array($data['user_id'], $read_id)) {
  4860. $read_id[] = $data['user_id'];
  4861. $result['read_id'] = json_encode($read_id);
  4862. Complaint::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4863. }
  4864. } else {
  4865. //如果不存在,就添加
  4866. $result['read_id'] = json_encode([$data['user_id']]);
  4867. Complaint::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4868. }
  4869. }
  4870. return Result::success($result);
  4871. }
  4872. public function addComplaint(array $data): array
  4873. {
  4874. date_default_timezone_set('Asia/Shanghai');
  4875. $data['created_at'] = date('Y-m-d H:i:s');
  4876. $data['updated_at'] = date('Y-m-d H:i:s');
  4877. $this->sendMessage([
  4878. 'talk_type' => 800,
  4879. 'title' => $data['title'],
  4880. 'content' => '提交了审核',
  4881. 'messageType' => 6,
  4882. ]);
  4883. $result = Complaint::create($data);
  4884. return Result::success($result);
  4885. }
  4886. public function updateComplaint(array $data): array
  4887. {
  4888. date_default_timezone_set('Asia/Shanghai');
  4889. $data['updated_at'] = date('Y-m-d H:i:s');
  4890. $user_id = $data['user_id'] ?? 0;
  4891. $type_id = $data['type_id'] ?? 0;
  4892. unset($data['user_id']);
  4893. unset($data['type_id']);
  4894. $this->sendMessage([
  4895. 'talk_type' => 800,
  4896. 'title' => $data['title'],
  4897. 'content' => '提交了审核',
  4898. 'messageType' => 6,
  4899. ]);
  4900. $result = Complaint::where('id', $data['id'])->update($data);
  4901. return Result::success($result);
  4902. }
  4903. public function deleteComplaint(array $data): array
  4904. {
  4905. $result = Complaint::where('id', $data['id'])->delete();
  4906. return Result::success($result);
  4907. }
  4908. public function getComplainInfo(array $data): array
  4909. {
  4910. $result = Complaint::where('id', $data['id'])->first();
  4911. if (empty($result)) {
  4912. return Result::error("查询失败", 0);
  4913. }
  4914. return Result::success($result);
  4915. }
  4916. public function updateComplaintStatus(array $data): array
  4917. {
  4918. date_default_timezone_set('Asia/Shanghai');
  4919. $data['updated_at'] = date('Y-m-d H:i:s');
  4920. $user_id = $data['user_id'] ?? 0;
  4921. $type_id = $data['type_id'] ?? 0;
  4922. unset($data['user_id']);
  4923. unset($data['type_id']);
  4924. //处理, 写入处理人
  4925. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  4926. $data['real_deal_user'] = $user_id;
  4927. }
  4928. //如果是deal 23,则判断是不是处理人
  4929. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  4930. $complaintInof = Complaint::where('id', $data['id'])
  4931. ->where('real_deal_user', $user_id)
  4932. ->first();
  4933. if (empty($complaintInof)) {
  4934. return Result::error("处理人错误", 0);
  4935. }
  4936. }
  4937. $complaintInfo = Complaint::where('id', $data['id'])->first();
  4938. if ($data['status'] == 1) {
  4939. $this->sendMessage([
  4940. 'talk_type' => 800,
  4941. 'title' => $complaintInfo['title'],
  4942. 'content' => '提交了审核',
  4943. 'messageType' => 6,
  4944. ]);
  4945. }
  4946. if ($data['status'] == 2 && !isset($data['deal'])) {
  4947. $this->sendMessage([
  4948. 'talk_type' => 801,
  4949. 'title' => $complaintInfo['title'],
  4950. 'content' => '审核通过',
  4951. 'messageType' => 6,
  4952. 'user_id' => $complaintInfo['user_id'],
  4953. ]);
  4954. $this->sendMessage([
  4955. 'talk_type' => 802,
  4956. 'title' => $complaintInfo['title'],
  4957. 'content' => '待处理',
  4958. 'messageType' => 6,
  4959. 'user_id' => $complaintInfo['re_user_ids'],
  4960. ]);
  4961. }
  4962. if ($data['status'] == 3 && !isset($data['deal'])) {
  4963. $this->sendMessage([
  4964. 'talk_type' => 801,
  4965. 'title' => $complaintInfo['title'],
  4966. 'content' => '审核拒绝',
  4967. 'messageType' => 6,
  4968. 'user_id' => $complaintInfo['user_id'],
  4969. ]);
  4970. }
  4971. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 2) {
  4972. $this->sendMessage([
  4973. 'talk_type' => 802,
  4974. 'title' => $complaintInfo['title'],
  4975. 'content' => '处理中',
  4976. 'messageType' => 6,
  4977. 'user_id' => $complaintInfo['re_user_ids'],
  4978. ]);
  4979. }
  4980. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 4) {
  4981. $this->sendMessage([
  4982. 'talk_type' => 802,
  4983. 'title' => $complaintInfo['title'],
  4984. 'content' => '不予处理',
  4985. 'messageType' => 6,
  4986. 'user_id' => $complaintInfo['re_user_ids'],
  4987. ]);
  4988. }
  4989. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 3) {
  4990. $this->sendMessage([
  4991. 'talk_type' => 802,
  4992. 'title' => $complaintInfo['title'],
  4993. 'content' => '已完结',
  4994. 'messageType' => 6,
  4995. 'user_id' => $complaintInfo['re_user_ids'],
  4996. ]);
  4997. }
  4998. $result = complaint::where('id', $data['id'])->update($data);
  4999. return Result::success($result);
  5000. }
  5001. public function updateGoodStatus(array $data): array
  5002. {
  5003. $user_id = $data['user_id'] ?? 0;
  5004. $type_id = $data['type_id'] ?? 0;
  5005. unset($data['user_id']);
  5006. unset($data['type_id']);
  5007. $goodInfo = Good::where('id', $data['id'])->first();
  5008. if ($data['status'] == 2) {
  5009. $this->sendMessage([
  5010. 'talk_type' => 201,
  5011. 'title' => $goodInfo['name'],
  5012. 'content' => '审核通过',
  5013. 'messageType' => 3,
  5014. 'user_id' => $goodInfo['user_id'],
  5015. ]);
  5016. }
  5017. if ($data['status'] == 3) {
  5018. $this->sendMessage([
  5019. 'talk_type' => 201,
  5020. 'title' => $goodInfo['name'],
  5021. 'content' => '审核拒绝',
  5022. 'messageType' => 3,
  5023. 'user_id' => $goodInfo['user_id'],
  5024. ]);
  5025. }
  5026. if ($data['status'] == 1) {
  5027. $this->sendMessage([
  5028. 'talk_type' => 200,
  5029. 'title' => $goodInfo['name'],
  5030. 'content' => '提交了审核',
  5031. 'messageType' => 3,
  5032. ]);
  5033. }
  5034. $result = Good::where('id', $data['id'])->update($data);
  5035. return Result::success($result);
  5036. }
  5037. public function updateJobHuntingStatus(array $data): array
  5038. {
  5039. $user_id = $data['user_id'] ?? 0;
  5040. $type_id = $data['type_id'] ?? 0;
  5041. unset($data['user_id']);
  5042. unset($data['type_id']);
  5043. $jogHuntingInfo = JobHunting::where('id', $data['id'])->first();
  5044. if ($data['status'] == 2) {
  5045. $this->sendMessage([
  5046. 'talk_type' => 601,
  5047. 'title' => $jogHuntingInfo['name'],
  5048. 'content' => '审核通过',
  5049. 'messageType' => 11,
  5050. 'user_id' => $jogHuntingInfo['user_id'],
  5051. ]);
  5052. }
  5053. if ($data['status'] == 3) {
  5054. $this->sendMessage([
  5055. 'talk_type' => 601,
  5056. 'title' => $jogHuntingInfo['name'],
  5057. 'content' => '审核拒绝',
  5058. 'messageType' => 11,
  5059. 'user_id' => $jogHuntingInfo['user_id'],
  5060. ]);
  5061. }
  5062. if ($data['status'] == 1) {
  5063. $this->sendMessage([
  5064. 'talk_type' => 600,
  5065. 'title' => $jogHuntingInfo['name'],
  5066. 'content' => '提交了审核',
  5067. 'messageType' => 11,
  5068. ]);
  5069. }
  5070. $result = JobHunting::where('id', $data['id'])->update($data);
  5071. return Result::success($result);
  5072. }
  5073. public function updateNoticeStatus(array $data): array
  5074. {
  5075. $user_id = $data['user_id'] ?? 0;
  5076. $type_id = $data['type_id'] ?? 0;
  5077. unset($data['user_id']);
  5078. unset($data['type_id']);
  5079. //查询公告
  5080. $notice = Notice::where('id', $data['id'])->first();
  5081. if (empty($notice)) {
  5082. return Result::error("公告不存在", 0);
  5083. }
  5084. //$chat_ids 去除掉$data['user_id']
  5085. $chat_ids = json_decode($notice['re_user_ids'], true);
  5086. $chat_ids = array_diff($chat_ids, [$notice['user_id']]);
  5087. //如果公告的状态是2,且是群聊公告,且状态是1,则创建群聊,第一次审核通过的时候处理成群聊
  5088. if ($data['status'] == 2 && $notice['is_group'] == 1 && ($notice['status'] == 1 || $notice['status'] == 3) && empty($notice['group_id'])) {
  5089. //chat_group
  5090. $group_id = PublicData::uuid();
  5091. $groupData = [
  5092. 'id' => $group_id,
  5093. 'creator_id' => $notice['user_id'],
  5094. 'group_name' => $notice['group_name'] ?? '',
  5095. 'profile' => $notice['profile'] ?? 0,
  5096. ];
  5097. var_dump($groupData, '-----------------groupData-------');
  5098. $groupResult = ChatGroups::insertGetId($groupData);
  5099. var_dump($groupResult, '-----------------groupid-------');
  5100. $groupMemberData = [
  5101. 'id' => PublicData::uuid(),
  5102. 'user_id' => $notice['user_id'],
  5103. 'group_id' => $group_id,
  5104. 'leader' => 2,
  5105. ];
  5106. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  5107. //插入群成员表
  5108. $groupMemberDataUser = [];
  5109. $chatData = [];
  5110. foreach ($chat_ids as $key => $value) {
  5111. $groupMemberDataUser[] = [
  5112. 'id' => PublicData::uuid(),
  5113. 'user_id' => $value,
  5114. 'group_id' => $group_id,
  5115. 'leader' => 1,
  5116. ];
  5117. $chatData[] = [
  5118. 'user_id' => $value,
  5119. 'msg_type' => 1,
  5120. 'receiver_id' => $group_id,
  5121. 'content' => '通过通知创建群聊',
  5122. 'group_receiver_id' => $notice['user_id'],
  5123. 'action' => 'recieved',
  5124. 'created_at' => date('Y-m-d H:i:s'),
  5125. ];
  5126. }
  5127. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  5128. ChatGroupsMember::insert($groupMemberDataUser);
  5129. //插入一条管理员聊天记录
  5130. $chatData[] = [
  5131. 'user_id' => $notice['user_id'],
  5132. 'msg_type' => 1,
  5133. 'receiver_id' => $group_id,
  5134. 'content' => '通过通知创建群聊',
  5135. 'group_receiver_id' => $notice['user_id'],
  5136. 'action' => 'said',
  5137. 'created_at' => date('Y-m-d H:i:s'),
  5138. ];
  5139. var_dump($chatData, '-----------------chatData-------');
  5140. $chatResult = ChatRecords::insert($chatData);
  5141. //处理imp
  5142. $group = [
  5143. 'type' => 1,
  5144. 'name' => $notice['group_name'] ?? '',
  5145. 'profile' => '',
  5146. 'avatar' => '',
  5147. 'creator_id' => $notice['user_id'],
  5148. ];
  5149. $groupResult = GroupImp::insertGetId($group);
  5150. var_dump($groupResult, '获取imp group_id');
  5151. $groupMember = [
  5152. 'user_id' => $notice['user_id'],
  5153. 'group_id' => $groupResult,
  5154. 'leader' => 1,
  5155. 'join_time' => Date('Y-m-d H:i:s')
  5156. ];
  5157. $groupMemberResult = GroupMemberImp::insertGetId($groupMember);
  5158. $talk_session = [
  5159. 'user_id' => $notice['user_id'],
  5160. 'to_from_id' => $groupResult,
  5161. 'talk_mode' => 2,
  5162. 'created_at' => Date('Y-m-d H:i:s'),
  5163. 'updated_at' => Date('Y-m-d H:i:s'),
  5164. ];
  5165. $talk_session_result = GroupTalkImp::insertGetId($talk_session);
  5166. //被通知人员处理
  5167. foreach ($chat_ids as $key => $value) {
  5168. $groupMemberdata[] = [
  5169. 'user_id' => $value,
  5170. 'group_id' => $groupResult,
  5171. 'leader' => 3,
  5172. 'join_time' => Date('Y-m-d H:i:s')
  5173. ];
  5174. $talk_sessionData[] = [
  5175. 'user_id' => $value,
  5176. 'to_from_id' => $groupResult,
  5177. 'talk_mode' => 2,
  5178. 'created_at' => Date('Y-m-d H:i:s'),
  5179. 'updated_at' => Date('Y-m-d H:i:s'),
  5180. ];
  5181. }
  5182. $groupResult1 = GroupMemberImp::insert($groupMemberdata);
  5183. $talk_sessionResult = GroupTalkImp::insert($talk_sessionData);
  5184. $group_id = $groupResult;
  5185. //更新result的 group_id
  5186. $data['group_id'] = $group_id;
  5187. Notice::where(['id' => $data['id']])->update($data);
  5188. }
  5189. if (($data['status'] == 1 || $data['status'] == 3) && $notice['is_group'] == 1 && $notice['status'] == 2 && !empty($notice['group_id'])) {
  5190. //删除掉信息
  5191. GroupImp::where('id', $notice['group_id'])->delete();
  5192. GroupMemberImp::where('group_id', $notice['group_id'])->delete();
  5193. GroupTalkImp::where('to_from_id', $notice['group_id'])->delete();
  5194. foreach ($chat_ids as $key => $value) {
  5195. }
  5196. //聊天记录删除
  5197. //如果是群聊公告,且已经有群聊id,则更新公告的group_id
  5198. $data['group_id'] = null;
  5199. Notice::where(['id' => $data['id']])->update($data);
  5200. }
  5201. $result = Notice::where('id', $data['id'])->update($data);
  5202. $noticeInfo = Notice::where('id', $data['id'])->first();
  5203. if ($data['status'] == 2) {
  5204. $this->sendMessage([
  5205. 'talk_type' => 701,
  5206. 'title' => $noticeInfo['title'],
  5207. 'content' => '审核通过',
  5208. 'messageType' => 3,
  5209. 'user_id' => $noticeInfo['user_id'],
  5210. ]);
  5211. }
  5212. if ($data['status'] == 3) {
  5213. $this->sendMessage([
  5214. 'talk_type' => 701,
  5215. 'title' => $noticeInfo['title'],
  5216. 'content' => '审核拒绝',
  5217. 'messageType' => 3,
  5218. 'user_id' => $noticeInfo['user_id'],
  5219. ]);
  5220. }
  5221. if ($data['status'] == 1) {
  5222. $this->sendMessage([
  5223. 'talk_type' => 700,
  5224. 'title' => $noticeInfo['title'],
  5225. 'content' => '提交了审核',
  5226. 'messageType' => 3,
  5227. ]);
  5228. }
  5229. return Result::success($result);
  5230. }
  5231. public function getDUser(array $data): array
  5232. {
  5233. if (!empty($data['ids'])) {
  5234. $user = User::whereIn('id', $data['ids'])->getall();
  5235. if (empty($user)) {
  5236. return Result::error('无数据', 0);
  5237. }
  5238. return Result::success($user);
  5239. }
  5240. $where = [];
  5241. if (!empty($data['department_id'])) {
  5242. $where['department_id'] = $data['department_id'];
  5243. }
  5244. if (!empty($data['city_id'])) {
  5245. $where['city_id'] = $data['city_id'];
  5246. }
  5247. $result = User::where('type_id', 2)
  5248. ->where('status', 1)
  5249. ->where($where)
  5250. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  5251. ->get();
  5252. if (empty($result)) {
  5253. return Result::error("查询失败", 0);
  5254. }
  5255. return Result::success($result);
  5256. }
  5257. /**
  5258. * 验证导航名称是否重复
  5259. * @return void
  5260. */
  5261. public function checkCategoryName(array $data): array
  5262. {
  5263. $result = Category::when($data, function ($query) use ($data) {
  5264. if (isset($data['name']) && $data['name']) {
  5265. $query->where("name", $data['name']);
  5266. }
  5267. if (isset($data['id']) && $data['id']) {
  5268. $query->where("id", "!=", $data['id']);
  5269. }
  5270. })->first();
  5271. if ($result) {
  5272. return Result::error("已存在");
  5273. } else {
  5274. return Result::success();
  5275. }
  5276. }
  5277. //20250226 产品列表
  5278. // 20250306 -------招聘--------fr
  5279. /*
  5280. * 招聘列表
  5281. * */
  5282. public function getJobRecruitingList(array $data): array
  5283. {
  5284. $where = [];
  5285. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  5286. if ($data['checkout'] == 0) {
  5287. $job_status = [0, 2];
  5288. } else {
  5289. $job_status = [1];
  5290. }
  5291. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5292. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  5293. }
  5294. $user = User::where('id', $data['user_id'])->first();
  5295. if (empty($user)) {
  5296. return Result::error("用户不存在", 0);
  5297. }
  5298. // 3:企业会员
  5299. if ($user['type_id'] == 3) {
  5300. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  5301. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  5302. }
  5303. // 如果 $where 为空,则不添加 where 条件
  5304. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5305. return $query->where($where);
  5306. })
  5307. ->whereIn('job_recruiting.status', $job_status)
  5308. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5309. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  5310. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  5311. ->orderBy("updated_at", "desc")
  5312. ->offset(($data['page'] - 1) * $data['page_size'])
  5313. ->limit($data['page_size'])
  5314. ->get()
  5315. ->all();
  5316. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5317. return $query->where($where);
  5318. })
  5319. ->whereIn('job_recruiting.status', $job_status)
  5320. ->count();
  5321. if (empty($result)) {
  5322. return Result::error("暂无招聘信息", 0);
  5323. }
  5324. return Result::success($result);
  5325. }
  5326. /*
  5327. * 招聘信息添加
  5328. * */
  5329. public function addJobRecruiting(array $data): array
  5330. {
  5331. // var_dump('添加招聘进入news------data',$data);
  5332. // return Result::success($data);
  5333. $user = User::where('user.id', $data['user_id'])
  5334. ->where('user.status', 1)
  5335. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5336. ->select(
  5337. 'user.type_id',
  5338. 'user.mobile',
  5339. 'user.email',
  5340. 'user_info.business_name',
  5341. 'user_info.company_hy_id',
  5342. 'user_info.company_nature',
  5343. 'user_info.company_size',
  5344. 'user_info.introduction',
  5345. 'user_info.real_name',
  5346. 'user_info.company_url',
  5347. 'user_info.address_arr_id',
  5348. 'user_info.address'
  5349. )
  5350. ->first();
  5351. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5352. return Result::error("用户不存在", 0);
  5353. }
  5354. $web = Website::where('id', $data['website_id'])->first();
  5355. if (empty($web)) {
  5356. return Result::error("网站不存在", 0);
  5357. }
  5358. // var_dump('添加招聘进入news---user---user',$user);
  5359. // 处理招聘关键词
  5360. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5361. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5362. } else {
  5363. Jieba::init(); // 初始化 jieba-php
  5364. Finalseg::init();
  5365. $segList = Jieba::cut($data['title']);
  5366. $segList1 = array_slice($segList, 0, 8);
  5367. $data['keyword'] = implode(',', $segList1);
  5368. }
  5369. if (!isset($data['seo_description']) || empty($data['seo_description'])) {
  5370. $content = $data['description'];
  5371. // 去除 <style> 和 <script> 标签及其内容
  5372. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5373. // 去除所有 HTML 标签
  5374. $content = strip_tags($content);
  5375. // 去除 HTML 实体
  5376. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5377. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5378. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5379. // 去除多余空白
  5380. $content = preg_replace('/\s+/u', '', $content);
  5381. // 截取 100 个字符
  5382. $data['seo_description'] = mb_substr($content, 0, 100);
  5383. }
  5384. // return Result::success($user);
  5385. $data['action_id'] = $data['user_id'] ?? null;
  5386. $data['user_type'] = $user['type_id'] ?? null;
  5387. $data['cat_arr_id'] = isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) ? array_values(array_unique($data['cat_arr_id'])) : [];
  5388. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5389. $data['catid'] = end($data['cat_arr_id']);
  5390. } else {
  5391. $data['catid'] = 0;
  5392. }
  5393. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? array_values(array_unique($data['city_arr_id'])) : [];
  5394. $data['cat_arr_id'] = isset($data['cat_arr_id']) && $data['cat_arr_id'] != [] ? json_encode(array_map('intval', $data['cat_arr_id'])) : '[]';
  5395. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '[]';
  5396. // 公司地址 管理员必填
  5397. $data['address_arr_id'] = isset($data['address_arr_id']) && !empty($data['address_arr_id']) ? array_values(array_unique($data['address_arr_id'])) : [];
  5398. $data['address_arr_id'] = isset($data['address_arr_id']) && $data['address_arr_id'] != [] ? json_encode(array_map('intval', $data['address_arr_id'])) : '[]';
  5399. // 管理员-企业相关信息
  5400. $company = [
  5401. // 'user_id' => $data['user_id']?? null,
  5402. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5403. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5404. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5405. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5406. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5407. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5408. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5409. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5410. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5411. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5412. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5413. ];
  5414. //去掉相关企业信息
  5415. $job = array_diff_key($data, array_flip(array_keys($company)));
  5416. // var_dump('添加招聘进入news---job---user',$job);
  5417. Db::beginTransaction();
  5418. try {
  5419. // // 先添加职位相关信息
  5420. if ($user['type_id'] == 10000) {
  5421. $job['status'] = 1;
  5422. }
  5423. $job['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5424. $job['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5425. $job['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5426. $job['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5427. $job['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5428. $job['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5429. $job['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5430. // return Result::success($job);
  5431. $jobId = JobRecruiting::insertGetId($job);
  5432. if (empty($jobId)) {
  5433. Db::rollBack();
  5434. return Result::error("添加失败");
  5435. }
  5436. // 添加公司信息
  5437. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5438. $company['job_id'] = $jobId;
  5439. $company['user_type'] = isset($user['type_id']) && $user['type_id'] !== '' ? $user['type_id'] : null;
  5440. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5441. if ($user['type_id'] == 10000) {
  5442. // 管理员添加企业信息
  5443. $companyId = JobCompany::insertGetId($company);
  5444. if (empty($companyId)) {
  5445. Db::rollBack();
  5446. return Result::error("添加失败");
  5447. }
  5448. } else {
  5449. // 企业会员添加企业信息
  5450. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5451. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5452. $company['user_type'] = isset($data['user_type']) && $data['user_type'] !== '' ? $data['user_type'] : null;
  5453. $company['job_id'] = $jobId;
  5454. $companyId = JobCompany::insertGetId($company);
  5455. if (empty($companyId)) {
  5456. Db::rollBack();
  5457. return Result::error("添加失败");
  5458. }
  5459. }
  5460. Db::commit();
  5461. $result = [
  5462. 'job_id' => $jobId,
  5463. 'company_id' => $companyId,
  5464. ];
  5465. return Result::success($result);
  5466. } catch (\Exception $e) {
  5467. Db::rollBack();
  5468. return Result::error($e->getMessage(), 0);
  5469. }
  5470. // return Result::success($result);
  5471. }
  5472. /*
  5473. * 获取招聘信息详情
  5474. * */
  5475. public function getJobRecruitingInfo(array $data): array
  5476. {
  5477. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  5478. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5479. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5480. ->select(
  5481. 'job_recruiting.*',
  5482. 'website.website_name as website_name',
  5483. 'job_company.business_name',
  5484. 'job_company.company_hy_id',
  5485. 'job_company.company_size',
  5486. 'job_company.company_nature',
  5487. 'job_company.introduction',
  5488. 'job_company.real_name',
  5489. 'job_company.mobile',
  5490. 'job_company.company_url',
  5491. 'job_company.address_arr_id',
  5492. 'job_company.address',
  5493. 'job_company.email'
  5494. )
  5495. ->first();
  5496. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  5497. if (!empty($cityId)) {
  5498. if (isset($cityId[1]) && $cityId[1] != null) {
  5499. $city = District::where('id', $cityId[1])->first(['name']);
  5500. } else {
  5501. $city = District::where('id', $cityId[0])->first(['name']);
  5502. }
  5503. $result['city'] = $city['name'] ?? '';
  5504. }
  5505. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  5506. if (is_array($addressId) && !empty($addressId)) {
  5507. $address = District::whereIn('id', $addressId)
  5508. ->orderBy('level', 'asc')
  5509. ->get(['name'])
  5510. ->pluck('name')
  5511. ->implode('');
  5512. // $job->address_name = $address ?? '';
  5513. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  5514. }
  5515. if (empty($result)) {
  5516. return Result::error("招聘信息不存在", 0);
  5517. }
  5518. // return Result::success($job);
  5519. return Result::success($result);
  5520. }
  5521. /*
  5522. * 修改招聘信息
  5523. * */
  5524. public function upJobRecruiting(array $data): array
  5525. {
  5526. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  5527. // return Result::success($job);
  5528. if (empty($job)) {
  5529. return Result::error("招聘信息不存在", 0);
  5530. }
  5531. $user = User::where('id', $data['user_id'])->first();
  5532. // return Result::success($user);
  5533. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5534. return Result::error("用户不存在", 0);
  5535. }
  5536. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5537. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5538. }
  5539. // 处理招聘关键词
  5540. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5541. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5542. } else {
  5543. Jieba::init(); // 初始化 jieba-php
  5544. Finalseg::init();
  5545. $segList = Jieba::cut($data['title']);
  5546. $segList1 = array_slice($segList, 0, 8);
  5547. $data['keyword'] = implode(',', $segList1);
  5548. }
  5549. if(!isset($data['seo_description']) || empty($data['seo_description'])){
  5550. $content = $data['description'];
  5551. // 去除 <style> 和 <script> 标签及其内容
  5552. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5553. // 去除所有 HTML 标签
  5554. $content = strip_tags($content);
  5555. // 去除 HTML 实体
  5556. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5557. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5558. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5559. // 去除多余空白
  5560. $content = preg_replace('/\s+/u', '', $content);
  5561. // 截取 100 个字符
  5562. $data['seo_description'] = mb_substr($content, 0, 100);
  5563. }
  5564. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  5565. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5566. $data['catid'] = end($data['cat_arr_id']);
  5567. } else {
  5568. }
  5569. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  5570. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  5571. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  5572. // 公司地址 管理员必填
  5573. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  5574. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5575. // 管理员-企业相关信息
  5576. $company = [
  5577. // 'user_id' => $data['user_id']?? null,
  5578. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5579. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5580. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5581. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5582. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5583. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5584. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5585. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5586. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5587. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5588. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5589. ];
  5590. //去掉相关企业信息
  5591. $data = array_diff_key($data, array_flip(array_keys($company)));
  5592. $jobId = $data['id'];
  5593. $web = $data['website_id'];
  5594. $data['action_id'] = $data['user_id'];
  5595. unset($data['user_id']);
  5596. unset($data['user_type']);
  5597. unset($data['id']);
  5598. unset($data['website_id']);
  5599. // return Result::success($data);
  5600. Db::beginTransaction();
  5601. try {
  5602. // 管理员修改招聘信息
  5603. if ($user['type_id'] == 10000) {
  5604. $data['website_id'] = $web;
  5605. $company['website_id'] = $data['website_id'];
  5606. $data['status'] = 1;
  5607. } else {
  5608. $data['status'] = 0;
  5609. }
  5610. $data['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5611. $data['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5612. $data['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5613. $data['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5614. $data['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5615. $data['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5616. $data['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5617. // return Result::success($job);
  5618. // Db::rollBack();
  5619. // return Result::success($company);
  5620. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  5621. $this->sendMessage([
  5622. 'talk_type' => 500,
  5623. 'title' => $data['title'],
  5624. 'content' => '提交了审核',
  5625. 'messageType' => 10,
  5626. ]);
  5627. }
  5628. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  5629. if (empty($result['job'])) {
  5630. Db::rollBack();
  5631. return Result::error("修改招聘信息失败");
  5632. }
  5633. // 管理员修改企业相关信息
  5634. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  5635. if (empty($result['company'])) {
  5636. Db::rollBack();
  5637. return Result::error("修改企业相关信息失败");
  5638. }
  5639. Db::commit();
  5640. // return Result::success($result);
  5641. } catch (\Exception $e) {
  5642. Db::rollBack();
  5643. return Result::error($e->getMessage(), 0);
  5644. }
  5645. return Result::success($result);
  5646. }
  5647. /*
  5648. * 招聘信息删除
  5649. * */
  5650. public function delJobRecruiting(array $data): array
  5651. {
  5652. $user = User::where('id', $data['user_id'])->first();
  5653. if (empty($user)) {
  5654. return Result::error("用户不存在", 0);
  5655. }
  5656. $job = JobRecruiting::where('id', $data['id'])->first();
  5657. if (empty($job)) {
  5658. return Result::error("招聘信息不存在", 0);
  5659. }
  5660. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5661. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5662. }
  5663. Db::beginTransaction();
  5664. try {
  5665. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  5666. if (empty($result['job'])) {
  5667. Db::rollBack();
  5668. return Result::error("删除招聘信息失败");
  5669. }
  5670. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  5671. if (empty($result['company'])) {
  5672. Db::rollBack();
  5673. return Result::error("删除企业相关信息失败");
  5674. }
  5675. Db::commit();
  5676. } catch (\Exception $e) {
  5677. Db::rollBack();
  5678. return Result::error($e->getMessage(), 0);
  5679. }
  5680. return Result::success($result);
  5681. }
  5682. /*
  5683. * 获取公司信息
  5684. * */
  5685. public function getJobCompany(array $data): array
  5686. {
  5687. $user = User::where('user.id', $data['user_id'])
  5688. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5689. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  5690. ->first();
  5691. // return Result::success($user);
  5692. if (empty($user)) {
  5693. return Result::error("用户不存在", 0);
  5694. }
  5695. if ($user['type_id'] == 3) {
  5696. $result = [
  5697. // 'id' => 0,
  5698. 'user_id' => $data['user_id'],
  5699. 'website_id' => $data['website_id'],
  5700. 'business_name' => $user['business_name'], // 企业名称
  5701. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  5702. 'company_nature' => $user['company_nature'], // 公司性质
  5703. 'company_size' => $user['company_size'], // 公司规模
  5704. 'introduction' => $user['introduction'], // 公司简介
  5705. 'real_name' => $user['real_name'], // 企业联系人
  5706. 'mobile' => $user['mobile'], // 企业联系电话
  5707. 'company_url' => $user['company_url'], // 企业网址
  5708. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  5709. 'address' => $user['address'], // 企业地址
  5710. 'email' => $user['email'], // 企业邮箱
  5711. ];
  5712. } else {
  5713. return Result::error("用户类型错误", 0);
  5714. }
  5715. if (empty($result)) {
  5716. return Result::error("公司信息不存在", 0);
  5717. }
  5718. return Result::success($result);
  5719. }
  5720. /*
  5721. * 修改公司信息
  5722. * */
  5723. public function upJobCompany(array $data): array
  5724. {
  5725. // return Result::success($data);
  5726. $user = User::where('user.id', $data['user_id'])
  5727. ->where('user.status', 1)
  5728. ->select('user.user_name', 'user.type_id')
  5729. ->first();
  5730. if (empty($user)) {
  5731. return Result::error("用户不存在", 0);
  5732. }
  5733. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5734. $job_company = JobCompany::where('user_id', $data['user_id'])->first();
  5735. $company = [
  5736. 'business_name' => $data['business_name'], // 企业名称
  5737. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5738. 'company_nature' => $data['company_nature'], // 公司性质
  5739. 'company_size' => $data['company_size'], // 公司规模
  5740. 'introduction' => $data['introduction'], // 公司简介
  5741. // 'real_name' => $data['real_name'], // 企业联系人
  5742. 'company_url' => $data['company_url'], // 企业网址
  5743. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5744. 'address' => $data['address'], // 企业详细地址
  5745. // 'email' => $data['email'], // 企业邮箱
  5746. ];
  5747. if ($user['type_id'] == 3) {
  5748. Db::beginTransaction();
  5749. try {
  5750. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  5751. 'business_name' => $data['business_name'], // 企业名称
  5752. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5753. 'company_nature' => $data['company_nature'], // 公司性质
  5754. 'company_size' => $data['company_size'], // 公司规模
  5755. 'introduction' => $data['introduction'], // 公司简介
  5756. // 'real_name' => $data['real_name'], // 企业联系人
  5757. 'company_url' => $data['company_url'], // 企业网址
  5758. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5759. 'address' => $data['address'], // 企业详细地址
  5760. ]);
  5761. if (empty($result['userinfo'])) {
  5762. Db::rollBack();
  5763. return Result::error('修改企业会员信息失败!');
  5764. }
  5765. $result['user'] = User::where('id', $data['user_id'])->update([
  5766. 'email' => $data['email'], // 企业邮箱
  5767. ]);
  5768. if (empty($result['user'])) {
  5769. Db::rollBack();
  5770. return Result::error('修改个人中心信息失败!');
  5771. }
  5772. // 该企业会员若是未发布招聘信息则暂无该企业会员的企业信息
  5773. if (!empty($job_company)) {
  5774. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  5775. if (empty($result['job_company'])) {
  5776. Db::rollBack();
  5777. return Result::error('修改企业会员信息失败!');
  5778. }
  5779. }
  5780. Db::commit();
  5781. return Result::success($result);
  5782. } catch (\Exception $e) {
  5783. Db::rollBack();
  5784. return Result::error($e->getMessage(), 0);
  5785. }
  5786. } else {
  5787. return Result::error("用户类型错误", 0);
  5788. }
  5789. }
  5790. /*
  5791. * 获取省-市
  5792. * */
  5793. public function getJobRecruitingArea(array $data): array
  5794. {
  5795. if (isset($data['pid']) && $data['pid'] != null) {
  5796. $result = District::where('pid', $data['pid'])->get()->all();
  5797. } else {
  5798. $result = District::where('level', 1)->get()->all();
  5799. }
  5800. if (empty($result)) {
  5801. return Result::error("暂无此省市", 0);
  5802. }
  5803. return Result::success($result);
  5804. }
  5805. /*
  5806. * 获取行业分类
  5807. * */
  5808. public function getIndustry(array $data): array
  5809. {
  5810. $result = JobIndustry::get()->all();
  5811. if (empty($result)) {
  5812. return Result::error("暂无行业分类", 0);
  5813. }
  5814. return Result::success($result);
  5815. }
  5816. /*
  5817. * 获取职位
  5818. * */
  5819. public function getPositionList(array $data): array
  5820. {
  5821. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  5822. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  5823. } else {
  5824. $result = JobPosition::where('zwpid', 0)->get()->all();
  5825. }
  5826. if (empty($result)) {
  5827. return Result::error("暂无此职位", 0);
  5828. }
  5829. return Result::success($result);
  5830. }
  5831. /*
  5832. * 获取工作性质-菜单
  5833. * */
  5834. public function getJobNature(array $data): array
  5835. {
  5836. $result = JobEnum::where('egroup', 'nature')->get()->all();
  5837. if (empty($result)) {
  5838. return Result::error("暂无工作性质", 0);
  5839. }
  5840. return Result::success($result);
  5841. }
  5842. /*
  5843. * 获取工作经验-菜单
  5844. * */
  5845. public function getExperience(array $data): array
  5846. {
  5847. $result = JobEnum::where('egroup', 'years')->get()->all();
  5848. if (empty($result)) {
  5849. return Result::error("暂无工作经验", 0);
  5850. }
  5851. return Result::success($result);
  5852. }
  5853. /*
  5854. * 获取学历-菜单
  5855. * */
  5856. public function getEducation(array $data): array
  5857. {
  5858. $result = JobEnum::where('egroup', 'education')->get()->all();
  5859. if (empty($result)) {
  5860. return Result::error("暂无学历", 0);
  5861. }
  5862. return Result::success($result);
  5863. }
  5864. /*
  5865. * 获取薪资-菜单
  5866. * */
  5867. public function getSalary(array $data): array
  5868. {
  5869. $result = JobEnum::where('egroup', 'income')->get()->all();
  5870. if (empty($result)) {
  5871. return Result::error("暂无薪资", 0);
  5872. }
  5873. return Result::success($result);
  5874. }
  5875. /*
  5876. * 获取语言-菜单
  5877. * */
  5878. public function getLanguage(array $data): array
  5879. {
  5880. $result = JobEnum::where('egroup', 'language')->get()->all();
  5881. if (empty($result)) {
  5882. return Result::error("暂无语言", 0);
  5883. }
  5884. return Result::success($result);
  5885. }
  5886. /*
  5887. * 获取掌握程度-菜单
  5888. * */
  5889. public function getLevel(array $data): array
  5890. {
  5891. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  5892. if (empty($result)) {
  5893. return Result::error("暂无工作性质", 0);
  5894. }
  5895. return Result::success($result);
  5896. }
  5897. // 公司信息
  5898. /*
  5899. * 获取公司性质-菜单
  5900. * */
  5901. public function getCompanyNature(array $data): array
  5902. {
  5903. $result = JobNature::get()->all();
  5904. if (empty($result)) {
  5905. return Result::error("暂无公司性质", 0);
  5906. }
  5907. return Result::success($result);
  5908. }
  5909. /*
  5910. * 获取公司规模-菜单
  5911. * */
  5912. public function getCompanySize(array $data): array
  5913. {
  5914. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  5915. if (empty($result)) {
  5916. return Result::error("暂无公司规模", 0);
  5917. }
  5918. return Result::success($result);
  5919. }
  5920. /*
  5921. * 招聘信息审核
  5922. * */
  5923. public function checkJobRecruiting(array $data): array
  5924. {
  5925. $user = User::where('id', $data['user_id'])->first();
  5926. if (empty($user)) {
  5927. return Result::error("用户不存在", 0);
  5928. }
  5929. $job = JobRecruiting::where('id', $data['id'])->first();
  5930. if (empty($job)) {
  5931. return Result::error("招聘信息不存在", 0);
  5932. }
  5933. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  5934. if ($user['type_id'] != 10000) {
  5935. return Result::error("用户暂无权限审核此招聘信息!", 0);
  5936. }
  5937. // 驳回原因
  5938. if ($data['status'] == 2) {
  5939. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  5940. }
  5941. $data['action_id'] = $data['user_id'];
  5942. unset($data['user_id']);
  5943. if ($data['status'] == 1) {
  5944. $this->sendMessage([
  5945. 'talk_type' => 501,
  5946. 'title' => $job['title'],
  5947. 'content' => '审核通过',
  5948. 'messageType' => 10,
  5949. 'user_id' => $job['user_id'],
  5950. ]);
  5951. }
  5952. if ($data['status'] == 2) {
  5953. $this->sendMessage([
  5954. 'talk_type' => 501,
  5955. 'title' => $job['title'],
  5956. 'content' => '审核拒绝',
  5957. 'messageType' => 10,
  5958. 'user_id' => $job['user_id'],
  5959. ]);
  5960. }
  5961. if ($data['status'] == 0) {
  5962. $this->sendMessage([
  5963. 'talk_type' => 500,
  5964. 'title' => $job['title'],
  5965. 'content' => '提交了审核',
  5966. 'messageType' => 10,
  5967. ]);
  5968. }
  5969. $result = JobRecruiting::where('id', $data['id'])->update($data);
  5970. if (empty($result)) {
  5971. return Result::error("审核失败", 0);
  5972. }
  5973. return Result::success($result);
  5974. }
  5975. public function myApplyList(array $data): array
  5976. {
  5977. var_dump($data, '------参数');
  5978. $user = User::where('id', $data['user_id'])->first();
  5979. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5980. return Result::error("用户不存在", 0);
  5981. }
  5982. // 1:个人会员 职场机会
  5983. if ($user['type_id'] == 1) {
  5984. $where['user_id'] = $user['id'];
  5985. }
  5986. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  5987. $query->where('user_id', $user['id']);
  5988. })
  5989. ->pluck('recruit_id');
  5990. $where = [];
  5991. if (isset($data['salary']) && $data['salary'] != null) {
  5992. $where['job_recruiting.salary'] = $data['salary'];
  5993. }
  5994. if (isset($data['experience']) && $data['experience'] != null) {
  5995. $where['job_recruiting.experience'] = $data['experience'];
  5996. }
  5997. if (isset($data['business_name']) && $data['business_name'] != null) {
  5998. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  5999. }
  6000. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6001. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6002. ->where($where);
  6003. // ->count();
  6004. $count = $query->count();
  6005. $query = clone $query;
  6006. $job = $query
  6007. ->leftJoin('job_enum as income_enum', function ($join) {
  6008. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6009. ->where('income_enum.egroup', 'income');
  6010. })
  6011. ->leftJoin('job_enum as years_enum', function ($join) {
  6012. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6013. ->where('years_enum.egroup', 'years');
  6014. })
  6015. // ->where($where)
  6016. ->orderBy('job_recruiting.updated_at', 'desc')
  6017. ->select(
  6018. 'job_recruiting.id',
  6019. 'job_recruiting.title',
  6020. 'job_company.business_name',
  6021. 'income_enum.evalue as salary_evalue',
  6022. 'income_enum.ename as salary_ename',
  6023. 'years_enum.evalue as experience_evalue',
  6024. 'years_enum.ename as experience_ename',
  6025. 'job_recruiting.updated_at'
  6026. )
  6027. ->offset(($data['page'] - 1) * $data['pageSize'])
  6028. ->limit($data['pageSize'])
  6029. ->get()
  6030. ->all();
  6031. if (empty($job)) {
  6032. return Result::error("暂无招聘信息", 0);
  6033. }
  6034. $result = [
  6035. 'row' => $job,
  6036. 'count' => $count,
  6037. ];
  6038. return Result::success($result);
  6039. }
  6040. public function readJobApply(array $data): array
  6041. {
  6042. $result = JobApply::where('id', $data['id'])->first();
  6043. if (empty($result)) {
  6044. return Result::error("查询失败", 0);
  6045. }
  6046. $result = JobApply::where('id', $data['id'])->update([
  6047. 'status' => 2,
  6048. ]);
  6049. return Result::success($result);
  6050. }
  6051. /*
  6052. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  6053. * */
  6054. public function getRecruitingList(array $data): array
  6055. {
  6056. $user = User::where('id', $data['user_id'])->first();
  6057. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6058. return Result::error("用户不存在", 0);
  6059. }
  6060. // 1:个人会员 职场机会
  6061. if ($user['type_id'] == 1) {
  6062. $where['user_id'] = $user['id'];
  6063. }
  6064. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  6065. $query->where('receiver_id', $user['id']);
  6066. })
  6067. ->pluck('recruit_id');
  6068. // return Result::success($recruitingId);
  6069. $where = [];
  6070. if (isset($data['salary']) && $data['salary'] != null) {
  6071. $where['job_recruiting.salary'] = $data['salary'];
  6072. }
  6073. if (isset($data['experience']) && $data['experience'] != null) {
  6074. $where['job_recruiting.experience'] = $data['experience'];
  6075. }
  6076. if (isset($data['business_name']) && $data['business_name'] != null) {
  6077. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6078. }
  6079. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6080. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6081. ->where($where);
  6082. // ->count();
  6083. $count = $query->count();
  6084. $query = clone $query;
  6085. $job = $query
  6086. ->leftJoin('job_enum as income_enum', function ($join) {
  6087. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6088. ->where('income_enum.egroup', 'income');
  6089. })
  6090. ->leftJoin('job_enum as years_enum', function ($join) {
  6091. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6092. ->where('years_enum.egroup', 'years');
  6093. })
  6094. // ->where($where)
  6095. ->orderBy('job_recruiting.updated_at', 'desc')
  6096. ->select(
  6097. 'job_recruiting.id',
  6098. 'job_recruiting.title',
  6099. 'job_company.business_name',
  6100. 'income_enum.evalue as salary_evalue',
  6101. 'income_enum.ename as salary_ename',
  6102. 'years_enum.evalue as experience_evalue',
  6103. 'years_enum.ename as experience_ename',
  6104. 'job_recruiting.updated_at'
  6105. )
  6106. ->offset(($data['page'] - 1) * $data['pageSize'])
  6107. ->limit($data['pageSize'])
  6108. ->get()
  6109. ->all();
  6110. if (empty($job)) {
  6111. return Result::error("暂无招聘信息", 0);
  6112. }
  6113. $result = [
  6114. 'row' => $job,
  6115. 'count' => $count,
  6116. ];
  6117. return Result::success($result);
  6118. }
  6119. /*
  6120. * 获取企业会员-招聘信息列表
  6121. * */
  6122. public function getRecruitingInfo(array $data): array
  6123. {
  6124. $user = User::where('id', $data['user_id'])->first();
  6125. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6126. return Result::error("用户不存在", 0);
  6127. }
  6128. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  6129. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6130. ->select(
  6131. 'job_recruiting.*',
  6132. 'job_company.business_name',
  6133. 'job_company.company_hy_id',
  6134. 'job_company.company_size',
  6135. 'job_company.company_nature',
  6136. 'job_company.introduction',
  6137. 'job_company.real_name',
  6138. 'job_company.mobile',
  6139. 'job_company.company_url',
  6140. 'job_company.address_arr_id',
  6141. 'job_company.address',
  6142. 'job_company.email'
  6143. )
  6144. ->get();
  6145. if (empty($recruiting)) {
  6146. return Result::error("暂无招聘信息", 0);
  6147. }
  6148. return Result::success($recruiting);
  6149. }
  6150. /*
  6151. * 获取企业会员-我的沟通
  6152. * */
  6153. public function getJobResumeList(array $data): array
  6154. {
  6155. $user = User::where('id', $data['user_id'])->first();
  6156. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  6157. return Result::error("用户不存在", 0);
  6158. }
  6159. $where = [];
  6160. if (isset($data['salary']) && $data['salary'] != null) {
  6161. $where['job_hunting.salary'] = $data['salary'];
  6162. }
  6163. if (isset($data['user_name']) && $data['user_name'] != null) {
  6164. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  6165. }
  6166. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  6167. $query->where('job_resume.user_id', $user['id']);
  6168. })
  6169. ->when(!empty($where), function ($query) use ($where) {
  6170. $query->where($where);
  6171. })
  6172. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  6173. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  6174. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  6175. ->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');
  6176. $count = $job->count();
  6177. if ($count == 0) {
  6178. return Result::error("暂无沟通记录", 0);
  6179. }
  6180. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  6181. ->offset(($data['page'] - 1) * $data['pageSize'])
  6182. ->limit($data['pageSize'])
  6183. ->get();
  6184. if (empty($jobs)) {
  6185. return Result::error("暂无沟通记录", 0);
  6186. }
  6187. $result['row'] = $this->processJob($jobs, '');
  6188. $result['count'] = $count;
  6189. return Result::success($result);
  6190. }
  6191. public function readJobResume(array $data): array
  6192. {
  6193. $result = JobResume::where('id', $data['id'])->first();
  6194. if (empty($result)) {
  6195. return Result::error("查询失败", 0);
  6196. }
  6197. $result = JobResume::where('id', $data['id'])->update([
  6198. 'status' => 2,
  6199. ]);
  6200. return Result::success($result);
  6201. }
  6202. // 20250306 招聘
  6203. //20250422 书刊音像
  6204. public function addBook(array $data): array
  6205. {
  6206. $user_id = $data['user_id'] ?? 0;
  6207. $type_id = $data['type_id'] ?? 0;
  6208. // $website_id = $data['website_id'] ?? 0;
  6209. // unset($data['user_id']);
  6210. unset($data['type_id']);
  6211. // unset($data['website_id']);
  6212. //处理数组
  6213. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6214. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6215. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6216. if ($data['img_url'] == '') {
  6217. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6218. preg_match_all($reg, $data['detail'], $matches);
  6219. if (isset($matches[1][0])) {
  6220. //截取varchar240
  6221. $data['img_url'] = substr($matches[1][0], 0, 240);
  6222. }
  6223. }
  6224. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  6225. //提取标题+内容中的关键词
  6226. $data['keyword'] = $data['title'];
  6227. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6228. Jieba::init(); // 初始化 jieba-php
  6229. Finalseg::init();
  6230. $segList = Jieba::cut($data['keyword']);
  6231. $segList1 = array_slice($segList, 0, 8);
  6232. $data['keyword'] = implode(',', $segList1);
  6233. }
  6234. if ($data['description'] == '') {
  6235. //提取内容中的描述
  6236. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6237. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6238. }
  6239. var_dump($data, '--');
  6240. if ($data['status'] == 1) {
  6241. $this->sendMessage([
  6242. 'talk_type' => 400,
  6243. 'title' => $data['title'],
  6244. 'content' => '提交了审核',
  6245. 'messageType' => 7,
  6246. ]);
  6247. }
  6248. $result = Book::insertGetId($data);
  6249. if (empty($result)) {
  6250. return Result::error("添加失败", 0);
  6251. }
  6252. return Result::success($result);
  6253. }
  6254. public function getBookList(array $data): array
  6255. {
  6256. $where = [];
  6257. if (!empty($data["title"])) {
  6258. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  6259. }
  6260. if (!empty($data['website_name'])) {
  6261. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  6262. }
  6263. if (!empty($data['status'])) {
  6264. $where[] = ['book.status', '=', $data['status']];
  6265. }
  6266. $user_id = $data['user_id'];
  6267. $type_id = $data['type_id'];
  6268. // $type_id = 4;
  6269. var_dump($type_id, '------1--------');
  6270. if ($type_id != 10000) {
  6271. $where[] = ['book.user_id', '=', $user_id];
  6272. }
  6273. var_dump(!empty($data['status1']), '=-===1');
  6274. $result = Book::where($where)
  6275. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  6276. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  6277. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  6278. ->when(isset($data['status1']), function ($query) use ($data) {
  6279. $query->whereIn('book.status', [1, 3]);
  6280. })
  6281. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  6282. ->orderBy("updated_at", "desc")
  6283. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  6284. if (empty($result)) {
  6285. return Result::error("暂无数据", 0);
  6286. }
  6287. // 取出数据
  6288. $rows = $result->items();
  6289. $count = $result->total();
  6290. $responseData = [
  6291. 'rows' => $rows,
  6292. 'count' => $count,
  6293. ];
  6294. return Result::success($responseData);
  6295. }
  6296. public function deleteBook(array $data): array
  6297. {
  6298. $result = Book::where('id', $data['id'])->delete();
  6299. if (empty($result)) {
  6300. return Result::error("删除失败", 0);
  6301. }
  6302. return Result::success($result);
  6303. }
  6304. public function updateBook(array $data): array
  6305. {
  6306. // $user_id = $data['user_id'] ?? 0;
  6307. $type_id = $data['type_id'] ?? 0;
  6308. // $website_id = $data['website_id'] ?? 0;
  6309. unset($data['user_id']);
  6310. unset($data['type_id']);
  6311. // unset($data['website_id']);
  6312. //处理数组
  6313. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6314. if ($data['img_url'] == '') {
  6315. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6316. preg_match_all($reg, $data['detail'], $matches);
  6317. if (isset($matches[1][0])) {
  6318. //截取varchar240
  6319. $data['img_url'] = substr($matches[1][0], 0, 240);
  6320. }
  6321. }
  6322. if ($data['keyword'] == '') {
  6323. //提取标题+内容中的关键词
  6324. $data['keyword'] = $data['title'];
  6325. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6326. Jieba::init(); // 初始化 jieba-php
  6327. Finalseg::init();
  6328. $segList = Jieba::cut($data['keyword']);
  6329. $segList1 = array_slice($segList, 0, 8);
  6330. $data['keyword'] = implode(',', $segList1);
  6331. }
  6332. if ($data['description'] == '') {
  6333. //提取内容中的描述
  6334. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6335. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6336. }
  6337. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6338. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6339. if ($data['status'] == 1) {
  6340. $this->sendMessage([
  6341. 'talk_type' => 400,
  6342. 'title' => $data['title'],
  6343. 'content' => '提交了审核',
  6344. 'messageType' => 7,
  6345. ]);
  6346. }
  6347. $result = Book::where("id", $data["id"])->update($data);
  6348. if (empty($result)) {
  6349. return Result::error("更新失败", 0);
  6350. }
  6351. return Result::success($result);
  6352. }
  6353. public function getBookInfo(array $data): array
  6354. {
  6355. $result = Book::where("id", $data["id"])->first();
  6356. if (empty($result)) {
  6357. return Result::error("获取失败", 0);
  6358. }
  6359. return Result::success($result);
  6360. }
  6361. public function updateBookStatus(array $data): array
  6362. {
  6363. //审核
  6364. unset($data['user_id']);
  6365. $bookInfo = Book::where("id", $data["id"])->first();
  6366. var_dump($bookInfo, '----');
  6367. if ($data['status'] == 2) {
  6368. $this->sendMessage([
  6369. 'talk_type' => 401,
  6370. 'title' => $bookInfo['title'],
  6371. 'content' => '审核通过',
  6372. 'messageType' => 7,
  6373. 'user_id' => $bookInfo['user_id'],
  6374. ]);
  6375. }
  6376. if ($data['status'] == 3) {
  6377. $this->sendMessage([
  6378. 'talk_type' => 401,
  6379. 'title' => $bookInfo['title'],
  6380. 'content' => '审核拒绝',
  6381. 'messageType' => 7,
  6382. 'user_id' => $bookInfo['user_id'],
  6383. ]);
  6384. }
  6385. if ($data['status'] == 1) {
  6386. $this->sendMessage([
  6387. 'talk_type' => 400,
  6388. 'title' => $bookInfo['title'],
  6389. 'content' => '提交了审核',
  6390. 'messageType' => 7,
  6391. // 'user_id'=>$bookInfo['user_id'],
  6392. ]);
  6393. }
  6394. $result = Book::where("id", $data["id"])->update($data);
  6395. if (empty($result)) {
  6396. return Result::error("更新失败", 0);
  6397. }
  6398. return Result::success($result);
  6399. }
  6400. //20250422 书刊音像
  6401. /**
  6402. * 贴身宝贝
  6403. * @param array $data
  6404. * @return array
  6405. */
  6406. public function getWebsiteTsbb(array $data): array
  6407. {
  6408. $month = $data['month'] ?? date('m');
  6409. $day = $data['day'] ?? date('d');
  6410. // 使用缓存键
  6411. $cacheKey = "tsbb_data_{$month}_{$day}";
  6412. // 尝试从缓存获取数据
  6413. $container = \Hyperf\Context\ApplicationContext::getContainer();
  6414. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  6415. if ($cachedData = $cache->get($cacheKey)) {
  6416. return Result::success(unserialize($cachedData));
  6417. }
  6418. //查询老黄历
  6419. try {
  6420. $date = date('Y-m-d');
  6421. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  6422. // 使用 curl 替代 file_get_contents
  6423. $ch = curl_init();
  6424. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  6425. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  6426. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  6427. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  6428. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  6429. 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');
  6430. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  6431. 'Accept: application/json',
  6432. 'Content-Type: application/json',
  6433. 'Referer: https://www.36jxs.com/'
  6434. ]);
  6435. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  6436. curl_setopt($ch, CURLOPT_ENCODING, '');
  6437. $almanacResponse = curl_exec($ch);
  6438. var_dump("====:", $almanacResponse);
  6439. if (curl_errno($ch)) {
  6440. var_dump('Curl error:', curl_error($ch));
  6441. throw new \Exception('Curl error: ' . curl_error($ch));
  6442. }
  6443. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  6444. curl_close($ch);
  6445. if ($almanacResponse === false) {
  6446. throw new \Exception('Failed to fetch almanac data');
  6447. }
  6448. $almanacData = json_decode($almanacResponse, true);
  6449. if (json_last_error() !== JSON_ERROR_NONE) {
  6450. throw new \Exception('Failed to parse almanac data');
  6451. }
  6452. $almanacInfo = $almanacData['data'] ?? [];
  6453. } catch (\Exception $e) {
  6454. var_dump('Exception:', $e->getMessage());
  6455. $almanacInfo = [];
  6456. }
  6457. // 获取历史上的今天数据
  6458. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6459. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  6460. ->orderBy('year', 'asc')
  6461. ->select("title", "id", "year", DB::raw('1 as type'))
  6462. ->limit(16)
  6463. ->get();
  6464. // 获取节日数据 - 从今天开始获取未来4条
  6465. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  6466. ->orderBy('showtime', 'asc')
  6467. ->select("title", "id", "showtime", DB::raw('2 as type'))
  6468. ->limit(16)
  6469. ->get();
  6470. //说文解字
  6471. $chartacterList = Character::orderBy('updated_at', 'desc')
  6472. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  6473. ->limit(6)
  6474. ->get();
  6475. //谜语沙龙
  6476. $riddletList = Riddle::orderBy('updated_at', 'desc')
  6477. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  6478. ->limit(4)
  6479. ->get();
  6480. //成语欣赏
  6481. $idiomList = Idiom::orderBy('updated_at', 'desc')
  6482. ->select("id", "title", "duyin", DB::raw('5 as type'))
  6483. ->limit(32)
  6484. ->get();
  6485. //名联赏析
  6486. $coupletList = Couplet::orderBy('updated_at', 'desc')
  6487. ->select("id", "first", "second", DB::raw('6 as type'))
  6488. ->limit(6)
  6489. ->get();
  6490. // 获取分类文章数据
  6491. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  6492. ->pluck('category_id')
  6493. ->toArray();
  6494. $articlesList = [];
  6495. foreach ($categoryIds as $catid) {
  6496. // 先查有图片的
  6497. $withImg = DB::table('article')
  6498. ->where('status', 1)
  6499. ->where('catid', $catid)
  6500. ->whereNotNull('imgurl')
  6501. ->where('imgurl', '!=', '')
  6502. ->orderBy('updated_at', 'desc')
  6503. ->limit(6)
  6504. ->get();
  6505. $count = $withImg->count();
  6506. if ($count < 6) {
  6507. // 不足6条再查无图片的补足
  6508. $withoutImg = DB::table('article')
  6509. ->where('status', 1)
  6510. ->where('catid', $catid)
  6511. ->where(function ($q) {
  6512. $q->whereNull('imgurl')->orWhere('imgurl', '');
  6513. })
  6514. ->orderBy('updated_at', 'desc')
  6515. ->limit(6 - $count)
  6516. ->get();
  6517. $articles = $withImg->concat($withoutImg);
  6518. } else {
  6519. $articles = $withImg;
  6520. }
  6521. // 组装
  6522. $category = \App\Model\Category::find($catid);
  6523. $websiteCategory = WebsiteCategory::where('category_id', $catid)->first();
  6524. $articlesList[] = [
  6525. 'category_name' => $category ? $category->name : '',
  6526. 'catid' => $catid,
  6527. 'pinyin' => $websiteCategory ? $websiteCategory->aLIas_pinyin : '',
  6528. 'type' => 100,
  6529. 'list' => $articles->map(function ($item) {
  6530. return [
  6531. 'id' => $item->id,
  6532. 'title' => $item->title,
  6533. 'imgurl' => $item->imgurl,
  6534. 'created_at' => $item->created_at
  6535. ];
  6536. })->values()
  6537. ];
  6538. }
  6539. $result = [
  6540. 'almanac' => $almanacInfo,
  6541. 'historyTodayList' => [
  6542. 'category_name' => '历史上的今天',
  6543. 'list' => $historyTodayList,
  6544. 'type' => 1
  6545. ],
  6546. 'festivalList' => [
  6547. 'category_name' => '节日预告',
  6548. 'list' => $festivalList,
  6549. 'type' => 2
  6550. ],
  6551. 'chartacterList' => [
  6552. 'category_name' => '说文解字',
  6553. 'list' => $chartacterList,
  6554. 'type' => 3
  6555. ],
  6556. 'coupletList' => [
  6557. 'category_name' => '名联赏析',
  6558. 'list' => $coupletList,
  6559. 'type' => 6
  6560. ],
  6561. 'riddletList' => [
  6562. 'category_name' => '谜语沙龙',
  6563. 'list' => $riddletList,
  6564. 'type' => 4
  6565. ],
  6566. 'idiomList' => [
  6567. 'category_name' => '成语欣赏',
  6568. 'list' => $idiomList,
  6569. 'type' => 5
  6570. ],
  6571. 'articlesList' => $articlesList
  6572. ];
  6573. // 缓存结果,设置1小时过期
  6574. $cache->set($cacheKey, serialize($result), 3600);
  6575. return Result::success($result);
  6576. }
  6577. /**
  6578. * 获取资讯列表
  6579. */
  6580. public function getWebsiteTsbbList(array $data): array
  6581. {
  6582. $page = $data['page'] ?? 1;
  6583. $pageSize = $data['pageSize'] ?? 10;
  6584. // 如果没有传入月份和日期,则使用今天的日期
  6585. $month = $data['month'] ?? date('m');
  6586. $day = $data['day'] ?? date('d');
  6587. $total = 0;
  6588. $result = [];
  6589. $data['type'] = intval($data['type']);
  6590. var_dump("接收参数:", $data);
  6591. switch ($data['type']) {
  6592. case 1:
  6593. $query = HistoryToday::where(function ($q) use ($month, $day) {
  6594. // 当前月份之后的数据
  6595. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  6596. // 或者当前月份且日期大于等于当前日期的数据
  6597. ->orWhere(function ($q) use ($month, $day) {
  6598. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6599. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  6600. });
  6601. })
  6602. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  6603. $total = $query->count();
  6604. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  6605. ->offset(($page - 1) * $pageSize)
  6606. ->limit($pageSize)
  6607. ->get();
  6608. break;
  6609. case 2:
  6610. $query = Festival::where(function ($q) use ($month, $day) {
  6611. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  6612. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  6613. ->orWhere(function ($q) use ($month, $day) {
  6614. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  6615. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  6616. });
  6617. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  6618. $total = $query->count();
  6619. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  6620. ->offset(($page - 1) * $pageSize)
  6621. ->limit($pageSize)
  6622. ->get();
  6623. break;
  6624. case 3:
  6625. $query = Character::orderBy("updated_at", "desc");
  6626. $total = $query->count();
  6627. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  6628. ->offset(($page - 1) * $pageSize)
  6629. ->limit($pageSize)
  6630. ->get();
  6631. break;
  6632. case 4:
  6633. $query = Riddle::orderBy("updated_at", "desc");
  6634. $total = $query->count();
  6635. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  6636. ->offset(($page - 1) * $pageSize)
  6637. ->limit($pageSize)
  6638. ->get();
  6639. break;
  6640. case 5:
  6641. $query = Idiom::orderBy("updated_at", "desc");
  6642. $total = $query->count();
  6643. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  6644. ->offset(($page - 1) * $pageSize)
  6645. ->limit($pageSize)
  6646. ->get();
  6647. break;
  6648. case 6:
  6649. $query = Couplet::orderBy("updated_at", "desc");
  6650. $total = $query->count();
  6651. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  6652. ->offset(($page - 1) * $pageSize)
  6653. ->limit($pageSize)
  6654. ->get();
  6655. break;
  6656. default:
  6657. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  6658. $total = $query->count();
  6659. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  6660. ->offset(($page - 1) * $pageSize)
  6661. ->limit($pageSize)
  6662. ->get();
  6663. }
  6664. return Result::success([
  6665. 'list' => $result,
  6666. 'total' => $total,
  6667. 'page' => (int)$page,
  6668. 'pageSize' => (int)$pageSize,
  6669. 'month' => $month,
  6670. 'day' => $day
  6671. ]);
  6672. }
  6673. /**
  6674. * 1:历史上的今天
  6675. * 2:节日
  6676. * 3:文章
  6677. *
  6678. * 资讯详情信息
  6679. */
  6680. public function getWebsiteTsbbDetail(array $data): array
  6681. {
  6682. $data['type'] = intval($data['type']);
  6683. switch ($data['type']) {
  6684. case 1:
  6685. $result = HistoryToday::where("id", $data['id'])->first();
  6686. break;
  6687. case 2:
  6688. $result = Festival::where("id", $data['id'])->first();
  6689. break;
  6690. case 3:
  6691. $result = Character::where("id", $data['id'])->first();
  6692. break;
  6693. case 4:
  6694. $result = Riddle::where("id", $data['id'])->first();
  6695. break;
  6696. case 5:
  6697. $result = Idiom::where("id", $data['id'])->first();
  6698. break;
  6699. case 6:
  6700. $result = Couplet::where("id", $data['id'])->first();
  6701. break;
  6702. default:
  6703. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  6704. break;
  6705. }
  6706. return Result::success($result);
  6707. }
  6708. /**
  6709. * 农网导航首页数据
  6710. */
  6711. public function getWebsiteNwHomeList(array $data): array
  6712. {
  6713. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  6714. ->pluck('category_id')
  6715. ->toArray();
  6716. // 使用子查询优化
  6717. $articlesList = DB::table('article')
  6718. ->select([
  6719. 'article.id',
  6720. 'article.title',
  6721. 'article.imgurl',
  6722. 'article.created_at',
  6723. 'category.name as category_name',
  6724. 'category.id as category_id',
  6725. 'website_category.aLIas_pinyin as pinyin',
  6726. 'parent_wc.aLIas_pinyin as parent_pinyin',
  6727. DB::raw('100 as type')
  6728. ])
  6729. ->join('category', 'article.catid', '=', 'category.id')
  6730. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  6731. ->leftJoin('website_category as parent_wc', function ($join) {
  6732. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  6733. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  6734. })
  6735. ->where('website_category.website_id', $data['website_id'])
  6736. ->where('article.status', 1)
  6737. ->whereIn('category.id', $categoryIds)
  6738. ->orderBy('article.created_at', 'desc')
  6739. ->get()
  6740. ->groupBy('category_id')
  6741. ->map(function ($group) {
  6742. // 确保第一条数据有图片
  6743. $firstWithImage = $group->first(function ($item) {
  6744. return !empty($item->imgurl);
  6745. });
  6746. if ($firstWithImage) {
  6747. // 如果有带图片的文章,将其放在第一位
  6748. $group = $group->filter(function ($item) use ($firstWithImage) {
  6749. return $item->id !== $firstWithImage->id;
  6750. })->prepend($firstWithImage);
  6751. }
  6752. return [
  6753. 'category_name' => $group->first()->category_name,
  6754. 'catid' => $group->first()->category_id,
  6755. 'pinyin' => $group->first()->pinyin,
  6756. 'parent_pinyin' => $group->first()->parent_pinyin,
  6757. 'list' => $group->take(4)->map(function ($item) {
  6758. return [
  6759. 'id' => $item->id,
  6760. 'title' => $item->title,
  6761. ];
  6762. })->values()
  6763. ];
  6764. })
  6765. ->values()
  6766. ->toArray();
  6767. return Result::success($articlesList);
  6768. }
  6769. /**
  6770. * 企业管理
  6771. * @param array $data
  6772. * @return array
  6773. */
  6774. public function getCompanyList(array $data): array
  6775. {
  6776. // return Result::success($data);
  6777. $where = [];
  6778. $user = User::where('id', $data['user_id'])->first();
  6779. if (empty($user)) {
  6780. return Result::error('用户不存在!');
  6781. }
  6782. if ($user['type_id'] != 10000) {
  6783. $where['user_id'] = $data['user_id'];
  6784. }
  6785. if (isset($data['title']) && !empty($data['title'])) {
  6786. array_push($where, ['company.title', 'like', '%' . $data['title'] . '%']);
  6787. }
  6788. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6789. array_push($where, ['website.id', $data['website_id']]);
  6790. }
  6791. if (isset($data['ischeck']) && !empty($data['ischeck'])) {
  6792. if ($data['ischeck'] == 1) {
  6793. if (isset($data['status']) && $data['status'] != '') {
  6794. array_push($where, ['company.status', $data['status']]);
  6795. $query = Company::where($where);
  6796. } else {
  6797. $query = Company::whereIn('company.status', [0, 2]);
  6798. }
  6799. } else {
  6800. $query = Company::where('company.status', 1);
  6801. }
  6802. }
  6803. $result = $query->where($where)
  6804. ->leftJoin('website_category', function ($query) {
  6805. $query->on('website_category.category_id', '=', 'company.category_id')
  6806. ->on('website_category.website_id', '=', 'company.website_id');
  6807. })
  6808. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  6809. ->select(
  6810. 'company.id',
  6811. 'company.title',
  6812. 'company.website_id',
  6813. 'company.category_id',
  6814. 'website.website_name',
  6815. 'website_category.alias as category_name',
  6816. 'company.status',
  6817. 'company.updated_at',
  6818. 'company.user_id'
  6819. )
  6820. ->orderBy('company.updated_at', 'desc')
  6821. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  6822. if ($result->isEmpty()) {
  6823. return Result::error("暂无企业", 0);
  6824. }
  6825. return Result::success($result);
  6826. }
  6827. /**
  6828. * 添加企业
  6829. * @param array $data
  6830. * @return array
  6831. */
  6832. public function addCompany(array $data): array
  6833. {
  6834. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  6835. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6836. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6837. $data['cat_arr_id'] = json_encode($car_arr_id);
  6838. } else {
  6839. $data['cat_arr_id'] = '';
  6840. }
  6841. if ($data['imgurl'] == '') {
  6842. //content中提取图片第一个图,正则提取
  6843. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6844. preg_match_all($reg, $data['content'], $matches);
  6845. if (isset($matches[1][0])) {
  6846. //截取varchar240
  6847. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6848. }
  6849. }
  6850. if ($data['keyword'] == '') {
  6851. //提取标题+内容中的关键词
  6852. $data['keyword'] = $data['title'];
  6853. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6854. Jieba::init(); // 初始化 jieba-php
  6855. Finalseg::init();
  6856. $segList = Jieba::cut($data['keyword']);
  6857. $segList1 = array_slice($segList, 0, 8);
  6858. $data['keyword'] = implode(',', $segList1);
  6859. }
  6860. if ($data['introduce'] == '' || empty($data['introduce'])) {
  6861. //提取内容中的描述
  6862. $content = $data['content'];
  6863. // 去除 <style> 和 <script> 标签及其内容
  6864. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6865. // 去除所有 HTML 标签
  6866. $content = strip_tags($content);
  6867. // 去除 HTML 实体
  6868. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6869. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6870. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6871. // 去除多余空白
  6872. $content = preg_replace('/\s+/u', '', $content);
  6873. // 截取 100 个字符
  6874. $data['introduce'] = mb_substr($content, 0, 100);
  6875. }
  6876. $user = User::where('id', $data['user_id'])->first();
  6877. if (empty($user)) {
  6878. return Result::error('用户不存在!');
  6879. }
  6880. if ($user['type_id'] == 10000) {
  6881. $data['status'] = 1;
  6882. }
  6883. if (isset($data['level']) && $data['level'] != null) {
  6884. $data['level'] = intval($data['level']);
  6885. } else {
  6886. $data['level'] = null;
  6887. }
  6888. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  6889. $this->sendMessage([
  6890. 'talk_type' => 900,
  6891. 'title' => $data['title'],
  6892. 'content' => '提交了审核',
  6893. 'messageType' => 8,
  6894. ]);
  6895. }
  6896. $result = Company::insertGetId($data);
  6897. if ($result) {
  6898. return Result::success($result);
  6899. } else {
  6900. return Result::error('添加失败');
  6901. }
  6902. }
  6903. /**
  6904. * 更新企业
  6905. * @param array $data
  6906. * @return array
  6907. */
  6908. public function upCompany(array $data): array
  6909. {
  6910. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6911. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6912. $data['cat_arr_id'] = json_encode($car_arr_id);
  6913. $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
  6914. } else {
  6915. $data['cat_arr_id'] = '';
  6916. }
  6917. if ($data['imgurl'] == '') {
  6918. //content中提取图片第一个图,正则提取
  6919. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6920. preg_match_all($reg, $data['content'], $matches);
  6921. if (isset($matches[1][0])) {
  6922. //截取varchar
  6923. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6924. }
  6925. }
  6926. if ($data['keyword'] == '') {
  6927. //提取标题+内容中的关键词
  6928. $data['keyword'] = $data['title'];
  6929. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6930. Jieba::init(); // 初始化 jieba-php
  6931. Finalseg::init();
  6932. $segList = Jieba::cut($data['keyword']);
  6933. $segList1 = array_slice($segList, 0, 8);
  6934. $data['keyword'] = implode(',', $segList1);
  6935. }
  6936. if ($data['introduce'] == '') {
  6937. //提取内容中的描述
  6938. $content = $data['content'];
  6939. // 去除 <style> 和 <script> 标签及其内容
  6940. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6941. // 去除所有 HTML 标签
  6942. $content = strip_tags($content);
  6943. // 去除 HTML 实体
  6944. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6945. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6946. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6947. // 去除多余空白
  6948. $content = preg_replace('/\s+/u', '', $content);
  6949. // 截取 100 个字符
  6950. $data['introduce'] = mb_substr($content, 0, 100);
  6951. }
  6952. if (isset($data['level']) && $data['level'] != null) {
  6953. $data['level'] = intval($data['level']);
  6954. } else {
  6955. $data['level'] = null;
  6956. }
  6957. $user = User::where('id', $data['user_id'])->first();
  6958. if (empty($user)) {
  6959. return Result::error('用户不存在!');
  6960. }
  6961. if ($user['type_id'] == 10000) {
  6962. $data['status'] = 1;
  6963. } else {
  6964. $data['status'] = 0;
  6965. }
  6966. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  6967. $this->sendMessage([
  6968. 'talk_type' => 900,
  6969. 'title' => $data['title'],
  6970. 'content' => '提交了审核',
  6971. 'messageType' => 8,
  6972. ]);
  6973. }
  6974. $result = Company::where('id', $data['id'])->update($data);
  6975. if ($result) {
  6976. return Result::success($result);
  6977. } else {
  6978. return Result::error('修改失败');
  6979. }
  6980. }
  6981. /**
  6982. * 删除企业
  6983. * @param array $data
  6984. * @return array
  6985. */
  6986. public function delCompany(array $data): array
  6987. {
  6988. $result = Company::where('id', $data['id'])->delete();
  6989. if ($result) {
  6990. return Result::success($result);
  6991. } else {
  6992. return Result::error('删除失败');
  6993. }
  6994. }
  6995. /**
  6996. * 审核企业
  6997. * @param array $data
  6998. * @return array
  6999. */
  7000. public function checkCompany(array $data): array
  7001. {
  7002. $user = User::where('id', $data['user_id'])->first();
  7003. if (empty($user)) {
  7004. return Result::error('用户不存在!');
  7005. }
  7006. $company = Company::where('id', $data['id'])->first();
  7007. if (empty($company)) {
  7008. return Result::error('企业不存在!');
  7009. }
  7010. // 状态:0:未审核 1:已审核 2:已拒绝
  7011. if ($data['status'] == 2 || $data['status'] == '2') {
  7012. $this->sendMessage([
  7013. 'talk_type' => 901,
  7014. 'title' => $company['title'],
  7015. 'content' => '审核拒绝',
  7016. 'messageType' => 8,
  7017. 'user_id' => $company['user_id'],
  7018. ]);
  7019. $result = Company::where('id', $data['id'])->update(['status' => $data['status'], 'reject_reason' => $data['reason']]);
  7020. } else {
  7021. if ($data['status'] == 1) {
  7022. $this->sendMessage([
  7023. 'talk_type' => 901,
  7024. 'title' => $company['title'],
  7025. 'content' => '审核通过',
  7026. 'messageType' => 8,
  7027. 'user_id' => $company['user_id'],
  7028. ]);
  7029. } else if ($data['status'] == 0) {
  7030. $this->sendMessage([
  7031. 'talk_type' => 900,
  7032. 'title' => $company['title'],
  7033. 'content' => '提交了审核',
  7034. 'messageType' => 8,
  7035. ]);
  7036. }
  7037. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  7038. }
  7039. if (empty($result)) {
  7040. return Result::error('审核失败!');
  7041. } else {
  7042. return Result::success($result);
  7043. }
  7044. }
  7045. /**
  7046. * 获取企业信息
  7047. * @param array $data
  7048. * @return array
  7049. */
  7050. public function getCompanyInfo(array $data): array
  7051. {
  7052. $result = Company::where('id', $data['id'])->first();
  7053. $city_arr = json_decode($result['city_arr_id']);
  7054. $result['city_name'] = District::whereIn('id', $city_arr)
  7055. ->pluck('name')
  7056. ->implode('-');
  7057. if (empty($result)) {
  7058. return Result::error('企业不存在!');
  7059. } else {
  7060. return Result::success($result);
  7061. }
  7062. }
  7063. /**
  7064. * @param array $data
  7065. * @return array
  7066. */
  7067. public function getWebsiteCompany(array $data): array
  7068. {
  7069. $categorys = json_decode($data['id'], true);
  7070. $category_arr = $this->processArticlePro($data['website_id']);
  7071. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7072. $catiall = $category_arr['catiall'];
  7073. $categoryIds = $category_arr['categoryIds'];
  7074. // return Result::success($category_arr);
  7075. foreach ($categorys as $key => $value) {
  7076. if (array_key_exists('level', $value)) {
  7077. $parts = explode(',', $value['level']);
  7078. $level = $parts[0] ?? null;
  7079. $imgnum = $parts[1] ?? null;
  7080. $textnum = $parts[2] ?? null;
  7081. if (!empty($textnum) && $textnum > 0) {
  7082. $text_num = Company::where('level', $level)
  7083. ->whereIn('category_id', $categoryIds)
  7084. ->where('status', 1)
  7085. ->select(
  7086. 'company.id',
  7087. 'company.title',
  7088. 'company.description',
  7089. 'company.updated_at',
  7090. 'company.category_id',
  7091. 'company.cat_arr_id'
  7092. )
  7093. ->orderBy('updated_at', 'desc')
  7094. ->limit($textnum)
  7095. ->get()->all();
  7096. }
  7097. if (!empty($imgnum) && $imgnum > 0) {
  7098. $img_num = Company::where('level', $level)
  7099. ->whereIn('category_id', $categoryIds)
  7100. ->where('status', 1)
  7101. ->where('imgurl', '!=', '')
  7102. ->whereNotNull('imgurl')
  7103. ->select(
  7104. 'company.id',
  7105. 'company.title',
  7106. 'company.description',
  7107. 'company.updated_at',
  7108. 'company.imgurl as imgs',
  7109. 'company.category_id',
  7110. 'company.cat_arr_id'
  7111. )
  7112. ->orderBy('updated_at', 'desc')
  7113. ->limit($imgnum)
  7114. ->get()->all();
  7115. }
  7116. }
  7117. if (array_key_exists('id', $value)) {
  7118. $parts = explode(',', $value['id']);
  7119. $category_id = $parts[0] ?? null;
  7120. $imgnum = $parts[1] ?? null;
  7121. $textnum = $parts[2] ?? null;
  7122. $category_arr = array_merge([$category_id], $cat_1st_arr[$category_id] ?? [0]);
  7123. if (!empty($textnum) && $textnum > 0) {
  7124. $text_num = Company::whereIn('category_id', $category_arr)
  7125. // ->where('website_id', $data['website_id'])
  7126. ->where('status', 1)
  7127. ->select(
  7128. 'company.id',
  7129. 'company.title',
  7130. 'company.description',
  7131. 'company.updated_at',
  7132. 'company.category_id',
  7133. 'company.cat_arr_id'
  7134. )
  7135. ->orderBy('updated_at', 'desc')
  7136. ->limit($textnum)
  7137. ->get()->all();
  7138. }
  7139. if (!empty($imgnum) && $imgnum > 0) {
  7140. $img_num = Company::whereIn('category_id', $category_arr)
  7141. // ->where('website_id', $data['website_id'])
  7142. ->where('status', 1)
  7143. ->where('imgurl', '!=', '')
  7144. ->whereNotNull('imgurl')
  7145. ->select(
  7146. 'company.id',
  7147. 'company.title',
  7148. 'company.description',
  7149. 'company.updated_at',
  7150. 'company.imgurl as imgs',
  7151. 'company.category_id',
  7152. 'company.cat_arr_id'
  7153. )
  7154. ->orderBy('updated_at', 'desc')
  7155. ->limit($imgnum)
  7156. ->get()->all();
  7157. }
  7158. }
  7159. if (!empty($text_num)) {
  7160. foreach ($text_num as $k => $v) {
  7161. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7162. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7163. }
  7164. }
  7165. if (!empty($img_num)) {
  7166. foreach ($img_num as $k => $v) {
  7167. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7168. $imgurl = json_decode($v['imgs'], true);
  7169. if (!empty($imgurl)) {
  7170. $img_num[$k]->imgurl = $imgurl[0];
  7171. }
  7172. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7173. }
  7174. }
  7175. $company[$key]['img_num'] = $img_num ?? [];
  7176. $company[$key]['text_num'] = $text_num ?? [];
  7177. }
  7178. if (empty($company)) {
  7179. return Result::error("暂无相关企业信息", 0);
  7180. }
  7181. return Result::success($company);
  7182. }
  7183. /**
  7184. * @param array $data
  7185. * @return array
  7186. */
  7187. public function getWebsiteCompanyList(array $data): array
  7188. {
  7189. $where['website_id'] = $data['website_id'];
  7190. $where['status'] = 1;
  7191. $categoryIds = [];
  7192. if (isset($data['category_id']) && !empty($data['category_id'])) {
  7193. $category_id = $data['category_id'];
  7194. }
  7195. $category_arr = $this->processArticlePro($data['website_id']);
  7196. $categoryIds = $category_arr['categoryIds'];
  7197. // return Result::success($cat_1st_arr);
  7198. $company = Company::when(isset($data['keyword']) && !empty($data['keyword']), function ($query) use ($data) {
  7199. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  7200. })
  7201. ->when(!isset($category_id) || empty($category_id), function ($query) use ($categoryIds) {
  7202. $query->whereIn('category_id', $categoryIds);
  7203. })
  7204. ->when(isset($data['category_id']) && !empty($data['category_id']), function ($query) use ($category_id) {
  7205. $query->where('category_id', $category_id);
  7206. })
  7207. ->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id', 'updated_at')
  7208. ->orderBy('updated_at', 'desc')
  7209. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  7210. if (empty($company)) {
  7211. return Result::error("暂无相关公司信息", 0);
  7212. }
  7213. $result = [
  7214. 'count' => $company->total(),
  7215. 'data' => $company->items(), // 使用 items() 方法替代不存在的 data() 方法
  7216. ];
  7217. return Result::success($result);
  7218. }
  7219. /**
  7220. * 获取项目列表
  7221. * @param array $data
  7222. * @return array
  7223. */
  7224. public function getProjectList(array $data): array
  7225. {
  7226. $where = [];
  7227. $user = User::where('id', $data['user_id'])->first();
  7228. if (empty($user)) {
  7229. return Result::error('用户不存在!');
  7230. }
  7231. if ($user->type_id != 10000) {
  7232. array_push($where, ['project.user_id', $data['user_id']]);
  7233. }
  7234. $query = Project::query();
  7235. if (isset($data['website_id']) && !empty($data['website_id'])) {
  7236. array_push($where, ['project.website_id', $data['website_id']]);
  7237. }
  7238. if (isset($data['title']) && !empty($data['title'])) {
  7239. array_push($where, ['project.title', 'like', '%' . $data['title'] . '%']);
  7240. }
  7241. if ($data['status'] != 3) {
  7242. array_push($where, ['project.status', $data['status']]);
  7243. }
  7244. $query = Project::where($where)
  7245. ->when($data['status'] == 3, function ($query) {
  7246. $query->whereIn('project.status', [0, 2]);
  7247. });
  7248. $count = $query->clone()
  7249. ->count();
  7250. $rows = $query->clone()
  7251. ->leftJoin('website', 'project.website_id', 'website.id')
  7252. ->leftJoin('website_category', function ($join) {
  7253. $join->on('project.website_id', '=', 'website_category.website_id')
  7254. ->on('project.category_id', '=', 'website_category.category_id');
  7255. })
  7256. ->select(
  7257. 'project.id',
  7258. 'project.title',
  7259. 'project.updated_at',
  7260. 'project.status',
  7261. 'website.website_name',
  7262. 'website_category.alias as category_name',
  7263. 'project.website_id',
  7264. 'project.user_id'
  7265. )
  7266. ->orderBy('project.updated_at', 'desc')
  7267. ->offset(($data['page'] - 1) * $data['pageSize'])
  7268. ->limit($data['pageSize'])
  7269. ->get();
  7270. if ($rows->isEmpty()) {
  7271. return Result::error("暂无相关项目信息", 0);
  7272. }
  7273. $result = [
  7274. 'count' => $count,
  7275. 'rows' => $rows,
  7276. ];
  7277. return Result::success($result);
  7278. }
  7279. /**
  7280. * 添加项目
  7281. * @param array $data
  7282. * @return array
  7283. */
  7284. public function addProject(array $data): array
  7285. {
  7286. $user = User::where('id', $data['user_id'])->first();
  7287. if (empty($user)) {
  7288. return Result::error("暂无相关用户信息", 0);
  7289. }
  7290. if ($user->type_id == 10000) {
  7291. $data['status'] = 1;
  7292. } else {
  7293. $data['status'] = 0;
  7294. }
  7295. if ($data['keyword'] == '') {
  7296. //提取标题+内容中的关键词
  7297. $data['keyword'] = $data['title'];
  7298. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7299. Jieba::init(); // 初始化 jieba-php
  7300. Finalseg::init();
  7301. $segList = Jieba::cut($data['keyword']);
  7302. $segList1 = array_slice($segList, 0, 8);
  7303. $data['keyword'] = implode(',', $segList1);
  7304. }
  7305. if ($data['description'] == '') {
  7306. //提取内容中的描述
  7307. // var_dump(11111);
  7308. //提取内容中的描述
  7309. $content = $data['introduce'];
  7310. // 去除 <style> 和 <script> 标签及其内容
  7311. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7312. // 去除所有 HTML 标签
  7313. $content = strip_tags($content);
  7314. // 去除 HTML 实体
  7315. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7316. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7317. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7318. // 去除多余空白
  7319. $content = preg_replace('/\s+/u', '', $content);
  7320. // 截取 100 个字符
  7321. $data['description'] = mb_substr($content, 0, 100);
  7322. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7323. }
  7324. if ($data['status'] == 0) {
  7325. $this->sendMessage([
  7326. 'talk_type' => 1000,
  7327. 'title' => $data['title'],
  7328. 'content' => '提交了审核',
  7329. 'messageType' => 9,
  7330. ]);
  7331. }
  7332. $project = Project::insertGetId($data);
  7333. if (empty($project)) {
  7334. return Result::error("暂无相关项目信息", 0);
  7335. }
  7336. return Result::success($project);
  7337. }
  7338. /**
  7339. * 更新项目
  7340. * @param array $data
  7341. * @return array
  7342. */
  7343. public function upProject(array $data): array
  7344. {
  7345. $project = Project::where('id', $data['id'])->first();
  7346. if (empty($project)) {
  7347. return Result::error("暂无相关项目信息", 0);
  7348. }
  7349. $id = $data['id'];
  7350. unset($data['id']);
  7351. $user = User::where('id', $data['user_id'])->first();
  7352. if (empty($user)) {
  7353. return Result::error("暂无相关用户信息", 0);
  7354. }
  7355. if ($user->type_id == 10000) {
  7356. $data['status'] = 1;
  7357. } else {
  7358. $data['status'] = 0;
  7359. }
  7360. unset($data['user_id']);
  7361. if ($data['keyword'] == '') {
  7362. //提取标题+内容中的关键词
  7363. $data['keyword'] = $data['title'];
  7364. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7365. Jieba::init(); // 初始化 jieba-php
  7366. Finalseg::init();
  7367. $segList = Jieba::cut($data['keyword']);
  7368. $segList1 = array_slice($segList, 0, 8);
  7369. $data['keyword'] = implode(',', $segList1);
  7370. }
  7371. if ($data['description'] == '') {
  7372. //提取内容中的描述
  7373. // var_dump(11111);
  7374. //提取内容中的描述
  7375. $content = $data['introduce'];
  7376. // 去除 <style> 和 <script> 标签及其内容
  7377. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7378. // 去除所有 HTML 标签
  7379. $content = strip_tags($content);
  7380. // 去除 HTML 实体
  7381. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7382. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7383. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7384. // 去除多余空白
  7385. $content = preg_replace('/\s+/u', '', $content);
  7386. // 截取 100 个字符
  7387. $data['description'] = mb_substr($content, 0, 100);
  7388. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7389. }
  7390. if ($data['status'] == 0) {
  7391. $this->sendMessage([
  7392. 'talk_type' => 1000,
  7393. 'title' => $data['title'],
  7394. 'content' => '提交了审核',
  7395. 'messageType' => 9,
  7396. ]);
  7397. }
  7398. $result = Project::where('id', $id)->update($data);
  7399. if (empty($result)) {
  7400. return Result::error("更新失败", 0);
  7401. }
  7402. return Result::success($result);
  7403. }
  7404. /**
  7405. * 删除项目
  7406. * @param array $data
  7407. * @return array
  7408. */
  7409. public function delProject(array $data): array
  7410. {
  7411. $user = User::where('id', $data['user_id'])->first();
  7412. if (empty($user)) {
  7413. return Result::error("暂无相关用户信息", 0);
  7414. }
  7415. $project = Project::where('id', $data['id'])->first();
  7416. if (empty($project)) {
  7417. return Result::error("暂无相关项目信息", 0);
  7418. }
  7419. $result = Project::where('id', $data['id'])->delete();
  7420. if (empty($result)) {
  7421. return Result::error("删除失败", 0);
  7422. }
  7423. return Result::success($result);
  7424. }
  7425. /**
  7426. * 审核项目
  7427. * @param array $data
  7428. * @return array
  7429. */
  7430. public function checkProject(array $data): array
  7431. {
  7432. $user = User::where('id', $data['user_id'])->first();
  7433. if (empty($user)) {
  7434. return Result::error("暂无相关用户信息", 0);
  7435. }
  7436. // 0:未审核; 1:已审核; 2:已拒绝;
  7437. if ($user->type_id != 10000) {
  7438. if ($data['status'] == 1 || $data['status'] == 2) {
  7439. return Result::error("此用户权限不足", 0);
  7440. }
  7441. }
  7442. $project = Project::where('id', $data['id'])->first();
  7443. if (empty($project)) {
  7444. return Result::error("暂无相关项目信息", 0);
  7445. }
  7446. if ($data['status'] == 2) {
  7447. $this->sendMessage([
  7448. 'talk_type' => 1001,
  7449. 'title' => $project['title'],
  7450. 'content' => '审核拒绝',
  7451. 'messageType' => 9,
  7452. 'user_id' => $project['user_id'],
  7453. ]);
  7454. $result = Project::where('id', $data['id'])->update(['status' => $data['status'], 'refuse_reason' => $data['refuse_reason']]);
  7455. } else {
  7456. if ($data['status'] == 1) {
  7457. $this->sendMessage([
  7458. 'talk_type' => 1001,
  7459. 'title' => $project['title'],
  7460. 'content' => '审核通过',
  7461. 'messageType' => 9,
  7462. 'user_id' => $project['user_id'],
  7463. ]);
  7464. } else if ($data['status'] == 0) {
  7465. $this->sendMessage([
  7466. 'talk_type' => 1000,
  7467. 'title' => $project['title'],
  7468. 'content' => '提交了审核',
  7469. 'messageType' => 9,
  7470. ]);
  7471. }
  7472. $result = Project::where('id', $data['id'])->update(['status' => $data['status']]);
  7473. }
  7474. if (empty($result)) {
  7475. return Result::error("审核失败", 0);
  7476. }
  7477. return Result::success($result);
  7478. }
  7479. /**
  7480. * 获取项目详情
  7481. * @param array $data
  7482. * @return array
  7483. */
  7484. public function getProjectInfo(array $data): array
  7485. {
  7486. $project = Project::where('id', $data['id'])->first();
  7487. if (empty($project)) {
  7488. return Result::error("暂无相关项目信息", 0);
  7489. }
  7490. return Result::success($project);
  7491. }
  7492. public function getWebsiteCompanyInfo(array $data): array
  7493. {
  7494. $company = Company::where('id', $data['id'])
  7495. ->leftJoin('job_industry', 'job_industry.hyid', 'company.hy_id')
  7496. ->where('status', 1)
  7497. // ->where('website_id', $data['website_id'])
  7498. ->select('company.*', 'job_industry.hyname as hy_name')
  7499. ->first();
  7500. // 企业性质:0:市场监管;1:信访纪检;2:公检法司;3:高关注机构
  7501. switch ($company->jobnature_id) {
  7502. case null:
  7503. $company->jobnature_name = '';
  7504. break;
  7505. case 0:
  7506. $company->jobnature_name = '市场监督';
  7507. break;
  7508. case 1:
  7509. $company->jobnature_name = '信访纪检';
  7510. break;
  7511. case 2:
  7512. $company->jobnature_name = '公检法司';
  7513. break;
  7514. case 3:
  7515. $company->jobnature_name = '高关注机构';
  7516. break;
  7517. default:
  7518. $company->jobnature_name = '';
  7519. break;
  7520. }
  7521. $city_arr = $company->city_arr_id;
  7522. if (!empty($city_arr)) {
  7523. $city_arr = json_decode($city_arr, true);
  7524. $cityNames = District::whereIn('id', $city_arr)
  7525. ->pluck('name')
  7526. ->implode('-');
  7527. $company->city_name = $cityNames;
  7528. } else {
  7529. $company->city_name = '';
  7530. }
  7531. if (empty($company)) {
  7532. return Result::error("暂无相关公司信息", 0);
  7533. }
  7534. return Result::success($company);
  7535. }
  7536. public function getMSG(array $data): array
  7537. {
  7538. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  7539. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  7540. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  7541. $result = [];
  7542. if ($type_id == 1 or $type_id == 2 or $type_id == 3 or $type_id == 4) {
  7543. //最近的5篇已审的文章
  7544. $apply_articale = Article::where('status', 1)
  7545. ->where('admin_user_id', $user_id)
  7546. ->orderBy('updated_at', 'desc')
  7547. // ->limit(5)
  7548. ->get();
  7549. //获取5条用户的已审核商品
  7550. $good = Good::where('status', 2)
  7551. ->where('user_id', $user_id)
  7552. ->orderBy('updated_at', 'desc')
  7553. // ->limit(5)
  7554. ->get();
  7555. //获取5条用户待审核的公告
  7556. $notice = Notice::where('status', 2)
  7557. ->where('user_id', $user_id)
  7558. ->orderBy('updated_at', 'desc')
  7559. ->limit(5)->get();
  7560. //获取5条用户的待审核投诉
  7561. $complaint = Complaint::where('status', 2)
  7562. ->where('user_id', $user_id)
  7563. ->orderBy('updated_at', 'desc')
  7564. // ->limit(5)
  7565. ->get();
  7566. //获取5条用户的book
  7567. $book = Book::where('status', 2)
  7568. ->where('user_id', $user_id)
  7569. ->orderBy('updated_at', 'desc')
  7570. // ->limit(5)
  7571. ->get();
  7572. //获取5条用户的求职
  7573. //获取5条用户的求职 1
  7574. $job_hunting = JobHunting::where('job_hunting.status', 2)
  7575. ->where('job_hunting.user_id', $user_id)
  7576. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7577. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7578. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7579. ->orderBy('updated_at', 'desc')
  7580. // ->limit(5)
  7581. ->get();
  7582. //获取5条用户的求职 2
  7583. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  7584. ->where('job_recruiting.user_id', $user_id)
  7585. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7586. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7587. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7588. ->orderBy('updated_at', 'desc')
  7589. // ->limit(5)
  7590. ->get();
  7591. //人才库 1
  7592. $job_apply = JobApply::where('job_apply.status', 1)
  7593. ->where('job_apply.receiver_id', $user_id)
  7594. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7595. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7596. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7597. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7598. ->select('job_recruiting', 'job_recruiting.', '', '')
  7599. ->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')
  7600. ->orderBy('updated_at', 'desc')
  7601. // ->limit(5)
  7602. ->get();
  7603. // 职场机会 2
  7604. $job_resume = JobResume::where('job_resume.status', 1)
  7605. ->where('job_resume.receiver_id', $user_id)
  7606. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7607. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7608. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7609. ->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')
  7610. ->orderBy('updated_at', 'desc')
  7611. // ->limit(5)
  7612. ->get();
  7613. //获取5条用户待处理的投诉
  7614. $complaint_deal = Complaint::where('status', 2)
  7615. ->where('deal', 1)
  7616. ->whereJsonContains('re_user_ids', $user_id)
  7617. ->orderBy('updated_at', 'desc')
  7618. // ->limit(5)
  7619. ->get();
  7620. //获取 被通知者未读信息
  7621. $notice_unread = Notice::where('status', 2)
  7622. ->whereJsonContains('re_user_ids', $user_id)
  7623. //未读消息
  7624. ->where(function ($query) use ($user_id) {
  7625. $query->whereJsonDoesntContain('read_id', $user_id)
  7626. ->orWhereNull('read_id');
  7627. })
  7628. ->orderBy('updated_at', 'desc')
  7629. ->get();
  7630. $complaint_unread = Complaint::where('status', 2)
  7631. ->whereJsonContains('re_user_ids', $user_id)
  7632. //未读消息
  7633. ->where(function ($query) use ($user_id) {
  7634. $query->whereJsonDoesntContain('read_id', $user_id)
  7635. ->orWhereNull('read_id');
  7636. })
  7637. ->orderBy('updated_at', 'desc')
  7638. ->get();
  7639. //获取5条用户的yijing审核公司 :0:未审核;1:已审核;2:已拒绝
  7640. $complany = Company::where('status', 1)
  7641. ->where('user_id', $user_id)
  7642. ->orderBy('updated_at', 'desc')
  7643. // ->limit(5)
  7644. ->get();
  7645. //获取5条单聊未读聊天消息
  7646. // $chat = ChatRecords::where('is_read', 0)
  7647. // ->where('user_id', $user_id)
  7648. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7649. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7650. // ->where('action', 'recieved')
  7651. // ->where('talk_type', 1)
  7652. // ->orderBy('created_at', 'desc')
  7653. // // ->limit(5)
  7654. // ->get();
  7655. //获取5条未读群聊信息
  7656. // $chat_group = ChatRecords::where('is_read', 0)
  7657. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7658. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7659. // ->where('user_id', $user_id)
  7660. // ->where('talk_type', 2)
  7661. // ->orderBy('created_at', 'desc')
  7662. // // ->limit(5)
  7663. // ->get();
  7664. //获取5条用户的待审核项目
  7665. $project = Project::where('status', 1)
  7666. ->where('user_id', $user_id)
  7667. ->orderBy('updated_at', 'desc')
  7668. // ->limit(5)
  7669. ->get();
  7670. // count($chat) + count($chat_group) +
  7671. $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)
  7672. + count($complany)
  7673. + count($project)
  7674. + count($notice_unread)
  7675. + count($complaint_unread)
  7676. // + count($chat) + count($chat_group)
  7677. ;
  7678. $result = [
  7679. 'apply_articale' => $apply_articale,
  7680. // 'chat' => $chat,
  7681. // 'chat_group' => $chat_group,
  7682. 'good' => $good,
  7683. 'notice' => $notice,
  7684. 'complaint' => $complaint,
  7685. 'book' => $book,
  7686. 'job_hunting' => $job_hunting,
  7687. 'job_recruiting' => $job_recruiting,
  7688. 'job_apply' => $job_apply,
  7689. 'job_resume' => $job_resume,
  7690. 'complaint_deal' => $complaint_deal,
  7691. 'complany' => $complany,
  7692. 'project' => $project,
  7693. 'notice_unread' => $notice_unread,
  7694. 'complaint_unread' => $complaint_unread,
  7695. 'count' => $count,
  7696. ];
  7697. } elseif ($type_id == 12) {
  7698. //最近的5篇已审的文章
  7699. $apply_articale = Article::where('status', 1)
  7700. ->where('admin_user_id', $user_id)
  7701. ->limit(5)->get();
  7702. //获取5条单聊未读聊天消息
  7703. $chat = ChatRecords::where('is_read', 0)
  7704. ->where('user_id', $user_id)
  7705. ->where('talk_type', 1)
  7706. ->orderBy('created_at', 'desc')
  7707. ->limit(5)->get();
  7708. //获取5条未读群聊信息
  7709. $chat_group = ChatRecords::where('is_read', 0)
  7710. ->where('user_id', $user_id)
  7711. ->where('talk_type', 2)
  7712. ->orderBy('created_at', 'desc')
  7713. ->limit(5)->get();
  7714. //获取5条用户的已审核商品
  7715. $good = Good::where('status', 2)
  7716. ->where('user_id', $user_id)
  7717. ->orderBy('updated_at', 'desc')
  7718. ->limit(5)->get();
  7719. //获取5条用户的book
  7720. $book = Book::where('status', 2)
  7721. ->where('user_id', $user_id)
  7722. ->orderBy('updated_at', 'desc')
  7723. ->limit(5)->get();
  7724. //获取5条用户的求职
  7725. //获取5条用户的求职 1
  7726. //count($chat) + count($chat_group)
  7727. $count = count($apply_articale) + count($good);
  7728. $result = [
  7729. 'apply_articale' => $apply_articale,
  7730. 'chat' => $chat,
  7731. 'chat_group' => $chat_group,
  7732. 'good' => $good,
  7733. 'book' => $book,
  7734. 'count' => $count,
  7735. ];
  7736. } elseif ($type_id == 13) {
  7737. //最近的5篇已审的文章
  7738. $apply_articale = Article::where('status', 1)
  7739. ->where('admin_user_id', $user_id)
  7740. ->limit(5)->get();
  7741. //获取5条单聊未读聊天消息
  7742. $chat = ChatRecords::where('is_read', 0)
  7743. ->where('user_id', $user_id)
  7744. ->where('talk_type', 1)
  7745. ->orderBy('created_at', 'desc')
  7746. ->limit(5)->get();
  7747. //获取5条未读群聊信息
  7748. $chat_group = ChatRecords::where('is_read', 0)
  7749. ->where('user_id', $user_id)
  7750. ->where('talk_type', 2)
  7751. ->orderBy('created_at', 'desc')
  7752. ->limit(5)->get();
  7753. //获取5条用户的已审核商品
  7754. $good = Good::where('status', 2)
  7755. ->where('user_id', $user_id)
  7756. ->orderBy('updated_at', 'desc')
  7757. ->limit(5)->get();
  7758. //count($chat) + count($chat_group) +
  7759. $count = count($apply_articale) + count($good);
  7760. $result = [
  7761. 'apply_articale' => $apply_articale,
  7762. 'chat' => $chat,
  7763. 'chat_group' => $chat_group,
  7764. 'good' => $good,
  7765. 'count' => $count,
  7766. ];
  7767. } elseif ($type_id == 14) {
  7768. //最近的5篇已审的文章
  7769. $apply_articale = Article::where('status', 1)
  7770. ->where('admin_user_id', $user_id)
  7771. // ->limit(5)
  7772. ->get();
  7773. //获取5条用户的已审核商品
  7774. $good = Good::where('status', 2)
  7775. ->where('user_id', $user_id)
  7776. ->orderBy('updated_at', 'desc')
  7777. // ->limit(5)
  7778. ->get();
  7779. $count = count($apply_articale) + count($good);
  7780. $result = [
  7781. 'apply_articale' => $apply_articale,
  7782. 'chat' => '',
  7783. 'chat_group' => '',
  7784. 'good' => $good,
  7785. 'count' => $count,
  7786. ];
  7787. } elseif ($type_id == 10000) {
  7788. //获取未审核的5篇文章
  7789. $apply_articale = Article::where('status', 0)
  7790. ->orderBy('updated_at', 'desc')
  7791. // ->limit(5)
  7792. ->get();
  7793. //获取5条单聊未读聊天消息
  7794. //获取5条单聊未读聊天消息
  7795. // $chat = ChatRecords::where('is_read', 0)
  7796. // ->where('user_id', $user_id)
  7797. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7798. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7799. // ->where('action', 'recieved')
  7800. // ->where('talk_type', 1)
  7801. // ->orderBy('created_at', 'desc')
  7802. // // ->limit(5)
  7803. // ->get();
  7804. // //获取5条未读群聊信息
  7805. // $chat_group = ChatRecords::where('is_read', 0)
  7806. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7807. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7808. // ->where('user_id', $user_id)
  7809. // ->where('talk_type', 2)
  7810. // ->orderBy('created_at', 'desc')
  7811. // // ->limit(5)
  7812. // ->get();
  7813. //获取5条用户的已审核商品
  7814. $good = Good::where('status', 1)
  7815. // ->where('user_id', $user_id)
  7816. ->orderBy('updated_at', 'desc')
  7817. // ->limit(5)
  7818. ->get();
  7819. //获取5条用户待审核的公告
  7820. $notice = Notice::where('status', 1)
  7821. ->orderBy('updated_at', 'desc')
  7822. // ->limit(5)
  7823. ->get();
  7824. //获取5条用户的待审核投诉
  7825. $complaint = Complaint::where('status', 1)
  7826. ->orderBy('updated_at', 'desc')
  7827. // ->limit(5)
  7828. ->get();
  7829. //获取5条用户的book
  7830. $book = Book::where('status', 1)
  7831. ->orderBy('updated_at', 'desc')
  7832. // ->limit(5)
  7833. ->get();
  7834. //获取5条用户的求职 1
  7835. $job_hunting = JobHunting::where('job_hunting.status', 1)
  7836. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7837. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7838. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7839. ->orderBy('updated_at', 'desc')
  7840. // ->limit(5)
  7841. ->get();
  7842. //获取5条用户的求职 2
  7843. $job_recruiting = JobRecruiting::where('job_recruiting.status', 0)
  7844. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7845. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7846. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7847. ->orderBy('updated_at', 'desc')
  7848. // ->limit(5)
  7849. ->get();
  7850. //人才库 1
  7851. $job_apply = JobApply::where('job_apply.status', 1)
  7852. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7853. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7854. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7855. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7856. ->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')
  7857. ->orderBy('updated_at', 'desc')
  7858. // ->limit(5)
  7859. ->get();
  7860. // 职场机会 2
  7861. $job_resume = JobResume::where('job_resume.status', 1)
  7862. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7863. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7864. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7865. ->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')
  7866. ->orderBy('updated_at', 'desc')
  7867. // ->limit(5)
  7868. ->get();
  7869. //待审核数据com pro
  7870. $complany = Company::where('status', 0)
  7871. ->orderBy('updated_at', 'desc')
  7872. // ->limit(5)
  7873. ->get();
  7874. $project = Project::where('status', 0)
  7875. ->orderBy('updated_at', 'desc')
  7876. // ->limit(5)
  7877. ->get();
  7878. $count =
  7879. // count($chat) +
  7880. // count($chat_group) +
  7881. count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting)
  7882. // + count($job_apply)
  7883. // + count($job_resume)
  7884. + count($complany)
  7885. + count($project);
  7886. $result = [
  7887. 'apply_articale' => $apply_articale,
  7888. // 'chat' => $chat,
  7889. // 'chat_group' => $chat_group,
  7890. 'good' => $good,
  7891. 'notice' => $notice,
  7892. 'complaint' => $complaint,
  7893. 'book' => $book,
  7894. 'job_hunting' => $job_hunting,
  7895. 'job_recruiting' => $job_recruiting,
  7896. // 'job_apply' => $job_apply,
  7897. // 'job_resume' => $job_resume,
  7898. 'complany' => $complany,
  7899. 'project' => $project,
  7900. 'count' => $count,
  7901. ];
  7902. } elseif ($type_id == 20000) {
  7903. }
  7904. var_dump($type_id, '-----------------test---------');
  7905. return Result::success($result);
  7906. }
  7907. /**
  7908. * @param array $data
  7909. * @return array
  7910. */
  7911. public function getWebsiteProject(array $data): array
  7912. {
  7913. $categorys = json_decode($data['id'], true);
  7914. if (!empty($categorys)) {
  7915. $category_arr = $this->processArticlePro($data['website_id']);
  7916. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7917. $catiall = $category_arr['catiall'];
  7918. // return Result::success($catiall);
  7919. foreach ($categorys as $key => $val) {
  7920. if (isset($val['level'][0]) && !empty($val['level'][0])) {
  7921. $level = explode(',', $val['level'])[0];
  7922. $imgnum = explode(',', $val['level'])[1] ?? null;
  7923. $textnum = explode(',', $val['level'])[2] ?? null;
  7924. if ($level == 1) {
  7925. if (!empty($textnum) && $textnum > 0) {
  7926. $text_num = Project::where('level', $level)
  7927. ->where('website_id', $data['website_id'])
  7928. ->where('status', 1)
  7929. ->select(
  7930. 'project.id',
  7931. 'project.title',
  7932. 'project.description',
  7933. 'project.updated_at',
  7934. 'project.category_id',
  7935. 'project.cat_arr_id'
  7936. )
  7937. ->orderBy('updated_at', 'desc')
  7938. ->limit($textnum)
  7939. ->get()->all();
  7940. }
  7941. if (!empty($imgnum) && $imgnum > 0) {
  7942. $img_num = Project::where('level', $level)
  7943. ->where('website_id', $data['website_id'])
  7944. ->where('status', 1)
  7945. ->where('imgurl', '!=', '')
  7946. ->whereNotNull('imgurl')
  7947. ->select(
  7948. 'project.id',
  7949. 'project.title',
  7950. 'project.description',
  7951. 'project.updated_at',
  7952. 'project.imgurl as imgs',
  7953. 'project.category_id',
  7954. 'project.cat_arr_id'
  7955. )
  7956. ->orderBy('updated_at', 'desc')
  7957. ->limit($imgnum)
  7958. ->get()->all();
  7959. }
  7960. } else {
  7961. if (!empty($textnum) && $textnum > 0) {
  7962. $text_num = Project::where('website_id', $data['website_id'])
  7963. ->where('status', 1)
  7964. ->select(
  7965. 'project.id',
  7966. 'project.title',
  7967. 'project.description',
  7968. 'project.updated_at',
  7969. 'project.category_id',
  7970. 'project.cat_arr_id',
  7971. 'project.website_id',
  7972. 'project.updated_at',
  7973. 'project.created_at'
  7974. )
  7975. ->orderBy('updated_at', 'desc')
  7976. ->limit($textnum)
  7977. ->get()->all();
  7978. }
  7979. if (!empty($imgnum) && $imgnum > 0) {
  7980. $img_num = Project::where('website_id', $data['website_id'])
  7981. ->where('status', 1)
  7982. ->where('imgurl', '!=', '')
  7983. ->whereNotNull('imgurl')
  7984. ->select(
  7985. 'project.id',
  7986. 'project.title',
  7987. 'project.description',
  7988. 'project.updated_at',
  7989. 'project.imgurl as imgs',
  7990. 'project.category_id',
  7991. 'project.cat_arr_id'
  7992. )
  7993. ->orderBy('updated_at', 'desc')
  7994. ->limit($imgnum)
  7995. ->get()->all();
  7996. }
  7997. }
  7998. }
  7999. if (isset($val['id'][0]) && !empty($val['id'][0])) {
  8000. $category_ids = explode(',', $val['id'])[0];
  8001. $cat_imgnum = explode(',', $val['id'])[1] ?? null;
  8002. $cat_textnum = explode(',', $val['id'])[2] ?? null;
  8003. $category_arr = array_merge([$category_ids], $cat_1st_arr[$category_ids] ?? [0]);
  8004. if (!empty($cat_textnum) && $cat_textnum > 0) {
  8005. $text_num = Project::whereIn('category_id', $category_arr)
  8006. ->where('website_id', $data['website_id'])
  8007. ->where('status', 1)
  8008. ->select(
  8009. 'project.id',
  8010. 'project.title',
  8011. 'project.description',
  8012. 'project.updated_at',
  8013. 'project.category_id',
  8014. 'project.cat_arr_id'
  8015. )
  8016. ->orderBy('updated_at', 'desc')
  8017. ->limit($cat_textnum)
  8018. ->get()->all();
  8019. }
  8020. if (!empty($cat_imgnum) && $cat_imgnum > 0) {
  8021. $img_num = Project::whereIn('category_id', $category_arr)
  8022. ->where('website_id', $data['website_id'])
  8023. ->where('status', 1)
  8024. ->where('imgurl', '!=', '')
  8025. ->whereNotNull('imgurl')
  8026. ->select(
  8027. 'project.id',
  8028. 'project.title',
  8029. 'project.description',
  8030. 'project.updated_at',
  8031. 'project.imgurl as imgs',
  8032. 'project.category_id',
  8033. 'project.cat_arr_id'
  8034. )
  8035. ->orderBy('updated_at', 'desc')
  8036. ->limit($cat_imgnum)
  8037. ->get()->all();
  8038. }
  8039. }
  8040. if (!empty($img_num)) {
  8041. foreach ($img_num as $k => $v) {
  8042. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8043. $imgurl = json_decode($v['imgs'], true);
  8044. if (!empty($imgurl)) {
  8045. $img_num[$k]->imgurl = $imgurl[0];
  8046. }
  8047. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8048. }
  8049. }
  8050. if (!empty($text_num)) {
  8051. foreach ($text_num as $k => $v) {
  8052. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8053. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8054. }
  8055. }
  8056. $project[$key]['img_num'] = $img_num ?? [];
  8057. $project[$key]['text_num'] = $text_num ?? [];
  8058. }
  8059. }
  8060. if (empty($project)) {
  8061. return Result::error("暂无相关项目信息", 0);
  8062. }
  8063. return Result::success($project);
  8064. }
  8065. /**
  8066. * @param array $data
  8067. * @return array
  8068. */
  8069. public function getWebsiteProjectInfo(array $data): array
  8070. {
  8071. $project = Project::where('id', $data['id'])
  8072. ->where('status', 1)
  8073. ->where('website_id', $data['website_id'])
  8074. ->select('project.*')
  8075. ->first();
  8076. if (empty($project)) {
  8077. return Result::error("暂无相关项目信息", 0);
  8078. }
  8079. return Result::success($project);
  8080. }
  8081. /**
  8082. * @param array $data
  8083. * @return array
  8084. */
  8085. public function getWebsiteProjectList(array $data): array
  8086. {
  8087. $where = [];
  8088. if (isset($data['category_id']) && !empty($data['category_id'])) {
  8089. $where['category_id'] = $data['category_id'];
  8090. }
  8091. if (isset($data['keyword']) && !empty($data['keyword'])) {
  8092. $where[] = ['title', 'like', '%' . $data['keyword'] . '%'];
  8093. }
  8094. $query = Project::where($where)
  8095. ->where('status', 1)
  8096. ->where('website_id', $data['website_id'])
  8097. ->select(
  8098. 'project.id',
  8099. 'project.title',
  8100. 'project.description',
  8101. 'project.imgurl as imgs',
  8102. 'project.category_id',
  8103. 'project.cat_arr_id'
  8104. )
  8105. ->orderBy('updated_at', 'desc');
  8106. $count = $query->count();
  8107. $project = $query->clone()
  8108. ->offset(($data['page'] - 1) * $data['pageSize'])
  8109. ->limit($data['pageSize'])
  8110. ->get()->all();
  8111. if (empty($project)) {
  8112. return Result::error("暂无相关项目信息", 0);
  8113. }
  8114. $categorys = $this->processArticlePro($data['website_id']);
  8115. $catiall = $categorys['catiall'];
  8116. foreach ($project as $key => $val) {
  8117. $project[$key]->category_name = $catiall[$val->category_id]['alias'];
  8118. if (!empty($val['imgs'])) {
  8119. $imgurl = json_decode($val['imgs'], true);
  8120. if (!empty($imgurl)) {
  8121. $project[$key]->imgurl = $imgurl[0];
  8122. }
  8123. } else {
  8124. $project[$key]->imgurl = '';
  8125. }
  8126. $project[$key]->pinyin = $catiall[$val->category_id]['pinyin'];
  8127. }
  8128. $result = [
  8129. 'rows' => $project,
  8130. 'count' => $count,
  8131. ];
  8132. return Result::success($result);
  8133. }
  8134. /**
  8135. * @param array $data
  8136. * @return array
  8137. */
  8138. public function getWebsiteCategoryJob(array $data): array
  8139. {
  8140. $categorys = json_decode($data['id'], true);
  8141. if (!empty($categorys)) {
  8142. $category_arr = $this->processArticlePro($data['website_id']);
  8143. $cat_1st_arr = $category_arr['cat_1st_arr'];
  8144. $catiall = $category_arr['catiall'];
  8145. foreach ($categorys as $key => $val) {
  8146. if (isset($val['id']) && !empty($val['id'])) {
  8147. $catid = explode(',', $val['id'])[0] ?? null;
  8148. $type = explode(',', $val['id'])[1] ?? null;
  8149. $textnum = explode(',', $val['id'])[2] ?? null;
  8150. }
  8151. // 4:招聘;5:求职;
  8152. if ($textnum > 0 && $type == 4 && !empty($catid)) {
  8153. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  8154. $job = JobRecruiting::WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($catid) . "') = 1")
  8155. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  8156. ->where('job_recruiting.status', 1)
  8157. ->where('job_recruiting.website_id', $data['website_id'])
  8158. ->select(
  8159. 'job_recruiting.id',
  8160. 'job_recruiting.title',
  8161. 'job_company.business_name',
  8162. 'job_recruiting.updated_at',
  8163. 'job_recruiting.cat_arr_id',
  8164. 'job_recruiting.keyword',
  8165. 'job_recruiting.description'
  8166. )
  8167. ->orderBy('job_recruiting.updated_at', 'desc')
  8168. ->limit($textnum)
  8169. ->get()->all();
  8170. } else if ($textnum > 0 && $type == 5 && !empty($catid)) {
  8171. // 状态 审核状态,1待审核2已审核3已拒绝
  8172. $job = JobHunting::WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($catid) . "') = 1")
  8173. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  8174. ->where('job_hunting.status', 2)
  8175. ->where('job_hunting.website_id', $data['website_id'])
  8176. ->select(
  8177. 'job_hunting.id',
  8178. 'job_hunting.name',
  8179. 'job_hunting.cat_arr_id',
  8180. 'job_position.zwname as job_name',
  8181. 'job_hunting.updated_at',
  8182. 'job_hunting.keyword',
  8183. 'job_hunting.slelf_evaluation'
  8184. )
  8185. ->orderBy('updated_at', 'desc')
  8186. ->limit($textnum)
  8187. ->get()->all();
  8188. } else {
  8189. $job = [];
  8190. }
  8191. // var_dump($catid.'222uuuuuuu'.$key);
  8192. if (!empty($job)) {
  8193. foreach ($job as $k => $value) {
  8194. if (isset($value->cat_arr_id)) {
  8195. $catArr = json_decode($value->cat_arr_id, true);
  8196. $catId = end($catArr);
  8197. } else {
  8198. continue;
  8199. }
  8200. if (isset($catiall[$catId])) {
  8201. $job[$k]->pinyin = $catiall[$catId]['pinyin'];
  8202. }
  8203. }
  8204. }
  8205. // var_dump($catid.'xxxxx'.$key);
  8206. $result[$key] = $job ?? [];
  8207. }
  8208. }
  8209. if (empty($result)) {
  8210. return Result::error("暂无相关分类信息", 0);
  8211. }
  8212. return Result::success($result);
  8213. }
  8214. /**
  8215. * 发送消息
  8216. * @param array $messageData
  8217. * @return void
  8218. */
  8219. public function sendMessage($messageData)
  8220. {
  8221. $msg = [
  8222. 'talk_type' => $messageData['talk_type'],
  8223. 'title' => $messageData['title'],
  8224. 'content' => $messageData['content'],
  8225. 'messageType' => $messageData['messageType'],
  8226. 'user_id' => $messageData['user_id'] ?? '',
  8227. 'time' => microtime(),
  8228. ];
  8229. $message = new MqProducer($msg);
  8230. $producer = ContextApplicationContext::getContainer()->get(Producer::class);
  8231. $producer->produce($message);
  8232. }
  8233. }