NewsService.php 324 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849
  1. <?php
  2. namespace App\JsonRpc;
  3. use App\Model\Article;
  4. use App\Model\ArticleData;
  5. use App\Model\Category;
  6. use App\Model\HistoryToday;
  7. use App\Model\WebsiteCategory;
  8. use App\Model\ArticleSurvey;
  9. use App\Model\District;
  10. use App\Model\Good;
  11. use App\Model\JobCompany;
  12. use App\Model\Website;
  13. use App\Model\JobRecruiting;
  14. use App\Model\JobIndustry;
  15. use App\Model\Book;
  16. use App\Model\JobPosition;
  17. use App\Model\Notice;
  18. use App\Model\JobNature;
  19. use App\Model\JobEnum;
  20. use App\Model\User;
  21. use App\Model\UserRole;
  22. use App\Model\News;
  23. use App\Model\UserInfo;
  24. use App\Model\WebsiteGroup;;
  25. use App\Model\JobResume;
  26. use Hyperf\DbConnection\Db;
  27. use Hyperf\RpcServer\Annotation\RpcService;
  28. use App\Tools\Result;
  29. use Directory;
  30. use Ramsey\Uuid\Uuid;
  31. use Hyperf\Utils\Random;
  32. use Fukuball\Jieba\Jieba;
  33. use Fukuball\Jieba\Finalseg;
  34. use Hyperf\Utils\Collection;
  35. use function Hyperf\Support\retry;
  36. use App\Tools\PublicData;
  37. use App\Model\ChatGroups;
  38. use App\Model\ChatGroupsMember;
  39. use App\Model\ChatRecords;
  40. use App\Model\Complaint;
  41. use Hamcrest\Arrays\IsArray;
  42. use Hyperf\Codec\Json;
  43. use App\Tools\buildMenuTree;
  44. use App\Model\JobApply;
  45. use App\Model\JobHunting;
  46. use App\Model\JobRemuse;
  47. use Hyperf\Redis\Redis;
  48. use Hyperf\Di\Annotation\Inject;
  49. use App\Model\Festival;
  50. use App\Model\Character;
  51. use App\Model\Couplet;
  52. use App\Model\Riddle;
  53. use App\Model\Idiom;
  54. use App\Model\WhiteRouter;
  55. use Illuminate\Support\Facades\Cache;
  56. use App\Model\Company;
  57. use Hyperf\Paginator\Paginator;
  58. use App\Model\Project;
  59. use Hyperf\Context\Context;
  60. use Hyperf\Context\ApplicationContext as ContextApplicationContext;
  61. use Hyperf\Amqp\Producer;
  62. use App\Amqp\Producer\MqProducer;
  63. use App\Model\Web;
  64. use App\Model\GroupMemberImp;
  65. use App\Model\GroupImp;
  66. use App\Model\GroupTalkImp;
  67. use App\Model\GroupTalkMessagerImp;
  68. use App\Model\ArticleIgnore;
  69. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  70. class NewsService implements NewsServiceInterface
  71. {
  72. #[Inject]
  73. protected Redis $redis;
  74. /**
  75. * 获取导航池列表
  76. * @param array $data
  77. * @return array
  78. */
  79. public function getCategoryList(array $data): array
  80. {
  81. $search = $data['name'] ?? '';
  82. $page = (int)($data['page'] ?? 1);
  83. $perPage = (int)($data['pageSize'] ?? 10);
  84. // 1. 查出所有匹配的分类id
  85. if ($search) {
  86. $matchedIds = Category::where('name', 'like', "%{$search}%")->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  87. if (empty($matchedIds)) {
  88. return Result::success(['rows' => [], 'total' => 0]);
  89. }
  90. // 2. 递归查所有父级,直到一级分类
  91. $idsStr = implode(',', $matchedIds);
  92. $sql = "
  93. WITH RECURSIVE parents AS (
  94. SELECT * FROM category WHERE id IN ($idsStr)
  95. UNION ALL
  96. SELECT c.* FROM category c
  97. INNER JOIN parents p ON c.id = p.pid
  98. )
  99. SELECT * FROM parents
  100. ";
  101. $parents = Db::select($sql);
  102. $parentIds = [];
  103. foreach ($parents as $row) {
  104. if ($row->pid == 0) {
  105. $parentIds[] = $row->id;
  106. }
  107. }
  108. $parentIds = array_unique($parentIds);
  109. } else {
  110. // 没有搜索,一级分类就是根
  111. $parentIds = Category::where('pid', 0)->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  112. }
  113. // 3. 一级分类分页
  114. $total = count($parentIds);
  115. $parentIds = array_slice($parentIds, ($page - 1) * $perPage, $perPage);
  116. if (empty($parentIds)) {
  117. return Result::success(['rows' => [], 'total' => $total]);
  118. }
  119. // 4. 递归查所有子孙
  120. $idsStr = implode(',', $parentIds);
  121. $sql = "
  122. WITH RECURSIVE subcategories AS (
  123. SELECT * FROM category WHERE id IN ($idsStr)
  124. UNION ALL
  125. SELECT c.* FROM category c
  126. INNER JOIN subcategories s ON c.pid = s.id
  127. )
  128. SELECT * FROM subcategories ORDER BY updated_at DESC
  129. ";
  130. $allCategories = Db::select($sql);
  131. // 5. 组装树结构
  132. $categoryMap = [];
  133. foreach ($allCategories as $cat) {
  134. $cat = (array)$cat;
  135. $cat['children'] = [];
  136. $categoryMap[$cat['id']] = $cat;
  137. }
  138. foreach ($categoryMap as $id => &$cat) {
  139. if ($cat['pid'] && isset($categoryMap[$cat['pid']])) {
  140. $categoryMap[$cat['pid']]['children'][] = &$cat;
  141. }
  142. }
  143. unset($cat);
  144. $categoryTree = [];
  145. foreach ($parentIds as $id) {
  146. if (isset($categoryMap[$id])) {
  147. $categoryTree[] = $categoryMap[$id];
  148. }
  149. }
  150. return Result::success([
  151. 'rows' => $categoryTree,
  152. 'total' => $total,
  153. ]);
  154. }
  155. private function findMatchedCategories($search)
  156. {
  157. if ($search) {
  158. return Category::where('name', 'like', "%{$search}%")
  159. ->orderBy('updated_at', 'desc')
  160. ->get();
  161. }
  162. return Category::orderBy('updated_at', 'desc') // 按 updated_at 字段倒序排序
  163. ->get();
  164. }
  165. private function findAllParents($categories)
  166. {
  167. $allCategories = [];
  168. foreach ($categories as $category) {
  169. $parentId = $category->pid;
  170. while ($parentId > 0) {
  171. $parent = Category::find($parentId);
  172. if ($parent) {
  173. $allCategories[$parent->id] = $parent;
  174. $parentId = $parent->pid;
  175. } else {
  176. break;
  177. }
  178. }
  179. $allCategories[$category->id] = $category;
  180. }
  181. return array_values($allCategories);
  182. }
  183. private function buildCategoryTree($category, $allRequiredCategories)
  184. {
  185. $categoryData = $category->toArray();
  186. $children = [];
  187. foreach ($allRequiredCategories as $c) {
  188. if ($c->pid === $category->id) {
  189. $children[] = $this->buildCategoryTree($c, $allRequiredCategories);
  190. }
  191. }
  192. if (!empty($children)) {
  193. $categoryData['children'] = $children;
  194. }
  195. return $categoryData;
  196. }
  197. public function myCategoryList(array $data): array
  198. {
  199. $sszq = $data['sszq'] ?? '';
  200. unset($data['sszq']);
  201. //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
  202. $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
  203. $where[] = [
  204. 'pid',
  205. '=',
  206. $data['pid'],
  207. ];
  208. if (isset($data['name'])) {
  209. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  210. }
  211. var_dump($where);
  212. //根据分类id,从category表中取出分类信息
  213. $result = Category::where($where)
  214. ->whereIn('category.id', $catorytids)
  215. ->select('category.*', 'category.id as category_id')->get();
  216. if (empty($result)) {
  217. return Result::error("没有栏目数据");
  218. }
  219. return Result::success($result);
  220. }
  221. /**
  222. * @param array $data
  223. * @return array
  224. */
  225. public function categoryList(array $data): array
  226. {
  227. $where[] = [
  228. 'pid',
  229. '=',
  230. $data['pid']
  231. ];
  232. if (isset($data['name'])) {
  233. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  234. }
  235. var_dump($where);
  236. $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
  237. if (empty($result)) {
  238. return Result::error("没有栏目数据");
  239. }
  240. return Result::success($result);
  241. }
  242. /**
  243. * @param array $data
  244. * @return array
  245. */
  246. public function addCategory(array $data): array
  247. {
  248. if (isset($data['id'])) {
  249. unset($data['id']);
  250. }
  251. $id = Category::insertGetId($data);
  252. if (empty($id)) {
  253. return Result::error("添加失败");
  254. }
  255. return Result::success(['id' => $id]);
  256. }
  257. /**
  258. * @param array $data
  259. * @return array
  260. */
  261. public function delCategory(array $data): array
  262. {
  263. Db::beginTransaction();
  264. try {
  265. $categoryList = Category::where(['pid' => $data['id']])->get();
  266. if ($categoryList->toArray()) {
  267. Db::rollBack();
  268. return Result::error("分类下面有子分类不能删除");
  269. }
  270. $articleList = Article::where(['catid' => $data['id']])->get();
  271. if ($articleList->toArray()) {
  272. Db::rollBack();
  273. return Result::error("分类下面有资讯不能删除");
  274. }
  275. $result = Category::where($data)->delete();
  276. WebsiteCategory::where(['category_id' => $data['id']])->delete();
  277. if (!$result) {
  278. Db::rollBack();
  279. return Result::error("删除失败");
  280. }
  281. Db::commit();
  282. return Result::success($result);
  283. } catch (\Exception $e) {
  284. Db::rollBack();
  285. return Result::error("删除失败" . $e->getMessage());
  286. }
  287. }
  288. /**
  289. * @param array $data
  290. * @return array
  291. */
  292. public function updateCategory(array $data): array
  293. {
  294. $where = [
  295. 'id' => $data['id'],
  296. ];
  297. $result = Category::where($where)->update($data);
  298. if ($result) {
  299. return Result::success($result);
  300. } else {
  301. return Result::error("更新失败");
  302. }
  303. }
  304. /**
  305. * 获取导航池信息
  306. * @param array $data
  307. * @return array
  308. */
  309. public function getCategoryInfo(array $data): array
  310. {
  311. $where = [
  312. 'id' => $data['id'],
  313. ];
  314. $result = Category::where($where)->first();
  315. if ($result) {
  316. return Result::success($result);
  317. } else {
  318. return Result::error("更新失败");
  319. }
  320. }
  321. public function getArticleCommend(array $data): array
  322. {
  323. $where = [
  324. 'website_id' => $data['website_id'],
  325. ];
  326. $ids = WebsiteCategory::where($where)->pluck('category_id')->toArray();
  327. var_dump($ids);
  328. if (empty($ids)) {
  329. return Result::error("没有推荐数据");
  330. }
  331. //id
  332. $whereArticle = [];
  333. if (isset($data['id'])) {
  334. $whereArticle['id'] = $data['id'];
  335. }
  336. //title like
  337. if (isset($data['title'])) {
  338. array_push($whereArticle, ['title', 'like', "%{$data['title']}%"]);
  339. }
  340. $article = Article::whereIn('catid', values: $ids)->where('status', 1)
  341. ->where($whereArticle)
  342. ->orderBy('id', 'desc')
  343. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  344. if ($article) {
  345. $data = [
  346. 'rows' => $article->items(),
  347. 'count' => $article->total(),
  348. ];
  349. return Result::success($data);
  350. } else {
  351. return Result::error("获取失败失败");
  352. }
  353. }
  354. /**
  355. * @param array $data
  356. * @return array
  357. */
  358. public function getArticleList(array $data): array
  359. {
  360. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  361. $type_id = $data['type_id'];
  362. unset($data['type_id']);
  363. $user_id = $data['user_id'];
  364. unset($data['user_id']);
  365. $where = [];
  366. $status1 = [];
  367. if (isset($data['id']) && $data['id']) {
  368. array_push($where, ['article.id', '=', $data['id']]);
  369. }
  370. if (isset($data['title']) && $data['title']) {
  371. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  372. }
  373. if (isset($data['category_name']) && $data['category_name']) {
  374. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  375. }
  376. if (isset($data['catid']) && $data['catid']) {
  377. array_push($where, ['article.catid', '=', $data['catid']]);
  378. }
  379. if (isset($data['author']) && $data['author']) {
  380. array_push($where, ['article.author', '=', $data['author']]);
  381. }
  382. if (isset($data['islink']) && $data['islink'] !== "") {
  383. array_push($where, ['article.islink', '=', $data['islink']]);
  384. }
  385. if (isset($data['status']) && $data['status'] !== "") {
  386. array_push($where, ['article.status', '=', $data['status']]);
  387. }
  388. if (isset($data['status1'])) {
  389. $status1 = json_decode(($data['status1']));
  390. }
  391. //不是管理员展示个人数据;
  392. if ($type_id != 10000) {
  393. $where[] = ['article.admin_user_id', '=', $user_id];
  394. }
  395. $startTime = microtime(true);
  396. $rep = Article::query()
  397. // 预加载相关关联
  398. ->with([
  399. 'category' => function ($query) {
  400. $query->select('id', 'name');
  401. },
  402. 'websiteCategory' => function ($query) {
  403. $query->select('website_id', 'category_id', 'alias');
  404. }
  405. ])
  406. // 构建where条件
  407. ->when(isset($data['id']) && $data['id'], function ($query) use ($data) {
  408. $query->where('article.id', '=', $data['id']);
  409. })
  410. ->when(isset($data['title']) && $data['title'], function ($query) use ($data) {
  411. $query->where('article.title', 'like', '%' . $data['title'] . '%');
  412. })
  413. ->when(isset($data['category_name']) && $data['category_name'], function ($query) use ($data) {
  414. // 使用子查询替代左连接进行模糊搜索
  415. $query->whereHas('category', function ($subQuery) use ($data) {
  416. $subQuery->where('name', 'like', '%' . $data['category_name'] . '%');
  417. });
  418. })
  419. ->when(isset($data['catid']) && $data['catid'], function ($query) use ($data) {
  420. $query->where('article.catid', '=', $data['catid']);
  421. })
  422. ->when(isset($data['author']) && $data['author'], function ($query) use ($data) {
  423. $query->where('article.author', '=', $data['author']);
  424. })
  425. ->when(isset($data['islink']) && $data['islink'] !== "", function ($query) use ($data) {
  426. $query->where('article.islink', '=', $data['islink']);
  427. })
  428. ->when(isset($data['status']) && $data['status'] !== "", function ($query) use ($data) {
  429. $query->where('article.status', '=', $data['status']);
  430. })
  431. ->when(isset($data['status1']) && $data['status1'], function ($query) use ($data) {
  432. // 安全地处理JSON字符串
  433. $status1 = is_array($data['status1']) ? $data['status1'] : json_decode($data['status1'], true) ?? [];
  434. if (!empty($status1)) {
  435. $query->whereIn('article.status', $status1);
  436. }
  437. })
  438. // 非管理员限制
  439. ->when($type_id != 10000, function ($query) use ($user_id) {
  440. $query->where('article.admin_user_id', '=', $user_id);
  441. })
  442. // 基础条件
  443. ->whereNotIn('article.status', [404])
  444. // 排序和分页
  445. ->orderBy('article.updated_at', 'desc')
  446. ->paginate($data['pageSize'], ["article.*"]);
  447. // 获取结果并格式化
  448. $data = [
  449. 'rows' => $rep->items(),
  450. 'count' => $rep->total(),
  451. ];
  452. // 执行查询
  453. $endTime = microtime(true);
  454. $executionTime = ($endTime - $startTime) * 1000;
  455. echo "查询执行时间: {$executionTime}ms\n";
  456. return Result::success($data);
  457. }
  458. /**
  459. * @param array $data
  460. * @return array
  461. */
  462. public function addArticle(array $data): array
  463. {
  464. var_dump($data, '----------12-----------1');
  465. // ------c_show_time********add***1****
  466. $is_collect = $data['is_collect'] ?? 0;
  467. $user_type = $data['user_type'];
  468. unset($data['is_collect']);
  469. unset($data['user_type']);
  470. // ------c_show_time********add***1****
  471. unset($data['nav_add_pool_id']);
  472. // unset($data['commend_id']);
  473. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  474. Db::beginTransaction();
  475. try {
  476. //处理投票
  477. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  478. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  479. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  480. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  481. unset($data['is_survey']);
  482. unset($data['survey_name']);
  483. unset($data['suvey_array']);
  484. // unset($data['website_id']);
  485. // unset($data['web_site_id']);
  486. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  487. if ($data['hits'] == '') {
  488. $data['hits'] = 0;
  489. }
  490. if ($data['is_original'] == '') {
  491. $data['is_original'] = 0;
  492. }
  493. if ($data['status'] == '') {
  494. $data['status'] = 0;
  495. }
  496. $articleData = $data;
  497. unset($articleData['content']);
  498. //自动处理缩略图、关键字、描述
  499. if ($articleData['imgurl'] == '') {
  500. //如果没有图,设置level=0
  501. $levelArr = json_decode($articleData['level'], true);
  502. var_dump($levelArr, '----------levelArr-----------1');
  503. //content中提取图片第一个图,正则提取
  504. // -------采集器相关优化-----
  505. // 优化正则表达式,仅匹配 src 属性值,避免匹配到多余内容
  506. if ($is_collect == 1) {
  507. $reg = '/<img.*?src=[\'"]?((?!.*\.gif)[^\'" >]+)[\'"]?.*?>/i';
  508. } else {
  509. $reg = '/<img.*?src=[\'"]?([^\'" >]+)[\'"]?.*?>/i';
  510. }
  511. // -------采集器相关优化-----
  512. preg_match_all($reg, $data['content'], $matches);
  513. if (isset($matches[1][0])) {
  514. //截取varchar240
  515. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  516. //如果有图,设置level=3
  517. if (!in_array(3, $levelArr)) {
  518. $levelArr[] = 3;
  519. }
  520. $articleData['level'] = json_encode($levelArr);
  521. } else {
  522. if (!in_array(0, $levelArr)) {
  523. $levelArr[] = 0;
  524. }
  525. $articleData['level'] = json_encode($levelArr);
  526. }
  527. }
  528. var_dump($articleData['level'], '----------$articleData[level]----------1');
  529. if ($articleData['keyword'] == '') {
  530. //提取标题+内容中的关键词
  531. $articleData['keyword'] = $data['title'];
  532. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  533. Jieba::init(); // 初始化 jieba-php
  534. Finalseg::init();
  535. $segList = Jieba::cut($articleData['keyword']);
  536. $segList1 = array_slice($segList, 0, 8);
  537. $articleData['keyword'] = implode(',', $segList1);
  538. }
  539. if ($articleData['introduce'] == '') {
  540. //提取内容中的描述
  541. $content = $data['content'];
  542. // 去除 <style> 和 <script> 标签及其内容
  543. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  544. // 去除所有 HTML 标签
  545. $content = strip_tags($content);
  546. // 去除 HTML 实体
  547. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  548. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  549. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  550. // 去除多余空白
  551. $content = preg_replace('/\s+/u', '', $content);
  552. // 截取 100 个字符
  553. $articleData['introduce'] = mb_substr($content, 0, 100);
  554. }
  555. if ($articleData['status'] == 0) {
  556. $this->sendMessage([
  557. 'talk_type' => 100,
  558. 'title' => $articleData['title'],
  559. 'content' => '提交了审核',
  560. 'messageType' => 2,
  561. ]);
  562. }
  563. $id = Article::insertGetId($articleData);
  564. if (!$id) {
  565. throw new \Exception('文章插入失败');
  566. }
  567. $articleDataContent = [
  568. 'article_id' => $id,
  569. 'content' => $data['content'],
  570. ];
  571. // 采集器中的文章内容,在添加时,去掉div标签
  572. if ($is_collect == 1) {
  573. // 采集来的文章,content中可能包含div标签,需要先移除
  574. $pattern = '/<\/?div\b(?:[^"\'>]|"[^"]*"|\'[^\']*\')*>/is';
  575. $article_data = preg_replace($pattern, '', $data['content']);
  576. $$articleDataContent['content'] = $article_data;
  577. }
  578. $contentInsertId = ArticleData::insertGetId($articleDataContent);
  579. if (!$contentInsertId) {
  580. throw new \Exception('文章内容插入失败');
  581. }
  582. // ------c_show_time********add***2****
  583. // 直接使用当前系统时间,不再强制添加8小时
  584. $now = date('Y-m-d H:i:s');
  585. if ($user_type == 10000 || $is_collect == 1) {
  586. // 管理员添加文章时,核心站c端显示时间就是创建时间;非核心站c端显示时间就是此创建时间往后推二十分钟;
  587. // 非管理员添加文章时,不做操作只有在审核通过时获取c端显示时间
  588. if (!isset($data['catid'])) {
  589. throw new \Exception('缺少必要字段:catid');
  590. }
  591. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  592. $web = WebsiteCategory::where('category_id', $data['catid'])
  593. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  594. ->select(
  595. 'website_id',
  596. 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')
  597. )
  598. ->get();
  599. // $id = 225; -----测试开启
  600. // 采集来的文章,错开时间在两小时之内发布
  601. if ($user_type == 10000 && $is_collect == 1) {
  602. $web_num = $web->where('is_core', '!=', 2)->count();
  603. $waiting_interval = 10;
  604. if ($web_num > 12) {
  605. // 若网站数量大于12个,则每个网站间隔时间取均值
  606. // 防止除数为 0,虽然这里 $web_num 是 count 结果不会为 0,但做健壮性检查
  607. $waiting_interval = 120 / max(1, $web_num);
  608. }
  609. $time = 0;
  610. } else {
  611. // 非核心站与核心站----显示时间-----间隔
  612. $time = 20;
  613. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  614. $waiting_interval = 5;
  615. }
  616. // 将 Hyperf\Database\Model\Collection 转换为数组
  617. $webArray = $web->toArray();
  618. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $id, $waiting_interval, $is_collect) {
  619. // 检查 $item 对象是否有 is_core 属性
  620. if (!isset($item['is_core'])) {
  621. throw new \Exception('$item 对象缺少 is_core 属性');
  622. }
  623. // 当 is_core 为 2 时,则表示此网站不存在
  624. if ($item['is_core'] == 2) {
  625. return null;
  626. }
  627. if ($is_collect == 1) {
  628. // 采集来的文章,错开时间在两小时之内发布
  629. // $time = 0;
  630. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  631. $time += $waiting_interval;
  632. } else if ($item['is_core'] == 1) {
  633. // 当 is_core 为 1 时,则表示此网站是核心站
  634. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  635. } else {
  636. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  637. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  638. if ($item['is_core'] == 0) {
  639. $time += $waiting_interval;
  640. }
  641. }
  642. return [
  643. 'article_id' => $id,
  644. 'website_id' => $item['website_id'],
  645. 'c_show_time' => $c_show_time,
  646. // 'is_core' => $item['is_core'],
  647. // 'time' => $time
  648. ];
  649. }, array_keys($webArray), $webArray)));
  650. // Db::commit();
  651. // return Result::success($article_ignore);
  652. if (!empty($article_ignore)) {
  653. $article_ignores = ArticleIgnore::insert($article_ignore);
  654. if (!$article_ignores) {
  655. throw new \Exception('c端展示时间插入失败');
  656. }
  657. }
  658. }
  659. // ------c_show_time********add***2****
  660. //处理投票
  661. if ($is_survey == 1) {
  662. //生成年月日时分秒+8位随机数
  663. $uuid = date('YmdHis') . rand(10000000, 99999999);
  664. var_dump($suvey_array, 'suvey_array________');
  665. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  666. var_dump($suveys_array, '---------------------1');
  667. var_dump($suvey_array, '---------------------2');
  668. $suvey_data = [];
  669. foreach ($suveys_array as $key => $value) {
  670. if ($value == '') {
  671. continue;
  672. }
  673. if (is_array($value)) {
  674. $suvey_data[] = [
  675. 'sur_id' => $uuid,
  676. 'art_id' => $id,
  677. 'website_id' => $website_id ?? 2,
  678. 'survey_name' => $survey_name,
  679. 'choice_name' => $value[1],
  680. 'is_other' => 1,
  681. 'other_id' => 0,
  682. 'results' => 0,
  683. ];
  684. } else {
  685. $suvey_data[] = [
  686. 'sur_id' => $uuid,
  687. 'art_id' => $id,
  688. 'website_id' => $website_id ?? 2,
  689. 'survey_name' => $survey_name,
  690. 'choice_name' => $value,
  691. 'is_other' => 0,
  692. 'other_id' => 0,
  693. 'results' => 0,
  694. ];
  695. }
  696. if (empty($suvey_data)) {
  697. throw new \Exception("投票数据为空");
  698. }
  699. }
  700. $result = ArticleSurvey::insert($suvey_data);
  701. if (!$result) {
  702. throw new \Exception("投票失败,ArticleSurvey插入失败");
  703. }
  704. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  705. if (!$result) {
  706. throw new \Exception("投票失败,更新主表失败");
  707. }
  708. }
  709. Db::commit();
  710. return Result::success(['id' => $id]);
  711. } catch (\Throwable $ex) {
  712. Db::rollBack();
  713. var_dump($ex->getMessage());
  714. return Result::error("创建失败", 0);
  715. }
  716. }
  717. /**
  718. * @param array $data
  719. * @return array
  720. */
  721. public function delArticle(array $data): array
  722. {
  723. // ------c_show_time********del*******
  724. Db::beginTransaction();
  725. try {
  726. $article = Article::where(['id' => $data['id']])->delete();
  727. // 若文章删除失败,抛出异常,后续 SQL 语句不会执行
  728. if (!$article) {
  729. throw new \Exception("删除失败,文章删除失败");
  730. }
  731. //survey投票删除
  732. ArticleSurvey::where(['art_id' => $data['id']])->delete(); // 修正类名大小写
  733. $articleIgnore = ArticleIgnore::where(['article_id' => $data['id']])->delete();
  734. $article_data = ArticleData::where(['article_id' => $data['id']])->delete();
  735. // 若文章详情删除失败,抛出异常
  736. if (!$article_data) {
  737. throw new \Exception("删除失败,文章详情删除失败");
  738. }
  739. Db::commit(); // 所有操作成功,提交事务
  740. } catch (\Throwable $ex) {
  741. Db::rollBack();
  742. var_dump($ex->getMessage());
  743. return Result::error("删除失败: " . $ex->getMessage(), 0);
  744. }
  745. // ------c_show_time********del*******
  746. if (!$article) {
  747. return Result::error("删除失败");
  748. }
  749. return Result::success($article);
  750. }
  751. /**
  752. * @param array $data
  753. * @return array
  754. */
  755. public function updateArticle(array $data): array
  756. {
  757. var_dump($data, '----------12-----------1');
  758. Db::beginTransaction();
  759. // ------c_show_time********up*******
  760. $user_type = isset($data['user_type']) ? $data['user_type'] : 0;
  761. // 无论是否改变了c端显示时间或者栏目,都需要将未屏蔽的网站显示时间删除记录
  762. // 若是存在交集,则进行修改,若无,则合并(此表中的记录应该包含被屏蔽网站及涉及所有网站的展示时间)
  763. $web = WebsiteCategory::where('category_id', $data['catid'])
  764. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  765. ->select(
  766. 'website_id',
  767. 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')
  768. )
  769. ->get();
  770. // 根据错误信息,问题在于 $web 可能是一个包含对象的集合,不能直接用于 whereNotIn 方法
  771. // 先从 $web 集合中提取 website_id 字段的值,再进行删除操作
  772. $websiteIds = $web->pluck('website_id')->toArray();
  773. $del_article_ignore = ArticleIgnore::where('article_id', $data['id'])->whereNotIn('website_id', $websiteIds)->delete();
  774. if ($user_type == 0) {
  775. throw new \Exception("用户类型不能为空");
  776. }
  777. if ($user_type == 10000) {
  778. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  779. $web = WebsiteCategory::where('category_id', $data['catid'])
  780. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  781. ->select(
  782. 'website_id',
  783. 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')
  784. )
  785. ->get();
  786. // 非核心站与核心站----显示时间-----间隔
  787. $time = 20;
  788. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  789. $waiting_interval = 5;
  790. $webArray = $web->toArray();
  791. if (empty($webArray)) {
  792. throw new \Exception('网站分类不存在');
  793. }
  794. // 直接使用当前系统时间,不再强制添加8小时
  795. $now = date('Y-m-d H:i:s');
  796. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  797. // 检查 $item 对象是否有 is_core 属性
  798. if (!isset($item['is_core'])) {
  799. throw new \Exception('$item 对象缺少 is_core 属性');
  800. }
  801. // 当 is_core 为 2 时,则表示此网站不存在
  802. if ($item['is_core'] == 2) {
  803. return null;
  804. } else if ($item['is_core'] == 1) {
  805. // 当 is_core 为 1 时,则表示此网站是核心站
  806. $c_show_time = date('Y-m-d H:i:s', strtotime($now));
  807. } else {
  808. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  809. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  810. if ($item['is_core'] == 0) {
  811. $time += $waiting_interval;
  812. }
  813. }
  814. return [
  815. 'article_id' => $data['id'],
  816. 'website_id' => $item['website_id'],
  817. 'c_show_time' => $c_show_time,
  818. ];
  819. }, array_keys($webArray), $webArray)));
  820. if (!empty($article_ignore)) {
  821. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  822. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  823. $article_ignores = ArticleIgnore::upsert(
  824. $article_ignore,
  825. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  826. ['c_show_time'] // 需要更新的字段
  827. );
  828. if (!$article_ignores) {
  829. throw new \Exception('c端展示时间插入失败');
  830. }
  831. }
  832. // Db::commit();
  833. // return Result::success($article_ignore);
  834. }
  835. // ------c_show_time********up*******
  836. unset($data['user_type']);
  837. // unset($data['web_site_id']);
  838. unset($data['nav_add_pool_id']);
  839. try {
  840. //处理投票
  841. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  842. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  843. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  844. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  845. unset($data['is_survey']);
  846. unset($data['survey_name']);
  847. unset($data['suvey_array']);
  848. unset($data['website_id']);
  849. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  850. if ($data['hits'] == '') {
  851. $data['hits'] = 0;
  852. }
  853. if ($data['is_original'] == '') {
  854. $data['is_original'] = 0;
  855. }
  856. if ($data['status'] == '') {
  857. $data['status'] = 0;
  858. }
  859. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  860. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  861. $articleData = $data;
  862. unset($articleData['content']);
  863. unset($articleData['status_name']);
  864. unset($articleData['name']);
  865. unset($articleData['content']);
  866. unset($articleData['pid_arr']);
  867. unset($articleData['pid']);
  868. //自动处理缩略图、关键字、描述
  869. if ($articleData['imgurl'] == '') {
  870. //如果没有图,设置level=0
  871. $levelArr = json_decode($articleData['level'], true);
  872. var_dump($levelArr, '----------levelArr-----------1');
  873. //content中提取图片第一个图,正则提取
  874. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  875. preg_match_all($reg, $data['content'], $matches);
  876. if (isset($matches[1][0])) {
  877. //截取varchar240
  878. // 截取到第一个<
  879. $articleData['imgurl'] = $matches[1][0];
  880. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  881. $pos = strpos($articleData['imgurl'], '"');
  882. if ($pos !== false) {
  883. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  884. }
  885. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  886. //如果有图,设置level=3
  887. if (!in_array(3, $levelArr)) {
  888. $levelArr[] = 3;
  889. }
  890. $articleData['level'] = json_encode($levelArr);
  891. } else {
  892. if (!in_array(0, $levelArr)) {
  893. $levelArr[] = 0;
  894. }
  895. $articleData['level'] = json_encode($levelArr);
  896. }
  897. }
  898. var_dump($articleData['level'], '----------$articleData[level]----------1');
  899. if ($articleData['keyword'] == '') {
  900. //提取标题+内容中的关键词
  901. $articleData['keyword'] = $data['title'];
  902. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  903. Jieba::init(); // 初始化 jieba-php
  904. Finalseg::init();
  905. $segList = Jieba::cut($articleData['keyword']);
  906. $segList1 = array_slice($segList, 0, 8);
  907. $articleData['keyword'] = implode(',', $segList1);
  908. }
  909. if ($articleData['introduce'] == '') {
  910. //提取内容中的描述
  911. $content = $data['content'];
  912. // 去除 <style> 和 <script> 标签及其内容
  913. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  914. // 去除所有 HTML 标签
  915. $content = strip_tags($content);
  916. // 去除 HTML 实体
  917. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  918. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  919. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  920. // 去除多余空白
  921. $content = preg_replace('/\s+/u', '', $content);
  922. // 截取 100 个字符
  923. $articleData['introduce'] = mb_substr($content, 0, 100);
  924. }
  925. if ($articleData['status'] == 0) {
  926. $this->sendMessage([
  927. 'talk_type' => 100,
  928. 'title' => $articleData['title'],
  929. 'content' => '提交了审核',
  930. 'messageType' => 2,
  931. ]);
  932. }
  933. $id = Article::where(['id' => $data['id']])->update($articleData);
  934. // $articleDataContent = [
  935. // 'content' => $data['content'],
  936. // ];
  937. // 采集来的文章,content中可能包含div标签,需要先移除
  938. $pattern = '/<\/?div\b(?:[^"\'>]|"[^"]*"|\'[^\']*\')*>/is';
  939. $article_data = preg_replace($pattern, '', $data['content']);
  940. $articleDataContent['content'] = $article_data;
  941. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  942. //处理投票
  943. $id = $data['id'];
  944. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  945. var_dump($suvey_array, 'suvey_array________delete');
  946. //处理投票
  947. if ($is_survey == 1) {
  948. //生成年月日时分秒+8位随机数
  949. $uuid = date('YmdHis') . rand(10000000, 99999999);
  950. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  951. var_dump($suveys_array, '---------------------1');
  952. $suvey_data = [];
  953. if (is_array($suveys_array)) {
  954. foreach ($suveys_array as $key => $value) {
  955. if ($value == '') {
  956. continue;
  957. }
  958. if (is_array($value)) {
  959. $suvey_data[] = [
  960. 'sur_id' => $uuid,
  961. 'art_id' => $id,
  962. 'website_id' => $website_id ?? 2,
  963. 'survey_name' => $survey_name,
  964. 'choice_name' => $value[1],
  965. 'is_other' => 1,
  966. 'other_id' => 0,
  967. 'results' => 0,
  968. ];
  969. } else {
  970. $suvey_data[] = [
  971. 'sur_id' => $uuid,
  972. 'art_id' => $id,
  973. 'website_id' => $website_id ?? 2,
  974. 'survey_name' => $survey_name,
  975. 'choice_name' => $value,
  976. 'is_other' => 0,
  977. 'other_id' => 0,
  978. 'results' => 0,
  979. ];
  980. }
  981. if (empty($suvey_data)) {
  982. throw new \Exception("投票数据为空");
  983. }
  984. }
  985. }
  986. $result = ArticleSurvey::insert($suvey_data);
  987. if (!$result) {
  988. throw new \Exception("投票失败");
  989. }
  990. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  991. if (!$result) {
  992. throw new \Exception("投票失败");
  993. }
  994. } else {
  995. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  996. }
  997. Db::commit();
  998. return Result::success([]);
  999. } catch (\Throwable $ex) {
  1000. Db::rollBack();
  1001. var_dump($ex->getMessage());
  1002. return Result::error("更新失败" . $ex->getMessage(), 0);
  1003. }
  1004. }
  1005. /**
  1006. * 更新资讯状态
  1007. * @param array $data
  1008. * @return array
  1009. */
  1010. public function upArticleStatus(array $data): array
  1011. {
  1012. $articleData = Article::where(['id' => $data['id']])->first();
  1013. //发送10次
  1014. // for ($i = 0; $i < 10; $i++) {
  1015. // $this->sendMessage([
  1016. // 'talk_type' => 100,
  1017. // 'title' => $i . $articleData['title'],
  1018. // 'content' => '审核通过',
  1019. // 'messageType' => 2,
  1020. // 'user_id' => $articleData['admin_user_id'],
  1021. // ]);
  1022. // }
  1023. // var_dump($data['status'], 'status');
  1024. // return Result::success();
  1025. if ($data['status'] == 1) {
  1026. $this->sendMessage([
  1027. 'talk_type' => 101,
  1028. 'title' => $articleData['title'],
  1029. 'content' => '审核通过',
  1030. 'messageType' => 2,
  1031. 'user_id' => $articleData['admin_user_id'],
  1032. ]);
  1033. }
  1034. if ($data['status'] == 2) {
  1035. $this->sendMessage([
  1036. 'talk_type' => 101,
  1037. 'title' => $articleData['title'],
  1038. 'content' => '审核拒绝',
  1039. 'messageType' => 2,
  1040. 'user_id' => $articleData['admin_user_id'],
  1041. ]);
  1042. }
  1043. if ($data['status'] == 0) {
  1044. $this->sendMessage([
  1045. 'talk_type' => 100,
  1046. 'title' => $articleData['title'],
  1047. 'content' => '提交了审核',
  1048. 'messageType' => 2,
  1049. ]);
  1050. }
  1051. $result = Article::where(['id' => $data['id']])->update($data);
  1052. // ------c_show_time********up_status*******
  1053. // 若是审核通过 则更新c_show_time
  1054. if ($data['status'] == 1) {
  1055. // 查找网站,若是核心站则返回字段is_core=1,否则返回is_core=0,若是不存在此网站则为is_core=2
  1056. $web = Article::where('article.id', $data['id'])
  1057. ->leftJoin('website_category', 'article.catid', 'website_category.category_id')
  1058. ->leftJoin('website', 'website_category.website_id', '=', 'website.id')
  1059. ->select(
  1060. 'website_id',
  1061. Db::raw('CASE WHEN website.id IS NULL THEN 2 WHEN JSON_CONTAINS(website.`website_column_arr_id`, \'3\') THEN 1 ELSE 0 END as is_core')
  1062. )
  1063. ->get();
  1064. // 非核心站与核心站----显示时间-----间隔
  1065. $time = 20;
  1066. // 若不是采集来的文章,则非核心站之间的间隔时间为5分钟;初始时间与当前时间差二十分钟
  1067. $waiting_interval = 5;
  1068. $webArray = $web->toArray();
  1069. if (empty($webArray)) {
  1070. throw new \Exception('网站分类不存在');
  1071. }
  1072. // 直接使用当前系统时间,不再强制添加8小时
  1073. $now = date('Y-m-d H:i:s');
  1074. $article_ignore = array_values(array_filter(array_map(function ($index, $item) use (&$time, $now, $data, $waiting_interval) {
  1075. if (isset($data['ignore_ids'])) {
  1076. $ignore_website_ids = is_array($data['ignore_ids']) ? $data['ignore_ids'] : json_decode($data['ignore_ids'], true);
  1077. if (in_array($item['website_id'], $ignore_website_ids)) {
  1078. $is_ignore = 1;
  1079. } else {
  1080. $is_ignore = 0;
  1081. }
  1082. return [
  1083. 'article_id' => $data['id'],
  1084. 'website_id' => $item['website_id'],
  1085. 'is_ignore' => $is_ignore,
  1086. ];
  1087. } else {
  1088. // 检查 $item 对象是否有 is_core 属性
  1089. if (!isset($item['is_core'])) {
  1090. throw new \Exception('$item 对象缺少 is_core 属性');
  1091. }
  1092. // 当 is_core 为 2 时,则表示此网站不存在
  1093. if ($item['is_core'] == 2) {
  1094. return null;
  1095. } else if ($item['is_core'] == 1) {
  1096. // 当 is_core 为 1 时,则表示此网站是核心站
  1097. $c_show_time = $now;
  1098. } else {
  1099. // 若是is_core为0,则表示此网站不是核心站,需要往后推时间
  1100. $c_show_time = date('Y-m-d H:i:s', strtotime($now) + $time * 60);
  1101. if ($item['is_core'] == 0) {
  1102. $time += $waiting_interval;
  1103. }
  1104. }
  1105. return [
  1106. 'article_id' => $data['id'],
  1107. 'website_id' => $item['website_id'],
  1108. 'c_show_time' => $c_show_time,
  1109. ];
  1110. }
  1111. }, array_keys($webArray), $webArray)));
  1112. if (!empty($article_ignore) && !isset($data['ignore_ids'])) {
  1113. // 使用 upsert 方法,当 article_id 和 website_id 组合存在时更新 c_show_time,不存在时插入新记录
  1114. // 使用 upsert 方法,根据 article_id 和 website_id 作为唯一键判断记录是否存在,存在则更新 c_show_time 字段,不存在则新增
  1115. $websiteIds = $web->pluck('website_id')->toArray();
  1116. $del_article_ignore = ArticleIgnore::where('article_id', $data['id'])->whereNotIn('website_id', $websiteIds)->delete();
  1117. $article_ignores = ArticleIgnore::upsert(
  1118. $article_ignore,
  1119. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  1120. ['c_show_time'] // 需要更新的字段
  1121. );
  1122. if (!$article_ignores) {
  1123. throw new \Exception('c端展示时间插入失败');
  1124. }
  1125. }
  1126. if (!empty($data['ignore_ids'])) {
  1127. // return Result::success($article_ignore);
  1128. // 从数据库中删除 article_id 为 $data['id'] 且 website_id 在 $website_ids 中的记录
  1129. if (!empty($article_ignore)) {
  1130. $article_ignores = ArticleIgnore::upsert(
  1131. $article_ignore,
  1132. ['article_id', 'website_id'], // 用于判断记录是否存在的唯一键
  1133. ['is_ignore'] // 需要更新的字段
  1134. );
  1135. // if(!$article_ignores){
  1136. // throw new \Exception('屏蔽网站更新失败');
  1137. // }
  1138. }
  1139. }
  1140. }
  1141. // ------c_show_time********up_status*******
  1142. if ($result) {
  1143. return Result::success();
  1144. } else {
  1145. return Result::error("更新状态失败", 0);
  1146. }
  1147. }
  1148. /**
  1149. * 获取新闻详情
  1150. * @param array $data
  1151. * @return array
  1152. */
  1153. public function getArticleInfo(array $data): array
  1154. {
  1155. $where = [
  1156. 'article.id' => $data['id'],
  1157. // 'article.status' => 1,
  1158. ];
  1159. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  1160. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  1161. $info = $result;
  1162. // var_dump($info, 'info');
  1163. $info['survey_array'] = $articleSurvey;
  1164. if ($result) {
  1165. return Result::success($info);
  1166. } else {
  1167. return Result::error("查询失败", 0);
  1168. }
  1169. }
  1170. /**
  1171. * 获取头条新闻
  1172. * @param array $data
  1173. * @return array
  1174. */
  1175. public function getWebsiteArticlett(array $data): array
  1176. {
  1177. $website_id = $data['website_id'];
  1178. $website = Website::where('id', $data['website_id'])->first();
  1179. if (empty($website)) {
  1180. return Result::error("网站不存在", 0);
  1181. }
  1182. $categorys = $this->processArticlePro($website_id);
  1183. $catiall = $categorys['catiall'];
  1184. $categoryIds = $categorys['categoryIds'];
  1185. $where = [
  1186. 'status' => 1
  1187. ];
  1188. // $website_column = $website['column'];
  1189. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1190. $website_column = json_decode($website['website_column_arr_id'], true);
  1191. }
  1192. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1193. // return Result::success($diff_pid_categoryIds);
  1194. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1195. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1196. }
  1197. // $website_id = $data['website_id'];
  1198. $month = date("Y-m-d H:i:s", strtotime("-30 day"));
  1199. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  1200. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  1201. switch ($data['level']) {
  1202. case 1:
  1203. case 2:
  1204. case 3:
  1205. case 6: //1.头条资讯;2.轮播图;3.推荐图;6.今日热点
  1206. $query = Article::where($where)
  1207. ->where('level', 'like', '%' . $data['level'] . '%')
  1208. ->orderBy('updated_at', 'desc');
  1209. break;
  1210. case 4: //最新资讯
  1211. $query = Article::where($where)->orderBy('updated_at', 'desc');
  1212. break;
  1213. case 5: //资讯推荐
  1214. $query = Article::where($where)
  1215. ->where('updated_at', '>', $month);
  1216. break;
  1217. case 7: //资讯分类
  1218. if (isset($data['id']) && !empty($data['id'])) {
  1219. $keyword = Article::where('id', $data['id'])->value('keyword');
  1220. $keywordArray = explode(',', $keyword);
  1221. $whereL7 = [];
  1222. foreach ($keywordArray as $k => $v) {
  1223. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1224. }
  1225. $query = Article::where($where)->where($whereL7)->orderBy('updated_at', 'desc');;
  1226. break;
  1227. } else {
  1228. return Result::error("请输入资讯ID", 0);
  1229. break;
  1230. }
  1231. default:
  1232. break;
  1233. }
  1234. // $whereL7 = [];
  1235. // if(isset($data['id']) && !empty($data['id'])){
  1236. // $keyword = Article::where('id', $data['id'])->value('keyword');
  1237. // $keywordArray = explode(',', $keyword);
  1238. // foreach ($keywordArray as $k => $v) {
  1239. // $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  1240. // }
  1241. // }
  1242. // $query = Article::where($where)
  1243. // ->when(isset($data['level']) && !empty($data['level']), function ($query) use ($data,$whereL7) {
  1244. // if($data['level'] == 1 || $data['level'] == 2 || $data['level'] == 3 || $data['level'] == 6){
  1245. // $query = $query->where('article.level','like','%'.$data['level'].'%')->orderBy('updated_at','desc');
  1246. // }
  1247. // if($data['level'] == 7){
  1248. // $query = $query->where($whereL7)->orderBy('updated_at','desc');
  1249. // }
  1250. // if($data['level'] == 4){
  1251. // $query = $query->inRandomOrder()
  1252. // ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  1253. // }
  1254. // if($data['level'] == 5){
  1255. // $query = $query->orderBy('updated_at','desc');
  1256. // }
  1257. // });
  1258. if ($data['textnum'] > 0) {
  1259. $query = clone $query;
  1260. $result['text'] = $query
  1261. ->whereIn('catid', $categoryIds)
  1262. ->leftJoinSub(function ($query) use ($website_id) {
  1263. $query->from('article_ignore')
  1264. ->where('website_id', $website_id);
  1265. }, 'article_ignore', function ($join) {
  1266. $join->on('article_ignore.article_id', '=', 'article.id');
  1267. })
  1268. ->where(function ($query) {
  1269. $query->whereNull('article_ignore.article_id')
  1270. ->orWhere(function ($subQuery) {
  1271. $subQuery->whereNotNull('article_ignore.article_id')
  1272. ->where('article_ignore.is_ignore', 0)
  1273. ->where(function ($subSubQuery) {
  1274. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1275. ->orWhereNull('article_ignore.c_show_time');
  1276. });
  1277. });
  1278. })
  1279. // ->where(function ($query) use ($website_id) {
  1280. // $query->whereNull('article_ignore.article_id')
  1281. // ->orWhere('article_ignore.website_id', '!=', $website_id);
  1282. // })
  1283. ->select(
  1284. 'article.id',
  1285. 'article.title',
  1286. 'article.author',
  1287. 'article.updated_at',
  1288. 'article.introduce',
  1289. 'article.islink',
  1290. 'article.linkurl',
  1291. 'article.copyfrom',
  1292. 'article.cat_arr_id',
  1293. 'article.catid',
  1294. 'article.level',
  1295. // 'article_ignore.is_ignore',
  1296. // 'article_ignore.c_show_time',
  1297. )
  1298. ->offset($data['placeid'])
  1299. ->limit($data['textnum'])
  1300. ->get()->all();
  1301. foreach ($result['text'] as $k => $v) {
  1302. $result['text'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1303. $result['text'][$k]->alias = $catiall[$v->catid]['alias'];
  1304. }
  1305. }
  1306. if ($data['imgnum'] > 0) {
  1307. $query = clone $query;
  1308. if ($data['textnum'] == 0) {
  1309. $query = $query->leftJoinSub(function ($query) use ($website_id) {
  1310. $query->from('article_ignore')
  1311. ->where('website_id', $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(function ($subSubQuery) {
  1321. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1322. ->orWhereNull('article_ignore.c_show_time');
  1323. });
  1324. });
  1325. });
  1326. }
  1327. $result['img'] = $query
  1328. ->whereIn('catid', $categoryIds)
  1329. ->where('article.imgurl', '!=', '')
  1330. ->select(
  1331. 'article.id',
  1332. 'article.title',
  1333. 'article.imgurl',
  1334. 'article.author',
  1335. 'article.updated_at',
  1336. 'article.introduce',
  1337. 'article.islink',
  1338. 'article.linkurl',
  1339. 'article.copyfrom',
  1340. 'article.cat_arr_id',
  1341. 'article.catid',
  1342. 'article.level',
  1343. // 'article_ignore.is_ignore',
  1344. // 'article_ignore.c_show_time',
  1345. )
  1346. ->offset($data['placeid'])
  1347. ->limit($data['imgnum'])
  1348. ->get()->all();
  1349. foreach ($result['img'] as $k => $v) {
  1350. $result['img'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1351. $result['img'][$k]->alias = $catiall[$v->catid]['alias'];
  1352. }
  1353. }
  1354. if (empty($result)) {
  1355. return Result::error("暂无相关资讯", 0);
  1356. }
  1357. return Result::success($result);
  1358. }
  1359. /**
  1360. * 获取模块新闻
  1361. * @param array $data
  1362. * @return array
  1363. */
  1364. public function getWebsiteModelArticles(array $data): array
  1365. {
  1366. $catid = $data['catid'];
  1367. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  1368. $category = $category->toArray();
  1369. if (!empty($category)) {
  1370. $where = [
  1371. 'status' => 1,
  1372. 'catid' => $catid,
  1373. ];
  1374. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  1375. // 1:文字新闻;2:轮播图;3:图文;
  1376. // 级别:0:未分类
  1377. // 3:推荐图片
  1378. if ($data['level'] == 1) {
  1379. $data['level'] = 0;
  1380. }
  1381. $result = Article::where($where)
  1382. ->where(function ($query) use ($data) {
  1383. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  1384. ->orWhereNull("level")
  1385. ->orWhereRaw("level = '[]'");
  1386. })
  1387. ->leftJoinSub(function ($query) use ($data) {
  1388. $query->from('article_ignore')
  1389. ->where('website_id', $data['website_id']);
  1390. }, 'article_ignore', function ($join) {
  1391. $join->on('article_ignore.article_id', '=', 'article.id');
  1392. })
  1393. ->where(function ($query) {
  1394. $query->whereNull('article_ignore.article_id')
  1395. ->orWhere(function ($subQuery) {
  1396. $subQuery->whereNotNull('article_ignore.article_id')
  1397. ->where('article_ignore.is_ignore', 0)
  1398. ->where(function ($subSubQuery) {
  1399. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1400. ->orWhereNull('article_ignore.c_show_time');
  1401. });
  1402. });
  1403. })
  1404. // ->where(function ($query) use ($data) {
  1405. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1406. // ->orWhereNull("ignore_ids");
  1407. // })
  1408. ->orderBy("updated_at", "desc")
  1409. ->offset($placeid)
  1410. ->limit($data['pagesize'])
  1411. ->get();
  1412. if (empty($result)) {
  1413. return Result::error("此栏目暂无相关新闻", 0);
  1414. }
  1415. } else {
  1416. return Result::error("此网站暂无此栏目", 0);
  1417. }
  1418. return Result::success($result);
  1419. }
  1420. /**
  1421. *获取新闻列表
  1422. * @param array $data
  1423. * @return array
  1424. */
  1425. public function getWebsiteArticleList(array $data): array
  1426. {
  1427. // return Result::success($data);
  1428. $where[] = ['status', '=', 1];
  1429. $website_id = $data['website_id'];
  1430. $website = Website::where('id', $data['website_id'])->first();
  1431. if (empty($website)) {
  1432. return Result::error("网站不存在", 0);
  1433. }
  1434. // $website_column = $website['column'];
  1435. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1436. $website_column = json_decode($website['website_column_arr_id'], true);
  1437. }
  1438. $categorys = $this->processArticlePro($website_id);
  1439. $cat_1st_arr = $categorys['cat_1st_arr'];
  1440. $catiall = $categorys['catiall'];
  1441. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1442. // return Result::success($diff_pid_categoryIds);
  1443. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1444. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1445. }
  1446. if (isset($data['catid']) && !empty($data['catid'])) {
  1447. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  1448. if (empty($category)) {
  1449. return Result::error("此网站暂无此栏目", 0);
  1450. }
  1451. array_push($where, ['catid', '=', $data['catid']]);
  1452. }
  1453. // return Result::success($where);
  1454. $query = Article::where($where)
  1455. ->leftJoinSub(function ($query) use ($website_id) {
  1456. $query->from('article_ignore')
  1457. ->where('website_id', $website_id);
  1458. }, 'article_ignore', function ($join) {
  1459. $join->on('article_ignore.article_id', '=', 'article.id');
  1460. })
  1461. ->where(function ($query) {
  1462. $query->whereNull('article_ignore.article_id')
  1463. ->orWhere(function ($subQuery) {
  1464. $subQuery->whereNotNull('article_ignore.article_id')
  1465. ->where('article_ignore.is_ignore', 0)
  1466. ->where(function ($subSubQuery) {
  1467. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1468. ->orWhereNull('article_ignore.c_show_time');
  1469. });
  1470. });
  1471. })
  1472. ->select(
  1473. 'article.id',
  1474. 'article.title',
  1475. 'article.imgurl',
  1476. 'article.author',
  1477. 'article.updated_at',
  1478. 'article.introduce',
  1479. 'article.islink',
  1480. 'article.linkurl',
  1481. 'article.copyfrom',
  1482. 'article.cat_arr_id',
  1483. 'article.catid'
  1484. );
  1485. $count = $query->count();
  1486. $rep = $query->orderBy("updated_at", "desc")
  1487. ->offset(($data['page'] - 1) * $data['pageSize'])
  1488. ->limit($data['pageSize'])
  1489. ->get()->all();
  1490. $categorys = $this->processArticlePro($website_id);
  1491. $cat_1st_arr = $categorys['cat_1st_arr'];
  1492. $catiall = $categorys['catiall'];
  1493. // $web['website_id'] = $data['website_id'];
  1494. foreach ($rep as $k => $v) {
  1495. $rep[$k]->category_name = $catiall[$v->catid]['alias'];
  1496. $rep[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1497. }
  1498. // $rep = $this->processArticles($rep,$web);
  1499. $data = [
  1500. 'rows' => $rep,
  1501. 'count' => $count,
  1502. ];
  1503. if (empty($rep)) {
  1504. return Result::error("没有信息数据");
  1505. }
  1506. return Result::success($data);
  1507. }
  1508. /**
  1509. * 前端-获取新闻详情
  1510. * @param array $data
  1511. * @return array
  1512. */
  1513. public function selectWebsiteArticleInfo(array $data): array
  1514. {
  1515. $where = [
  1516. 'article.id' => $data['id'],
  1517. 'article.status' => 1,
  1518. ];
  1519. $result = Article::where($where)
  1520. ->leftJoin("article_data", "article.id", "article_data.article_id")
  1521. ->leftJoin("article_extend", "article_extend.article_id", "article.id")
  1522. // ->where(function ($query) use ($data) {
  1523. // $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1524. // ->orWhereNull("ignore_ids");
  1525. // })
  1526. ->leftJoinSub(function ($query) use ($data) {
  1527. $query->from('article_ignore')
  1528. ->where('website_id', $data['website_id']);
  1529. }, 'article_ignore', function ($join) {
  1530. $join->on('article_ignore.article_id', '=', 'article.id');
  1531. })
  1532. ->where(function ($query) {
  1533. $query->whereNull('article_ignore.article_id')
  1534. ->orWhere(function ($subQuery) {
  1535. $subQuery->whereNotNull('article_ignore.article_id')
  1536. ->where('article_ignore.is_ignore', 0)
  1537. ->where(function ($subSubQuery) {
  1538. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1539. ->orWhereNull('article_ignore.c_show_time');
  1540. });
  1541. });
  1542. })
  1543. ->select(
  1544. 'article.*',
  1545. 'article_data.content',
  1546. 'article_data.article_id',
  1547. 'article_extend.website_url',
  1548. 'article_extend.email',
  1549. 'article_extend.contacts',
  1550. 'article_extend.contacts_mobile',
  1551. 'article_extend.contacts_address',
  1552. 'article_extend.zip_code',
  1553. 'article_extend.enterprise_name'
  1554. )
  1555. ->first();
  1556. if (empty($result)) {
  1557. return Result::error("暂无此新闻!", 0);
  1558. }
  1559. if (!empty($result['publiced_at'])) {
  1560. $result['updated_at'] = $result['publiced_at'];
  1561. }
  1562. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  1563. ->select('website_category.*', 'website.website_name', 'website.suffix')
  1564. ->where('website_category.website_id', $data['website_id'])
  1565. ->where(['website_category.category_id' => $result['catid']])
  1566. ->first();
  1567. if (empty($category)) {
  1568. return Result::error("查询失败", 0);
  1569. }
  1570. //手动推荐文章
  1571. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  1572. if (empty($commend_ids)) {
  1573. $commendArticle = [];
  1574. } else {
  1575. //去除不存在的文章ID
  1576. $commendArticle = Article::whereIn('article.id', $commend_ids)
  1577. ->leftjoin('website_category', 'website_category.category_id', '=', 'article.catid')
  1578. ->leftJoinSub(function ($query) use ($data) {
  1579. $query->from('article_ignore')
  1580. ->where('website_id', $data['website_id']);
  1581. }, 'article_ignore', function ($join) {
  1582. $join->on('article_ignore.article_id', '=', 'article.id');
  1583. })
  1584. ->where(function ($query) {
  1585. $query->whereNull('article_ignore.article_id')
  1586. ->orWhere(function ($subQuery) {
  1587. $subQuery->whereNotNull('article_ignore.article_id')
  1588. ->where('article_ignore.is_ignore', 0)
  1589. ->where(function ($subSubQuery) {
  1590. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1591. ->orWhereNull('article_ignore.c_show_time');
  1592. });
  1593. });
  1594. })
  1595. ->where('article.status', 1)
  1596. ->where('website_category.website_id', $data['website_id'])
  1597. ->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')
  1598. ->orderByRaw("FIELD(article.id, " . implode(',', $commend_ids) . ")")
  1599. // ->orderBy('article.updated_at', 'desc')
  1600. ->limit(5)
  1601. ->get();
  1602. //循环数组,取出cat_arr_id中的不重复值,再从website_category取出alias_pinyin,再将cat_arr_id的json转成路径/隔开
  1603. foreach ($commendArticle as $k => $v) {
  1604. $cat_arr_id = json_decode($v->cat_arr_id, true);
  1605. if (!empty($cat_arr_id) && is_array($cat_arr_id)) {
  1606. $cat_arr_id = array_unique($cat_arr_id);
  1607. // 从website_category取出alias_pinyin
  1608. $cat_arr = WebsiteCategory::where('website_id', $data['website_id'])
  1609. ->whereIn('category_id', $cat_arr_id)
  1610. ->pluck('alias_pinyin', 'category_id')
  1611. ->toArray();
  1612. // 将cat_arr_id的json转成路径/隔开
  1613. $path_parts = [];
  1614. foreach ($cat_arr_id as $cat_id) {
  1615. if (isset($cat_arr[$cat_id])) {
  1616. $path_parts[] = $cat_arr[$cat_id];
  1617. }
  1618. }
  1619. $v->alias_pinyin = implode('/', $path_parts);
  1620. } else {
  1621. $v->alias_pinyin = '';
  1622. }
  1623. }
  1624. }
  1625. $result['category_id'] = $category['category_id'];
  1626. $result['cat_name'] = $category['alias'];
  1627. $result['website_name'] = $category['website_name'] ?? "";
  1628. $result['suffix'] = $category['suffix'] ?? "";
  1629. $result['commendArticle'] = $commendArticle;
  1630. $result['commend_ids'] = $commend_ids;
  1631. return Result::success($result);
  1632. }
  1633. /**
  1634. * 前端-获取网站调查问卷
  1635. * @param array $data
  1636. * @return array
  1637. */
  1638. public function getWebsiteSurvey(array $data): array
  1639. {
  1640. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1641. $website = Website::where('id', $data['website_id'])->first();
  1642. if (empty($website)) {
  1643. return Result::error("暂无此网站", 0);
  1644. }
  1645. }
  1646. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1647. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1648. if (empty($article)) {
  1649. return Result::error("暂无此文章", 0);
  1650. }
  1651. // return Result::error($data,0);
  1652. $where['art_id'] = $data['art_id'];
  1653. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1654. } else {
  1655. $survey = Article::where(function ($query) {
  1656. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1657. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1658. })
  1659. ->where('status', 1)
  1660. ->where('is_survey', 1)
  1661. ->select('survey_id')
  1662. ->orderBy('updated_at', 'desc')
  1663. ->first();
  1664. if (empty($survey)) {
  1665. return Result::error("暂无调查问卷", 0);
  1666. }
  1667. $where['sur_id'] = $survey['survey_id'];
  1668. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1669. }
  1670. // return Result::success($where);
  1671. $result = ArticleSurvey::where($where)
  1672. ->where(function ($query) {
  1673. $query->where('is_other', 0)
  1674. ->orWhere(function ($subQuery) {
  1675. $subQuery->where('is_other', 1)
  1676. ->where('other_id', 0);
  1677. });
  1678. })
  1679. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1680. ->select('article_survey.*', 'article.survey_type')
  1681. ->get()->all();
  1682. if (empty($result)) {
  1683. return Result::error("此文章暂无调查问卷", 0);
  1684. }
  1685. return Result::success($result);
  1686. }
  1687. /**
  1688. * 前端-添加网站调查问卷选项
  1689. * @param array $data
  1690. * @return array
  1691. */
  1692. public function addWebsiteSurveyOption(array $data): array
  1693. {
  1694. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1695. $website = Website::where('id', $data['website_id'])->first();
  1696. if (empty($website)) {
  1697. return Result::error("暂无此网站", 0);
  1698. }
  1699. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1700. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1701. if (empty($survey)) {
  1702. return Result::error("此调查问卷不可添加选项", 0);
  1703. }
  1704. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1705. $choice = [
  1706. 'art_id' => $survey['art_id'],
  1707. 'website_id' => $data['website_id'],
  1708. 'survey_name' => $survey['survey_name'],
  1709. 'choice_name' => $data['choice_name'],
  1710. 'sur_id' => $survey['sur_id'],
  1711. 'is_other' => 1,
  1712. 'other_id' => $survey['id'],
  1713. ];
  1714. $result = ArticleSurvey::insertGetId($choice);
  1715. if (empty($result)) {
  1716. return Result::error("添加失败", 0);
  1717. }
  1718. return Result::success($result);
  1719. }
  1720. }
  1721. return Result::error("添加失败", 0);
  1722. }
  1723. return Result::error("添加失败", 0);
  1724. }
  1725. /**
  1726. * 前端-调查问卷投票
  1727. * @param array $data
  1728. * @return array
  1729. */
  1730. public function addWebsiteSurveyVote(array $data): array
  1731. {
  1732. // return Result::success($data);
  1733. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1734. $website = Website::where('id', $data['website_id'])->first();
  1735. if (empty($website)) {
  1736. return Result::error("暂无此网站", 0);
  1737. }
  1738. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1739. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1740. // return Result::success($survey);
  1741. if (empty($is_survey)) {
  1742. return Result::error("此调查问卷不存在", 0);
  1743. }
  1744. // return Result::success($survey);
  1745. // 调查问卷类型
  1746. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1747. //多选 若是json型则转化成数组类型
  1748. if (strpos($data['choice_id'], '[') === 0) {
  1749. $data['choice_id'] = json_decode($data['choice_id'], true);
  1750. } else {
  1751. // 单选 也转换成数组
  1752. $data['choice_id'] = [$data['choice_id']];
  1753. }
  1754. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1755. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1756. // ->where('website_id',$data['website_id'])
  1757. ->where('is_other', 1)
  1758. ->where('other_id', 0)
  1759. ->first();
  1760. if (!empty($other)) {
  1761. return Result::error("请选择已有的选项!", 0);
  1762. }
  1763. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1764. // ->where('website_id',$data['website_id'])
  1765. ->where('is_other', 1)
  1766. ->where('other_id', '!=', 0)
  1767. ->first();
  1768. // return Result::success($choice['other']);
  1769. $choice_id = $data['choice_id'];
  1770. if (!empty($choice['other'])) {
  1771. // array_push($data['choice_id'],$choice['other']['other_id']);
  1772. if (!empty($choice_id)) {
  1773. $key = array_search($choice['other']['id'], $choice_id);
  1774. if ($key !== false) {
  1775. unset($choice_id[$key]);
  1776. $choice_id = array_values($choice_id);
  1777. }
  1778. array_push($choice_id, $choice['other']['other_id']);
  1779. } else {
  1780. $choice_id[0] = $choice['other']['other_id'];
  1781. }
  1782. array_push($data['choice_id'], $choice['other']['other_id']);
  1783. }
  1784. // return Result::success($data);
  1785. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1786. // ->where('website_id',$data['website_id'])
  1787. ->increment('results', 1);
  1788. if (empty($choice)) {
  1789. return Result::error("请选择已有的选项!", 0);
  1790. }
  1791. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1792. // ->where('website_id',$data['website_id'])
  1793. ->where('other_id', 0)
  1794. ->get();
  1795. $survey['choice'] = $choice_id;
  1796. return Result::success($survey);
  1797. }
  1798. return Result::error("参数必填!");
  1799. }
  1800. return Result::error("此调查问卷不存在", 0);
  1801. }
  1802. return Result::error("参数必填!");
  1803. }
  1804. /**
  1805. * 后端-获取网站调查问卷列表
  1806. * @param array $data
  1807. * @return array
  1808. */
  1809. public function getSurveyList(array $data): array
  1810. {
  1811. $where = [];
  1812. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1813. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1814. }
  1815. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  1816. array_push($where, ['survey_type', '=', $data['survey_type']]);
  1817. }
  1818. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  1819. array_push($where, ['is_survey', '=', $data['is_survey']]);
  1820. }
  1821. // return Result::success($where);
  1822. if (!empty($where)) {
  1823. $query = Article::where($where)->where(function ($q) {
  1824. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1825. });
  1826. } else {
  1827. $query = Article::where(function ($q) {
  1828. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1829. });
  1830. }
  1831. $count = $query->count();
  1832. $survey = $query->orderByDesc('id')
  1833. ->limit($data['pageSize'])
  1834. ->offset(($data['page'] - 1) * $data['pageSize'])
  1835. ->get();
  1836. if (empty($survey->toArray())) {
  1837. return Result::error("暂无调查问卷!", 0);
  1838. }
  1839. $result = [
  1840. 'rows' => $survey,
  1841. 'count' => $count,
  1842. ];
  1843. return Result::success($result);
  1844. }
  1845. /**
  1846. * 后端-获取网站调查问卷详情
  1847. * @param array $data
  1848. * @return array
  1849. */
  1850. public function getSurveyInfo(array $data): array
  1851. {
  1852. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1853. $where = ['sur_id' => $data['sur_id']];
  1854. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1855. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1856. ->select('article_survey.*', 'article.survey_type')
  1857. ->get()->all();
  1858. if (empty($choose)) {
  1859. return Result::error("此调查问卷不存在", 0);
  1860. }
  1861. $resultsArray = array_column($choose, 'results');
  1862. $total = array_sum($resultsArray);
  1863. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1864. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1865. // $total = 0;
  1866. if (!empty($other)) {
  1867. $total = $total + $other['results'];
  1868. $other['choice_name'] = '(其他)';
  1869. if (!empty($others)) {
  1870. $other['hasChildren'] = true;
  1871. // array_push($other,['hasChildren','=',true]);
  1872. $other['children'] = $others;
  1873. $other_choices = [$other->toArray()];
  1874. $mer_choice = array_merge($choose, $other_choices);
  1875. $value_choice = array_values($mer_choice);
  1876. } else {
  1877. // return Result::error('1111');
  1878. $other_choices = [$other->toArray()];
  1879. $other_choices = array_merge($choose, $other_choices);
  1880. $value_choice = array_values($other_choices);
  1881. // return Result::success($result);
  1882. }
  1883. } else {
  1884. $value_choice = $choose;
  1885. }
  1886. $result = [
  1887. 'choose' => $value_choice,
  1888. 'total' => $total,
  1889. ];
  1890. }
  1891. return Result::success($result);
  1892. }
  1893. /**
  1894. * 前端-搜索新闻列表
  1895. * @param array $data
  1896. * @return array
  1897. */
  1898. public function selectWebsiteArticle(array $data): array
  1899. {
  1900. $website = Website::where('id', $data['website_id'])->first();
  1901. if (empty($website)) {
  1902. return Result::error("网站不存在", 0);
  1903. }
  1904. // $website_column = $website['column'];
  1905. if (!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]') {
  1906. $website_column = json_decode($website['website_column_arr_id'], true);
  1907. }
  1908. $website_id = $data['website_id'];
  1909. $categorys = $this->processArticlePro($website_id);
  1910. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1911. // return Result::success($diff_pid_categoryIds);
  1912. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1913. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1914. }
  1915. // return Result::success(reset($diff_pid_categoryIds) == 0);
  1916. // $cat_1st_arr = $categorys['cat_1st_arr'];
  1917. $catiall = $categorys['catiall'];
  1918. $categoryIds = $categorys['categoryIds'];
  1919. // return Result::success($categoryIds);
  1920. $query = Article::where('status', 1)
  1921. ->whereIn('catid', $categoryIds)
  1922. ->leftJoinSub(function ($query) use ($website_id) {
  1923. $query->from('article_ignore')
  1924. ->where('website_id', $website_id);
  1925. }, 'article_ignore', function ($join) {
  1926. $join->on('article_ignore.article_id', '=', 'article.id');
  1927. })
  1928. ->where(function ($query) {
  1929. $query->whereNull('article_ignore.article_id')
  1930. ->orWhere(function ($subQuery) {
  1931. $subQuery->whereNotNull('article_ignore.article_id')
  1932. ->where('article_ignore.is_ignore', 0)
  1933. ->where(function ($subSubQuery) {
  1934. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  1935. ->orWhereNull('article_ignore.c_show_time');
  1936. });
  1937. });
  1938. });
  1939. // ->get()->all();
  1940. // return Result::success($query);
  1941. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1942. $query->whereRaw("JSON_CONTAINS(article.city_arr_id, '" . intval($data['cityid']) . "')");
  1943. }
  1944. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1945. $query->whereRaw("JSON_CONTAINS(article.department_arr_id, '" . intval($data['department_id']) . "')");
  1946. }
  1947. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1948. $query->where('article.title', 'like', '%' . $data['keyword'] . '%');
  1949. }
  1950. // 计算总数
  1951. $count = $query->count();
  1952. // return Result::success($count);
  1953. // 分页查询
  1954. $articles = $query
  1955. ->select(
  1956. 'article.id',
  1957. 'article.title',
  1958. 'article.imgurl',
  1959. 'article.author',
  1960. 'article.updated_at',
  1961. 'article.introduce',
  1962. 'article.islink',
  1963. 'article.linkurl',
  1964. 'article.copyfrom',
  1965. 'article.cat_arr_id',
  1966. 'article.catid',
  1967. 'article.department_arr_id',
  1968. 'article.city_arr_id',
  1969. // 'article_ignore.c_show_time',
  1970. // 'article_ignore.is_ignore'
  1971. )
  1972. ->orderBy("updated_at", "desc")
  1973. ->offset(($data['page'] - 1) * $data['pageSize'])
  1974. ->limit($data['pageSize'])
  1975. ->get();
  1976. // return Result::success($articles);
  1977. foreach ($articles as $k => $v) {
  1978. $articles[$k]->category_name = $catiall[$v->catid]['alias'];
  1979. $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1980. }
  1981. if (empty($articles)) {
  1982. return Result::error("没有符合条件的资讯数据");
  1983. }
  1984. $result = [
  1985. 'rows' => $articles,
  1986. 'count' => $count,
  1987. ];
  1988. return Result::success($result);
  1989. }
  1990. /**
  1991. * 模块新闻加强版
  1992. * @param array $data
  1993. * @return array
  1994. */
  1995. public function getWebsiteCatidArticle(array $data): array
  1996. {
  1997. $where = [
  1998. 'website_category.category_id' => $data['catid'],
  1999. 'website_category.website_id' => $data['website_id'],
  2000. ];
  2001. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  2002. $child_catnum = $data['child_catnum'] ?? 1;
  2003. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  2004. $childCategoryIds = array_column($category['child'], 'category_id');
  2005. if (empty($childCategoryIds)) {
  2006. return Result::error("暂无子栏目", 0);
  2007. }
  2008. $imgArticles = [];
  2009. $textArticles = [];
  2010. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  2011. // 初始化子分类图片新闻和文字新闻数组
  2012. // 查询所有子级栏目的图文新闻
  2013. $imgArticles = Article::where('catid', $childCategoryIds[0])
  2014. ->where(function ($query) use ($data) {
  2015. $query->where(function ($subQuery) use ($data) {
  2016. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  2017. })->orWhereNull("ignore_ids");
  2018. })
  2019. ->where('status', 1)
  2020. ->where('imgurl', '!=', '')
  2021. ->select('*')
  2022. ->orderBy('updated_at', 'desc')
  2023. ->limit($data['child_imgnum'])
  2024. ->get();
  2025. }
  2026. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  2027. // 查询所有子级栏目的文字新闻
  2028. $textArticles = Article::where('catid', $childCategoryIds[0])
  2029. ->where('status', 1)
  2030. ->where(function ($query) use ($data) {
  2031. $query->where(function ($subQuery) use ($data) {
  2032. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  2033. })->orWhereNull("ignore_ids");
  2034. })
  2035. ->select('*')
  2036. ->orderBy('updated_at', 'desc')
  2037. ->limit($data['child_textnum'])
  2038. ->get();
  2039. }
  2040. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  2041. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  2042. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  2043. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  2044. return $child;
  2045. }, $category['child']);
  2046. }
  2047. // }
  2048. if (isset($data['img_num']) && !empty($data['img_num'])) {
  2049. $category['img'] = WebsiteCategory::where($where)
  2050. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  2051. ->where('article.status', 1)
  2052. ->where('article.imgurl', '!=', '')
  2053. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  2054. ->orderBy('article.updated_at', 'desc')
  2055. ->limit($data['img_num'])
  2056. ->get();
  2057. }
  2058. if (isset($data['text_num']) && !empty($data['text_num'])) {
  2059. $category['text'] = WebsiteCategory::where($where)
  2060. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  2061. ->where('article.status', 1)
  2062. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  2063. ->orderBy('article.updated_at', 'desc')
  2064. ->limit($data['text_num'])
  2065. ->get();
  2066. }
  2067. // $category = $category->get();
  2068. if (empty($category)) {
  2069. return Result::error("查询失败", 0);
  2070. }
  2071. return Result::success($category);
  2072. }
  2073. /**
  2074. * 模块新闻加强plus版
  2075. * @param array $data
  2076. * @return array
  2077. */
  2078. public function getWebsiteAllArticle(array $data): array
  2079. {
  2080. // return Result::success($data);
  2081. $time1 = microtime(true);
  2082. $wetbsite_id = $data['website_id'] ?? 2;
  2083. $data = json_decode($data['id'], true);
  2084. $website = Website::where('id', $wetbsite_id)->first();
  2085. if (empty($website)) {
  2086. return Result::error("网站不存在", 0);
  2087. }
  2088. // return Result::success($website);
  2089. $website_column = $website['website_column_arr_id'] ?? '[]';
  2090. $website_column = json_decode($website_column, true);
  2091. $categorys = $this->processArticlePro($wetbsite_id);
  2092. $cat_1st_arr = $categorys['cat_1st_arr'];
  2093. $catiall = $categorys['catiall'];
  2094. // return Result::success($catiall);
  2095. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  2096. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2097. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2098. }
  2099. $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
  2100. // return Result::success($categorys);
  2101. $parent_category = array_column($data, 'parent');
  2102. $parent_cat = [];
  2103. $child_category = array_column($data, 'child');
  2104. if (!empty($parent_category)) {
  2105. foreach ($parent_category as $key => $value) {
  2106. $arr = array_map('intval', explode(',', $value));
  2107. $parent_cat[$key] = $arr[0] ?? 0;
  2108. $parent_category = $arr[0] ?? 0;
  2109. $article_imgnum = $arr[1] ?? 0;
  2110. $article_textnum = $arr[2] ?? 0;
  2111. if ($parent_category != 0) {
  2112. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2113. // return Result::success($category_arr);
  2114. if ($article_imgnum != 0) {
  2115. $img_article = Article::whereIn('catid', $category_arr)
  2116. ->where('status', 1)
  2117. ->where('imgurl', '!=', '')
  2118. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2119. $query->from('article_ignore')
  2120. ->where('website_id', $wetbsite_id);
  2121. }, 'article_ignore', function ($join) {
  2122. $join->on('article_ignore.article_id', '=', 'article.id');
  2123. })
  2124. ->where(function ($query) {
  2125. $query->whereNull('article_ignore.article_id')
  2126. ->orWhere(function ($subQuery) {
  2127. $subQuery->whereNotNull('article_ignore.article_id')
  2128. ->where('article_ignore.is_ignore', 0)
  2129. ->where(function ($subSubQuery) {
  2130. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2131. ->orWhereNull('article_ignore.c_show_time');
  2132. });
  2133. });
  2134. })
  2135. ->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')
  2136. ->orderBy('updated_at', 'desc')
  2137. ->limit($article_imgnum)
  2138. ->get()->all();
  2139. foreach ($img_article as $k => $v) {
  2140. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2141. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2142. }
  2143. } else {
  2144. $img_article = [];
  2145. }
  2146. if ($article_textnum != 0) {
  2147. $text_article = Article::whereIn('catid', $category_arr)
  2148. ->where('status', 1)
  2149. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2150. $query->from('article_ignore')
  2151. ->where('website_id', $wetbsite_id);
  2152. }, 'article_ignore', function ($join) {
  2153. $join->on('article_ignore.article_id', '=', 'article.id');
  2154. })
  2155. ->where(function ($query) {
  2156. $query->whereNull('article_ignore.article_id')
  2157. ->orWhere(function ($subQuery) {
  2158. $subQuery->whereNotNull('article_ignore.article_id')
  2159. ->where('article_ignore.is_ignore', 0)
  2160. ->where(function ($subSubQuery) {
  2161. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2162. ->orWhereNull('article_ignore.c_show_time');
  2163. });
  2164. });
  2165. })
  2166. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2167. ->orderBy('updated_at', 'desc')
  2168. ->limit($article_textnum)
  2169. ->get()->all();
  2170. foreach ($text_article as $k => $v) {
  2171. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2172. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2173. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2174. }
  2175. } else {
  2176. $text_article = [];
  2177. }
  2178. $catiall[$parent_category]['imgnum'] = $img_article;
  2179. $catiall[$parent_category]['textnum'] = $text_article;
  2180. $parent[$key] = $catiall[$parent_category];
  2181. } else {
  2182. $parent[$key] = '';
  2183. }
  2184. }
  2185. }
  2186. if (!empty($child_category)) {
  2187. foreach ($child_category as $key => $value) {
  2188. $arr = array_map('intval', explode(',', $value));
  2189. $parent_category = $parent_cat[$key];
  2190. $child_category = $arr[0] ?? 0;
  2191. $article_imgnum = $arr[1] ?? 0;
  2192. $article_textnum = $arr[2] ?? 0;
  2193. if ($child_category != 0) {
  2194. $all_childcat = $cat_1st_arr[$parent_category];
  2195. $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
  2196. // 从 $websiteInfoIndexed 中获取对应的数据
  2197. $info = $websiteInfoIndexed[$v];
  2198. // 返回一个包含所需信息的数组
  2199. return [
  2200. 'alias' => $info->alias,
  2201. 'category_id' => $info->category_id,
  2202. 'aLIas_pinyin' => $info->aLIas_pinyin,
  2203. 'pid' => $info->pid,
  2204. 'type' => $info->type,
  2205. 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
  2206. 'pinyin' => $info->pinyin,
  2207. ];
  2208. }, $all_childcat);
  2209. if ($article_imgnum != 0) {
  2210. $img_article = Article::where('catid', $child_category)
  2211. ->where('status', 1)
  2212. ->where('imgurl', '!=', '')
  2213. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2214. $query->from('article_ignore')
  2215. ->where('website_id', $wetbsite_id);
  2216. }, 'article_ignore', function ($join) {
  2217. $join->on('article_ignore.article_id', '=', 'article.id');
  2218. })
  2219. ->where(function ($query) {
  2220. $query->whereNull('article_ignore.article_id')
  2221. ->orWhere(function ($subQuery) {
  2222. $subQuery->whereNotNull('article_ignore.article_id')
  2223. ->where('article_ignore.is_ignore', 0)
  2224. ->where(function ($subSubQuery) {
  2225. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2226. ->orWhereNull('article_ignore.c_show_time');
  2227. });
  2228. });
  2229. })
  2230. ->select('id', 'title', 'imgurl', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2231. ->orderBy('updated_at', 'desc')
  2232. ->limit($article_imgnum)
  2233. ->get()->all();
  2234. foreach ($img_article as $k => $v) {
  2235. // var_dump($v);
  2236. // var_dump($k);
  2237. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2238. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2239. }
  2240. } else {
  2241. $img_article = [];
  2242. }
  2243. if ($article_textnum != 0) {
  2244. $text_article = Article::where('catid', $child_category)
  2245. ->where('status', 1)
  2246. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  2247. $query->from('article_ignore')
  2248. ->where('website_id', $wetbsite_id);
  2249. }, 'article_ignore', function ($join) {
  2250. $join->on('article_ignore.article_id', '=', 'article.id');
  2251. })
  2252. ->where(function ($query) {
  2253. $query->whereNull('article_ignore.article_id')
  2254. ->orWhere(function ($subQuery) {
  2255. $subQuery->whereNotNull('article_ignore.article_id')
  2256. ->where('article_ignore.is_ignore', 0)
  2257. ->where(function ($subSubQuery) {
  2258. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2259. ->orWhereNull('article_ignore.c_show_time');
  2260. });
  2261. });
  2262. })
  2263. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  2264. ->orderBy('updated_at', 'desc')
  2265. ->limit($article_textnum)
  2266. ->get()->all();
  2267. foreach ($text_article as $k => $v) {
  2268. // var_dump($v);
  2269. // var_dump($k);
  2270. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  2271. // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2272. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  2273. }
  2274. } else {
  2275. $text_article = [];
  2276. }
  2277. $catiall[$child_category]['all_childcat'] = $processedChildCat;
  2278. $catiall[$child_category]['imgnum'] = $img_article;
  2279. $catiall[$child_category]['textnum'] = $text_article;
  2280. $child[$key] = $catiall[$child_category];
  2281. // var_dump($pids);
  2282. } else {
  2283. $child[$key] = '';
  2284. }
  2285. }
  2286. }
  2287. foreach ($parent as $key => $value) {
  2288. $result[$key] = $value;
  2289. if (!empty($child[$key])) {
  2290. // var_dump($child[$key]);
  2291. $result[$key]['child'] = $child[$key];
  2292. // $value[$key]['child'] = $child[$key];
  2293. } else {
  2294. $result[$key]['child'] = [
  2295. "alias" => null,
  2296. "category_id" => null,
  2297. "type" => null,
  2298. "pinyin" => null,
  2299. "all_childcat" => [],
  2300. "imgnum" => [],
  2301. "textnum" => []
  2302. ];
  2303. }
  2304. }
  2305. return Result::success($result);
  2306. }
  2307. /**
  2308. * 辅助方法:获取文章列表
  2309. */
  2310. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  2311. {
  2312. sleep(1);
  2313. $query = Article::where('article.status', 1)
  2314. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  2315. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  2316. ->where(function ($query) use ($website) {
  2317. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  2318. })
  2319. ->leftJoin('website_category', function ($join) use ($website) {
  2320. $join->on('article.catid', '=', 'website_category.category_id')
  2321. ->where('website_category.website_id', '=', $website['website_id']);
  2322. })
  2323. ->select(
  2324. 'article.id',
  2325. 'article.title',
  2326. 'article.imgurl',
  2327. 'article.author',
  2328. 'article.updated_at',
  2329. 'article.introduce',
  2330. 'article.islink',
  2331. 'article.linkurl',
  2332. 'article.copyfrom',
  2333. 'article.cat_arr_id',
  2334. 'article.catid',
  2335. 'website_category.alias as category_name'
  2336. )
  2337. ->orderBy('updated_at', 'desc')
  2338. ->limit($limit);
  2339. // 如果是图片文章,添加图片URL条件
  2340. if ($isImageArticle) {
  2341. $query->where('imgurl', '!=', '');
  2342. } else {
  2343. // 文字文章不需要imgurl字段
  2344. $query->addSelect('article.introduce');
  2345. }
  2346. $articles = $query->get();
  2347. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  2348. }
  2349. /**
  2350. * 乡村网-获取特殊新闻模块
  2351. * @param array $data
  2352. * @return array
  2353. */
  2354. public function getWebsiteArticles(array $data): array
  2355. {
  2356. $website_id = $data['website_id'];
  2357. $website = Website::where('id', $website_id)->first();
  2358. if (empty($website)) {
  2359. return Result::error("网站不存在", 0);
  2360. }
  2361. // return Result::success($website);
  2362. $website_column = $website['website_column_arr_id'] ?? '[]';
  2363. $website_column = json_decode($website_column, true);
  2364. $catids = json_decode($data['id'], true);
  2365. $parent_category = array_column($catids, 'parent');
  2366. if (!empty($parent_category) && is_array($parent_category)) {
  2367. $categorys = $this->processArticlePro($website_id);
  2368. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  2369. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  2370. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  2371. }
  2372. $catiall = $categorys['catiall'];
  2373. $cat_1st_arr = $categorys['cat_1st_arr'];
  2374. // return Result::success($categorys);
  2375. foreach ($parent_category as $key => $value) {
  2376. $arr = array_map('intval', explode(',', $value));
  2377. $parent_category = $arr[0] ?? 0;
  2378. $article_imgnum = $arr[1] ?? 0;
  2379. $article_textnum = $arr[2] ?? 0;
  2380. if ($parent_category != 0) {
  2381. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  2382. // return Result::success($category_arr);
  2383. if ($article_imgnum != 0) {
  2384. $img_article = Article::whereIn('article.catid', $category_arr)
  2385. ->where('article.status', 1)
  2386. ->where('article.imgurl', '!=', '')
  2387. ->leftJoinSub(function ($query) use ($website_id) {
  2388. $query->from('article_ignore')
  2389. ->where('website_id', $website_id);
  2390. }, 'article_ignore', function ($join) {
  2391. $join->on('article_ignore.article_id', '=', 'article.id');
  2392. })
  2393. ->where(function ($query) {
  2394. $query->whereNull('article_ignore.article_id')
  2395. ->orWhere(function ($subQuery) {
  2396. $subQuery->whereNotNull('article_ignore.article_id')
  2397. ->where('article_ignore.is_ignore', 0)
  2398. ->where(function ($subSubQuery) {
  2399. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2400. ->orWhereNull('article_ignore.c_show_time');
  2401. });
  2402. });
  2403. })
  2404. ->select(
  2405. 'article.id',
  2406. 'article.title',
  2407. 'article.imgurl',
  2408. 'article.author',
  2409. 'article.updated_at',
  2410. 'article.introduce',
  2411. 'article.islink',
  2412. 'article.linkurl',
  2413. 'article.copyfrom',
  2414. 'article.cat_arr_id',
  2415. 'article.catid as category_id'
  2416. )
  2417. ->orderBy('updated_at', 'desc')
  2418. ->limit($article_imgnum)
  2419. ->get()->all();
  2420. foreach ($img_article as $k => $v) {
  2421. $img_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2422. // return Result::success($v);
  2423. $img_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2424. }
  2425. } else {
  2426. $img_article = [];
  2427. }
  2428. if ($article_textnum != 0) {
  2429. $text_article = Article::whereIn('article.catid', $category_arr)
  2430. ->where('article.status', 1)
  2431. ->leftJoinSub(function ($query) use ($website_id) {
  2432. $query->from('article_ignore')
  2433. ->where('website_id', $website_id);
  2434. }, 'article_ignore', function ($join) {
  2435. $join->on('article_ignore.article_id', '=', 'article.id');
  2436. })
  2437. ->where(function ($query) {
  2438. $query->whereNull('article_ignore.article_id')
  2439. ->orWhere(function ($subQuery) {
  2440. $subQuery->whereNotNull('article_ignore.article_id')
  2441. ->where('article_ignore.is_ignore', 0)
  2442. ->where(function ($subSubQuery) {
  2443. $subSubQuery->where('article_ignore.c_show_time', '<=', date('Y-m-d H:i:s'))
  2444. ->orWhereNull('article_ignore.c_show_time');
  2445. });
  2446. });
  2447. })
  2448. ->select(
  2449. 'article.id',
  2450. 'article.title',
  2451. 'article.author',
  2452. 'article.updated_at',
  2453. 'article.introduce',
  2454. 'article.islink',
  2455. 'article.linkurl',
  2456. 'article.copyfrom',
  2457. 'article.cat_arr_id',
  2458. 'article.catid as category_id'
  2459. )
  2460. ->orderBy('updated_at', 'desc')
  2461. ->limit($article_textnum)
  2462. ->get()->all();
  2463. foreach ($text_article as $k => $v) {
  2464. $text_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2465. $text_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2466. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2467. }
  2468. } else {
  2469. $text_article = [];
  2470. }
  2471. $catiall[$parent_category]['imgnum'] = $img_article ?? [];
  2472. $catiall[$parent_category]['textnum'] = $text_article ?? [];
  2473. $parent[$key] = $catiall[$parent_category];
  2474. } else {
  2475. $parent[$key] = [];
  2476. }
  2477. }
  2478. }
  2479. return Result::success($parent);
  2480. }
  2481. // 封装处理商品的路由问题
  2482. function processGoods($goods, $data)
  2483. {
  2484. return $goods->map(function ($good) use ($data) {
  2485. $catid = $good->catid ?? 0;
  2486. // $pinyin = '';
  2487. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2488. if (!empty($category->pid) && $category->pid != 0) {
  2489. $level = json_decode($category->category_arr_id, true);
  2490. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  2491. ->whereIn('category_id', $level)
  2492. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2493. ->get(['aLIas_pinyin'])
  2494. ->pluck('aLIas_pinyin')
  2495. ->implode('/');
  2496. } else {
  2497. $pinyin = $category->aLIas_pinyin ?? '';
  2498. }
  2499. if (isset($good->city_id) && !empty($good->city_id)) {
  2500. $city = District::where('id', $good->city_id)->first(['name']);
  2501. $good->city_name = $city->name ?? '';
  2502. }
  2503. // 解析imgurl JSON并取第一条数据
  2504. $imgUrls = json_decode($good->imgurl, true);
  2505. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  2506. $good->pinyin = $pinyin;
  2507. return $good;
  2508. });
  2509. }
  2510. /**
  2511. * 获取商城首页-根据栏目id
  2512. * @param array $data
  2513. * @return array
  2514. * */
  2515. function getWebsiteCatidshop(array $data): array
  2516. {
  2517. $input['catid'] = $data['catid'];
  2518. $input['website_id'] = $data['website_id'];
  2519. $data = json_decode($input['catid'] ?? '', true) ?? [];
  2520. $result = array_map(function ($item) use ($input) {
  2521. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  2522. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  2523. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  2524. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  2525. if (empty($category) || $category->type != 2) {
  2526. return Result::error("暂无此栏目", 0);
  2527. } else {
  2528. $website['website_id'] = $input['website_id'];
  2529. $goods = Good::where('good.status', 2)
  2530. ->where('good.website_id', $website['website_id'])
  2531. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  2532. ->select(
  2533. 'good.id',
  2534. 'good.name',
  2535. 'good.imgurl',
  2536. 'good.description',
  2537. 'good.updated_at',
  2538. 'good.catid',
  2539. 'good.type_id',
  2540. 'good.price',
  2541. 'good.com',
  2542. 'good.level',
  2543. 'good.unit'
  2544. )
  2545. ->orderBy('updated_at', 'desc')
  2546. ->offset($goodStart)
  2547. ->limit($goodNum);
  2548. $all_goods = $goods->get();
  2549. $all_goods = $this->processGoods($all_goods, $website);
  2550. }
  2551. return $all_goods ?? [];
  2552. }
  2553. }, $data);
  2554. return Result::success($result);
  2555. }
  2556. /**
  2557. * 获取商品模块
  2558. * @param array $data
  2559. * @return array
  2560. * */
  2561. public function getWebsiteshop(array $data): array
  2562. {
  2563. $input['id'] = $data['id'];
  2564. $input['website_id'] = $data['website_id'];
  2565. $catid = $data['catid'];
  2566. $data = json_decode($input['id'] ?? '', true) ?? [];
  2567. $result['goods'] = array_map(function ($item) use ($input) {
  2568. // 检查parent元素是否存在且不是undefined
  2569. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  2570. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  2571. $website = $input['website_id'];
  2572. $query = Good::where('good.status', 2)
  2573. ->where('good.website_id', $website);
  2574. switch ($Levelid) {
  2575. case 1:
  2576. case 2:
  2577. case 3:
  2578. $goods = $query->where(function ($q) use ($Levelid) {
  2579. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  2580. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  2581. });
  2582. break;
  2583. case 4:
  2584. $goods = $query;
  2585. break;
  2586. case 5:
  2587. $goods = $query->where('type_id', 1);
  2588. break;
  2589. case 6:
  2590. $goods = $query->where('type_id', 2);
  2591. break;
  2592. default:
  2593. return [];
  2594. }
  2595. $all_goods = $goods
  2596. ->select(
  2597. 'good.id',
  2598. 'good.name',
  2599. 'good.imgurl',
  2600. 'good.description',
  2601. 'good.updated_at',
  2602. 'good.catid',
  2603. 'good.type_id',
  2604. 'good.price',
  2605. 'good.level',
  2606. 'good.website_id'
  2607. )
  2608. ->orderBy('updated_at', 'desc')
  2609. ->offset($goodStart)
  2610. ->limit($goodNum)
  2611. ->get();
  2612. $web['website_id'] = $website;
  2613. $all_goods = $this->processGoods($all_goods, $web);
  2614. }
  2615. return $all_goods;
  2616. }, $data);
  2617. $website = $input['website_id'];
  2618. $result['article'] = Article::where(function ($query) use ($website) {
  2619. $query->where(function ($subQuery) use ($website) {
  2620. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  2621. })->orWhereNull("ignore_ids");
  2622. })
  2623. ->where('catid', $catid)
  2624. ->where('article.status', 1)
  2625. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  2626. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  2627. ->orderBy('article.updated_at', 'desc')
  2628. ->first();
  2629. return Result::success($result);
  2630. }
  2631. /**
  2632. * 获取商品分类
  2633. * @param array $data
  2634. * @return array
  2635. * */
  2636. public function getWebsiteshopCat(array $data): array
  2637. {
  2638. $website = $data['website_id'];
  2639. $category = WebsiteCategory::where('website_id', $website)
  2640. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  2641. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  2642. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  2643. ->orderBy('sort')
  2644. ->get();
  2645. $cat = $category->map(function ($item) use ($website) {
  2646. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  2647. $pid = $item->pid ?? 0;
  2648. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  2649. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  2650. ->where('website_id', $website)
  2651. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  2652. ->get(['aLIas_pinyin'])
  2653. ->pluck('aLIas_pinyin')
  2654. ->implode('/');
  2655. } else {
  2656. $pinyin = $item->aLIas_pinyin ?? '';
  2657. }
  2658. $item->pinyin = $pinyin;
  2659. });
  2660. if (empty($category)) {
  2661. return Result::error("栏目查询失败", 0);
  2662. }
  2663. $cat_tree = Result::buildMenuTree($category);
  2664. $web['website_id'] = $website;
  2665. $goods = Good::where('website_id', $website)
  2666. ->where('status', 2)
  2667. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  2668. ->latest('updated_at')
  2669. ->offset(($data['page'] - 1) * $data['pageSize'])
  2670. ->limit($data['pageSize'])
  2671. ->get();
  2672. if (!empty($goods)) {
  2673. if ($goods->count() > 1 && !empty($goods)) {
  2674. $goods = $this->processGoods($goods, $web);
  2675. }
  2676. } else {
  2677. $goods = [];
  2678. }
  2679. $result = [
  2680. 'category' => $cat_tree,
  2681. 'goods' => $goods,
  2682. ];
  2683. // $resul['goods'] = $goods;
  2684. if (empty($result)) {
  2685. return Result::error("查询失败", 0);
  2686. }
  2687. return Result::success($result);
  2688. }
  2689. /*
  2690. * 获取商品列表
  2691. * @param array $data
  2692. * @return array
  2693. * */
  2694. public function getWebsiteshopList(array $data): array
  2695. {
  2696. // return Result::success($data);
  2697. $where = [
  2698. 'status' => 2,
  2699. 'website_id' => $data['website_id'],
  2700. ];
  2701. // if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  2702. // return Result::error("查询失败", 0);
  2703. // }
  2704. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  2705. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  2706. $data['catid'] = $category->category_id ?? 0;
  2707. }
  2708. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2709. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  2710. }
  2711. if (isset($data['type_id']) && !empty($data['type_id'])) {
  2712. array_push($where, ['type_id', $data['type_id']]);
  2713. }
  2714. $query = Good::where($where)
  2715. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2716. $query->where(function ($q) use ($data) {
  2717. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  2718. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  2719. });
  2720. })
  2721. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2722. $query->where(function ($q) use ($data) {
  2723. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  2724. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  2725. });
  2726. })
  2727. ->select(
  2728. 'good.id',
  2729. 'good.name',
  2730. 'good.imgurl',
  2731. 'good.description',
  2732. 'good.updated_at',
  2733. 'good.com',
  2734. 'good.catid',
  2735. 'good.type_id',
  2736. 'good.website_id',
  2737. 'good.cat_arr_id',
  2738. 'good.created_at',
  2739. 'good.city_id'
  2740. )
  2741. ->latest('updated_at');
  2742. if (isset($data['ismix']) && $data['ismix'] == 1) {
  2743. $result['count'] = $query->clone()->count();
  2744. $result['goods'] = $this->processGoods(
  2745. $query->clone()
  2746. ->offset(($data['page'] - 1) * $data['pageSize'])
  2747. ->limit($data['pageSize'])
  2748. ->get(),
  2749. $data
  2750. );
  2751. } else {
  2752. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  2753. // 获取 type_id 为 1 的数据
  2754. $result['type1'] = $this->processGoods(
  2755. $query->clone()
  2756. ->where('type_id', 1)
  2757. ->offset(($data['page'] - 1) * $data['pageSize'])
  2758. ->limit($data['pageSize'])
  2759. ->get(),
  2760. $data
  2761. );
  2762. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2763. // 获取 type_id 为 2 的数据
  2764. $result['type2'] = $this->processGoods(
  2765. $query->clone()
  2766. ->where('type_id', 2)
  2767. ->offset(($data['page'] - 1) * $data['pageSize'])
  2768. ->limit($data['pageSize'])
  2769. ->get(),
  2770. $data
  2771. );
  2772. }
  2773. if (empty($result)) {
  2774. return Result::error("查询失败", 0);
  2775. }
  2776. return Result::success($result);
  2777. }
  2778. /**
  2779. * 获取商品详情
  2780. * @param array $data
  2781. * @return array
  2782. * */
  2783. public function getWebsiteshopInfo(array $data): array
  2784. {
  2785. $where = [
  2786. 'good.status' => 2,
  2787. 'good.website_id' => $data['website_id'],
  2788. 'good.id' => $data['id'],
  2789. ];
  2790. $goods = Good::where($where)
  2791. ->where('good.id', $data['id'])
  2792. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2793. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2794. ->first();
  2795. if (empty($goods)) {
  2796. return Result::error("查询失败", 0);
  2797. }
  2798. $goods->imgurl = json_decode($goods->imgurl, true);
  2799. return Result::success($goods);
  2800. }
  2801. /**
  2802. * plus pro 处理文章路由问题
  2803. */
  2804. function processArticlePro($website_id)
  2805. {
  2806. // $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2807. // // $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2808. // // 取出category_id 对应的aLIas_pinyin
  2809. // $categoryIds = array_column($categorys, 'category_id');
  2810. // $categoryPIds = array_column($categorys, 'pid');
  2811. // $aliasPinyins = array_column($categorys, 'path');
  2812. // $alias = array_column($categorys, 'alias');
  2813. // $cat_arr = array_combine($categoryIds, $aliasPinyins);
  2814. // $cat_alias_arr = array_combine($categoryIds, $categoryPIds);
  2815. // // return Result::success($cat_arr);
  2816. // // $catiall = [];
  2817. // //一级所有子级的记录
  2818. // $cat_alias_arr = array_combine($categoryIds, $alias);
  2819. // return [
  2820. // 'cat_1st_arr' => $cat_alias_arr,
  2821. // 'catiall' => $cat_arr,
  2822. // // 'websiteInfoIndexed' => $websiteInfoIndexed,
  2823. // 'categoryIds' => $categoryIds,
  2824. // ];
  2825. $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2826. $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2827. // 取出category_id 对应的aLIas_pinyin
  2828. $categoryIds = array_column($categorys, 'category_id');
  2829. $categoryPIds = array_values(array_unique(array_filter(array_column($categorys, 'pid'), function ($pid) {
  2830. return $pid != 0;
  2831. })));
  2832. $category_path = array_column($categorys, 'path');
  2833. $cat_arr = array_combine($categoryIds, $category_path);
  2834. // return Result::success(array_diff($categoryIds, $categoryPIds));
  2835. $catiall = [];
  2836. //一级所有子级的记录
  2837. $cat_1st_arr = [];
  2838. foreach ($categorys as $key => $value) {
  2839. // $category_arr_id = json_decode($value->category_arr_id);
  2840. // $pinyin_str = '';
  2841. // // 算出一级 并且算出子级
  2842. if ($value->pid != 0 && in_array($value->pid, $categoryIds)) {
  2843. $cat_1st_arr[$value->pid][] = $value->category_id;
  2844. }
  2845. // foreach ($category_arr_id as $k => $v) {
  2846. // $pinyin_str .= $cat_arr[$v] . '/';
  2847. // }
  2848. // $pinyin_str = rtrim($pinyin_str, '/');
  2849. $catiall[$value->category_id]['alias'] = $value->alias;
  2850. $catiall[$value->category_id]['category_id'] = $value->category_id;
  2851. $catiall[$value->category_id]['type'] = $value->type;
  2852. $catiall[$value->category_id]['pinyin'] = $cat_arr[$value->category_id];
  2853. $websiteInfoIndexed[$value->category_id]->pinyin = $cat_arr[$value->category_id];
  2854. }
  2855. return [
  2856. 'cat_1st_arr' => $cat_1st_arr,
  2857. 'catiall' => $catiall,
  2858. 'websiteInfoIndexed' => $websiteInfoIndexed,
  2859. 'categoryIds' => $categoryIds,
  2860. 'diff_pid_categoryIds' => array_diff($categoryPIds, $categoryIds),
  2861. 'categoryPIds' => $categoryPIds,
  2862. ];
  2863. }
  2864. /**
  2865. * 封装处理文章的路由问题
  2866. * */
  2867. function processArticles($articles, $data)
  2868. {
  2869. // 检查 $articles 是否为数组或可迭代对象
  2870. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  2871. return $articles->map(function ($article) use ($data) {
  2872. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  2873. $catid = $article->cat_arr_id ?? '';
  2874. }
  2875. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  2876. $catid = $article->category_arr_id ?? '';
  2877. }
  2878. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  2879. $level = json_decode($catid, true);
  2880. if (!is_array($level)) {
  2881. return $article;
  2882. } else {
  2883. $level = array_map('intval', $level);
  2884. }
  2885. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2886. ->where($data)
  2887. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2888. ->pluck('aLIas_pinyin')
  2889. ->implode('/');
  2890. $article->pinyin = $pinyin ?? '';
  2891. return $article;
  2892. });
  2893. } else {
  2894. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2895. $catid = $articles->cat_arr_id ?? '';
  2896. $level = json_decode($catid, true);
  2897. if (!is_array($level)) {
  2898. return $articles;
  2899. } else {
  2900. $level = array_map('intval', $level);
  2901. }
  2902. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2903. ->where($data)
  2904. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2905. ->pluck('aLIas_pinyin')
  2906. ->implode('/');
  2907. $articles->pinyin = $pinyin ?? '';
  2908. return $articles;
  2909. }
  2910. }
  2911. // 封装处理由问题
  2912. function processJob($job, $data)
  2913. {
  2914. return $job->map(function ($job) use ($data) {
  2915. $category = $job->cat_arr_id ?? '';
  2916. $cityid = $job->city_arr_id ?? '';
  2917. $city = json_decode($cityid, true);
  2918. $pinyin = '';
  2919. $level = json_decode($category, true);
  2920. // 路由
  2921. if (!empty($level) && is_array($level)) {
  2922. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2923. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2924. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2925. ->get(['aLIas_pinyin'])
  2926. ->pluck('aLIas_pinyin')
  2927. ->implode('/');
  2928. if (empty($pinyin)) {
  2929. $pinyin = $pinyin->aLIas_pinyin ?? '';
  2930. }
  2931. $job->pinyin = $pinyin;
  2932. }
  2933. // 取职位-城市 市??省
  2934. if (!empty($city) && is_array($city)) {
  2935. if (isset($city[1]) && !empty($city[1])) {
  2936. $city = District::where('id', $city[1])->first(['name']);
  2937. $job->city_name = $city->name ?? '';
  2938. } else if (isset($city[0]) && !empty($city[0])) {
  2939. $city = District::where('id', $city[0])->first(['name']);
  2940. $job->city_name = $city->name ?? '';
  2941. } else {
  2942. $job->city_name = '全国';
  2943. }
  2944. }
  2945. // 获取简历最后一级地区
  2946. if (isset($job->city_id) && !empty($job->city_id)) {
  2947. $city = District::where('id', $job->city_id)->first(['name']);
  2948. $job->hunt_cityname = $city->name ?? '';
  2949. }
  2950. // 组合详细地址
  2951. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  2952. $address_id = json_decode($job->address_arr_id, true) ?? [];
  2953. if (is_array($address_id) && !empty($address_id)) {
  2954. $address = District::whereIn('id', $address_id)
  2955. ->orderBy('level', 'asc')
  2956. ->get(['name'])
  2957. ->pluck('name')
  2958. ->implode('');
  2959. // $job->address_name = $address ?? '';
  2960. $job->address_name = ($address ?? '') . ($job->address ?? '');
  2961. }
  2962. }
  2963. // 取行业
  2964. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  2965. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  2966. if (!empty($job->industry)) {
  2967. $query->where('hyid', $job->industry);
  2968. } else if (!empty($job->hy_id)) {
  2969. $query->where('hyid', $job->hy_id);
  2970. } else if (!empty($job->company_hy_id)) {
  2971. $query->where('hyid', $job->company_hy_id);
  2972. } else {
  2973. $query->where('hyid', $job->job_industry);
  2974. }
  2975. })->first(['hyname']);
  2976. $job->hy_name = $hy_name->hyname ?? '';
  2977. }
  2978. // 取职位类别
  2979. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  2980. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  2981. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  2982. $job->zw_name = $zw_name->zwname ?? '';
  2983. }
  2984. // 取具体职位
  2985. 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))) {
  2986. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  2987. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  2988. $job->jtzw_name = $jtzw_name->zwname ?? '';
  2989. }
  2990. // 取工作经验
  2991. if (isset($job->experience) && !empty($job->experience)) {
  2992. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  2993. $job->experience_name = $experience->ename ?? '';
  2994. }
  2995. // 取学历
  2996. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  2997. $education = $job->educational ?? $job->school_education;
  2998. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  2999. $job->education_name = $education->ename ?? '';
  3000. }
  3001. // 语言
  3002. if (isset($job->language) && !empty($job->language)) {
  3003. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  3004. $job->language_name = $language->ename ?? '';
  3005. }
  3006. // 薪资
  3007. if (isset($job->salary) && !empty($job->salary)) {
  3008. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  3009. $job->salary_name = $salary->ename ?? '';
  3010. }
  3011. // 职位性质
  3012. if (isset($job->nature_id) && !empty($job->nature_id)) {
  3013. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  3014. $job->job_nature_name = $job_nature->ename ?? '';
  3015. }
  3016. // 公司规模
  3017. if (isset($job->company_size) && !empty($job->company_size)) {
  3018. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  3019. $job->company_size_name = $company_size->ename ?? '';
  3020. }
  3021. // 公司性质
  3022. if (isset($job->company_nature) && !empty($job->company_nature)) {
  3023. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  3024. $job->company_nature_name = $company_nature->nature_name ?? '';
  3025. }
  3026. // $job->pinyin = $pinyin;
  3027. return $job;
  3028. });
  3029. }
  3030. /**
  3031. * 获取书籍模块
  3032. * @param array $data
  3033. * @return array
  3034. * */
  3035. public function getWebsiteBook(array $data): array
  3036. {
  3037. $input['id'] = $data['id'];
  3038. $input['website_id'] = $data['website_id'];
  3039. // 将 JSON 字符串转换为 PHP 数组
  3040. $data = json_decode($input['id'], true);
  3041. // 使用 array_map 处理每个元素
  3042. $result = array_map(function ($item) use ($input) {
  3043. // 检查parent元素是否存在且不是undefined
  3044. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  3045. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  3046. $website = [
  3047. 'website_id' => $input['website_id'],
  3048. ];
  3049. // 查询栏目名称
  3050. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  3051. if (empty($category)) {
  3052. $parent_alias = '';
  3053. $parent_pinyin = null;
  3054. $imgBooks = [];
  3055. $textBooks = [];
  3056. } else {
  3057. $parent_alias = $category->alias ?? '';
  3058. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  3059. // 查找子分类ID数组
  3060. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  3061. array_push($childCategoryIds, $parentCatId);
  3062. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  3063. if ($parentImgNum != 0) {
  3064. // 查询图片新闻
  3065. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  3066. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  3067. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  3068. })
  3069. ->where('book.status', 2)
  3070. ->where('book.img_url', '!=', '')
  3071. ->where('book.website_id', $website['website_id'])
  3072. ->leftJoin('website_category', function ($join) use ($website) {
  3073. $join->on('book.cat_id', '=', 'website_category.category_id')
  3074. ->where('website_category.website_id', '=', $website['website_id']);
  3075. })
  3076. ->select(
  3077. 'book.id',
  3078. 'book.title',
  3079. 'book.img_url',
  3080. 'book.price',
  3081. 'book.market_price',
  3082. 'book.description',
  3083. 'book.cat_id',
  3084. 'book.description',
  3085. 'book.updated_at',
  3086. 'website_category.alias as category_name',
  3087. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3088. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3089. )
  3090. ->orderBy('updated_at', 'desc')
  3091. ->limit($parentImgNum)
  3092. ->get()->all();
  3093. // 查询文字新闻
  3094. }
  3095. if ($parentTextNum != 0) {
  3096. $textBooks = [];
  3097. $textBooks = Book::where(function ($query) use ($parentCatId) {
  3098. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  3099. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  3100. })
  3101. ->where('book.status', 2)
  3102. ->where('book.website_id', $website['website_id'])
  3103. ->leftJoin('website_category', function ($join) use ($website) {
  3104. $join->on('book.cat_id', '=', 'website_category.category_id')
  3105. ->where('website_category.website_id', '=', $website['website_id']);
  3106. })
  3107. ->select(
  3108. 'book.id',
  3109. 'book.title',
  3110. 'book.img_url',
  3111. 'book.price',
  3112. 'book.market_price',
  3113. 'book.description',
  3114. 'book.cat_id',
  3115. 'book.description',
  3116. 'book.updated_at',
  3117. 'website_category.alias as category_name',
  3118. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  3119. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  3120. )
  3121. ->orderBy('updated_at', 'desc')
  3122. ->limit($parentTextNum)
  3123. ->get()->all();
  3124. }
  3125. }
  3126. }
  3127. $resultItem = [
  3128. 'alias' => $parent_alias ?? '',
  3129. 'category_id' => $parentCatId ?? 0,
  3130. 'pinyin' => $parent_pinyin ?? null,
  3131. 'imgnum' => $imgBooks ?? [],
  3132. 'textnum' => $textBooks ?? [],
  3133. ];
  3134. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  3135. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  3136. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  3137. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3138. ->get()->all();
  3139. if (!empty($childCategory)) {
  3140. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  3141. // 查询子栏目名称
  3142. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  3143. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  3144. ->first();
  3145. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  3146. $childImgArticles = [];
  3147. $childTextArticles = [];
  3148. $resultItem['child'] = [];
  3149. } else {
  3150. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  3151. // 查询子栏目图片新闻
  3152. $childImgArticles = Book::where('cat_id', $childCatId)
  3153. ->where('status', 2)
  3154. ->where('img_url', '!=', '')
  3155. ->where('book.website_id', $website['website_id'])
  3156. ->leftJoin('website_category', function ($join) use ($website) {
  3157. $join->on('book.cat_id', '=', 'website_category.category_id')
  3158. ->where('website_category.website_id', '=', $website['website_id']);
  3159. })
  3160. ->select(
  3161. 'book.id',
  3162. 'book.title',
  3163. 'book.img_url',
  3164. 'book.price',
  3165. 'book.market_price',
  3166. 'book.description',
  3167. 'book.cat_id',
  3168. 'book.description',
  3169. 'book.updated_at',
  3170. DB::raw("'$child_pinyin' as pinyin")
  3171. )
  3172. ->orderBy('updated_at', 'desc')
  3173. ->limit($childImgNum)
  3174. ->get()->all();
  3175. // 查询子栏目文字新闻
  3176. $childTextArticles = Book::where('cat_id', $childCatId)
  3177. ->where('status', 2)
  3178. ->where('book.website_id', $website['website_id'])
  3179. ->leftJoin('website_category', function ($join) use ($website) {
  3180. $join->on('book.cat_id', '=', 'website_category.category_id')
  3181. ->where('website_category.website_id', '=', $website['website_id']);
  3182. })
  3183. ->select(
  3184. 'book.id',
  3185. 'book.title',
  3186. 'book.img_url',
  3187. 'book.price',
  3188. 'book.market_price',
  3189. 'book.description',
  3190. 'book.cat_id',
  3191. 'book.description',
  3192. 'book.updated_at',
  3193. DB::raw("'$child_pinyin' as pinyin")
  3194. )
  3195. ->orderBy('updated_at', 'desc')
  3196. ->limit($childTextNum)
  3197. ->get()->all();
  3198. $resultItem['child'] = [
  3199. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  3200. 'category_id' => $childCatId,
  3201. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  3202. 'all_childcat' => $childCategory,
  3203. 'imgnum' => $childImgArticles,
  3204. 'textnum' => $childTextArticles,
  3205. ];
  3206. }
  3207. }
  3208. } else {
  3209. $resultItem['child'] = [];
  3210. }
  3211. return $resultItem;
  3212. }, $data);
  3213. return Result::success($result);
  3214. }
  3215. /**
  3216. * 获取书刊列表
  3217. * @param array $data
  3218. * @return array
  3219. * */
  3220. public function getWebsiteBookList(array $data): array
  3221. {
  3222. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3223. if (empty($web)) {
  3224. return Result::error("查询失败", 0);
  3225. }
  3226. $catid = $data['id'];
  3227. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  3228. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  3229. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  3230. $category_pinyin = $category ? $category->aLias_pinyin : '';
  3231. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  3232. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  3233. ->where('pid', $category['pid'])
  3234. ->select(
  3235. 'category_id',
  3236. 'alias',
  3237. 'aLIas_pinyin',
  3238. 'pid',
  3239. 'sort',
  3240. 'is_url',
  3241. 'web_url',
  3242. 'seo_title',
  3243. 'seo_keywords',
  3244. 'seo_description',
  3245. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  3246. )
  3247. ->orderBy('sort')
  3248. ->get()->all();
  3249. if (empty($category)) {
  3250. return Result::error("查询失败", 0);
  3251. }
  3252. $query = Book::where('book.status', 2)
  3253. ->where('book.website_id', $data['website_id'])
  3254. ->where('book.cat_id', $catid)
  3255. ->select(
  3256. 'book.id',
  3257. 'book.title',
  3258. 'book.img_url',
  3259. 'book.description',
  3260. 'book.updated_at',
  3261. 'book.cat_id',
  3262. DB::raw("'$pinyin' as pinyin")
  3263. )
  3264. ->orderBy('book.updated_at', 'desc');
  3265. $count = $query->count();
  3266. $query = clone $query;
  3267. $Book = $query
  3268. ->limit($data['pageSize'])
  3269. ->offset(($data['page'] - 1) * $data['pageSize'])
  3270. ->get()->all();
  3271. $result = [
  3272. 'category' => $categorys,
  3273. 'books' => $Book,
  3274. 'count' => $count,
  3275. ];
  3276. // if(empty($result)){
  3277. // return Result::error("查询失败", 0);
  3278. // }
  3279. return Result::success($result);
  3280. }
  3281. /**
  3282. * 获取书刊详情
  3283. * @param array $data
  3284. * @return array
  3285. * */
  3286. public function getWebsiteBookInfo(array $data): array
  3287. {
  3288. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3289. if (empty($web)) {
  3290. return Result::error("查询失败", 0);
  3291. }
  3292. $book = Book::where('status', 2)
  3293. ->where('website_id', $data['website_id'])
  3294. ->where('id', $data['id'])
  3295. ->select(
  3296. 'book.*',
  3297. )
  3298. ->orderBy('updated_at', 'desc')
  3299. ->first();
  3300. if (empty($book)) {
  3301. return Result::error("查询失败", 0);
  3302. }
  3303. // 先查询当前分类的 pid
  3304. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  3305. ->where('category_id', $book['cat_id'])
  3306. ->first(['pid', 'category_id']);
  3307. $query = WebsiteCategory::where('website_id', $data['website_id']);
  3308. if (!empty($carpid)) {
  3309. if ($carpid->pid != 0) {
  3310. $pid = $carpid['pid'];
  3311. // $parent_pinyin = '';
  3312. } else {
  3313. $pid = $carpid['category_id'];
  3314. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  3315. }
  3316. }
  3317. $categorys = $query->where('pid', $pid)
  3318. ->select(
  3319. 'category_id',
  3320. 'alias',
  3321. 'aLIas_pinyin',
  3322. 'pid',
  3323. 'sort',
  3324. 'is_url',
  3325. 'web_url',
  3326. 'category_arr_id as cat_arr_id',
  3327. )
  3328. ->orderBy('sort')
  3329. ->get();
  3330. $category = $this->processArticle($categorys, $data);
  3331. $result = [
  3332. 'category' => $category,
  3333. 'books' => $book,
  3334. ];
  3335. return Result::success($result);
  3336. }
  3337. /**
  3338. * 尝试
  3339. * @param array $data
  3340. * @return array
  3341. * */
  3342. public function test(array $data): array
  3343. {
  3344. $input['id'] = $data['id'];
  3345. $input['website_id'] = $data['website_id'];
  3346. // 将 JSON 字符串转换为 PHP 数组
  3347. $data = json_decode($input['id'], true);
  3348. $result = [];
  3349. $article = $data;
  3350. $result = array_map(function ($item) use ($input) {
  3351. $website = [
  3352. 'website_id' => $input['website_id'],
  3353. ];
  3354. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  3355. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  3356. $parent = [
  3357. 0 => $category['category_id'] ?? [],
  3358. 1 => $parentImgNum ?? [],
  3359. 2 => $parentTextNum ?? [],
  3360. ];
  3361. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  3362. $child = [];
  3363. $resultItem = [
  3364. // 'alias' => $parent_alias ?? '',
  3365. 'category_id' => $parentCatId ?? 0,
  3366. 'pinyin' => $parentImgNum ?? null,
  3367. 'imgnum' => $parentTextNum ?? [],
  3368. // 'textnum' => $textArticles ?? [],
  3369. ];
  3370. return $parent;
  3371. }, $data);
  3372. return Result::success($result);
  3373. // });
  3374. }
  3375. /**
  3376. * 封装处理文章的路由问题
  3377. * */
  3378. function processArticle($article, $data)
  3379. {
  3380. return $article->map(function ($article) use ($data) {
  3381. $catid = $article->cat_arr_id ?? '';
  3382. $level = json_decode($catid, true);
  3383. $pinyin = '';
  3384. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  3385. if (!empty($level) && is_array($level)) {
  3386. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  3387. ->where('website_id', $data['website_id'])
  3388. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  3389. ->get(['aLIas_pinyin'])
  3390. ->pluck('aLIas_pinyin')
  3391. ->implode('/');
  3392. } else {
  3393. $pinyin = '';
  3394. }
  3395. $article->pinyin = $pinyin;
  3396. return $article;
  3397. });
  3398. }
  3399. /**
  3400. * c端-获取招工招聘下拉选框
  3401. * @param array $data
  3402. * @return array
  3403. * */
  3404. public function getWebsiteJobSelect(array $data): array
  3405. {
  3406. $web = Website::where('id', $data['website_id'])->first();
  3407. if (empty($web)) {
  3408. return Result::error("该网站不存在", 0);
  3409. }
  3410. $hy = JobIndustry::get()->all();
  3411. $zw = JobPosition::where('zwpid', 0)->get()->all();
  3412. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  3413. $result = [
  3414. 'hy' => $hy,
  3415. 'zw' => $zw,
  3416. 'jtzw' => $jtzw,
  3417. ];
  3418. if (empty($result)) {
  3419. return Result::error("查询失败", 0);
  3420. }
  3421. return Result::success($result);
  3422. }
  3423. /**
  3424. * c端-获取招工招聘
  3425. * @param array $data
  3426. * @return array
  3427. * */
  3428. public function getWebsiteJob(array $data): array
  3429. {
  3430. $web = Website::where('id', $data['website_id'])->first();
  3431. if (empty($web)) {
  3432. return Result::error("该网站不存在", 0);
  3433. }
  3434. $job_hunting = JobHunting::where('job_hunting.status', 2)
  3435. ->where('job_hunting.website_id', $data['website_id'])
  3436. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3437. $query->where(function ($q) use ($data) {
  3438. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3439. });
  3440. })
  3441. ->select(
  3442. 'job_hunting.id',
  3443. 'job_hunting.catid',
  3444. 'job_hunting.cat_arr_id',
  3445. 'job_hunting.job_name_get',
  3446. 'job_hunting.industry',
  3447. 'job_hunting.name',
  3448. 'job_hunting.sexy',
  3449. 'job_hunting.origin',
  3450. 'job_hunting.city_arr_id',
  3451. 'job_hunting.experience',
  3452. 'job_hunting.updated_at',
  3453. 'job_hunting.salary',
  3454. 'job_hunting.skillList',
  3455. 'job_hunting.slelf_evaluation',
  3456. )
  3457. ->orderBy('updated_at', 'desc')
  3458. ->limit($data['job1_num'])
  3459. ->get();
  3460. $web['website_id'] = $data['website_id'];
  3461. if (empty($job_hunting)) {
  3462. $job_huntings = "未查询到相关简历信息";
  3463. } else {
  3464. $job_huntings = $this->processJob($job_hunting, $web);
  3465. }
  3466. // 0:待审核 1:已通过 2:已拒绝
  3467. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3468. ->where('job_recruiting.website_id', $data['website_id'])
  3469. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3470. $query->where(function ($q) use ($data) {
  3471. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3472. });
  3473. })
  3474. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3475. ->select(
  3476. 'job_recruiting.id',
  3477. 'job_recruiting.catid',
  3478. 'job_recruiting.cat_arr_id',
  3479. 'job_recruiting.title',
  3480. 'job_recruiting.jtzw_id',
  3481. 'job_recruiting.hy_id',
  3482. 'job_recruiting.city_arr_id',
  3483. 'job_recruiting.due_data',
  3484. 'job_recruiting.updated_at',
  3485. 'job_recruiting.experience',
  3486. 'job_recruiting.educational',
  3487. 'job_recruiting.salary',
  3488. 'job_recruiting.zw_id',
  3489. 'job_company.business_name',
  3490. 'job_recruiting.keyword',
  3491. 'job_recruiting.description',
  3492. )
  3493. ->orderBy('updated_at', 'desc')
  3494. ->limit($data['job2_num'])
  3495. ->get();
  3496. if (empty($job_recruiting->toArray())) {
  3497. $job_recruitings = "未查询到相关职位信息";
  3498. } else {
  3499. $job_recruitings = $this->processJob($job_recruiting, $web);
  3500. }
  3501. $result = [
  3502. 'job_hunting' => $job_huntings,
  3503. 'job_recuiting' => $job_recruitings,
  3504. ];
  3505. return Result::success($result);
  3506. }
  3507. /**
  3508. * c端-获取招工招聘列表
  3509. * @param array $data
  3510. * @return array
  3511. * */
  3512. public function getWebsiteJobList(array $data): array
  3513. {
  3514. $recruit_where = [];
  3515. $hunt_where = [];
  3516. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3517. if (empty($web)) {
  3518. return Result::error("此网站不存在", 0);
  3519. }
  3520. $website_id['website_id'] = $data['website_id'];
  3521. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  3522. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3523. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  3524. }
  3525. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3526. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  3527. }
  3528. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3529. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  3530. }
  3531. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3532. array_push($recruit_where, ['title', 'like', '%' . $data['keyword'] . '%']);
  3533. }
  3534. $query = JobRecruiting::where('job_recruiting.status', 1)
  3535. ->where('job_recruiting.website_id', $data['website_id'])
  3536. ->where($recruit_where)
  3537. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3538. $query->where(function ($q) use ($data) {
  3539. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3540. });
  3541. })
  3542. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  3543. $query->where(function ($q) use ($data) {
  3544. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  3545. });
  3546. })
  3547. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3548. ->select(
  3549. 'job_recruiting.id',
  3550. 'job_recruiting.catid',
  3551. 'job_recruiting.hy_id',
  3552. 'job_recruiting.title',
  3553. 'job_recruiting.zw_id',
  3554. 'job_recruiting.educational',
  3555. 'job_recruiting.jtzw_id',
  3556. 'job_recruiting.city_arr_id',
  3557. 'job_recruiting.due_data',
  3558. 'job_recruiting.experience',
  3559. 'job_recruiting.cat_arr_id',
  3560. 'job_recruiting.updated_at',
  3561. 'job_company.business_name',
  3562. 'job_recruiting.keyword',
  3563. 'job_recruiting.description',
  3564. )
  3565. ->orderBy('job_recruiting.updated_at', 'desc');
  3566. $recruit_count = $query->count();
  3567. $query = clone $query;
  3568. $JobRecruiting = $query
  3569. ->offset(($data['page'] - 1) * $data['pageSize'])
  3570. ->limit($data['pageSize'])
  3571. ->get();
  3572. if (empty($JobRecruiting)) {
  3573. $JobRecruiting = "暂无相关职位信息";
  3574. } else {
  3575. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  3576. }
  3577. }
  3578. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  3579. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3580. array_push($hunt_where, ['job_hunting.job', $data['zw_id']]);
  3581. }
  3582. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3583. array_push($hunt_where, ['job_hunting.job_name_get', $data['jtzw_id']]);
  3584. }
  3585. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3586. array_push($hunt_where, ['job_hunting.industry', $data['hy_id']]);
  3587. }
  3588. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3589. array_push($hunt_where, ['job_position.zwname', 'like', '%' . $data['keyword'] . '%']);
  3590. }
  3591. $query = JobHunting::where('job_hunting.status', 2)
  3592. ->where('job_hunting.website_id', $data['website_id'])
  3593. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3594. ->where($hunt_where)
  3595. // ->when(isset($data['keyword']) &&!empty($data['keyword']), function ($query) use ($data) {
  3596. // $query->where('job_position.zwname','like','%'.$data['keyword'].'%');
  3597. // })
  3598. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3599. $query->where(function ($q) use ($data) {
  3600. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3601. });
  3602. })
  3603. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  3604. $query->where(function ($q) use ($data) {
  3605. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  3606. });
  3607. })
  3608. ->select(
  3609. 'job_hunting.id',
  3610. 'job_hunting.catid',
  3611. 'job_hunting.sexy',
  3612. 'job_hunting.experience',
  3613. 'job_hunting.origin',
  3614. 'job_hunting.industry',
  3615. 'job_hunting.name',
  3616. 'job_hunting.job',
  3617. 'job_hunting.job_name_get',
  3618. 'job_hunting.city_arr_id',
  3619. 'job_hunting.cat_arr_id',
  3620. 'job_hunting.created_at',
  3621. 'job_hunting.updated_at',
  3622. 'job_position.zwname as job_name',
  3623. 'job_hunting.skillList',
  3624. 'job_hunting.slelf_evaluation',
  3625. )
  3626. ->orderBy('job_hunting.updated_at', 'desc');
  3627. $hunt_count = $query->count();
  3628. $query = clone $query;
  3629. $JobHunting = $query
  3630. ->offset(($data['page'] - 1) * $data['pageSize'])
  3631. ->limit($data['pageSize'])
  3632. ->get();
  3633. if (empty($JobHunting)) {
  3634. $JobRecruiting = "暂无相关简历信息";
  3635. } else {
  3636. $JobHunting = $this->processJob($JobHunting, $website_id);
  3637. }
  3638. }
  3639. $result = [
  3640. 'JobRecruiting' => $JobRecruiting ?? [],
  3641. 'recruit_count' => $recruit_count ?? 0,
  3642. 'JobHunting' => $JobHunting ?? [],
  3643. 'hunt_count' => $hunt_count ?? 0,
  3644. ];
  3645. return Result::success($result);
  3646. }
  3647. /**
  3648. * c端-获取招工招聘详情
  3649. * @param array $data
  3650. * @return array
  3651. * */
  3652. public function getWebsiteJobInfo(array $data): array
  3653. {
  3654. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3655. if (empty($web)) {
  3656. return Result::error("该网站不存在", 0);
  3657. }
  3658. $webid = [
  3659. 'website_id' => $data['website_id'],
  3660. ];
  3661. // 职位相关信息
  3662. if ($data['type'] == 1) {
  3663. $query = JobRecruiting::where('status', 1)
  3664. ->where('website_id', $data['website_id'])
  3665. ->select('*');
  3666. $job = $query->where('job_recruiting.id', $data['id'])->get();
  3667. $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();
  3668. if (!empty($company)) {
  3669. $result['company'] = $this->processJob($company, $webid);
  3670. }
  3671. $other_job = JobRecruiting::where('status', 1)
  3672. ->where('website_id', $data['website_id'])
  3673. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  3674. ->where('id', '!=', $data['id'])
  3675. ->where('user_id', '=', $job[0]['user_id'])
  3676. ->limit($data['pageSize'])
  3677. ->get();
  3678. if (!empty($other_job)) {
  3679. $result['other_job'] = $this->processJob($other_job, $webid);
  3680. }
  3681. } else {
  3682. // 简历相关信息
  3683. $job = JobHunting::where('job_hunting.status', 2)
  3684. ->where('job_hunting.website_id', $data['website_id'])
  3685. ->where('job_hunting.id', $data['id'])
  3686. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3687. ->select('job_hunting.*', 'user_name')
  3688. ->get();
  3689. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  3690. if (!empty($resume->toArray())) {
  3691. $result['resume'] = 1;
  3692. } else {
  3693. $result['resume'] = 0;
  3694. }
  3695. }
  3696. if (empty($job->toArray())) {
  3697. return Result::error("id参数错误", 0);
  3698. }
  3699. if (!empty($job[0]['job_experience'])) {
  3700. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  3701. if (!empty($job_experience)) {
  3702. // $hy = [];
  3703. foreach ($job_experience as $key => $value) {
  3704. // $id = $value['id'];
  3705. $hy[$key] = $value['job_industry'];
  3706. $zw_id[$key] = $value['job_typename'];
  3707. $jtzw_id[$key] = $value['job_name'];
  3708. }
  3709. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  3710. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  3711. // 先将关联表转换为索引数组,提高查找效率
  3712. $hyLookup = [];
  3713. foreach ($hy_table as $item) {
  3714. $hyLookup[$item['hyid']] = $item['hyname'];
  3715. }
  3716. $zwLookup = [];
  3717. foreach ($zw_table as $item) {
  3718. $zwLookup[$item['zwid']] = $item['zwname'];
  3719. }
  3720. foreach ($job_experience as $key => &$value) {
  3721. // 处理行业名称
  3722. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  3723. $value['hy_name'] = $hyLookup[$hy[$key]];
  3724. }
  3725. // 处理职位名称
  3726. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  3727. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  3728. }
  3729. // 处理具体职位名称
  3730. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  3731. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  3732. }
  3733. }
  3734. // 释放引用,防止意外修改后续代码
  3735. unset($value);
  3736. }
  3737. $result['job_experience'] = $job_experience ?? [];
  3738. }
  3739. if (!empty($job[0]['education_experience'])) {
  3740. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  3741. if (!empty($education_experience)) {
  3742. foreach ($education_experience as $key => $value) {
  3743. // $id = $value['id'];
  3744. $education[$key] = $value['school_education'];
  3745. }
  3746. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  3747. // // 先将关联表转换为索引数组,提高查找效率
  3748. $educationLookup = [];
  3749. foreach ($education_table as $item) {
  3750. $educationLookup[$item['evalue']] = $item['ename'];
  3751. }
  3752. foreach ($education_experience as $key => &$value) {
  3753. // 处理学历名称
  3754. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  3755. $value['education_name'] = $educationLookup[$education[$key]];
  3756. }
  3757. }
  3758. }
  3759. $result['education_experience'] = $job_experience ?? [];
  3760. }
  3761. $result['job'] = $this->processJob($job, $webid);
  3762. // // 返现对应的栏目
  3763. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  3764. $category = WebsiteCategory::where('website_id', $data['website_id'])
  3765. ->whereIn('category_id', $catid)
  3766. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  3767. ->orderBy('pid')->get()->all();
  3768. if (!empty($category)) {
  3769. $result['category'] = $category;
  3770. }
  3771. $result['job'] = $job;
  3772. $result['job_experience'] = $job_experience ?? [];
  3773. $result['education_experience'] = $education_experience ?? [];
  3774. if (empty($result)) {
  3775. return Result::error("参数错误", 0);
  3776. }
  3777. return Result::success($result);
  3778. }
  3779. /**
  3780. * c端-申请职位
  3781. * @param array $data
  3782. * @return array
  3783. * */
  3784. public function getWebsiteJobApply(array $data): array
  3785. {
  3786. // 首先验证网站是否存在
  3787. // return Result::success($data);
  3788. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3789. if (empty($web)) {
  3790. return Result::error("该网站不存在", 0);
  3791. }
  3792. // 验证用户是否存在且为个人会员/管理员
  3793. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3794. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3795. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  3796. return Result::error("用户不存在", 0);
  3797. }
  3798. // 去除重复元素和空元素,并保持原始顺序
  3799. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  3800. return !empty($value);
  3801. }));
  3802. // 验证职位是否存在 1:审核通过
  3803. $recruiting = JobRecruiting::where('status', 1)
  3804. ->where('website_id', $data['website_id'])
  3805. ->whereIn('id', $data['recruit_id'])
  3806. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  3807. if (empty($recruiting)) {
  3808. return Result::error("该职位不存在", 0);
  3809. }
  3810. // 简历是否存在
  3811. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  3812. if (empty($hunt_id)) {
  3813. return Result::error("该简历不存在", 0);
  3814. }
  3815. $data['hunt_id'] = $hunt_id['hunt_id'];
  3816. // // 验证是否已投递过该职位
  3817. $apply = JobApply::where('user_id', $data['user_id'])
  3818. ->where('hunt_id', $data['hunt_id'])
  3819. ->where('website_id', $data['website_id'])
  3820. ->whereIn('recruit_id', $data['recruit_id'])
  3821. ->get(['recruit_id']);
  3822. if (!empty($apply->toArray())) {
  3823. return Result::error("您已投递过该职位!");
  3824. }
  3825. $insertData = array_map(function ($recruiting) use ($data) {
  3826. return [
  3827. 'user_id' => $data['user_id'],
  3828. 'hunt_id' => $data['hunt_id'],
  3829. 'website_id' => $data['website_id'],
  3830. 'recruit_id' => $recruiting['recruit_id'],
  3831. 'receiver_id' => $recruiting['receiver_id'],
  3832. 'status' => 1,
  3833. ];
  3834. }, $recruiting);
  3835. // 批量插入数据
  3836. $result = JobApply::insert($insertData);
  3837. if (empty($result)) {
  3838. return Result::error("投递失败", 0);
  3839. }
  3840. return Result::success($result);
  3841. }
  3842. /**
  3843. * 招工招聘-沟通简历
  3844. * @param array $data
  3845. * @return array
  3846. * */
  3847. public function getWebsiteJobResume(array $data): array
  3848. {
  3849. // 首先验证网站是否存在
  3850. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3851. if (empty($web)) {
  3852. return Result::error("该网站不存在", 0);
  3853. }
  3854. // return Result::success($data);
  3855. // 验证用户是否存在且为企业会员/管理员
  3856. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3857. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3858. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3859. return Result::error("用户不存在", 0);
  3860. }
  3861. // 去除重复元素和空元素,并保持原始顺序
  3862. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  3863. return !empty($value);
  3864. }));
  3865. // 验证简历是否存在
  3866. $hunting = JobHunting::where('status', 2)
  3867. ->where('website_id', $data['website_id'])
  3868. ->whereIn('id', $data['hunt_id'])
  3869. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  3870. if (empty($hunting)) {
  3871. return Result::error("该简历不存在", 0);
  3872. }
  3873. // 验证是否已沟通过该简历
  3874. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3875. ->where('recruit_id', $data['recruit_id'])
  3876. ->where('website_id', $data['website_id'])
  3877. ->whereIn('hunt_id', $data['hunt_id'])
  3878. ->get(['hunt_id']);
  3879. if (!empty($remuse->toArray())) {
  3880. return Result::error("您已沟通过该简历!");
  3881. }
  3882. // 准备要插入的数据数组
  3883. $insertData = array_map(function ($hunting) use ($data) {
  3884. return [
  3885. 'user_id' => $data['user_id'],
  3886. 'recruit_id' => $data['recruit_id'],
  3887. 'website_id' => $data['website_id'],
  3888. 'hunt_id' => $hunting['hunt_id'],
  3889. 'receiver_id' => $hunting['receiver_id'],
  3890. 'status' => 1,
  3891. ];
  3892. }, $hunting);
  3893. // 批量插入数据
  3894. $result = JobRemuse::insert($insertData);
  3895. if (empty($result)) {
  3896. return Result::error("沟通失败", 0);
  3897. }
  3898. return Result::success($result);
  3899. }
  3900. /**
  3901. * 招工招聘 -我的职位(企业会员)
  3902. * @param array $data
  3903. * @return array
  3904. */
  3905. public function getWebsiteJobRecruiting(array $data): array
  3906. {
  3907. $web = Website::where('id', $data['website_id'])->first('id');
  3908. if (empty($web)) {
  3909. return Result::error("该网站不存在", 0);
  3910. }
  3911. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3912. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3913. return Result::error("用户暂无权限!", 0);
  3914. }
  3915. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3916. $result = JobRecruiting::where('website_id', $data['website_id'])
  3917. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  3918. $query->where('user_id', $user['id']);
  3919. })
  3920. ->where('status', 1)
  3921. ->select('id', 'title', 'website_id', 'user_id', 'updated_at', 'keyword', 'catid', 'description')
  3922. ->orderBy('updated_at', 'desc')
  3923. ->limit($data['pageSize'])
  3924. ->get();
  3925. if (empty($result)) {
  3926. return Result::error("暂无相关职位信息", 0);
  3927. }
  3928. return Result::success($result);
  3929. }
  3930. /**
  3931. * c端 - 验证路由
  3932. * @param array $data
  3933. * @return array
  3934. */
  3935. /**
  3936. * c端 - 验证路由
  3937. * @param array $data
  3938. * @return array
  3939. */
  3940. public function checkWebsiteRoute(array $data): array
  3941. {
  3942. // 测试001111111222
  3943. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name', 'status']);
  3944. if (empty($web)) {
  3945. return Result::error("该网站不存在", 0);
  3946. } elseif ($web['status'] != 1) {
  3947. return Result::error("网站已经关闭", 0);
  3948. }
  3949. if (isset($data['other_route']) && !empty($data['other_route'])) {
  3950. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  3951. // 验证路由是否存在
  3952. if (empty($whiteRouterInfo)) {
  3953. $whiteRouterInfo = WhiteRouter::where("router_type", 1)->where('router_url', $data['other_route'])->first();
  3954. }
  3955. if (!empty($whiteRouterInfo)) {
  3956. return Result::success($whiteRouterInfo->toArray());
  3957. }
  3958. }
  3959. // 验证栏目路由
  3960. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  3961. ->where('path', $data['all_route'])
  3962. ->get()->all();
  3963. if (count($last_category) == 0) {
  3964. return Result::error("该栏目不存在", 0);
  3965. }
  3966. if (count($last_category) > 1) {
  3967. return Result::error("该栏目路由存在多个,路由验证失败!", 0);
  3968. }
  3969. if (count($last_category) == 1) {
  3970. $last_category = $last_category[0];
  3971. }
  3972. // return Result::success($last_category);
  3973. if (isset($data['id']) && !empty($data['id'])) {
  3974. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  3975. switch ($last_category['type']) {
  3976. case 1:
  3977. // 文章
  3978. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  3979. $article = Article::where('status', 1)
  3980. ->where('id', $data['id'])
  3981. ->where(function ($query) use ($data) {
  3982. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  3983. ->orWhereNull("ignore_ids");
  3984. })
  3985. ->first(['catid']);
  3986. if (empty($article)) {
  3987. return Result::error("该文章不存在", 0);
  3988. }
  3989. // return Result::success($article);
  3990. break;
  3991. case 2:
  3992. // 商品
  3993. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3994. $article = Good::where('website_id', $data['website_id'])
  3995. ->where('status', 2)
  3996. ->where('id', $data['id'])
  3997. ->first(['cat_arr_id']);
  3998. if (empty($article)) {
  3999. return Result::error("该商品不存在", 0);
  4000. }
  4001. break;
  4002. case 3:
  4003. // 书刊信息
  4004. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  4005. $article = Book::where('website_id', $data['website_id'])
  4006. ->where('status', 2)
  4007. ->where('id', $data['id'])
  4008. ->first(['id', 'cat_arr_id']);
  4009. if (empty($article)) {
  4010. return Result::error("该书刊不存在", 0);
  4011. }
  4012. break;
  4013. case 4:
  4014. // 招聘
  4015. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核通过;(只有企业会员需要审核)',
  4016. $article = JobRecruiting::where('website_id', $data['website_id'])
  4017. ->where('status', 1)
  4018. ->where('id', $data['id'])
  4019. ->first(['cat_arr_id']);
  4020. if (empty($article)) {
  4021. return Result::error("该招聘不存在", 0);
  4022. }
  4023. break;
  4024. case 5:
  4025. // 求职
  4026. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  4027. $article = JobHunting::where('website_id', $data['website_id'])
  4028. ->where('status', 2)
  4029. ->where('id', $data['id'])
  4030. ->first(['cat_arr_id']);
  4031. if (empty($article)) {
  4032. return Result::error("该求职不存在", 0);
  4033. }
  4034. break;
  4035. case 6:
  4036. // 企业
  4037. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  4038. $article = Company::
  4039. // where('website_id', $data['website_id'])
  4040. // ->
  4041. where('status', 1)
  4042. ->where('id', $data['id'])
  4043. ->first(['cat_arr_id']);
  4044. if (empty($article)) {
  4045. return Result::error("该企业不存在", 0);
  4046. }
  4047. break;
  4048. case 7:
  4049. // 项目
  4050. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  4051. $article = Project::where('website_id', $data['website_id'])
  4052. ->where('status', 1)
  4053. ->where('id', $data['id'])
  4054. ->first(['cat_arr_id']);
  4055. if (empty($article)) {
  4056. return Result::error("该项目不存在", 0);
  4057. }
  4058. break;
  4059. default:
  4060. return Result::error("该数据不存在", 0);
  4061. break;
  4062. }
  4063. // return Result::success($article);
  4064. // $catid =0 ;
  4065. if (!isset($article['cat_arr_id'])) {
  4066. $catid = isset($article['catid']) ? $article['catid'] : (isset($article['category_id']) ? $article['category_id'] : null);
  4067. } else {
  4068. $catidArray = json_decode($article['cat_arr_id'], true);
  4069. $catid = !empty($catidArray) ? end($catidArray) : null;
  4070. }
  4071. // return Result::success($catid);
  4072. // // return Result::success($article['cat_arr_id']);
  4073. if (empty($catid)) {
  4074. return Result::error("该栏目路径不存在", 0);
  4075. }
  4076. $path = WebsiteCategory::where('website_id', $data['website_id'])
  4077. ->where('category_id', $catid)
  4078. ->first('path');
  4079. }
  4080. // else{
  4081. // // if ($last_category['pid'] != 0) {
  4082. // $cat_arr = json_decode($last_category['category_arr_id'], true);
  4083. // $catid = !empty($cat_arr) && is_array($cat_arr) ? end($cat_arr) : null;
  4084. // $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  4085. // ->where('category_id',$catid)
  4086. // ->where('path',$data['all_route'])
  4087. // ->first('path');
  4088. // // } else {
  4089. // // $pinyin[0] = $last_category['aLIas_pinyin'];
  4090. // // }
  4091. // }
  4092. // return Result::success($path);
  4093. if (!empty($path) && $path['path'] != $data['all_route']) {
  4094. return Result::error('非法路径!');
  4095. } else {
  4096. return Result::success($last_category['path']);
  4097. }
  4098. }
  4099. /**
  4100. * 招工招聘 - 获取推荐职位
  4101. * @param array $data
  4102. * @return array
  4103. */
  4104. public function getWebsiteLevelJob(array $data): array
  4105. {
  4106. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  4107. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  4108. ->where('job_recruiting.status', 1)
  4109. ->where('job_level', $data['job_level'])
  4110. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4111. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  4112. ->orderBy('job_recruiting.updated_at', 'desc')
  4113. ->limit($data['pageSize'])
  4114. ->get();
  4115. $web = ['website_id' => $data['website_id']];
  4116. if (!empty($job)) {
  4117. $result = $this->processJob($job, $web);
  4118. }
  4119. if (empty($result)) {
  4120. return Result::error("暂无相关职位信息", 0);
  4121. }
  4122. return Result::success($result);
  4123. }
  4124. /**
  4125. * 验证导航名称是否重复
  4126. * @return void
  4127. */
  4128. //20250226 产品列表
  4129. public function getGoodList(array $data): array
  4130. {
  4131. var_dump($data, '---------1-2--');
  4132. $type_id = isset($data['user_type_id']) ? $data['user_type_id'] : '';
  4133. unset($data['user_type_id']);
  4134. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4135. $where = [];
  4136. if ($type_id != '10000') {
  4137. $where = [
  4138. 'good.user_id' => $user_id,
  4139. ];
  4140. }
  4141. //类型
  4142. if (isset($data['type_id']) && $data['type_id']) {
  4143. $where['good.type_id'] = $data['type_id'];
  4144. }
  4145. //名称
  4146. if (isset($data['name']) && $data['name']) {
  4147. $where[] = ['good.name', 'like', '%' . $data['name'] . '%'];
  4148. }
  4149. //status
  4150. if (isset($data['status']) && $data['status'] != '') {
  4151. $where['good.status'] = $data['status'];
  4152. }
  4153. //status1
  4154. // if (isset($data['status1']) && $data['status1'] == 1) {
  4155. // $status1 = 1;
  4156. // }
  4157. $where1 = [];
  4158. //website_id
  4159. // if (isset($data['website_id']) && $data['website_id']) {
  4160. // $where1 = [
  4161. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  4162. // ];
  4163. // }
  4164. // website_name
  4165. if (isset($data['website_name']) && $data['website_name']) {
  4166. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  4167. }
  4168. // catid
  4169. if (isset($data['category_name']) && $data['category_name']) {
  4170. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  4171. }
  4172. // $result = Good::where($where)
  4173. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  4174. var_dump($where, '---------1---');
  4175. $result = Good::where($where)
  4176. ->when(!empty($where1), function ($query) use ($where1) {
  4177. return $query->where($where1);
  4178. })
  4179. //status 1待审核2已审核3已拒绝
  4180. ->when(isset($data['status1']), function ($query) {
  4181. return $query->whereIn('good.status', [1, 3]);
  4182. })
  4183. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4184. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4185. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4186. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4187. ->orderBy("updated_at", "desc")
  4188. ->limit($data['page_size'])
  4189. ->offset(($data['page'] - 1) * $data['page_size'])
  4190. ->get();
  4191. $count = Good::where($where)
  4192. ->when(!empty($where1), function ($query) use ($where1) {
  4193. return $query->where($where1);
  4194. })
  4195. //status 1待审核2已审核3已拒绝
  4196. ->when(isset($data['status1']), function ($query) {
  4197. return $query->whereIn('good.status', [1, 3]);
  4198. })
  4199. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  4200. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  4201. ->leftJoin('category', 'good.catid', '=', 'category.id')
  4202. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  4203. ->orderBy("updated_at", "desc")->count();
  4204. $data = [
  4205. 'rows' => $result->toArray(),
  4206. 'count' => $count,
  4207. ];
  4208. if (empty($result)) {
  4209. return Result::error("此栏目暂无相关产品", 0);
  4210. }
  4211. return Result::success($data);
  4212. }
  4213. public function getGoodInfo(array $data): array
  4214. {
  4215. $result = Good::where('id', $data['id'])->first();
  4216. if (empty($result)) {
  4217. return Result::error("此产品不存在", 0);
  4218. }
  4219. return Result::success($result);
  4220. }
  4221. public function addGood(array $data): array
  4222. {
  4223. // unset($data['city_arr_id']);
  4224. // unset($data['cat_arr_id']);
  4225. $data['city_id'] = end($data['city_arr_id']);
  4226. $data['catid'] = end($data['cat_arr_id']);
  4227. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4228. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4229. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4230. unset($data['imgUrl']); //大小写
  4231. if (isset($data['price']) && $data['price'] == '') {
  4232. $data['price'] = 0;
  4233. }
  4234. if ($data['imgurl'] == '') {
  4235. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4236. preg_match_all($reg, $data['detail'], $matches);
  4237. if (isset($matches[1][0])) {
  4238. //截取varchar240
  4239. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4240. }
  4241. }
  4242. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4243. //提取标题+内容中的关键词
  4244. $data['keyword'] = $data['name'];
  4245. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4246. Jieba::init(); // 初始化 jieba-php
  4247. Finalseg::init();
  4248. $segList = Jieba::cut($data['keyword']);
  4249. $segList1 = array_slice($segList, 0, 8);
  4250. $data['keyword'] = implode(',', $segList1);
  4251. }
  4252. if ($data['description'] == '') {
  4253. //提取内容中的描述
  4254. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4255. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4256. // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  4257. }
  4258. if ($data['status'] == 1) {
  4259. $this->sendMessage([
  4260. 'talk_type' => 200,
  4261. 'title' => $data['name'],
  4262. 'content' => '提交了审核',
  4263. 'messageType' => 3,
  4264. ]);
  4265. }
  4266. $result = Good::insert($data);
  4267. if (empty($result)) {
  4268. return Result::error("添加失败", 0);
  4269. }
  4270. return Result::success($result);
  4271. }
  4272. public function updateGood(array $data): array
  4273. {
  4274. $data['city_id'] = end($data['city_arr_id']);
  4275. $data['catid'] = end($data['cat_arr_id']);
  4276. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  4277. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  4278. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  4279. //设置东八区
  4280. date_default_timezone_set('Asia/Shanghai');
  4281. $data['updated_at'] = date('Y-m-d H:i:s');
  4282. if (isset($data['price']) && $data['price'] == '') {
  4283. $data['price'] = 0;
  4284. }
  4285. if ($data['imgurl'] == '') {
  4286. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  4287. preg_match_all($reg, $data['detail'], $matches);
  4288. if (isset($matches[1][0])) {
  4289. //截取varchar240
  4290. $data['imgurl'] = substr($matches[1][0], 0, 240);
  4291. }
  4292. }
  4293. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  4294. //提取标题+内容中的关键词
  4295. $data['keyword'] = $data['name'];
  4296. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  4297. Jieba::init(); // 初始化 jieba-php
  4298. Finalseg::init();
  4299. $segList = Jieba::cut($data['keyword']);
  4300. $segList1 = array_slice($segList, 0, 8);
  4301. $data['keyword'] = implode(',', $segList1);
  4302. }
  4303. if ($data['description'] == '') {
  4304. //提取内容中的描述
  4305. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  4306. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  4307. }
  4308. if ($data['status'] == 1) {
  4309. $this->sendMessage([
  4310. 'talk_type' => 200,
  4311. 'title' => $data['name'],
  4312. 'content' => '提交了审核',
  4313. 'messageType' => 3,
  4314. ]);
  4315. }
  4316. $result = Good::where('id', $data['id'])->update($data);
  4317. if (empty($result)) {
  4318. return Result::error("更新失败", 0);
  4319. }
  4320. return Result::success($result);
  4321. }
  4322. public function delGood(array $data): array
  4323. {
  4324. $result = Good::where('id', $data['id'])->delete();
  4325. if (empty($result)) {
  4326. return Result::error("删除失败", 0);
  4327. }
  4328. return Result::success($result);
  4329. }
  4330. //20250226 产品列表
  4331. //20250306 求职信息
  4332. public function getJobHuntingList(array $data): array
  4333. {
  4334. $where = [];
  4335. if (isset($data['username']) && !empty($data['username'])) {
  4336. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4337. }
  4338. //status 1待审核2已审核3已拒绝
  4339. if (isset($data['status']) && $data['status'] != '') {
  4340. $where = [
  4341. 'job_hunting.status' => $data['status'],
  4342. ];
  4343. }
  4344. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4345. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4346. unset($data['type_id']);
  4347. if ($type_id != '10000') {
  4348. $where[] = ['job_hunting.user_id', '=', $user_id];
  4349. }
  4350. $result = JobHunting::where($where)
  4351. ->when(!empty($data['status1']), function ($query) use ($data) {
  4352. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4353. })
  4354. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4355. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4356. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  4357. ->orderBy("updated_at", "desc")
  4358. ->limit($data['page_size'])
  4359. ->offset(($data['page'] - 1) * $data['page_size'])
  4360. ->get();
  4361. if (empty($result)) {
  4362. return Result::error("查询失败", 0);
  4363. }
  4364. $count = JobHunting::where($where)
  4365. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  4366. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  4367. ->count();
  4368. $data = [
  4369. 'rows' => $result->toArray(),
  4370. 'count' => $count,
  4371. ];
  4372. return Result::success($data);
  4373. }
  4374. public function getJobHuntingApply(array $data): array
  4375. {
  4376. var_dump($data, '-----------------test--------1-');
  4377. $where = [];
  4378. if (isset($data['username']) && !empty($data['username'])) {
  4379. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  4380. }
  4381. if (isset($data['salary']) && !empty($data['salary'])) {
  4382. $where[] = [
  4383. 'job_hunting.salary',
  4384. '=',
  4385. $data['salary'],
  4386. ];
  4387. }
  4388. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4389. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4390. unset($data['type_id']);
  4391. if ($type_id != '10000') {
  4392. $where[] = ['job_apply.receiver_id', '=', $user_id];
  4393. }
  4394. var_dump($where, '-----------------test---------');
  4395. $result = jobApply::where($where)
  4396. // ->when(!empty($data['status1']), function ($query) use ($data) {
  4397. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  4398. // })
  4399. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  4400. ->where('job_enum.egroup', '=', 'income')
  4401. ->where('job_hunting.status', 2) //已审核
  4402. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4403. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4404. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4405. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4406. //职位----是申请职位
  4407. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4408. ->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')
  4409. ->orderBy("job_hunting.updated_at", "desc")
  4410. ->limit($data['page_size'])
  4411. ->offset(($data['page'] - 1) * $data['page_size'])
  4412. ->get();
  4413. if (empty($result)) {
  4414. return Result::error("查询失败", 0);
  4415. }
  4416. $count = jobApply::where($where)
  4417. ->where('job_enum.egroup', '=', 'income')
  4418. ->where('job_hunting.status', 2) //已审核
  4419. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  4420. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  4421. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  4422. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  4423. //职位----是申请职位
  4424. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  4425. ->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')
  4426. ->count();
  4427. $data = [
  4428. 'rows' => $result->toArray(),
  4429. 'count' => $count,
  4430. ];
  4431. return Result::success($data);
  4432. }
  4433. public function addJobHunting(array $data): array
  4434. {
  4435. date_default_timezone_set('Asia/Shanghai');
  4436. unset($data['company_name']);
  4437. unset($data['job_industry']);
  4438. unset($data['job_name']);
  4439. unset($data['department']);
  4440. unset($data['job_timeList']);
  4441. unset($data['job_content']);
  4442. unset($data['job_typename']); //不知道这是啥,
  4443. $data['created_at'] = date('Y-m-d H:i:s');
  4444. $data['updated_at'] = date('Y-m-d H:i:s');
  4445. //根据用户 user_id 只能添加一次
  4446. $result = JobHunting::where('user_id', $data['user_id'])->first();
  4447. if (!empty($result)) {
  4448. return Result::error("您已添加过求职信息", 0);
  4449. }
  4450. var_dump($result, '-----------------test---------');
  4451. if (isset($data['city_arr_id']) && !empty($data['city_arr_id'])) {
  4452. if (is_string($data['city_arr_id'])) {
  4453. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4454. $cityArr = json_decode($data['city_arr_id'], true);
  4455. // 确保 $cityArr 是数组
  4456. if (is_array($cityArr)) {
  4457. $data['city_id'] = end($cityArr);
  4458. }
  4459. } else {
  4460. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4461. if (is_array($data['city_arr_id'])) {
  4462. $data['city_id'] = end($data['city_arr_id']);
  4463. }
  4464. }
  4465. }
  4466. // 处理求职所绑定栏目
  4467. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id'])) {
  4468. if (is_string($data['cat_arr_id'])) {
  4469. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4470. // 先清理可能存在的无效 JSON 字符
  4471. $cleanedCatArrStr = trim($data['cat_arr_id']);
  4472. $catArr = json_decode($cleanedCatArrStr, true);
  4473. // 检查 JSON 解码是否成功且结果是数组
  4474. if (json_last_error() === JSON_ERROR_NONE && is_array($catArr)) {
  4475. $data['catid'] = end($catArr);
  4476. }
  4477. } else {
  4478. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4479. if (is_array($data['cat_arr_id'])) {
  4480. $data['catid'] = end($data['cat_arr_id']);
  4481. }
  4482. }
  4483. }
  4484. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4485. $this->sendMessage([
  4486. 'talk_type' => 600,
  4487. 'title' => $data['name'],
  4488. 'content' => '提交了审核',
  4489. 'messageType' => 11,
  4490. ]);
  4491. }
  4492. $result = JobHunting::create($data);
  4493. if (empty($result)) {
  4494. return Result::error("添加失败", 0);
  4495. }
  4496. return Result::success($result);
  4497. }
  4498. public function delJobHunting(array $data): array
  4499. {
  4500. $result = JobHunting::where('id', $data['id'])->delete();
  4501. if (empty($result)) {
  4502. return Result::error("删除失败", 0);
  4503. }
  4504. return Result::success($result);
  4505. }
  4506. public function updateJobHunting(array $data): array
  4507. {
  4508. //设置东八区
  4509. date_default_timezone_set('Asia/Shanghai');
  4510. unset($data['company_name']);
  4511. unset($data['job_industry']);
  4512. unset($data['job_name']);
  4513. unset($data['department']);
  4514. unset($data['job_timeList']);
  4515. unset($data['job_content']);
  4516. unset($data['job_typename']); //不知道这是啥,
  4517. $data['created_at'] = date('Y-m-d H:i:s');
  4518. $data['updated_at'] = date('Y-m-d H:i:s');
  4519. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  4520. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4521. $cityArr = json_decode($data['city_arr_id'], true);
  4522. $data['city_id'] = end($cityArr);
  4523. } else {
  4524. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4525. $data['city_id'] = end($data['city_arr_id']);
  4526. }
  4527. // 处理求职所绑定栏目
  4528. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_string($data['cat_arr_id'])) {
  4529. // 如果 cat_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4530. $catArr = json_decode($data['cat_arr_id'], true);
  4531. $data['catid'] = end($catArr);
  4532. } else {
  4533. // 如果 cat_arr_id 不是字符串,直接取最后一个数据
  4534. $data['catid'] = end($data['cat_arr_id']);
  4535. }
  4536. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4537. $this->sendMessage([
  4538. 'talk_type' => 600,
  4539. 'title' => $data['name'],
  4540. 'content' => '提交了审核',
  4541. 'messageType' => 11,
  4542. ]);
  4543. }
  4544. $result = JobHunting::where('id', $data['id'])->update($data);
  4545. if (empty($result)) {
  4546. return Result::error("更新失败", 0);
  4547. }
  4548. return Result::success($result);
  4549. }
  4550. public function getJobHuntingInfo(array $data): array
  4551. {
  4552. $result = JobHunting::where('id', $data['id'])->first();
  4553. if (empty($result)) {
  4554. return Result::error("查询失败", 0);
  4555. }
  4556. return Result::success($result);
  4557. }
  4558. public function getJobHuntingData(array $data): array
  4559. {
  4560. $jobEnum = JobEnum::get();
  4561. $jobIndustry = JobIndustry::get();
  4562. $jobNature = JobNature::get();
  4563. $jobPosition = JobPosition::get();
  4564. $data = [
  4565. 'jobEnum' => $jobEnum,
  4566. 'jobIndustry' => $jobIndustry,
  4567. 'jobNature' => $jobNature,
  4568. 'jobPosition' => $jobPosition,
  4569. ];
  4570. return Result::success($data);
  4571. }
  4572. public function delJobHuntingInfo(array $data): array
  4573. {
  4574. $result = JobHunting::where('id', $data['id'])->delete();
  4575. return Result::success();
  4576. }
  4577. //20250324 通知,公告,消息
  4578. public function delNotice(array $data): array
  4579. {
  4580. $result = Notice::where('id', $data['id'])->delete();
  4581. if ($result) {
  4582. return Result::success();
  4583. } else {
  4584. return Result::error("删除失败", 0);
  4585. }
  4586. }
  4587. public function getNoticeInfo(array $data): array
  4588. {
  4589. $result = Notice::where('id', $data['id'])->first();
  4590. // var_dump($result['re_user_ids'], '--------------------');
  4591. if (empty($result)) {
  4592. return Result::error("查询失败", 0);
  4593. }
  4594. return Result::success($result);
  4595. }
  4596. public function readNotice(array $data): array
  4597. {
  4598. $result = Notice::where('id', $data['id'])->first();
  4599. // var_dump($result['re_user_ids'], '--------------------');
  4600. if (empty($result)) {
  4601. return Result::error("查询失败", 0);
  4602. }
  4603. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4604. $re_user_ids = json_decode($result['re_user_ids'], true);
  4605. var_dump($re_user_ids, '--------------1---test---------');
  4606. var_dump($data, '--------------1---test---------');
  4607. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4608. //如果已经存在,就不再添加
  4609. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4610. $read_id = json_decode($result['read_id'], true);
  4611. if (!is_array($read_id)) {
  4612. $read_id = [];
  4613. }
  4614. if (!in_array($data['user_id'], $read_id)) {
  4615. $read_id[] = $data['user_id'];
  4616. $result['read_id'] = json_encode($read_id);
  4617. Notice::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4618. }
  4619. } else {
  4620. //如果不存在,就添加
  4621. $result['read_id'] = json_encode([$data['user_id']]);
  4622. Notice::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4623. }
  4624. }
  4625. return Result::success($result);
  4626. }
  4627. public function addNotice(array $data): array
  4628. {
  4629. date_default_timezone_set('Asia/Shanghai');
  4630. $data['created_at'] = date('Y-m-d H:i:s');
  4631. $data['updated_at'] = date('Y-m-d H:i:s');
  4632. // $data['level'] = "1,2,3,4,5";
  4633. $level = json_decode($data['level'], true);
  4634. $user_id = UserInfo::
  4635. //city_id不是null
  4636. whereNotNull('city_id')
  4637. ->whereNotNull('department_id')
  4638. ->where(function ($query) use ($data) {
  4639. $query->where(function ($subQuery) use ($data) {
  4640. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4641. });
  4642. })
  4643. ->where(function ($query) use ($data) {
  4644. $query->where(function ($subQuery) use ($data) {
  4645. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4646. });
  4647. })
  4648. ->when(isset($level) && is_array($level), function ($query) use ($level) {
  4649. $query->whereIn('level', $level);
  4650. })
  4651. ->pluck('user_id')->toArray();
  4652. $user_id = array_unique($user_id);
  4653. $chat_ids = $user_id;
  4654. $user_id = json_encode($user_id);
  4655. $data['re_user_ids'] = $user_id;
  4656. $this->sendMessage([
  4657. 'talk_type' => 700,
  4658. 'title' => $data['title'],
  4659. 'content' => '提交了审核',
  4660. 'messageType' => 5,
  4661. ]);
  4662. $result = Notice::insertGetId($data);
  4663. if (empty($result)) {
  4664. return Result::error("添加失败", 0);
  4665. }
  4666. return Result::success($result);
  4667. }
  4668. public function updateNotice(array $data): array
  4669. {
  4670. date_default_timezone_set('Asia/Shanghai');
  4671. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  4672. $user_id = UserInfo::
  4673. //city_id不是null
  4674. whereNotNull('city_id')
  4675. ->whereNotNull('department_id')
  4676. ->where(function ($query) use ($data) {
  4677. $query->where(function ($subQuery) use ($data) {
  4678. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4679. });
  4680. })
  4681. ->where(function ($query) use ($data) {
  4682. $query->where(function ($subQuery) use ($data) {
  4683. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4684. });
  4685. })
  4686. ->pluck('user_id')->toArray();
  4687. $user_id = array_unique($user_id);
  4688. $user_id = json_encode($user_id);
  4689. $data['re_user_ids'] = $user_id;
  4690. $data['updated_at'] = date('Y-m-d H:i:s');
  4691. $this->sendMessage([
  4692. 'talk_type' => 700,
  4693. 'title' => $data['title'],
  4694. 'content' => '提交了审核',
  4695. 'messageType' => 5,
  4696. ]);
  4697. $result = Notice::where('id', $data['id'])->update($data);
  4698. return Result::success($result);
  4699. }
  4700. public function getNoticeList(array $data): array
  4701. {
  4702. $where = [];
  4703. //title
  4704. if (isset($data['title']) && !empty($data['title'])) {
  4705. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4706. }
  4707. //level
  4708. if (isset($data['level']) && !empty($data['level'])) {
  4709. $where[] = ['notice.level', '=', $data['level']];
  4710. }
  4711. //status
  4712. if (isset($data['status']) && !empty($data['status'])) {
  4713. $where[] = ['notice.status', '=', $data['status']];
  4714. }
  4715. //type
  4716. if (isset($data['type']) && !empty($data['type'])) {
  4717. $where[] = ['notice.type', '=', $data['type']];
  4718. }
  4719. var_dump($data, '------------11111-2----test---------');
  4720. if ($data['type_id'] == 10000) {
  4721. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4722. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4723. })
  4724. ->where($where)
  4725. ->orderBy('updated_at', 'desc')
  4726. ->limit($data['page_size'])
  4727. ->offset(($data['page'] - 1) * $data['page_size'])
  4728. ->get();
  4729. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4730. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4731. })
  4732. ->where($where)
  4733. ->orderBy('updated_at', 'desc')
  4734. ->count();
  4735. } else {
  4736. $result = Notice::where($where)
  4737. // ->where('user_id', $data['user_id'])
  4738. ->Where(function ($query) use ($data) {
  4739. $query->Where(function ($q) use ($data) {
  4740. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4741. ->orWhere('notice.user_id', $data['user_id']);
  4742. });
  4743. })
  4744. ->when(!empty($data['status1']), function ($query) use ($data) {
  4745. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4746. })
  4747. ->orderBy('updated_at', 'desc')
  4748. ->limit($data['page_size'])
  4749. ->offset(($data['page'] - 1) * $data['page_size'])
  4750. ->get();
  4751. $total = Notice::where($where)
  4752. ->when(!empty($data['status1']), function ($query) use ($data) {
  4753. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4754. })
  4755. // ->where('user_id', $data['user_id'])
  4756. ->Where(function ($query) use ($data) {
  4757. $query->Where(function ($q) use ($data) {
  4758. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4759. ->orWhere('notice.user_id', $data['user_id']);
  4760. });
  4761. })
  4762. ->count();
  4763. }
  4764. if (empty($result)) {
  4765. return Result::error("查询失败", 0);
  4766. }
  4767. $data = [
  4768. 'rows' => $result,
  4769. 'count' => $total,
  4770. ];
  4771. return Result::success($data);
  4772. }
  4773. public function noticeList(array $data): array
  4774. {
  4775. $where = [];
  4776. //title
  4777. if (isset($data['title']) && !empty($data['title'])) {
  4778. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4779. }
  4780. //level
  4781. if (isset($data['level']) && !empty($data['level'])) {
  4782. $where[] = ['notice.level', '=', $data['level']];
  4783. }
  4784. //status
  4785. if (isset($data['status']) && !empty($data['status'])) {
  4786. $where[] = ['notice.status', '=', $data['status']];
  4787. }
  4788. //type
  4789. if (isset($data['type']) && !empty($data['type'])) {
  4790. $where[] = ['notice.type', '=', $data['type']];
  4791. }
  4792. var_dump($data, '------------11111-2----test---------');
  4793. if ($data['type_id'] == 10000) {
  4794. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4795. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4796. })
  4797. ->where($where)
  4798. ->orderBy('updated_at', 'desc')
  4799. ->limit($data['page_size'])
  4800. ->offset(($data['page'] - 1) * $data['page_size'])
  4801. ->get();
  4802. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4803. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4804. })
  4805. ->where($where)
  4806. ->orderBy('updated_at', 'desc')
  4807. ->count();
  4808. } else {
  4809. $result = Notice::where($where)
  4810. // ->where('user_id', $data['user_id'])
  4811. ->Where(function ($query) use ($data) {
  4812. $query->Where(function ($q) use ($data) {
  4813. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4814. ->orWhere('notice.user_id', $data['user_id']);
  4815. });
  4816. })
  4817. ->when(!empty($data['status1']), function ($query) use ($data) {
  4818. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4819. })
  4820. ->orderBy('updated_at', 'desc')
  4821. ->limit($data['page_size'])
  4822. ->offset(($data['page'] - 1) * $data['page_size'])
  4823. ->get();
  4824. $total = Notice::where($where)
  4825. ->when(!empty($data['status1']), function ($query) use ($data) {
  4826. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4827. })
  4828. // ->where('user_id', $data['user_id'])
  4829. ->Where(function ($query) use ($data) {
  4830. $query->Where(function ($q) use ($data) {
  4831. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4832. ->orWhere('notice.user_id', $data['user_id']);
  4833. });
  4834. })
  4835. ->count();
  4836. }
  4837. if (empty($result)) {
  4838. return Result::error("查询失败", 0);
  4839. }
  4840. $data = [
  4841. 'rows' => $result,
  4842. 'count' => $total,
  4843. ];
  4844. return Result::success($data);
  4845. }
  4846. public function getNoticeDetail(array $data): array
  4847. {
  4848. $result = Notice::where('id', $data['id'])->first();
  4849. if (empty($result)) {
  4850. return Result::error("查询失败", 0);
  4851. }
  4852. return Result::success($result);
  4853. }
  4854. public function deleteNotice(array $data): array
  4855. {
  4856. $notice = Notice::where('id', $data['id'])->first();
  4857. if (empty($notice)) {
  4858. return Result::error("删除失败", 0);
  4859. }
  4860. $chat_group_id = $notice->group_id;
  4861. if ($chat_group_id) {
  4862. //删除群聊
  4863. ChatGroups::where('id', $chat_group_id)->delete();
  4864. //删除群成员
  4865. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  4866. //删除群聊记录
  4867. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  4868. }
  4869. $result = Notice::where('id', $data['id'])->delete();
  4870. return Result::success($result);
  4871. }
  4872. public function complaintList(array $data): array
  4873. {
  4874. var_dump($data, '---------1---------');
  4875. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4876. unset($data['type_id']);
  4877. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4878. $where = [];
  4879. if ($type_id != 10000 && empty($data['deal_user'])) {
  4880. // $where['complaint.user_id'] = $user_id;
  4881. }
  4882. if (!empty($data['title'])) {
  4883. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4884. }
  4885. if (!empty($data['department_id'])) {
  4886. $where['complaint.department_id'] = $data['department_id'];
  4887. }
  4888. if (!empty($data['deal'])) {
  4889. $where['complaint.deal'] = $data['deal'];
  4890. }
  4891. if (!empty($data['status'])) {
  4892. $where['complaint.status'] = $data['status'];
  4893. }
  4894. var_dump(!empty($data['deal_user']), '----------1');
  4895. var_dump($where, '----------2');
  4896. $result = Complaint::where($where)
  4897. ->when(!empty($data['status1']), function ($query) use ($data) {
  4898. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4899. })
  4900. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4901. //json re_user_ids data[user_id]是不是在里面
  4902. $query->Where(function ($q) use ($data) {
  4903. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4904. ->where('complaint.status', 2);
  4905. });
  4906. })
  4907. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4908. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4909. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4910. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4911. ->orderBy('updated_at', 'desc')
  4912. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4913. //sql输出
  4914. if (empty($result)) {
  4915. return Result::error("暂无投诉信息", 0);
  4916. }
  4917. // 取出数据
  4918. $rows = $result->items();
  4919. $count = $result->total();
  4920. $responseData = [
  4921. 'rows' => $rows,
  4922. 'count' => $count,
  4923. ];
  4924. return Result::success($responseData);
  4925. }
  4926. public function getComplaintList(array $data): array
  4927. {
  4928. var_dump($data, '00000001000000000000');
  4929. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4930. unset($data['type_id']);
  4931. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4932. $where = [];
  4933. if ($type_id != 10000 && empty($data['deal_user'])) {
  4934. $where['complaint.user_id'] = $user_id;
  4935. }
  4936. if (!empty($data['title'])) {
  4937. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4938. }
  4939. if (!empty($data['department_id'])) {
  4940. $where['complaint.department_id'] = $data['department_id'];
  4941. }
  4942. if (!empty($data['deal'])) {
  4943. $where['complaint.deal'] = $data['deal'];
  4944. }
  4945. if (!empty($data['status'])) {
  4946. $where['complaint.status'] = $data['status'];
  4947. }
  4948. var_dump(!empty($data['deal_user']), '----------1');
  4949. var_dump($where, '----------2');
  4950. $result = Complaint::where($where)
  4951. ->when(!empty($data['status1']), function ($query) use ($data) {
  4952. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4953. })
  4954. // ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4955. // //json re_user_ids data[user_id]是不是在里面
  4956. // $query->Where(function ($q) use ($data) {
  4957. // $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4958. // ->where('complaint.status', 2);
  4959. // });
  4960. // })
  4961. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4962. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4963. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4964. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4965. ->orderBy('updated_at', 'desc')
  4966. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4967. //sql输出
  4968. if (empty($result)) {
  4969. return Result::error("暂无投诉信息", 0);
  4970. }
  4971. // 取出数据
  4972. $rows = $result->items();
  4973. $count = $result->total();
  4974. $responseData = [
  4975. 'rows' => $rows,
  4976. 'count' => $count,
  4977. ];
  4978. return Result::success($responseData);
  4979. }
  4980. public function getComplaintInfo(array $data): array
  4981. {
  4982. $result = Complaint::where('id', $data['id'])->first();
  4983. if (empty($result)) {
  4984. return Result::error("查询失败", 0);
  4985. }
  4986. return Result::success($result);
  4987. }
  4988. public function readComplaint(array $data): array
  4989. {
  4990. $result = Complaint::where('id', $data['id'])->first();
  4991. if (empty($result)) {
  4992. return Result::error("查询失败", 0);
  4993. }
  4994. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4995. $re_user_ids = json_decode($result['re_user_ids'], true);
  4996. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4997. //如果已经存在,就不再添加
  4998. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4999. $read_id = json_decode($result['read_id'], true);
  5000. if (!is_array($read_id)) {
  5001. $read_id = [];
  5002. }
  5003. if (!in_array($data['user_id'], $read_id)) {
  5004. $read_id[] = $data['user_id'];
  5005. $result['read_id'] = json_encode($read_id);
  5006. Complaint::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  5007. }
  5008. } else {
  5009. //如果不存在,就添加
  5010. $result['read_id'] = json_encode([$data['user_id']]);
  5011. Complaint::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  5012. }
  5013. }
  5014. return Result::success($result);
  5015. }
  5016. public function addComplaint(array $data): array
  5017. {
  5018. date_default_timezone_set('Asia/Shanghai');
  5019. $data['created_at'] = date('Y-m-d H:i:s');
  5020. $data['updated_at'] = date('Y-m-d H:i:s');
  5021. $this->sendMessage([
  5022. 'talk_type' => 800,
  5023. 'title' => $data['title'],
  5024. 'content' => '提交了审核',
  5025. 'messageType' => 6,
  5026. ]);
  5027. $result = Complaint::create($data);
  5028. return Result::success($result);
  5029. }
  5030. public function updateComplaint(array $data): array
  5031. {
  5032. date_default_timezone_set('Asia/Shanghai');
  5033. $data['updated_at'] = date('Y-m-d H:i:s');
  5034. $user_id = $data['user_id'] ?? 0;
  5035. $type_id = $data['type_id'] ?? 0;
  5036. unset($data['user_id']);
  5037. unset($data['type_id']);
  5038. $this->sendMessage([
  5039. 'talk_type' => 800,
  5040. 'title' => $data['title'],
  5041. 'content' => '提交了审核',
  5042. 'messageType' => 6,
  5043. ]);
  5044. $result = Complaint::where('id', $data['id'])->update($data);
  5045. return Result::success($result);
  5046. }
  5047. public function deleteComplaint(array $data): array
  5048. {
  5049. $result = Complaint::where('id', $data['id'])->delete();
  5050. return Result::success($result);
  5051. }
  5052. public function getComplainInfo(array $data): array
  5053. {
  5054. $result = Complaint::where('id', $data['id'])->first();
  5055. if (empty($result)) {
  5056. return Result::error("查询失败", 0);
  5057. }
  5058. return Result::success($result);
  5059. }
  5060. public function updateComplaintStatus(array $data): array
  5061. {
  5062. date_default_timezone_set('Asia/Shanghai');
  5063. $data['updated_at'] = date('Y-m-d H:i:s');
  5064. $user_id = $data['user_id'] ?? 0;
  5065. $type_id = $data['type_id'] ?? 0;
  5066. unset($data['user_id']);
  5067. unset($data['type_id']);
  5068. //处理, 写入处理人
  5069. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  5070. $data['real_deal_user'] = $user_id;
  5071. }
  5072. //如果是deal 23,则判断是不是处理人
  5073. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  5074. $complaintInof = Complaint::where('id', $data['id'])
  5075. ->where('real_deal_user', $user_id)
  5076. ->first();
  5077. if (empty($complaintInof)) {
  5078. return Result::error("处理人错误", 0);
  5079. }
  5080. }
  5081. $complaintInfo = Complaint::where('id', $data['id'])->first();
  5082. if ($data['status'] == 1) {
  5083. $this->sendMessage([
  5084. 'talk_type' => 800,
  5085. 'title' => $complaintInfo['title'],
  5086. 'content' => '提交了审核',
  5087. 'messageType' => 6,
  5088. ]);
  5089. }
  5090. if ($data['status'] == 2 && !isset($data['deal'])) {
  5091. $this->sendMessage([
  5092. 'talk_type' => 801,
  5093. 'title' => $complaintInfo['title'],
  5094. 'content' => '审核通过',
  5095. 'messageType' => 6,
  5096. 'user_id' => $complaintInfo['user_id'],
  5097. ]);
  5098. $this->sendMessage([
  5099. 'talk_type' => 802,
  5100. 'title' => $complaintInfo['title'],
  5101. 'content' => '待处理',
  5102. 'messageType' => 6,
  5103. 'user_id' => $complaintInfo['re_user_ids'],
  5104. ]);
  5105. }
  5106. if ($data['status'] == 3 && !isset($data['deal'])) {
  5107. $this->sendMessage([
  5108. 'talk_type' => 801,
  5109. 'title' => $complaintInfo['title'],
  5110. 'content' => '审核拒绝',
  5111. 'messageType' => 6,
  5112. 'user_id' => $complaintInfo['user_id'],
  5113. ]);
  5114. }
  5115. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 2) {
  5116. $this->sendMessage([
  5117. 'talk_type' => 802,
  5118. 'title' => $complaintInfo['title'],
  5119. 'content' => '处理中',
  5120. 'messageType' => 6,
  5121. 'user_id' => $complaintInfo['re_user_ids'],
  5122. ]);
  5123. }
  5124. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 4) {
  5125. $this->sendMessage([
  5126. 'talk_type' => 802,
  5127. 'title' => $complaintInfo['title'],
  5128. 'content' => '不予处理',
  5129. 'messageType' => 6,
  5130. 'user_id' => $complaintInfo['re_user_ids'],
  5131. ]);
  5132. }
  5133. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 3) {
  5134. $this->sendMessage([
  5135. 'talk_type' => 802,
  5136. 'title' => $complaintInfo['title'],
  5137. 'content' => '已完结',
  5138. 'messageType' => 6,
  5139. 'user_id' => $complaintInfo['re_user_ids'],
  5140. ]);
  5141. }
  5142. $result = complaint::where('id', $data['id'])->update($data);
  5143. return Result::success($result);
  5144. }
  5145. public function updateGoodStatus(array $data): array
  5146. {
  5147. $user_id = $data['user_id'] ?? 0;
  5148. $type_id = $data['type_id'] ?? 0;
  5149. unset($data['user_id']);
  5150. unset($data['type_id']);
  5151. $goodInfo = Good::where('id', $data['id'])->first();
  5152. if ($data['status'] == 2) {
  5153. $this->sendMessage([
  5154. 'talk_type' => 201,
  5155. 'title' => $goodInfo['name'],
  5156. 'content' => '审核通过',
  5157. 'messageType' => 3,
  5158. 'user_id' => $goodInfo['user_id'],
  5159. ]);
  5160. }
  5161. if ($data['status'] == 3) {
  5162. $this->sendMessage([
  5163. 'talk_type' => 201,
  5164. 'title' => $goodInfo['name'],
  5165. 'content' => '审核拒绝',
  5166. 'messageType' => 3,
  5167. 'user_id' => $goodInfo['user_id'],
  5168. ]);
  5169. }
  5170. if ($data['status'] == 1) {
  5171. $this->sendMessage([
  5172. 'talk_type' => 200,
  5173. 'title' => $goodInfo['name'],
  5174. 'content' => '提交了审核',
  5175. 'messageType' => 3,
  5176. ]);
  5177. }
  5178. $result = Good::where('id', $data['id'])->update($data);
  5179. return Result::success($result);
  5180. }
  5181. public function updateJobHuntingStatus(array $data): array
  5182. {
  5183. $user_id = $data['user_id'] ?? 0;
  5184. $type_id = $data['type_id'] ?? 0;
  5185. unset($data['user_id']);
  5186. unset($data['type_id']);
  5187. $jogHuntingInfo = JobHunting::where('id', $data['id'])->first();
  5188. if ($data['status'] == 2) {
  5189. $this->sendMessage([
  5190. 'talk_type' => 601,
  5191. 'title' => $jogHuntingInfo['name'],
  5192. 'content' => '审核通过',
  5193. 'messageType' => 11,
  5194. 'user_id' => $jogHuntingInfo['user_id'],
  5195. ]);
  5196. }
  5197. if ($data['status'] == 3) {
  5198. $this->sendMessage([
  5199. 'talk_type' => 601,
  5200. 'title' => $jogHuntingInfo['name'],
  5201. 'content' => '审核拒绝',
  5202. 'messageType' => 11,
  5203. 'user_id' => $jogHuntingInfo['user_id'],
  5204. ]);
  5205. }
  5206. if ($data['status'] == 1) {
  5207. $this->sendMessage([
  5208. 'talk_type' => 600,
  5209. 'title' => $jogHuntingInfo['name'],
  5210. 'content' => '提交了审核',
  5211. 'messageType' => 11,
  5212. ]);
  5213. }
  5214. $result = JobHunting::where('id', $data['id'])->update($data);
  5215. return Result::success($result);
  5216. }
  5217. public function updateNoticeStatus(array $data): array
  5218. {
  5219. $user_id = $data['user_id'] ?? 0;
  5220. $type_id = $data['type_id'] ?? 0;
  5221. unset($data['user_id']);
  5222. unset($data['type_id']);
  5223. //查询公告
  5224. $notice = Notice::where('id', $data['id'])->first();
  5225. if (empty($notice)) {
  5226. return Result::error("公告不存在", 0);
  5227. }
  5228. //$chat_ids 去除掉$data['user_id']
  5229. $chat_ids = json_decode($notice['re_user_ids'], true);
  5230. $chat_ids = array_diff($chat_ids, [$notice['user_id']]);
  5231. //如果公告的状态是2,且是群聊公告,且状态是1,则创建群聊,第一次审核通过的时候处理成群聊
  5232. if ($data['status'] == 2 && $notice['is_group'] == 1 && ($notice['status'] == 1 || $notice['status'] == 3) && empty($notice['group_id'])) {
  5233. //chat_group
  5234. $group_id = PublicData::uuid();
  5235. $groupData = [
  5236. 'id' => $group_id,
  5237. 'creator_id' => $notice['user_id'],
  5238. 'group_name' => $notice['group_name'] ?? '',
  5239. 'profile' => $notice['profile'] ?? 0,
  5240. ];
  5241. var_dump($groupData, '-----------------groupData-------');
  5242. $groupResult = ChatGroups::insertGetId($groupData);
  5243. var_dump($groupResult, '-----------------groupid-------');
  5244. $groupMemberData = [
  5245. 'id' => PublicData::uuid(),
  5246. 'user_id' => $notice['user_id'],
  5247. 'group_id' => $group_id,
  5248. 'leader' => 2,
  5249. ];
  5250. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  5251. //插入群成员表
  5252. $groupMemberDataUser = [];
  5253. $chatData = [];
  5254. foreach ($chat_ids as $key => $value) {
  5255. $groupMemberDataUser[] = [
  5256. 'id' => PublicData::uuid(),
  5257. 'user_id' => $value,
  5258. 'group_id' => $group_id,
  5259. 'leader' => 1,
  5260. ];
  5261. $chatData[] = [
  5262. 'user_id' => $value,
  5263. 'msg_type' => 1,
  5264. 'receiver_id' => $group_id,
  5265. 'content' => '通过通知创建群聊',
  5266. 'group_receiver_id' => $notice['user_id'],
  5267. 'action' => 'recieved',
  5268. 'created_at' => date('Y-m-d H:i:s'),
  5269. ];
  5270. }
  5271. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  5272. ChatGroupsMember::insert($groupMemberDataUser);
  5273. //插入一条管理员聊天记录
  5274. $chatData[] = [
  5275. 'user_id' => $notice['user_id'],
  5276. 'msg_type' => 1,
  5277. 'receiver_id' => $group_id,
  5278. 'content' => '通过通知创建群聊',
  5279. 'group_receiver_id' => $notice['user_id'],
  5280. 'action' => 'said',
  5281. 'created_at' => date('Y-m-d H:i:s'),
  5282. ];
  5283. var_dump($chatData, '-----------------chatData-------');
  5284. $chatResult = ChatRecords::insert($chatData);
  5285. //处理imp
  5286. $group = [
  5287. 'type' => 1,
  5288. 'name' => $notice['group_name'] ?? '',
  5289. 'profile' => '',
  5290. 'avatar' => '',
  5291. 'creator_id' => $notice['user_id'],
  5292. ];
  5293. $groupResult = GroupImp::insertGetId($group);
  5294. var_dump($groupResult, '获取imp group_id');
  5295. $groupMember = [
  5296. 'user_id' => $notice['user_id'],
  5297. 'group_id' => $groupResult,
  5298. 'leader' => 1,
  5299. 'join_time' => Date('Y-m-d H:i:s')
  5300. ];
  5301. $groupMemberResult = GroupMemberImp::insertGetId($groupMember);
  5302. $talk_session = [
  5303. 'user_id' => $notice['user_id'],
  5304. 'to_from_id' => $groupResult,
  5305. 'talk_mode' => 2,
  5306. 'created_at' => Date('Y-m-d H:i:s'),
  5307. 'updated_at' => Date('Y-m-d H:i:s'),
  5308. ];
  5309. $talk_session_result = GroupTalkImp::insertGetId($talk_session);
  5310. //被通知人员处理
  5311. foreach ($chat_ids as $key => $value) {
  5312. $groupMemberdata[] = [
  5313. 'user_id' => $value,
  5314. 'group_id' => $groupResult,
  5315. 'leader' => 3,
  5316. 'join_time' => Date('Y-m-d H:i:s')
  5317. ];
  5318. $talk_sessionData[] = [
  5319. 'user_id' => $value,
  5320. 'to_from_id' => $groupResult,
  5321. 'talk_mode' => 2,
  5322. 'created_at' => Date('Y-m-d H:i:s'),
  5323. 'updated_at' => Date('Y-m-d H:i:s'),
  5324. ];
  5325. }
  5326. $groupResult1 = GroupMemberImp::insert($groupMemberdata);
  5327. $talk_sessionResult = GroupTalkImp::insert($talk_sessionData);
  5328. $group_id = $groupResult;
  5329. //更新result的 group_id
  5330. $data['group_id'] = $group_id;
  5331. Notice::where(['id' => $data['id']])->update($data);
  5332. }
  5333. if (($data['status'] == 1 || $data['status'] == 3) && $notice['is_group'] == 1 && $notice['status'] == 2 && !empty($notice['group_id'])) {
  5334. //删除掉信息
  5335. GroupImp::where('id', $notice['group_id'])->delete();
  5336. GroupMemberImp::where('group_id', $notice['group_id'])->delete();
  5337. GroupTalkImp::where('to_from_id', $notice['group_id'])->delete();
  5338. foreach ($chat_ids as $key => $value) {
  5339. }
  5340. //聊天记录删除
  5341. //如果是群聊公告,且已经有群聊id,则更新公告的group_id
  5342. $data['group_id'] = null;
  5343. Notice::where(['id' => $data['id']])->update($data);
  5344. }
  5345. $result = Notice::where('id', $data['id'])->update($data);
  5346. $noticeInfo = Notice::where('id', $data['id'])->first();
  5347. if ($data['status'] == 2) {
  5348. $this->sendMessage([
  5349. 'talk_type' => 701,
  5350. 'title' => $noticeInfo['title'],
  5351. 'content' => '审核通过',
  5352. 'messageType' => 3,
  5353. 'user_id' => $noticeInfo['user_id'],
  5354. ]);
  5355. }
  5356. if ($data['status'] == 3) {
  5357. $this->sendMessage([
  5358. 'talk_type' => 701,
  5359. 'title' => $noticeInfo['title'],
  5360. 'content' => '审核拒绝',
  5361. 'messageType' => 3,
  5362. 'user_id' => $noticeInfo['user_id'],
  5363. ]);
  5364. }
  5365. if ($data['status'] == 1) {
  5366. $this->sendMessage([
  5367. 'talk_type' => 700,
  5368. 'title' => $noticeInfo['title'],
  5369. 'content' => '提交了审核',
  5370. 'messageType' => 3,
  5371. ]);
  5372. }
  5373. return Result::success($result);
  5374. }
  5375. public function getDUser(array $data): array
  5376. {
  5377. if (!empty($data['ids'])) {
  5378. $user = User::whereIn('id', $data['ids'])->getall();
  5379. if (empty($user)) {
  5380. return Result::error('无数据', 0);
  5381. }
  5382. return Result::success($user);
  5383. }
  5384. $where = [];
  5385. if (!empty($data['department_id'])) {
  5386. $where['department_id'] = $data['department_id'];
  5387. }
  5388. if (!empty($data['city_id'])) {
  5389. $where['city_id'] = $data['city_id'];
  5390. }
  5391. $result = User::where('type_id', 2)
  5392. ->where('status', 1)
  5393. ->where($where)
  5394. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  5395. ->get();
  5396. if (empty($result)) {
  5397. return Result::error("查询失败", 0);
  5398. }
  5399. return Result::success($result);
  5400. }
  5401. /**
  5402. * 验证导航名称是否重复
  5403. * @return void
  5404. */
  5405. public function checkCategoryName(array $data): array
  5406. {
  5407. $result = Category::when($data, function ($query) use ($data) {
  5408. if (isset($data['name']) && $data['name']) {
  5409. $query->where("name", $data['name']);
  5410. }
  5411. if (isset($data['id']) && $data['id']) {
  5412. $query->where("id", "!=", $data['id']);
  5413. }
  5414. })->first();
  5415. if ($result) {
  5416. return Result::error("已存在");
  5417. } else {
  5418. return Result::success();
  5419. }
  5420. }
  5421. //20250226 产品列表
  5422. // 20250306 -------招聘--------fr
  5423. /*
  5424. * 招聘列表
  5425. * */
  5426. public function getJobRecruitingList(array $data): array
  5427. {
  5428. $where = [];
  5429. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  5430. if ($data['checkout'] == 0) {
  5431. $job_status = [0, 2];
  5432. } else {
  5433. $job_status = [1];
  5434. }
  5435. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5436. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  5437. }
  5438. $user = User::where('id', $data['user_id'])->first();
  5439. if (empty($user)) {
  5440. return Result::error("用户不存在", 0);
  5441. }
  5442. // 3:企业会员
  5443. if ($user['type_id'] == 3) {
  5444. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  5445. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  5446. }
  5447. // 如果 $where 为空,则不添加 where 条件
  5448. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5449. return $query->where($where);
  5450. })
  5451. ->whereIn('job_recruiting.status', $job_status)
  5452. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5453. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  5454. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  5455. ->orderBy("updated_at", "desc")
  5456. ->offset(($data['page'] - 1) * $data['page_size'])
  5457. ->limit($data['page_size'])
  5458. ->get()
  5459. ->all();
  5460. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  5461. return $query->where($where);
  5462. })
  5463. ->whereIn('job_recruiting.status', $job_status)
  5464. ->count();
  5465. if (empty($result)) {
  5466. return Result::error("暂无招聘信息", 0);
  5467. }
  5468. return Result::success($result);
  5469. }
  5470. /*
  5471. * 招聘信息添加
  5472. * */
  5473. public function addJobRecruiting(array $data): array
  5474. {
  5475. // var_dump('添加招聘进入news------data',$data);
  5476. // return Result::success($data);
  5477. $user = User::where('user.id', $data['user_id'])
  5478. ->where('user.status', 1)
  5479. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5480. ->select(
  5481. 'user.type_id',
  5482. 'user.mobile',
  5483. 'user.email',
  5484. 'user_info.business_name',
  5485. 'user_info.company_hy_id',
  5486. 'user_info.company_nature',
  5487. 'user_info.company_size',
  5488. 'user_info.introduction',
  5489. 'user_info.real_name',
  5490. 'user_info.company_url',
  5491. 'user_info.address_arr_id',
  5492. 'user_info.address'
  5493. )
  5494. ->first();
  5495. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5496. return Result::error("用户不存在", 0);
  5497. }
  5498. $web = Website::where('id', $data['website_id'])->first();
  5499. if (empty($web)) {
  5500. return Result::error("网站不存在", 0);
  5501. }
  5502. // var_dump('添加招聘进入news---user---user',$user);
  5503. // 处理招聘关键词
  5504. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5505. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5506. } else {
  5507. Jieba::init(); // 初始化 jieba-php
  5508. Finalseg::init();
  5509. $segList = Jieba::cut($data['title']);
  5510. $segList1 = array_slice($segList, 0, 8);
  5511. $data['keyword'] = implode(',', $segList1);
  5512. }
  5513. if (!isset($data['seo_description']) || empty($data['seo_description'])) {
  5514. $content = $data['description'];
  5515. // 去除 <style> 和 <script> 标签及其内容
  5516. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5517. // 去除所有 HTML 标签
  5518. $content = strip_tags($content);
  5519. // 去除 HTML 实体
  5520. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5521. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5522. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5523. // 去除多余空白
  5524. $content = preg_replace('/\s+/u', '', $content);
  5525. // 截取 100 个字符
  5526. $data['seo_description'] = mb_substr($content, 0, 100);
  5527. }
  5528. // return Result::success($user);
  5529. $data['action_id'] = $data['user_id'] ?? null;
  5530. $data['user_type'] = $user['type_id'] ?? null;
  5531. $data['cat_arr_id'] = isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) ? array_values(array_unique($data['cat_arr_id'])) : [];
  5532. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5533. $data['catid'] = end($data['cat_arr_id']);
  5534. } else {
  5535. $data['catid'] = 0;
  5536. }
  5537. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? array_values(array_unique($data['city_arr_id'])) : [];
  5538. $data['cat_arr_id'] = isset($data['cat_arr_id']) && $data['cat_arr_id'] != [] ? json_encode(array_map('intval', $data['cat_arr_id'])) : '[]';
  5539. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '[]';
  5540. // 公司地址 管理员必填
  5541. $data['address_arr_id'] = isset($data['address_arr_id']) && !empty($data['address_arr_id']) ? array_values(array_unique($data['address_arr_id'])) : [];
  5542. $data['address_arr_id'] = isset($data['address_arr_id']) && $data['address_arr_id'] != [] ? json_encode(array_map('intval', $data['address_arr_id'])) : '[]';
  5543. // 管理员-企业相关信息
  5544. $company = [
  5545. // 'user_id' => $data['user_id']?? null,
  5546. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5547. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5548. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5549. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5550. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5551. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5552. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5553. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5554. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5555. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5556. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5557. ];
  5558. //去掉相关企业信息
  5559. $job = array_diff_key($data, array_flip(array_keys($company)));
  5560. // var_dump('添加招聘进入news---job---user',$job);
  5561. Db::beginTransaction();
  5562. try {
  5563. // // 先添加职位相关信息
  5564. if ($user['type_id'] == 10000) {
  5565. $job['status'] = 1;
  5566. }
  5567. $job['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5568. $job['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5569. $job['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5570. $job['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5571. $job['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5572. $job['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5573. $job['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5574. // return Result::success($job);
  5575. $jobId = JobRecruiting::insertGetId($job);
  5576. if (empty($jobId)) {
  5577. Db::rollBack();
  5578. return Result::error("添加失败");
  5579. }
  5580. // 添加公司信息
  5581. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5582. $company['job_id'] = $jobId;
  5583. $company['user_type'] = isset($user['type_id']) && $user['type_id'] !== '' ? $user['type_id'] : null;
  5584. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5585. if ($user['type_id'] == 10000) {
  5586. // 管理员添加企业信息
  5587. $companyId = JobCompany::insertGetId($company);
  5588. if (empty($companyId)) {
  5589. Db::rollBack();
  5590. return Result::error("添加失败");
  5591. }
  5592. } else {
  5593. // 企业会员添加企业信息
  5594. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5595. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5596. $company['user_type'] = isset($data['user_type']) && $data['user_type'] !== '' ? $data['user_type'] : null;
  5597. $company['job_id'] = $jobId;
  5598. $companyId = JobCompany::insertGetId($company);
  5599. if (empty($companyId)) {
  5600. Db::rollBack();
  5601. return Result::error("添加失败");
  5602. }
  5603. }
  5604. Db::commit();
  5605. $result = [
  5606. 'job_id' => $jobId,
  5607. 'company_id' => $companyId,
  5608. ];
  5609. return Result::success($result);
  5610. } catch (\Exception $e) {
  5611. Db::rollBack();
  5612. return Result::error($e->getMessage(), 0);
  5613. }
  5614. // return Result::success($result);
  5615. }
  5616. /*
  5617. * 获取招聘信息详情
  5618. * */
  5619. public function getJobRecruitingInfo(array $data): array
  5620. {
  5621. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  5622. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5623. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5624. ->select(
  5625. 'job_recruiting.*',
  5626. 'website.website_name as website_name',
  5627. 'job_company.business_name',
  5628. 'job_company.company_hy_id',
  5629. 'job_company.company_size',
  5630. 'job_company.company_nature',
  5631. 'job_company.introduction',
  5632. 'job_company.real_name',
  5633. 'job_company.mobile',
  5634. 'job_company.company_url',
  5635. 'job_company.address_arr_id',
  5636. 'job_company.address',
  5637. 'job_company.email'
  5638. )
  5639. ->first();
  5640. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  5641. if (!empty($cityId)) {
  5642. if (isset($cityId[1]) && $cityId[1] != null) {
  5643. $city = District::where('id', $cityId[1])->first(['name']);
  5644. } else {
  5645. $city = District::where('id', $cityId[0])->first(['name']);
  5646. }
  5647. $result['city'] = $city['name'] ?? '';
  5648. }
  5649. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  5650. if (is_array($addressId) && !empty($addressId)) {
  5651. $address = District::whereIn('id', $addressId)
  5652. ->orderBy('level', 'asc')
  5653. ->get(['name'])
  5654. ->pluck('name')
  5655. ->implode('');
  5656. // $job->address_name = $address ?? '';
  5657. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  5658. }
  5659. if (empty($result)) {
  5660. return Result::error("招聘信息不存在", 0);
  5661. }
  5662. // return Result::success($job);
  5663. return Result::success($result);
  5664. }
  5665. /*
  5666. * 修改招聘信息
  5667. * */
  5668. public function upJobRecruiting(array $data): array
  5669. {
  5670. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  5671. // return Result::success($job);
  5672. if (empty($job)) {
  5673. return Result::error("招聘信息不存在", 0);
  5674. }
  5675. $user = User::where('id', $data['user_id'])->first();
  5676. // return Result::success($user);
  5677. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5678. return Result::error("用户不存在", 0);
  5679. }
  5680. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5681. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5682. }
  5683. // 处理招聘关键词
  5684. if (isset($data['keyword']) && !empty($data['keyword'])) {
  5685. $data['keyword'] = str_replace(',', ',', $data['keyword']);
  5686. } else {
  5687. Jieba::init(); // 初始化 jieba-php
  5688. Finalseg::init();
  5689. $segList = Jieba::cut($data['title']);
  5690. $segList1 = array_slice($segList, 0, 8);
  5691. $data['keyword'] = implode(',', $segList1);
  5692. }
  5693. if (!isset($data['seo_description']) || empty($data['seo_description'])) {
  5694. $content = $data['description'];
  5695. // 去除 <style> 和 <script> 标签及其内容
  5696. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5697. // 去除所有 HTML 标签
  5698. $content = strip_tags($content);
  5699. // 去除 HTML 实体
  5700. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5701. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5702. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5703. // 去除多余空白
  5704. $content = preg_replace('/\s+/u', '', $content);
  5705. // 截取 100 个字符
  5706. $data['seo_description'] = mb_substr($content, 0, 100);
  5707. }
  5708. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  5709. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5710. $data['catid'] = end($data['cat_arr_id']);
  5711. } else {
  5712. }
  5713. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  5714. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  5715. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  5716. // 公司地址 管理员必填
  5717. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  5718. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5719. // 管理员-企业相关信息
  5720. $company = [
  5721. // 'user_id' => $data['user_id']?? null,
  5722. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5723. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5724. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5725. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5726. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5727. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5728. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5729. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5730. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5731. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5732. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5733. ];
  5734. //去掉相关企业信息
  5735. $data = array_diff_key($data, array_flip(array_keys($company)));
  5736. $jobId = $data['id'];
  5737. $web = $data['website_id'];
  5738. $data['action_id'] = $data['user_id'];
  5739. unset($data['user_id']);
  5740. unset($data['user_type']);
  5741. unset($data['id']);
  5742. unset($data['website_id']);
  5743. // return Result::success($data);
  5744. Db::beginTransaction();
  5745. try {
  5746. // 管理员修改招聘信息
  5747. if ($user['type_id'] == 10000) {
  5748. $data['website_id'] = $web;
  5749. $company['website_id'] = $data['website_id'];
  5750. $data['status'] = 1;
  5751. } else {
  5752. $data['status'] = 0;
  5753. }
  5754. $data['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5755. $data['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5756. $data['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5757. $data['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5758. $data['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5759. $data['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5760. $data['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5761. // return Result::success($job);
  5762. // Db::rollBack();
  5763. // return Result::success($company);
  5764. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  5765. $this->sendMessage([
  5766. 'talk_type' => 500,
  5767. 'title' => $data['title'],
  5768. 'content' => '提交了审核',
  5769. 'messageType' => 10,
  5770. ]);
  5771. }
  5772. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  5773. if (empty($result['job'])) {
  5774. Db::rollBack();
  5775. return Result::error("修改招聘信息失败");
  5776. }
  5777. // 管理员修改企业相关信息
  5778. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  5779. if (empty($result['company'])) {
  5780. Db::rollBack();
  5781. return Result::error("修改企业相关信息失败");
  5782. }
  5783. Db::commit();
  5784. // return Result::success($result);
  5785. } catch (\Exception $e) {
  5786. Db::rollBack();
  5787. return Result::error($e->getMessage(), 0);
  5788. }
  5789. return Result::success($result);
  5790. }
  5791. /*
  5792. * 招聘信息删除
  5793. * */
  5794. public function delJobRecruiting(array $data): array
  5795. {
  5796. $user = User::where('id', $data['user_id'])->first();
  5797. if (empty($user)) {
  5798. return Result::error("用户不存在", 0);
  5799. }
  5800. $job = JobRecruiting::where('id', $data['id'])->first();
  5801. if (empty($job)) {
  5802. return Result::error("招聘信息不存在", 0);
  5803. }
  5804. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5805. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5806. }
  5807. Db::beginTransaction();
  5808. try {
  5809. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  5810. if (empty($result['job'])) {
  5811. Db::rollBack();
  5812. return Result::error("删除招聘信息失败");
  5813. }
  5814. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  5815. if (empty($result['company'])) {
  5816. Db::rollBack();
  5817. return Result::error("删除企业相关信息失败");
  5818. }
  5819. Db::commit();
  5820. } catch (\Exception $e) {
  5821. Db::rollBack();
  5822. return Result::error($e->getMessage(), 0);
  5823. }
  5824. return Result::success($result);
  5825. }
  5826. /*
  5827. * 获取公司信息
  5828. * */
  5829. public function getJobCompany(array $data): array
  5830. {
  5831. $user = User::where('user.id', $data['user_id'])
  5832. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5833. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  5834. ->first();
  5835. // return Result::success($user);
  5836. if (empty($user)) {
  5837. return Result::error("用户不存在", 0);
  5838. }
  5839. if ($user['type_id'] == 3) {
  5840. $result = [
  5841. // 'id' => 0,
  5842. 'user_id' => $data['user_id'],
  5843. 'website_id' => $data['website_id'],
  5844. 'business_name' => $user['business_name'], // 企业名称
  5845. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  5846. 'company_nature' => $user['company_nature'], // 公司性质
  5847. 'company_size' => $user['company_size'], // 公司规模
  5848. 'introduction' => $user['introduction'], // 公司简介
  5849. 'real_name' => $user['real_name'], // 企业联系人
  5850. 'mobile' => $user['mobile'], // 企业联系电话
  5851. 'company_url' => $user['company_url'], // 企业网址
  5852. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  5853. 'address' => $user['address'], // 企业地址
  5854. 'email' => $user['email'], // 企业邮箱
  5855. ];
  5856. } else {
  5857. return Result::error("用户类型错误", 0);
  5858. }
  5859. if (empty($result)) {
  5860. return Result::error("公司信息不存在", 0);
  5861. }
  5862. return Result::success($result);
  5863. }
  5864. /*
  5865. * 修改公司信息
  5866. * */
  5867. public function upJobCompany(array $data): array
  5868. {
  5869. // return Result::success($data);
  5870. $user = User::where('user.id', $data['user_id'])
  5871. ->where('user.status', 1)
  5872. ->select('user.user_name', 'user.type_id')
  5873. ->first();
  5874. if (empty($user)) {
  5875. return Result::error("用户不存在", 0);
  5876. }
  5877. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5878. $job_company = JobCompany::where('user_id', $data['user_id'])->first();
  5879. $company = [
  5880. 'business_name' => $data['business_name'], // 企业名称
  5881. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5882. 'company_nature' => $data['company_nature'], // 公司性质
  5883. 'company_size' => $data['company_size'], // 公司规模
  5884. 'introduction' => $data['introduction'], // 公司简介
  5885. // 'real_name' => $data['real_name'], // 企业联系人
  5886. 'company_url' => $data['company_url'], // 企业网址
  5887. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5888. 'address' => $data['address'], // 企业详细地址
  5889. // 'email' => $data['email'], // 企业邮箱
  5890. ];
  5891. if ($user['type_id'] == 3) {
  5892. Db::beginTransaction();
  5893. try {
  5894. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  5895. 'business_name' => $data['business_name'], // 企业名称
  5896. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5897. 'company_nature' => $data['company_nature'], // 公司性质
  5898. 'company_size' => $data['company_size'], // 公司规模
  5899. 'introduction' => $data['introduction'], // 公司简介
  5900. // 'real_name' => $data['real_name'], // 企业联系人
  5901. 'company_url' => $data['company_url'], // 企业网址
  5902. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5903. 'address' => $data['address'], // 企业详细地址
  5904. ]);
  5905. if (empty($result['userinfo'])) {
  5906. Db::rollBack();
  5907. return Result::error('修改企业会员信息失败!');
  5908. }
  5909. $result['user'] = User::where('id', $data['user_id'])->update([
  5910. 'email' => $data['email'], // 企业邮箱
  5911. ]);
  5912. if (empty($result['user'])) {
  5913. Db::rollBack();
  5914. return Result::error('修改个人中心信息失败!');
  5915. }
  5916. // 该企业会员若是未发布招聘信息则暂无该企业会员的企业信息
  5917. if (!empty($job_company)) {
  5918. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  5919. if (empty($result['job_company'])) {
  5920. Db::rollBack();
  5921. return Result::error('修改企业会员信息失败!');
  5922. }
  5923. }
  5924. Db::commit();
  5925. return Result::success($result);
  5926. } catch (\Exception $e) {
  5927. Db::rollBack();
  5928. return Result::error($e->getMessage(), 0);
  5929. }
  5930. } else {
  5931. return Result::error("用户类型错误", 0);
  5932. }
  5933. }
  5934. /*
  5935. * 获取省-市
  5936. * */
  5937. public function getJobRecruitingArea(array $data): array
  5938. {
  5939. if (isset($data['pid']) && $data['pid'] != null) {
  5940. $result = District::where('pid', $data['pid'])->get()->all();
  5941. } else {
  5942. $result = District::where('level', 1)->get()->all();
  5943. }
  5944. if (empty($result)) {
  5945. return Result::error("暂无此省市", 0);
  5946. }
  5947. return Result::success($result);
  5948. }
  5949. /*
  5950. * 获取行业分类
  5951. * */
  5952. public function getIndustry(array $data): array
  5953. {
  5954. $result = JobIndustry::get()->all();
  5955. if (empty($result)) {
  5956. return Result::error("暂无行业分类", 0);
  5957. }
  5958. return Result::success($result);
  5959. }
  5960. /*
  5961. * 获取职位
  5962. * */
  5963. public function getPositionList(array $data): array
  5964. {
  5965. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  5966. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  5967. } else {
  5968. $result = JobPosition::where('zwpid', 0)->get()->all();
  5969. }
  5970. if (empty($result)) {
  5971. return Result::error("暂无此职位", 0);
  5972. }
  5973. return Result::success($result);
  5974. }
  5975. /*
  5976. * 获取工作性质-菜单
  5977. * */
  5978. public function getJobNature(array $data): array
  5979. {
  5980. $result = JobEnum::where('egroup', 'nature')->get()->all();
  5981. if (empty($result)) {
  5982. return Result::error("暂无工作性质", 0);
  5983. }
  5984. return Result::success($result);
  5985. }
  5986. /*
  5987. * 获取工作经验-菜单
  5988. * */
  5989. public function getExperience(array $data): array
  5990. {
  5991. $result = JobEnum::where('egroup', 'years')->get()->all();
  5992. if (empty($result)) {
  5993. return Result::error("暂无工作经验", 0);
  5994. }
  5995. return Result::success($result);
  5996. }
  5997. /*
  5998. * 获取学历-菜单
  5999. * */
  6000. public function getEducation(array $data): array
  6001. {
  6002. $result = JobEnum::where('egroup', 'education')->get()->all();
  6003. if (empty($result)) {
  6004. return Result::error("暂无学历", 0);
  6005. }
  6006. return Result::success($result);
  6007. }
  6008. /*
  6009. * 获取薪资-菜单
  6010. * */
  6011. public function getSalary(array $data): array
  6012. {
  6013. $result = JobEnum::where('egroup', 'income')->get()->all();
  6014. if (empty($result)) {
  6015. return Result::error("暂无薪资", 0);
  6016. }
  6017. return Result::success($result);
  6018. }
  6019. /*
  6020. * 获取语言-菜单
  6021. * */
  6022. public function getLanguage(array $data): array
  6023. {
  6024. $result = JobEnum::where('egroup', 'language')->get()->all();
  6025. if (empty($result)) {
  6026. return Result::error("暂无语言", 0);
  6027. }
  6028. return Result::success($result);
  6029. }
  6030. /*
  6031. * 获取掌握程度-菜单
  6032. * */
  6033. public function getLevel(array $data): array
  6034. {
  6035. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  6036. if (empty($result)) {
  6037. return Result::error("暂无工作性质", 0);
  6038. }
  6039. return Result::success($result);
  6040. }
  6041. // 公司信息
  6042. /*
  6043. * 获取公司性质-菜单
  6044. * */
  6045. public function getCompanyNature(array $data): array
  6046. {
  6047. $result = JobNature::get()->all();
  6048. if (empty($result)) {
  6049. return Result::error("暂无公司性质", 0);
  6050. }
  6051. return Result::success($result);
  6052. }
  6053. /*
  6054. * 获取公司规模-菜单
  6055. * */
  6056. public function getCompanySize(array $data): array
  6057. {
  6058. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  6059. if (empty($result)) {
  6060. return Result::error("暂无公司规模", 0);
  6061. }
  6062. return Result::success($result);
  6063. }
  6064. /*
  6065. * 招聘信息审核
  6066. * */
  6067. public function checkJobRecruiting(array $data): array
  6068. {
  6069. $user = User::where('id', $data['user_id'])->first();
  6070. if (empty($user)) {
  6071. return Result::error("用户不存在", 0);
  6072. }
  6073. $job = JobRecruiting::where('id', $data['id'])->first();
  6074. if (empty($job)) {
  6075. return Result::error("招聘信息不存在", 0);
  6076. }
  6077. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  6078. if ($user['type_id'] != 10000) {
  6079. return Result::error("用户暂无权限审核此招聘信息!", 0);
  6080. }
  6081. // 驳回原因
  6082. if ($data['status'] == 2) {
  6083. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  6084. }
  6085. $data['action_id'] = $data['user_id'];
  6086. unset($data['user_id']);
  6087. if ($data['status'] == 1) {
  6088. $this->sendMessage([
  6089. 'talk_type' => 501,
  6090. 'title' => $job['title'],
  6091. 'content' => '审核通过',
  6092. 'messageType' => 10,
  6093. 'user_id' => $job['user_id'],
  6094. ]);
  6095. }
  6096. if ($data['status'] == 2) {
  6097. $this->sendMessage([
  6098. 'talk_type' => 501,
  6099. 'title' => $job['title'],
  6100. 'content' => '审核拒绝',
  6101. 'messageType' => 10,
  6102. 'user_id' => $job['user_id'],
  6103. ]);
  6104. }
  6105. if ($data['status'] == 0) {
  6106. $this->sendMessage([
  6107. 'talk_type' => 500,
  6108. 'title' => $job['title'],
  6109. 'content' => '提交了审核',
  6110. 'messageType' => 10,
  6111. ]);
  6112. }
  6113. $result = JobRecruiting::where('id', $data['id'])->update($data);
  6114. if (empty($result)) {
  6115. return Result::error("审核失败", 0);
  6116. }
  6117. return Result::success($result);
  6118. }
  6119. public function myApplyList(array $data): array
  6120. {
  6121. var_dump($data, '------参数');
  6122. $user = User::where('id', $data['user_id'])->first();
  6123. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6124. return Result::error("用户不存在", 0);
  6125. }
  6126. // 1:个人会员 职场机会
  6127. if ($user['type_id'] == 1) {
  6128. $where['user_id'] = $user['id'];
  6129. }
  6130. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  6131. $query->where('user_id', $user['id']);
  6132. })
  6133. ->pluck('recruit_id');
  6134. $where = [];
  6135. if (isset($data['salary']) && $data['salary'] != null) {
  6136. $where['job_recruiting.salary'] = $data['salary'];
  6137. }
  6138. if (isset($data['experience']) && $data['experience'] != null) {
  6139. $where['job_recruiting.experience'] = $data['experience'];
  6140. }
  6141. if (isset($data['business_name']) && $data['business_name'] != null) {
  6142. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6143. }
  6144. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6145. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6146. ->where($where);
  6147. // ->count();
  6148. $count = $query->count();
  6149. $query = clone $query;
  6150. $job = $query
  6151. ->leftJoin('job_enum as income_enum', function ($join) {
  6152. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6153. ->where('income_enum.egroup', 'income');
  6154. })
  6155. ->leftJoin('job_enum as years_enum', function ($join) {
  6156. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6157. ->where('years_enum.egroup', 'years');
  6158. })
  6159. // ->where($where)
  6160. ->orderBy('job_recruiting.updated_at', 'desc')
  6161. ->select(
  6162. 'job_recruiting.id',
  6163. 'job_recruiting.title',
  6164. 'job_company.business_name',
  6165. 'income_enum.evalue as salary_evalue',
  6166. 'income_enum.ename as salary_ename',
  6167. 'years_enum.evalue as experience_evalue',
  6168. 'years_enum.ename as experience_ename',
  6169. 'job_recruiting.updated_at'
  6170. )
  6171. ->offset(($data['page'] - 1) * $data['pageSize'])
  6172. ->limit($data['pageSize'])
  6173. ->get()
  6174. ->all();
  6175. if (empty($job)) {
  6176. return Result::error("暂无招聘信息", 0);
  6177. }
  6178. $result = [
  6179. 'row' => $job,
  6180. 'count' => $count,
  6181. ];
  6182. return Result::success($result);
  6183. }
  6184. public function readJobApply(array $data): array
  6185. {
  6186. $result = JobApply::where('id', $data['id'])->first();
  6187. if (empty($result)) {
  6188. return Result::error("查询失败", 0);
  6189. }
  6190. $result = JobApply::where('id', $data['id'])->update([
  6191. 'status' => 2,
  6192. ]);
  6193. return Result::success($result);
  6194. }
  6195. /*
  6196. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  6197. * */
  6198. public function getRecruitingList(array $data): array
  6199. {
  6200. $user = User::where('id', $data['user_id'])->first();
  6201. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6202. return Result::error("用户不存在", 0);
  6203. }
  6204. // 1:个人会员 职场机会
  6205. if ($user['type_id'] == 1) {
  6206. $where['user_id'] = $user['id'];
  6207. }
  6208. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  6209. $query->where('receiver_id', $user['id']);
  6210. })
  6211. ->pluck('recruit_id');
  6212. // return Result::success($recruitingId);
  6213. $where = [];
  6214. if (isset($data['salary']) && $data['salary'] != null) {
  6215. $where['job_recruiting.salary'] = $data['salary'];
  6216. }
  6217. if (isset($data['experience']) && $data['experience'] != null) {
  6218. $where['job_recruiting.experience'] = $data['experience'];
  6219. }
  6220. if (isset($data['business_name']) && $data['business_name'] != null) {
  6221. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  6222. }
  6223. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  6224. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6225. ->where($where);
  6226. // ->count();
  6227. $count = $query->count();
  6228. $query = clone $query;
  6229. $job = $query
  6230. ->leftJoin('job_enum as income_enum', function ($join) {
  6231. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  6232. ->where('income_enum.egroup', 'income');
  6233. })
  6234. ->leftJoin('job_enum as years_enum', function ($join) {
  6235. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  6236. ->where('years_enum.egroup', 'years');
  6237. })
  6238. // ->where($where)
  6239. ->orderBy('job_recruiting.updated_at', 'desc')
  6240. ->select(
  6241. 'job_recruiting.id',
  6242. 'job_recruiting.title',
  6243. 'job_company.business_name',
  6244. 'income_enum.evalue as salary_evalue',
  6245. 'income_enum.ename as salary_ename',
  6246. 'years_enum.evalue as experience_evalue',
  6247. 'years_enum.ename as experience_ename',
  6248. 'job_recruiting.updated_at'
  6249. )
  6250. ->offset(($data['page'] - 1) * $data['pageSize'])
  6251. ->limit($data['pageSize'])
  6252. ->get()
  6253. ->all();
  6254. if (empty($job)) {
  6255. return Result::error("暂无招聘信息", 0);
  6256. }
  6257. $result = [
  6258. 'row' => $job,
  6259. 'count' => $count,
  6260. ];
  6261. return Result::success($result);
  6262. }
  6263. /*
  6264. * 获取企业会员-招聘信息列表
  6265. * */
  6266. public function getRecruitingInfo(array $data): array
  6267. {
  6268. $user = User::where('id', $data['user_id'])->first();
  6269. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  6270. return Result::error("用户不存在", 0);
  6271. }
  6272. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  6273. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  6274. ->select(
  6275. 'job_recruiting.*',
  6276. 'job_company.business_name',
  6277. 'job_company.company_hy_id',
  6278. 'job_company.company_size',
  6279. 'job_company.company_nature',
  6280. 'job_company.introduction',
  6281. 'job_company.real_name',
  6282. 'job_company.mobile',
  6283. 'job_company.company_url',
  6284. 'job_company.address_arr_id',
  6285. 'job_company.address',
  6286. 'job_company.email'
  6287. )
  6288. ->get();
  6289. if (empty($recruiting)) {
  6290. return Result::error("暂无招聘信息", 0);
  6291. }
  6292. return Result::success($recruiting);
  6293. }
  6294. /*
  6295. * 获取企业会员-我的沟通
  6296. * */
  6297. public function getJobResumeList(array $data): array
  6298. {
  6299. $user = User::where('id', $data['user_id'])->first();
  6300. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  6301. return Result::error("用户不存在", 0);
  6302. }
  6303. $where = [];
  6304. if (isset($data['salary']) && $data['salary'] != null) {
  6305. $where['job_hunting.salary'] = $data['salary'];
  6306. }
  6307. if (isset($data['user_name']) && $data['user_name'] != null) {
  6308. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  6309. }
  6310. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  6311. $query->where('job_resume.user_id', $user['id']);
  6312. })
  6313. ->when(!empty($where), function ($query) use ($where) {
  6314. $query->where($where);
  6315. })
  6316. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  6317. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  6318. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  6319. ->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');
  6320. $count = $job->count();
  6321. if ($count == 0) {
  6322. return Result::error("暂无沟通记录", 0);
  6323. }
  6324. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  6325. ->offset(($data['page'] - 1) * $data['pageSize'])
  6326. ->limit($data['pageSize'])
  6327. ->get();
  6328. if (empty($jobs)) {
  6329. return Result::error("暂无沟通记录", 0);
  6330. }
  6331. $result['row'] = $this->processJob($jobs, '');
  6332. $result['count'] = $count;
  6333. return Result::success($result);
  6334. }
  6335. public function readJobResume(array $data): array
  6336. {
  6337. $result = JobResume::where('id', $data['id'])->first();
  6338. if (empty($result)) {
  6339. return Result::error("查询失败", 0);
  6340. }
  6341. $result = JobResume::where('id', $data['id'])->update([
  6342. 'status' => 2,
  6343. ]);
  6344. return Result::success($result);
  6345. }
  6346. // 20250306 招聘
  6347. //20250422 书刊音像
  6348. public function addBook(array $data): array
  6349. {
  6350. $user_id = $data['user_id'] ?? 0;
  6351. $type_id = $data['type_id'] ?? 0;
  6352. // $website_id = $data['website_id'] ?? 0;
  6353. // unset($data['user_id']);
  6354. unset($data['type_id']);
  6355. // unset($data['website_id']);
  6356. //处理数组
  6357. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6358. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6359. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6360. if ($data['img_url'] == '') {
  6361. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6362. preg_match_all($reg, $data['detail'], $matches);
  6363. if (isset($matches[1][0])) {
  6364. //截取varchar240
  6365. $data['img_url'] = substr($matches[1][0], 0, 240);
  6366. }
  6367. }
  6368. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  6369. //提取标题+内容中的关键词
  6370. $data['keyword'] = $data['title'];
  6371. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6372. Jieba::init(); // 初始化 jieba-php
  6373. Finalseg::init();
  6374. $segList = Jieba::cut($data['keyword']);
  6375. $segList1 = array_slice($segList, 0, 8);
  6376. $data['keyword'] = implode(',', $segList1);
  6377. }
  6378. if ($data['description'] == '') {
  6379. //提取内容中的描述
  6380. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6381. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6382. }
  6383. var_dump($data, '--');
  6384. if ($data['status'] == 1) {
  6385. $this->sendMessage([
  6386. 'talk_type' => 400,
  6387. 'title' => $data['title'],
  6388. 'content' => '提交了审核',
  6389. 'messageType' => 7,
  6390. ]);
  6391. }
  6392. $result = Book::insertGetId($data);
  6393. if (empty($result)) {
  6394. return Result::error("添加失败", 0);
  6395. }
  6396. return Result::success($result);
  6397. }
  6398. public function getBookList(array $data): array
  6399. {
  6400. $where = [];
  6401. if (!empty($data["title"])) {
  6402. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  6403. }
  6404. if (!empty($data['website_name'])) {
  6405. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  6406. }
  6407. if (!empty($data['status'])) {
  6408. $where[] = ['book.status', '=', $data['status']];
  6409. }
  6410. $user_id = $data['user_id'];
  6411. $type_id = $data['type_id'];
  6412. // $type_id = 4;
  6413. var_dump($type_id, '------1--------');
  6414. if ($type_id != 10000) {
  6415. $where[] = ['book.user_id', '=', $user_id];
  6416. }
  6417. var_dump(!empty($data['status1']), '=-===1');
  6418. $result = Book::where($where)
  6419. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  6420. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  6421. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  6422. ->when(isset($data['status1']), function ($query) use ($data) {
  6423. $query->whereIn('book.status', [1, 3]);
  6424. })
  6425. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  6426. ->orderBy("updated_at", "desc")
  6427. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  6428. if (empty($result)) {
  6429. return Result::error("暂无数据", 0);
  6430. }
  6431. // 取出数据
  6432. $rows = $result->items();
  6433. $count = $result->total();
  6434. $responseData = [
  6435. 'rows' => $rows,
  6436. 'count' => $count,
  6437. ];
  6438. return Result::success($responseData);
  6439. }
  6440. public function deleteBook(array $data): array
  6441. {
  6442. $result = Book::where('id', $data['id'])->delete();
  6443. if (empty($result)) {
  6444. return Result::error("删除失败", 0);
  6445. }
  6446. return Result::success($result);
  6447. }
  6448. public function updateBook(array $data): array
  6449. {
  6450. // $user_id = $data['user_id'] ?? 0;
  6451. $type_id = $data['type_id'] ?? 0;
  6452. // $website_id = $data['website_id'] ?? 0;
  6453. unset($data['user_id']);
  6454. unset($data['type_id']);
  6455. // unset($data['website_id']);
  6456. //处理数组
  6457. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  6458. if ($data['img_url'] == '') {
  6459. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6460. preg_match_all($reg, $data['detail'], $matches);
  6461. if (isset($matches[1][0])) {
  6462. //截取varchar240
  6463. $data['img_url'] = substr($matches[1][0], 0, 240);
  6464. }
  6465. }
  6466. if ($data['keyword'] == '') {
  6467. //提取标题+内容中的关键词
  6468. $data['keyword'] = $data['title'];
  6469. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6470. Jieba::init(); // 初始化 jieba-php
  6471. Finalseg::init();
  6472. $segList = Jieba::cut($data['keyword']);
  6473. $segList1 = array_slice($segList, 0, 8);
  6474. $data['keyword'] = implode(',', $segList1);
  6475. }
  6476. if ($data['description'] == '') {
  6477. //提取内容中的描述
  6478. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  6479. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  6480. }
  6481. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  6482. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  6483. if ($data['status'] == 1) {
  6484. $this->sendMessage([
  6485. 'talk_type' => 400,
  6486. 'title' => $data['title'],
  6487. 'content' => '提交了审核',
  6488. 'messageType' => 7,
  6489. ]);
  6490. }
  6491. $result = Book::where("id", $data["id"])->update($data);
  6492. if (empty($result)) {
  6493. return Result::error("更新失败", 0);
  6494. }
  6495. return Result::success($result);
  6496. }
  6497. public function getBookInfo(array $data): array
  6498. {
  6499. $result = Book::where("id", $data["id"])->first();
  6500. if (empty($result)) {
  6501. return Result::error("获取失败", 0);
  6502. }
  6503. return Result::success($result);
  6504. }
  6505. public function updateBookStatus(array $data): array
  6506. {
  6507. //审核
  6508. unset($data['user_id']);
  6509. $bookInfo = Book::where("id", $data["id"])->first();
  6510. var_dump($bookInfo, '----');
  6511. if ($data['status'] == 2) {
  6512. $this->sendMessage([
  6513. 'talk_type' => 401,
  6514. 'title' => $bookInfo['title'],
  6515. 'content' => '审核通过',
  6516. 'messageType' => 7,
  6517. 'user_id' => $bookInfo['user_id'],
  6518. ]);
  6519. }
  6520. if ($data['status'] == 3) {
  6521. $this->sendMessage([
  6522. 'talk_type' => 401,
  6523. 'title' => $bookInfo['title'],
  6524. 'content' => '审核拒绝',
  6525. 'messageType' => 7,
  6526. 'user_id' => $bookInfo['user_id'],
  6527. ]);
  6528. }
  6529. if ($data['status'] == 1) {
  6530. $this->sendMessage([
  6531. 'talk_type' => 400,
  6532. 'title' => $bookInfo['title'],
  6533. 'content' => '提交了审核',
  6534. 'messageType' => 7,
  6535. // 'user_id'=>$bookInfo['user_id'],
  6536. ]);
  6537. }
  6538. $result = Book::where("id", $data["id"])->update($data);
  6539. if (empty($result)) {
  6540. return Result::error("更新失败", 0);
  6541. }
  6542. return Result::success($result);
  6543. }
  6544. //20250422 书刊音像
  6545. /**
  6546. * 贴身宝贝
  6547. * @param array $data
  6548. * @return array
  6549. */
  6550. public function getWebsiteTsbb(array $data): array
  6551. {
  6552. $month = $data['month'] ?? date('m');
  6553. $day = $data['day'] ?? date('d');
  6554. // 使用缓存键
  6555. $cacheKey = "tsbb_data_{$month}_{$day}";
  6556. // 尝试从缓存获取数据
  6557. $container = \Hyperf\Context\ApplicationContext::getContainer();
  6558. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  6559. if ($cachedData = $cache->get($cacheKey)) {
  6560. return Result::success(unserialize($cachedData));
  6561. }
  6562. //查询老黄历
  6563. try {
  6564. $date = date('Y-m-d');
  6565. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  6566. // 使用 curl 替代 file_get_contents
  6567. $ch = curl_init();
  6568. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  6569. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  6570. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  6571. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  6572. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  6573. 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');
  6574. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  6575. 'Accept: application/json',
  6576. 'Content-Type: application/json',
  6577. 'Referer: https://www.36jxs.com/'
  6578. ]);
  6579. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  6580. curl_setopt($ch, CURLOPT_ENCODING, '');
  6581. $almanacResponse = curl_exec($ch);
  6582. var_dump("====:", $almanacResponse);
  6583. if (curl_errno($ch)) {
  6584. var_dump('Curl error:', curl_error($ch));
  6585. throw new \Exception('Curl error: ' . curl_error($ch));
  6586. }
  6587. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  6588. curl_close($ch);
  6589. if ($almanacResponse === false) {
  6590. throw new \Exception('Failed to fetch almanac data');
  6591. }
  6592. $almanacData = json_decode($almanacResponse, true);
  6593. if (json_last_error() !== JSON_ERROR_NONE) {
  6594. throw new \Exception('Failed to parse almanac data');
  6595. }
  6596. $almanacInfo = $almanacData['data'] ?? [];
  6597. } catch (\Exception $e) {
  6598. var_dump('Exception:', $e->getMessage());
  6599. $almanacInfo = [];
  6600. }
  6601. // 获取历史上的今天数据
  6602. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6603. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  6604. ->orderBy('year', 'asc')
  6605. ->select("title", "id", "year", DB::raw('1 as type'))
  6606. ->limit(16)
  6607. ->get();
  6608. // 获取节日数据 - 从今天开始获取未来4条
  6609. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  6610. ->orderBy('showtime', 'asc')
  6611. ->select("title", "id", "showtime", DB::raw('2 as type'))
  6612. ->limit(16)
  6613. ->get();
  6614. //说文解字
  6615. $chartacterList = Character::orderBy('updated_at', 'desc')
  6616. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  6617. ->limit(6)
  6618. ->get();
  6619. //谜语沙龙
  6620. $riddletList = Riddle::orderBy('updated_at', 'desc')
  6621. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  6622. ->limit(4)
  6623. ->get();
  6624. //成语欣赏
  6625. $idiomList = Idiom::orderBy('updated_at', 'desc')
  6626. ->select("id", "title", "duyin", DB::raw('5 as type'))
  6627. ->limit(32)
  6628. ->get();
  6629. //名联赏析
  6630. $coupletList = Couplet::orderBy('updated_at', 'desc')
  6631. ->select("id", "first", "second", DB::raw('6 as type'))
  6632. ->limit(6)
  6633. ->get();
  6634. // 获取分类文章数据
  6635. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  6636. ->pluck('category_id')
  6637. ->toArray();
  6638. $articlesList = [];
  6639. foreach ($categoryIds as $catid) {
  6640. // 先查有图片的
  6641. $withImg = DB::table('article')
  6642. ->where('status', 1)
  6643. ->where('catid', $catid)
  6644. ->whereNotNull('imgurl')
  6645. ->where('imgurl', '!=', '')
  6646. ->orderBy('updated_at', 'desc')
  6647. ->limit(6)
  6648. ->get();
  6649. $count = $withImg->count();
  6650. if ($count < 6) {
  6651. // 不足6条再查无图片的补足
  6652. $withoutImg = DB::table('article')
  6653. ->where('status', 1)
  6654. ->where('catid', $catid)
  6655. ->where(function ($q) {
  6656. $q->whereNull('imgurl')->orWhere('imgurl', '');
  6657. })
  6658. ->orderBy('updated_at', 'desc')
  6659. ->limit(6 - $count)
  6660. ->get();
  6661. $articles = $withImg->concat($withoutImg);
  6662. } else {
  6663. $articles = $withImg;
  6664. }
  6665. // 组装
  6666. $category = \App\Model\Category::find($catid);
  6667. $websiteCategory = WebsiteCategory::where('category_id', $catid)->first();
  6668. $articlesList[] = [
  6669. 'category_name' => $category ? $category->name : '',
  6670. 'catid' => $catid,
  6671. 'pinyin' => $websiteCategory ? $websiteCategory->aLIas_pinyin : '',
  6672. 'type' => 100,
  6673. 'list' => $articles->map(function ($item) {
  6674. return [
  6675. 'id' => $item->id,
  6676. 'title' => $item->title,
  6677. 'imgurl' => $item->imgurl,
  6678. 'created_at' => $item->created_at
  6679. ];
  6680. })->values()
  6681. ];
  6682. }
  6683. $result = [
  6684. 'almanac' => $almanacInfo,
  6685. 'historyTodayList' => [
  6686. 'category_name' => '历史上的今天',
  6687. 'list' => $historyTodayList,
  6688. 'type' => 1
  6689. ],
  6690. 'festivalList' => [
  6691. 'category_name' => '节日预告',
  6692. 'list' => $festivalList,
  6693. 'type' => 2
  6694. ],
  6695. 'chartacterList' => [
  6696. 'category_name' => '说文解字',
  6697. 'list' => $chartacterList,
  6698. 'type' => 3
  6699. ],
  6700. 'coupletList' => [
  6701. 'category_name' => '名联赏析',
  6702. 'list' => $coupletList,
  6703. 'type' => 6
  6704. ],
  6705. 'riddletList' => [
  6706. 'category_name' => '谜语沙龙',
  6707. 'list' => $riddletList,
  6708. 'type' => 4
  6709. ],
  6710. 'idiomList' => [
  6711. 'category_name' => '成语欣赏',
  6712. 'list' => $idiomList,
  6713. 'type' => 5
  6714. ],
  6715. 'articlesList' => $articlesList
  6716. ];
  6717. // 缓存结果,设置1小时过期
  6718. $cache->set($cacheKey, serialize($result), 3600);
  6719. return Result::success($result);
  6720. }
  6721. /**
  6722. * 获取资讯列表
  6723. */
  6724. public function getWebsiteTsbbList(array $data): array
  6725. {
  6726. $page = $data['page'] ?? 1;
  6727. $pageSize = $data['pageSize'] ?? 10;
  6728. // 如果没有传入月份和日期,则使用今天的日期
  6729. $month = $data['month'] ?? date('m');
  6730. $day = $data['day'] ?? date('d');
  6731. $total = 0;
  6732. $result = [];
  6733. $data['type'] = intval($data['type']);
  6734. var_dump("接收参数:", $data);
  6735. switch ($data['type']) {
  6736. case 1:
  6737. $query = HistoryToday::where(function ($q) use ($month, $day) {
  6738. // 当前月份之后的数据
  6739. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  6740. // 或者当前月份且日期大于等于当前日期的数据
  6741. ->orWhere(function ($q) use ($month, $day) {
  6742. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6743. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  6744. });
  6745. })
  6746. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  6747. $total = $query->count();
  6748. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  6749. ->offset(($page - 1) * $pageSize)
  6750. ->limit($pageSize)
  6751. ->get();
  6752. break;
  6753. case 2:
  6754. $query = Festival::where(function ($q) use ($month, $day) {
  6755. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  6756. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  6757. ->orWhere(function ($q) use ($month, $day) {
  6758. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  6759. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  6760. });
  6761. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  6762. $total = $query->count();
  6763. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  6764. ->offset(($page - 1) * $pageSize)
  6765. ->limit($pageSize)
  6766. ->get();
  6767. break;
  6768. case 3:
  6769. $query = Character::orderBy("updated_at", "desc");
  6770. $total = $query->count();
  6771. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  6772. ->offset(($page - 1) * $pageSize)
  6773. ->limit($pageSize)
  6774. ->get();
  6775. break;
  6776. case 4:
  6777. $query = Riddle::orderBy("updated_at", "desc");
  6778. $total = $query->count();
  6779. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  6780. ->offset(($page - 1) * $pageSize)
  6781. ->limit($pageSize)
  6782. ->get();
  6783. break;
  6784. case 5:
  6785. $query = Idiom::orderBy("updated_at", "desc");
  6786. $total = $query->count();
  6787. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  6788. ->offset(($page - 1) * $pageSize)
  6789. ->limit($pageSize)
  6790. ->get();
  6791. break;
  6792. case 6:
  6793. $query = Couplet::orderBy("updated_at", "desc");
  6794. $total = $query->count();
  6795. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  6796. ->offset(($page - 1) * $pageSize)
  6797. ->limit($pageSize)
  6798. ->get();
  6799. break;
  6800. default:
  6801. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  6802. $total = $query->count();
  6803. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  6804. ->offset(($page - 1) * $pageSize)
  6805. ->limit($pageSize)
  6806. ->get();
  6807. }
  6808. return Result::success([
  6809. 'list' => $result,
  6810. 'total' => $total,
  6811. 'page' => (int)$page,
  6812. 'pageSize' => (int)$pageSize,
  6813. 'month' => $month,
  6814. 'day' => $day
  6815. ]);
  6816. }
  6817. /**
  6818. * 1:历史上的今天
  6819. * 2:节日
  6820. * 3:文章
  6821. *
  6822. * 资讯详情信息
  6823. */
  6824. public function getWebsiteTsbbDetail(array $data): array
  6825. {
  6826. $data['type'] = intval($data['type']);
  6827. switch ($data['type']) {
  6828. case 1:
  6829. $result = HistoryToday::where("id", $data['id'])->first();
  6830. break;
  6831. case 2:
  6832. $result = Festival::where("id", $data['id'])->first();
  6833. break;
  6834. case 3:
  6835. $result = Character::where("id", $data['id'])->first();
  6836. break;
  6837. case 4:
  6838. $result = Riddle::where("id", $data['id'])->first();
  6839. break;
  6840. case 5:
  6841. $result = Idiom::where("id", $data['id'])->first();
  6842. break;
  6843. case 6:
  6844. $result = Couplet::where("id", $data['id'])->first();
  6845. break;
  6846. default:
  6847. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  6848. break;
  6849. }
  6850. return Result::success($result);
  6851. }
  6852. /**
  6853. * 农网导航首页数据
  6854. */
  6855. public function getWebsiteNwHomeList(array $data): array
  6856. {
  6857. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  6858. ->pluck('category_id')
  6859. ->toArray();
  6860. // 使用子查询优化
  6861. $articlesList = DB::table('article')
  6862. ->select([
  6863. 'article.id',
  6864. 'article.title',
  6865. 'article.imgurl',
  6866. 'article.created_at',
  6867. 'category.name as category_name',
  6868. 'category.id as category_id',
  6869. 'website_category.aLIas_pinyin as pinyin',
  6870. 'parent_wc.aLIas_pinyin as parent_pinyin',
  6871. DB::raw('100 as type')
  6872. ])
  6873. ->join('category', 'article.catid', '=', 'category.id')
  6874. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  6875. ->leftJoin('website_category as parent_wc', function ($join) {
  6876. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  6877. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  6878. })
  6879. ->where('website_category.website_id', $data['website_id'])
  6880. ->where('article.status', 1)
  6881. ->whereIn('category.id', $categoryIds)
  6882. ->orderBy('article.created_at', 'desc')
  6883. ->get()
  6884. ->groupBy('category_id')
  6885. ->map(function ($group) {
  6886. // 确保第一条数据有图片
  6887. $firstWithImage = $group->first(function ($item) {
  6888. return !empty($item->imgurl);
  6889. });
  6890. if ($firstWithImage) {
  6891. // 如果有带图片的文章,将其放在第一位
  6892. $group = $group->filter(function ($item) use ($firstWithImage) {
  6893. return $item->id !== $firstWithImage->id;
  6894. })->prepend($firstWithImage);
  6895. }
  6896. return [
  6897. 'category_name' => $group->first()->category_name,
  6898. 'catid' => $group->first()->category_id,
  6899. 'pinyin' => $group->first()->pinyin,
  6900. 'parent_pinyin' => $group->first()->parent_pinyin,
  6901. 'list' => $group->take(4)->map(function ($item) {
  6902. return [
  6903. 'id' => $item->id,
  6904. 'title' => $item->title,
  6905. ];
  6906. })->values()
  6907. ];
  6908. })
  6909. ->values()
  6910. ->toArray();
  6911. return Result::success($articlesList);
  6912. }
  6913. /**
  6914. * 企业管理
  6915. * @param array $data
  6916. * @return array
  6917. */
  6918. public function getCompanyList(array $data): array
  6919. {
  6920. // return Result::success($data);
  6921. $where = [];
  6922. $user = User::where('id', $data['user_id'])->first();
  6923. if (empty($user)) {
  6924. return Result::error('用户不存在!');
  6925. }
  6926. if ($user['type_id'] != 10000) {
  6927. $where['user_id'] = $data['user_id'];
  6928. }
  6929. if (isset($data['title']) && !empty($data['title'])) {
  6930. array_push($where, ['company.title', 'like', '%' . $data['title'] . '%']);
  6931. }
  6932. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6933. array_push($where, ['website.id', $data['website_id']]);
  6934. }
  6935. if (isset($data['ischeck']) && !empty($data['ischeck'])) {
  6936. if ($data['ischeck'] == 1) {
  6937. if (isset($data['status']) && $data['status'] != '') {
  6938. array_push($where, ['company.status', $data['status']]);
  6939. $query = Company::where($where);
  6940. } else {
  6941. $query = Company::whereIn('company.status', [0, 2]);
  6942. }
  6943. } else {
  6944. $query = Company::where('company.status', 1);
  6945. }
  6946. }
  6947. $result = $query->where($where)
  6948. ->leftJoin('website_category', function ($query) {
  6949. $query->on('website_category.category_id', '=', 'company.category_id')
  6950. ->on('website_category.website_id', '=', 'company.website_id');
  6951. })
  6952. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  6953. ->select(
  6954. 'company.id',
  6955. 'company.title',
  6956. 'company.website_id',
  6957. 'company.category_id',
  6958. 'website.website_name',
  6959. 'website_category.alias as category_name',
  6960. 'company.status',
  6961. 'company.updated_at',
  6962. 'company.user_id'
  6963. )
  6964. ->orderBy('company.updated_at', 'desc')
  6965. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  6966. if ($result->isEmpty()) {
  6967. return Result::error("暂无企业", 0);
  6968. }
  6969. return Result::success($result);
  6970. }
  6971. /**
  6972. * 添加企业
  6973. * @param array $data
  6974. * @return array
  6975. */
  6976. public function addCompany(array $data): array
  6977. {
  6978. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  6979. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6980. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6981. $data['cat_arr_id'] = json_encode($car_arr_id);
  6982. } else {
  6983. $data['cat_arr_id'] = '';
  6984. }
  6985. if ($data['imgurl'] == '') {
  6986. //content中提取图片第一个图,正则提取
  6987. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6988. preg_match_all($reg, $data['content'], $matches);
  6989. if (isset($matches[1][0])) {
  6990. //截取varchar240
  6991. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6992. }
  6993. }
  6994. if ($data['keyword'] == '') {
  6995. //提取标题+内容中的关键词
  6996. $data['keyword'] = $data['title'];
  6997. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6998. Jieba::init(); // 初始化 jieba-php
  6999. Finalseg::init();
  7000. $segList = Jieba::cut($data['keyword']);
  7001. $segList1 = array_slice($segList, 0, 8);
  7002. $data['keyword'] = implode(',', $segList1);
  7003. }
  7004. if ($data['introduce'] == '' || empty($data['introduce'])) {
  7005. //提取内容中的描述
  7006. $content = $data['content'];
  7007. // 去除 <style> 和 <script> 标签及其内容
  7008. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7009. // 去除所有 HTML 标签
  7010. $content = strip_tags($content);
  7011. // 去除 HTML 实体
  7012. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7013. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7014. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7015. // 去除多余空白
  7016. $content = preg_replace('/\s+/u', '', $content);
  7017. // 截取 100 个字符
  7018. $data['introduce'] = mb_substr($content, 0, 100);
  7019. }
  7020. $user = User::where('id', $data['user_id'])->first();
  7021. if (empty($user)) {
  7022. return Result::error('用户不存在!');
  7023. }
  7024. if ($user['type_id'] == 10000) {
  7025. $data['status'] = 1;
  7026. }
  7027. if (isset($data['level']) && $data['level'] != null) {
  7028. $data['level'] = intval($data['level']);
  7029. } else {
  7030. $data['level'] = null;
  7031. }
  7032. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  7033. $this->sendMessage([
  7034. 'talk_type' => 900,
  7035. 'title' => $data['title'],
  7036. 'content' => '提交了审核',
  7037. 'messageType' => 8,
  7038. ]);
  7039. }
  7040. $result = Company::insertGetId($data);
  7041. if ($result) {
  7042. return Result::success($result);
  7043. } else {
  7044. return Result::error('添加失败');
  7045. }
  7046. }
  7047. /**
  7048. * 更新企业
  7049. * @param array $data
  7050. * @return array
  7051. */
  7052. public function upCompany(array $data): array
  7053. {
  7054. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  7055. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  7056. $data['cat_arr_id'] = json_encode($car_arr_id);
  7057. $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
  7058. } else {
  7059. $data['cat_arr_id'] = '';
  7060. }
  7061. if ($data['imgurl'] == '') {
  7062. //content中提取图片第一个图,正则提取
  7063. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  7064. preg_match_all($reg, $data['content'], $matches);
  7065. if (isset($matches[1][0])) {
  7066. //截取varchar
  7067. $data['imgurl'] = substr($matches[1][0], 0, 240);
  7068. }
  7069. }
  7070. if ($data['keyword'] == '') {
  7071. //提取标题+内容中的关键词
  7072. $data['keyword'] = $data['title'];
  7073. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7074. Jieba::init(); // 初始化 jieba-php
  7075. Finalseg::init();
  7076. $segList = Jieba::cut($data['keyword']);
  7077. $segList1 = array_slice($segList, 0, 8);
  7078. $data['keyword'] = implode(',', $segList1);
  7079. }
  7080. if ($data['introduce'] == '') {
  7081. //提取内容中的描述
  7082. $content = $data['content'];
  7083. // 去除 <style> 和 <script> 标签及其内容
  7084. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7085. // 去除所有 HTML 标签
  7086. $content = strip_tags($content);
  7087. // 去除 HTML 实体
  7088. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7089. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7090. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7091. // 去除多余空白
  7092. $content = preg_replace('/\s+/u', '', $content);
  7093. // 截取 100 个字符
  7094. $data['introduce'] = mb_substr($content, 0, 100);
  7095. }
  7096. if (isset($data['level']) && $data['level'] != null) {
  7097. $data['level'] = intval($data['level']);
  7098. } else {
  7099. $data['level'] = null;
  7100. }
  7101. $user = User::where('id', $data['user_id'])->first();
  7102. if (empty($user)) {
  7103. return Result::error('用户不存在!');
  7104. }
  7105. if ($user['type_id'] == 10000) {
  7106. $data['status'] = 1;
  7107. } else {
  7108. $data['status'] = 0;
  7109. }
  7110. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  7111. $this->sendMessage([
  7112. 'talk_type' => 900,
  7113. 'title' => $data['title'],
  7114. 'content' => '提交了审核',
  7115. 'messageType' => 8,
  7116. ]);
  7117. }
  7118. $result = Company::where('id', $data['id'])->update($data);
  7119. if ($result) {
  7120. return Result::success($result);
  7121. } else {
  7122. return Result::error('修改失败');
  7123. }
  7124. }
  7125. /**
  7126. * 删除企业
  7127. * @param array $data
  7128. * @return array
  7129. */
  7130. public function delCompany(array $data): array
  7131. {
  7132. $result = Company::where('id', $data['id'])->delete();
  7133. if ($result) {
  7134. return Result::success($result);
  7135. } else {
  7136. return Result::error('删除失败');
  7137. }
  7138. }
  7139. /**
  7140. * 审核企业
  7141. * @param array $data
  7142. * @return array
  7143. */
  7144. public function checkCompany(array $data): array
  7145. {
  7146. $user = User::where('id', $data['user_id'])->first();
  7147. if (empty($user)) {
  7148. return Result::error('用户不存在!');
  7149. }
  7150. $company = Company::where('id', $data['id'])->first();
  7151. if (empty($company)) {
  7152. return Result::error('企业不存在!');
  7153. }
  7154. // 状态:0:未审核 1:已审核 2:已拒绝
  7155. if ($data['status'] == 2 || $data['status'] == '2') {
  7156. $this->sendMessage([
  7157. 'talk_type' => 901,
  7158. 'title' => $company['title'],
  7159. 'content' => '审核拒绝',
  7160. 'messageType' => 8,
  7161. 'user_id' => $company['user_id'],
  7162. ]);
  7163. $result = Company::where('id', $data['id'])->update(['status' => $data['status'], 'reject_reason' => $data['reason']]);
  7164. } else {
  7165. if ($data['status'] == 1) {
  7166. $this->sendMessage([
  7167. 'talk_type' => 901,
  7168. 'title' => $company['title'],
  7169. 'content' => '审核通过',
  7170. 'messageType' => 8,
  7171. 'user_id' => $company['user_id'],
  7172. ]);
  7173. } else if ($data['status'] == 0) {
  7174. $this->sendMessage([
  7175. 'talk_type' => 900,
  7176. 'title' => $company['title'],
  7177. 'content' => '提交了审核',
  7178. 'messageType' => 8,
  7179. ]);
  7180. }
  7181. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  7182. }
  7183. if (empty($result)) {
  7184. return Result::error('审核失败!');
  7185. } else {
  7186. return Result::success($result);
  7187. }
  7188. }
  7189. /**
  7190. * 获取企业信息
  7191. * @param array $data
  7192. * @return array
  7193. */
  7194. public function getCompanyInfo(array $data): array
  7195. {
  7196. $result = Company::where('id', $data['id'])->first();
  7197. $city_arr = json_decode($result['city_arr_id']);
  7198. $result['city_name'] = District::whereIn('id', $city_arr)
  7199. ->pluck('name')
  7200. ->implode('-');
  7201. if (empty($result)) {
  7202. return Result::error('企业不存在!');
  7203. } else {
  7204. return Result::success($result);
  7205. }
  7206. }
  7207. /**
  7208. * @param array $data
  7209. * @return array
  7210. */
  7211. public function getWebsiteCompany(array $data): array
  7212. {
  7213. $categorys = json_decode($data['id'], true);
  7214. $category_arr = $this->processArticlePro($data['website_id']);
  7215. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7216. $catiall = $category_arr['catiall'];
  7217. $categoryIds = $category_arr['categoryIds'];
  7218. // return Result::success($category_arr);
  7219. foreach ($categorys as $key => $value) {
  7220. if (array_key_exists('level', $value)) {
  7221. $parts = explode(',', $value['level']);
  7222. $level = $parts[0] ?? null;
  7223. $imgnum = $parts[1] ?? null;
  7224. $textnum = $parts[2] ?? null;
  7225. if (!empty($textnum) && $textnum > 0) {
  7226. $text_num = Company::where('level', $level)
  7227. ->whereIn('category_id', $categoryIds)
  7228. ->where('status', 1)
  7229. ->select(
  7230. 'company.id',
  7231. 'company.title',
  7232. 'company.description',
  7233. 'company.updated_at',
  7234. 'company.category_id',
  7235. 'company.cat_arr_id'
  7236. )
  7237. ->orderBy('updated_at', 'desc')
  7238. ->limit($textnum)
  7239. ->get()->all();
  7240. }
  7241. if (!empty($imgnum) && $imgnum > 0) {
  7242. $img_num = Company::where('level', $level)
  7243. ->whereIn('category_id', $categoryIds)
  7244. ->where('status', 1)
  7245. ->where('imgurl', '!=', '')
  7246. ->whereNotNull('imgurl')
  7247. ->select(
  7248. 'company.id',
  7249. 'company.title',
  7250. 'company.description',
  7251. 'company.updated_at',
  7252. 'company.imgurl as imgs',
  7253. 'company.category_id',
  7254. 'company.cat_arr_id'
  7255. )
  7256. ->orderBy('updated_at', 'desc')
  7257. ->limit($imgnum)
  7258. ->get()->all();
  7259. }
  7260. }
  7261. if (array_key_exists('id', $value)) {
  7262. $parts = explode(',', $value['id']);
  7263. $category_id = $parts[0] ?? null;
  7264. $imgnum = $parts[1] ?? null;
  7265. $textnum = $parts[2] ?? null;
  7266. $category_arr = array_merge([$category_id], $cat_1st_arr[$category_id] ?? [0]);
  7267. if (!empty($textnum) && $textnum > 0) {
  7268. $text_num = Company::whereIn('category_id', $category_arr)
  7269. // ->where('website_id', $data['website_id'])
  7270. ->where('status', 1)
  7271. ->select(
  7272. 'company.id',
  7273. 'company.title',
  7274. 'company.description',
  7275. 'company.updated_at',
  7276. 'company.category_id',
  7277. 'company.cat_arr_id'
  7278. )
  7279. ->orderBy('updated_at', 'desc')
  7280. ->limit($textnum)
  7281. ->get()->all();
  7282. }
  7283. if (!empty($imgnum) && $imgnum > 0) {
  7284. $img_num = Company::whereIn('category_id', $category_arr)
  7285. // ->where('website_id', $data['website_id'])
  7286. ->where('status', 1)
  7287. ->where('imgurl', '!=', '')
  7288. ->whereNotNull('imgurl')
  7289. ->select(
  7290. 'company.id',
  7291. 'company.title',
  7292. 'company.description',
  7293. 'company.updated_at',
  7294. 'company.imgurl as imgs',
  7295. 'company.category_id',
  7296. 'company.cat_arr_id'
  7297. )
  7298. ->orderBy('updated_at', 'desc')
  7299. ->limit($imgnum)
  7300. ->get()->all();
  7301. }
  7302. }
  7303. if (!empty($text_num)) {
  7304. foreach ($text_num as $k => $v) {
  7305. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7306. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7307. }
  7308. }
  7309. if (!empty($img_num)) {
  7310. foreach ($img_num as $k => $v) {
  7311. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7312. $imgurl = json_decode($v['imgs'], true);
  7313. if (!empty($imgurl)) {
  7314. $img_num[$k]->imgurl = $imgurl[0];
  7315. }
  7316. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7317. }
  7318. }
  7319. $company[$key]['img_num'] = $img_num ?? [];
  7320. $company[$key]['text_num'] = $text_num ?? [];
  7321. }
  7322. if (empty($company)) {
  7323. return Result::error("暂无相关企业信息", 0);
  7324. }
  7325. return Result::success($company);
  7326. }
  7327. /**
  7328. * @param array $data
  7329. * @return array
  7330. */
  7331. public function getWebsiteCompanyList(array $data): array
  7332. {
  7333. $where['website_id'] = $data['website_id'];
  7334. $where['status'] = 1;
  7335. $categoryIds = [];
  7336. if (isset($data['category_id']) && !empty($data['category_id'])) {
  7337. $category_id = $data['category_id'];
  7338. }
  7339. $category_arr = $this->processArticlePro($data['website_id']);
  7340. $categoryIds = $category_arr['categoryIds'];
  7341. // return Result::success($cat_1st_arr);
  7342. $company = Company::when(isset($data['keyword']) && !empty($data['keyword']), function ($query) use ($data) {
  7343. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  7344. })
  7345. ->when(!isset($category_id) || empty($category_id), function ($query) use ($categoryIds) {
  7346. $query->whereIn('category_id', $categoryIds);
  7347. })
  7348. ->when(isset($data['category_id']) && !empty($data['category_id']), function ($query) use ($category_id) {
  7349. $query->where('category_id', $category_id);
  7350. })
  7351. ->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id', 'updated_at')
  7352. ->orderBy('updated_at', 'desc')
  7353. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  7354. if (empty($company)) {
  7355. return Result::error("暂无相关公司信息", 0);
  7356. }
  7357. $result = [
  7358. 'count' => $company->total(),
  7359. 'data' => $company->items(), // 使用 items() 方法替代不存在的 data() 方法
  7360. ];
  7361. return Result::success($result);
  7362. }
  7363. /**
  7364. * 获取项目列表
  7365. * @param array $data
  7366. * @return array
  7367. */
  7368. public function getProjectList(array $data): array
  7369. {
  7370. $where = [];
  7371. $user = User::where('id', $data['user_id'])->first();
  7372. if (empty($user)) {
  7373. return Result::error('用户不存在!');
  7374. }
  7375. if ($user->type_id != 10000) {
  7376. array_push($where, ['project.user_id', $data['user_id']]);
  7377. }
  7378. $query = Project::query();
  7379. if (isset($data['website_id']) && !empty($data['website_id'])) {
  7380. array_push($where, ['project.website_id', $data['website_id']]);
  7381. }
  7382. if (isset($data['title']) && !empty($data['title'])) {
  7383. array_push($where, ['project.title', 'like', '%' . $data['title'] . '%']);
  7384. }
  7385. if ($data['status'] != 3) {
  7386. array_push($where, ['project.status', $data['status']]);
  7387. }
  7388. $query = Project::where($where)
  7389. ->when($data['status'] == 3, function ($query) {
  7390. $query->whereIn('project.status', [0, 2]);
  7391. });
  7392. $count = $query->clone()
  7393. ->count();
  7394. $rows = $query->clone()
  7395. ->leftJoin('website', 'project.website_id', 'website.id')
  7396. ->leftJoin('website_category', function ($join) {
  7397. $join->on('project.website_id', '=', 'website_category.website_id')
  7398. ->on('project.category_id', '=', 'website_category.category_id');
  7399. })
  7400. ->select(
  7401. 'project.id',
  7402. 'project.title',
  7403. 'project.updated_at',
  7404. 'project.status',
  7405. 'website.website_name',
  7406. 'website_category.alias as category_name',
  7407. 'project.website_id',
  7408. 'project.user_id'
  7409. )
  7410. ->orderBy('project.updated_at', 'desc')
  7411. ->offset(($data['page'] - 1) * $data['pageSize'])
  7412. ->limit($data['pageSize'])
  7413. ->get();
  7414. if ($rows->isEmpty()) {
  7415. return Result::error("暂无相关项目信息", 0);
  7416. }
  7417. $result = [
  7418. 'count' => $count,
  7419. 'rows' => $rows,
  7420. ];
  7421. return Result::success($result);
  7422. }
  7423. /**
  7424. * 添加项目
  7425. * @param array $data
  7426. * @return array
  7427. */
  7428. public function addProject(array $data): array
  7429. {
  7430. $user = User::where('id', $data['user_id'])->first();
  7431. if (empty($user)) {
  7432. return Result::error("暂无相关用户信息", 0);
  7433. }
  7434. if ($user->type_id == 10000) {
  7435. $data['status'] = 1;
  7436. } else {
  7437. $data['status'] = 0;
  7438. }
  7439. if ($data['keyword'] == '') {
  7440. //提取标题+内容中的关键词
  7441. $data['keyword'] = $data['title'];
  7442. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7443. Jieba::init(); // 初始化 jieba-php
  7444. Finalseg::init();
  7445. $segList = Jieba::cut($data['keyword']);
  7446. $segList1 = array_slice($segList, 0, 8);
  7447. $data['keyword'] = implode(',', $segList1);
  7448. }
  7449. if ($data['description'] == '') {
  7450. //提取内容中的描述
  7451. // var_dump(11111);
  7452. //提取内容中的描述
  7453. $content = $data['introduce'];
  7454. // 去除 <style> 和 <script> 标签及其内容
  7455. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7456. // 去除所有 HTML 标签
  7457. $content = strip_tags($content);
  7458. // 去除 HTML 实体
  7459. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7460. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7461. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7462. // 去除多余空白
  7463. $content = preg_replace('/\s+/u', '', $content);
  7464. // 截取 100 个字符
  7465. $data['description'] = mb_substr($content, 0, 100);
  7466. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7467. }
  7468. if ($data['status'] == 0) {
  7469. $this->sendMessage([
  7470. 'talk_type' => 1000,
  7471. 'title' => $data['title'],
  7472. 'content' => '提交了审核',
  7473. 'messageType' => 9,
  7474. ]);
  7475. }
  7476. $project = Project::insertGetId($data);
  7477. if (empty($project)) {
  7478. return Result::error("暂无相关项目信息", 0);
  7479. }
  7480. return Result::success($project);
  7481. }
  7482. /**
  7483. * 更新项目
  7484. * @param array $data
  7485. * @return array
  7486. */
  7487. public function upProject(array $data): array
  7488. {
  7489. $project = Project::where('id', $data['id'])->first();
  7490. if (empty($project)) {
  7491. return Result::error("暂无相关项目信息", 0);
  7492. }
  7493. $id = $data['id'];
  7494. unset($data['id']);
  7495. $user = User::where('id', $data['user_id'])->first();
  7496. if (empty($user)) {
  7497. return Result::error("暂无相关用户信息", 0);
  7498. }
  7499. if ($user->type_id == 10000) {
  7500. $data['status'] = 1;
  7501. } else {
  7502. $data['status'] = 0;
  7503. }
  7504. unset($data['user_id']);
  7505. if ($data['keyword'] == '') {
  7506. //提取标题+内容中的关键词
  7507. $data['keyword'] = $data['title'];
  7508. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  7509. Jieba::init(); // 初始化 jieba-php
  7510. Finalseg::init();
  7511. $segList = Jieba::cut($data['keyword']);
  7512. $segList1 = array_slice($segList, 0, 8);
  7513. $data['keyword'] = implode(',', $segList1);
  7514. }
  7515. if ($data['description'] == '') {
  7516. //提取内容中的描述
  7517. // var_dump(11111);
  7518. //提取内容中的描述
  7519. $content = $data['introduce'];
  7520. // 去除 <style> 和 <script> 标签及其内容
  7521. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  7522. // 去除所有 HTML 标签
  7523. $content = strip_tags($content);
  7524. // 去除 HTML 实体
  7525. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  7526. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  7527. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  7528. // 去除多余空白
  7529. $content = preg_replace('/\s+/u', '', $content);
  7530. // 截取 100 个字符
  7531. $data['description'] = mb_substr($content, 0, 100);
  7532. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  7533. }
  7534. if ($data['status'] == 0) {
  7535. $this->sendMessage([
  7536. 'talk_type' => 1000,
  7537. 'title' => $data['title'],
  7538. 'content' => '提交了审核',
  7539. 'messageType' => 9,
  7540. ]);
  7541. }
  7542. $result = Project::where('id', $id)->update($data);
  7543. if (empty($result)) {
  7544. return Result::error("更新失败", 0);
  7545. }
  7546. return Result::success($result);
  7547. }
  7548. /**
  7549. * 删除项目
  7550. * @param array $data
  7551. * @return array
  7552. */
  7553. public function delProject(array $data): array
  7554. {
  7555. $user = User::where('id', $data['user_id'])->first();
  7556. if (empty($user)) {
  7557. return Result::error("暂无相关用户信息", 0);
  7558. }
  7559. $project = Project::where('id', $data['id'])->first();
  7560. if (empty($project)) {
  7561. return Result::error("暂无相关项目信息", 0);
  7562. }
  7563. $result = Project::where('id', $data['id'])->delete();
  7564. if (empty($result)) {
  7565. return Result::error("删除失败", 0);
  7566. }
  7567. return Result::success($result);
  7568. }
  7569. /**
  7570. * 审核项目
  7571. * @param array $data
  7572. * @return array
  7573. */
  7574. public function checkProject(array $data): array
  7575. {
  7576. $user = User::where('id', $data['user_id'])->first();
  7577. if (empty($user)) {
  7578. return Result::error("暂无相关用户信息", 0);
  7579. }
  7580. // 0:未审核; 1:已审核; 2:已拒绝;
  7581. if ($user->type_id != 10000) {
  7582. if ($data['status'] == 1 || $data['status'] == 2) {
  7583. return Result::error("此用户权限不足", 0);
  7584. }
  7585. }
  7586. $project = Project::where('id', $data['id'])->first();
  7587. if (empty($project)) {
  7588. return Result::error("暂无相关项目信息", 0);
  7589. }
  7590. if ($data['status'] == 2) {
  7591. $this->sendMessage([
  7592. 'talk_type' => 1001,
  7593. 'title' => $project['title'],
  7594. 'content' => '审核拒绝',
  7595. 'messageType' => 9,
  7596. 'user_id' => $project['user_id'],
  7597. ]);
  7598. $result = Project::where('id', $data['id'])->update(['status' => $data['status'], 'refuse_reason' => $data['refuse_reason']]);
  7599. } else {
  7600. if ($data['status'] == 1) {
  7601. $this->sendMessage([
  7602. 'talk_type' => 1001,
  7603. 'title' => $project['title'],
  7604. 'content' => '审核通过',
  7605. 'messageType' => 9,
  7606. 'user_id' => $project['user_id'],
  7607. ]);
  7608. } else if ($data['status'] == 0) {
  7609. $this->sendMessage([
  7610. 'talk_type' => 1000,
  7611. 'title' => $project['title'],
  7612. 'content' => '提交了审核',
  7613. 'messageType' => 9,
  7614. ]);
  7615. }
  7616. $result = Project::where('id', $data['id'])->update(['status' => $data['status']]);
  7617. }
  7618. if (empty($result)) {
  7619. return Result::error("审核失败", 0);
  7620. }
  7621. return Result::success($result);
  7622. }
  7623. /**
  7624. * 获取项目详情
  7625. * @param array $data
  7626. * @return array
  7627. */
  7628. public function getProjectInfo(array $data): array
  7629. {
  7630. $project = Project::where('id', $data['id'])->first();
  7631. if (empty($project)) {
  7632. return Result::error("暂无相关项目信息", 0);
  7633. }
  7634. return Result::success($project);
  7635. }
  7636. public function getWebsiteCompanyInfo(array $data): array
  7637. {
  7638. $company = Company::where('id', $data['id'])
  7639. ->leftJoin('job_industry', 'job_industry.hyid', 'company.hy_id')
  7640. ->where('status', 1)
  7641. // ->where('website_id', $data['website_id'])
  7642. ->select('company.*', 'job_industry.hyname as hy_name')
  7643. ->first();
  7644. // 企业性质:0:市场监管;1:信访纪检;2:公检法司;3:高关注机构
  7645. switch ($company->jobnature_id) {
  7646. case null:
  7647. $company->jobnature_name = '';
  7648. break;
  7649. case 0:
  7650. $company->jobnature_name = '市场监督';
  7651. break;
  7652. case 1:
  7653. $company->jobnature_name = '信访纪检';
  7654. break;
  7655. case 2:
  7656. $company->jobnature_name = '公检法司';
  7657. break;
  7658. case 3:
  7659. $company->jobnature_name = '高关注机构';
  7660. break;
  7661. default:
  7662. $company->jobnature_name = '';
  7663. break;
  7664. }
  7665. $city_arr = $company->city_arr_id;
  7666. if (!empty($city_arr)) {
  7667. $city_arr = json_decode($city_arr, true);
  7668. $cityNames = District::whereIn('id', $city_arr)
  7669. ->pluck('name')
  7670. ->implode('-');
  7671. $company->city_name = $cityNames;
  7672. } else {
  7673. $company->city_name = '';
  7674. }
  7675. if (empty($company)) {
  7676. return Result::error("暂无相关公司信息", 0);
  7677. }
  7678. return Result::success($company);
  7679. }
  7680. public function getMSG(array $data): array
  7681. {
  7682. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  7683. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  7684. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  7685. $result = [];
  7686. if ($type_id == 1 or $type_id == 2 or $type_id == 3 or $type_id == 4) {
  7687. //最近的5篇已审的文章
  7688. $apply_articale = Article::where('status', 1)
  7689. ->where('admin_user_id', $user_id)
  7690. ->orderBy('updated_at', 'desc')
  7691. // ->limit(5)
  7692. ->get();
  7693. //获取5条用户的已审核商品
  7694. $good = Good::where('status', 2)
  7695. ->where('user_id', $user_id)
  7696. ->orderBy('updated_at', 'desc')
  7697. // ->limit(5)
  7698. ->get();
  7699. //获取5条用户待审核的公告
  7700. $notice = Notice::where('status', 2)
  7701. ->where('user_id', $user_id)
  7702. ->orderBy('updated_at', 'desc')
  7703. ->limit(5)->get();
  7704. //获取5条用户的待审核投诉
  7705. $complaint = Complaint::where('status', 2)
  7706. ->where('user_id', $user_id)
  7707. ->orderBy('updated_at', 'desc')
  7708. // ->limit(5)
  7709. ->get();
  7710. //获取5条用户的book
  7711. $book = Book::where('status', 2)
  7712. ->where('user_id', $user_id)
  7713. ->orderBy('updated_at', 'desc')
  7714. // ->limit(5)
  7715. ->get();
  7716. //获取5条用户的求职
  7717. //获取5条用户的求职 1
  7718. $job_hunting = JobHunting::where('job_hunting.status', 2)
  7719. ->where('job_hunting.user_id', $user_id)
  7720. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7721. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7722. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7723. ->orderBy('updated_at', 'desc')
  7724. // ->limit(5)
  7725. ->get();
  7726. //获取5条用户的求职 2
  7727. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  7728. ->where('job_recruiting.user_id', $user_id)
  7729. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7730. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7731. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7732. ->orderBy('updated_at', 'desc')
  7733. // ->limit(5)
  7734. ->get();
  7735. //人才库 1
  7736. $job_apply = JobApply::where('job_apply.status', 1)
  7737. ->where('job_apply.receiver_id', $user_id)
  7738. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7739. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7740. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7741. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7742. ->select('job_recruiting', 'job_recruiting.', '', '')
  7743. ->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')
  7744. ->orderBy('updated_at', 'desc')
  7745. // ->limit(5)
  7746. ->get();
  7747. // 职场机会 2
  7748. $job_resume = JobResume::where('job_resume.status', 1)
  7749. ->where('job_resume.receiver_id', $user_id)
  7750. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7751. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7752. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7753. ->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')
  7754. ->orderBy('updated_at', 'desc')
  7755. // ->limit(5)
  7756. ->get();
  7757. //获取5条用户待处理的投诉
  7758. $complaint_deal = Complaint::where('status', 2)
  7759. ->where('deal', 1)
  7760. ->whereJsonContains('re_user_ids', $user_id)
  7761. ->orderBy('updated_at', 'desc')
  7762. // ->limit(5)
  7763. ->get();
  7764. //获取 被通知者未读信息
  7765. $notice_unread = Notice::where('status', 2)
  7766. ->whereJsonContains('re_user_ids', $user_id)
  7767. //未读消息
  7768. ->where(function ($query) use ($user_id) {
  7769. $query->whereJsonDoesntContain('read_id', $user_id)
  7770. ->orWhereNull('read_id');
  7771. })
  7772. ->orderBy('updated_at', 'desc')
  7773. ->get();
  7774. $complaint_unread = Complaint::where('status', 2)
  7775. ->whereJsonContains('re_user_ids', $user_id)
  7776. //未读消息
  7777. ->where(function ($query) use ($user_id) {
  7778. $query->whereJsonDoesntContain('read_id', $user_id)
  7779. ->orWhereNull('read_id');
  7780. })
  7781. ->orderBy('updated_at', 'desc')
  7782. ->get();
  7783. //获取5条用户的yijing审核公司 :0:未审核;1:已审核;2:已拒绝
  7784. $complany = Company::where('status', 1)
  7785. ->where('user_id', $user_id)
  7786. ->orderBy('updated_at', 'desc')
  7787. // ->limit(5)
  7788. ->get();
  7789. //获取5条单聊未读聊天消息
  7790. // $chat = ChatRecords::where('is_read', 0)
  7791. // ->where('user_id', $user_id)
  7792. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7793. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7794. // ->where('action', 'recieved')
  7795. // ->where('talk_type', 1)
  7796. // ->orderBy('created_at', 'desc')
  7797. // // ->limit(5)
  7798. // ->get();
  7799. //获取5条未读群聊信息
  7800. // $chat_group = ChatRecords::where('is_read', 0)
  7801. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7802. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7803. // ->where('user_id', $user_id)
  7804. // ->where('talk_type', 2)
  7805. // ->orderBy('created_at', 'desc')
  7806. // // ->limit(5)
  7807. // ->get();
  7808. //获取5条用户的待审核项目
  7809. $project = Project::where('status', 1)
  7810. ->where('user_id', $user_id)
  7811. ->orderBy('updated_at', 'desc')
  7812. // ->limit(5)
  7813. ->get();
  7814. // count($chat) + count($chat_group) +
  7815. $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)
  7816. + count($complany)
  7817. + count($project)
  7818. + count($notice_unread)
  7819. + count($complaint_unread)
  7820. // + count($chat) + count($chat_group)
  7821. ;
  7822. $result = [
  7823. 'apply_articale' => $apply_articale,
  7824. // 'chat' => $chat,
  7825. // 'chat_group' => $chat_group,
  7826. 'good' => $good,
  7827. 'notice' => $notice,
  7828. 'complaint' => $complaint,
  7829. 'book' => $book,
  7830. 'job_hunting' => $job_hunting,
  7831. 'job_recruiting' => $job_recruiting,
  7832. 'job_apply' => $job_apply,
  7833. 'job_resume' => $job_resume,
  7834. 'complaint_deal' => $complaint_deal,
  7835. 'complany' => $complany,
  7836. 'project' => $project,
  7837. 'notice_unread' => $notice_unread,
  7838. 'complaint_unread' => $complaint_unread,
  7839. 'count' => $count,
  7840. ];
  7841. } elseif ($type_id == 12) {
  7842. //最近的5篇已审的文章
  7843. $apply_articale = Article::where('status', 1)
  7844. ->where('admin_user_id', $user_id)
  7845. ->limit(5)->get();
  7846. //获取5条单聊未读聊天消息
  7847. $chat = ChatRecords::where('is_read', 0)
  7848. ->where('user_id', $user_id)
  7849. ->where('talk_type', 1)
  7850. ->orderBy('created_at', 'desc')
  7851. ->limit(5)->get();
  7852. //获取5条未读群聊信息
  7853. $chat_group = ChatRecords::where('is_read', 0)
  7854. ->where('user_id', $user_id)
  7855. ->where('talk_type', 2)
  7856. ->orderBy('created_at', 'desc')
  7857. ->limit(5)->get();
  7858. //获取5条用户的已审核商品
  7859. $good = Good::where('status', 2)
  7860. ->where('user_id', $user_id)
  7861. ->orderBy('updated_at', 'desc')
  7862. ->limit(5)->get();
  7863. //获取5条用户的book
  7864. $book = Book::where('status', 2)
  7865. ->where('user_id', $user_id)
  7866. ->orderBy('updated_at', 'desc')
  7867. ->limit(5)->get();
  7868. //获取5条用户的求职
  7869. //获取5条用户的求职 1
  7870. //count($chat) + count($chat_group)
  7871. $count = count($apply_articale) + count($good);
  7872. $result = [
  7873. 'apply_articale' => $apply_articale,
  7874. 'chat' => $chat,
  7875. 'chat_group' => $chat_group,
  7876. 'good' => $good,
  7877. 'book' => $book,
  7878. 'count' => $count,
  7879. ];
  7880. } elseif ($type_id == 13) {
  7881. //最近的5篇已审的文章
  7882. $apply_articale = Article::where('status', 1)
  7883. ->where('admin_user_id', $user_id)
  7884. ->limit(5)->get();
  7885. //获取5条单聊未读聊天消息
  7886. $chat = ChatRecords::where('is_read', 0)
  7887. ->where('user_id', $user_id)
  7888. ->where('talk_type', 1)
  7889. ->orderBy('created_at', 'desc')
  7890. ->limit(5)->get();
  7891. //获取5条未读群聊信息
  7892. $chat_group = ChatRecords::where('is_read', 0)
  7893. ->where('user_id', $user_id)
  7894. ->where('talk_type', 2)
  7895. ->orderBy('created_at', 'desc')
  7896. ->limit(5)->get();
  7897. //获取5条用户的已审核商品
  7898. $good = Good::where('status', 2)
  7899. ->where('user_id', $user_id)
  7900. ->orderBy('updated_at', 'desc')
  7901. ->limit(5)->get();
  7902. //count($chat) + count($chat_group) +
  7903. $count = count($apply_articale) + count($good);
  7904. $result = [
  7905. 'apply_articale' => $apply_articale,
  7906. 'chat' => $chat,
  7907. 'chat_group' => $chat_group,
  7908. 'good' => $good,
  7909. 'count' => $count,
  7910. ];
  7911. } elseif ($type_id == 14) {
  7912. //最近的5篇已审的文章
  7913. $apply_articale = Article::where('status', 1)
  7914. ->where('admin_user_id', $user_id)
  7915. // ->limit(5)
  7916. ->get();
  7917. //获取5条用户的已审核商品
  7918. $good = Good::where('status', 2)
  7919. ->where('user_id', $user_id)
  7920. ->orderBy('updated_at', 'desc')
  7921. // ->limit(5)
  7922. ->get();
  7923. $count = count($apply_articale) + count($good);
  7924. $result = [
  7925. 'apply_articale' => $apply_articale,
  7926. 'chat' => '',
  7927. 'chat_group' => '',
  7928. 'good' => $good,
  7929. 'count' => $count,
  7930. ];
  7931. } elseif ($type_id == 10000) {
  7932. //获取未审核的5篇文章
  7933. $apply_articale = Article::where('status', 0)
  7934. ->orderBy('updated_at', 'desc')
  7935. // ->limit(5)
  7936. ->get();
  7937. //获取5条单聊未读聊天消息
  7938. //获取5条单聊未读聊天消息
  7939. // $chat = ChatRecords::where('is_read', 0)
  7940. // ->where('user_id', $user_id)
  7941. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7942. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7943. // ->where('action', 'recieved')
  7944. // ->where('talk_type', 1)
  7945. // ->orderBy('created_at', 'desc')
  7946. // // ->limit(5)
  7947. // ->get();
  7948. // //获取5条未读群聊信息
  7949. // $chat_group = ChatRecords::where('is_read', 0)
  7950. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7951. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7952. // ->where('user_id', $user_id)
  7953. // ->where('talk_type', 2)
  7954. // ->orderBy('created_at', 'desc')
  7955. // // ->limit(5)
  7956. // ->get();
  7957. //获取5条用户的已审核商品
  7958. $good = Good::where('status', 1)
  7959. // ->where('user_id', $user_id)
  7960. ->orderBy('updated_at', 'desc')
  7961. // ->limit(5)
  7962. ->get();
  7963. //获取5条用户待审核的公告
  7964. $notice = Notice::where('status', 1)
  7965. ->orderBy('updated_at', 'desc')
  7966. // ->limit(5)
  7967. ->get();
  7968. //获取5条用户的待审核投诉
  7969. $complaint = Complaint::where('status', 1)
  7970. ->orderBy('updated_at', 'desc')
  7971. // ->limit(5)
  7972. ->get();
  7973. //获取5条用户的book
  7974. $book = Book::where('status', 1)
  7975. ->orderBy('updated_at', 'desc')
  7976. // ->limit(5)
  7977. ->get();
  7978. //获取5条用户的求职 1
  7979. $job_hunting = JobHunting::where('job_hunting.status', 1)
  7980. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7981. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7982. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7983. ->orderBy('updated_at', 'desc')
  7984. // ->limit(5)
  7985. ->get();
  7986. //获取5条用户的求职 2
  7987. $job_recruiting = JobRecruiting::where('job_recruiting.status', 0)
  7988. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7989. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7990. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7991. ->orderBy('updated_at', 'desc')
  7992. // ->limit(5)
  7993. ->get();
  7994. //人才库 1
  7995. $job_apply = JobApply::where('job_apply.status', 1)
  7996. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7997. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7998. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7999. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  8000. ->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')
  8001. ->orderBy('updated_at', 'desc')
  8002. // ->limit(5)
  8003. ->get();
  8004. // 职场机会 2
  8005. $job_resume = JobResume::where('job_resume.status', 1)
  8006. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  8007. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  8008. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  8009. ->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')
  8010. ->orderBy('updated_at', 'desc')
  8011. // ->limit(5)
  8012. ->get();
  8013. //待审核数据com pro
  8014. $complany = Company::where('status', 0)
  8015. ->orderBy('updated_at', 'desc')
  8016. // ->limit(5)
  8017. ->get();
  8018. $project = Project::where('status', 0)
  8019. ->orderBy('updated_at', 'desc')
  8020. // ->limit(5)
  8021. ->get();
  8022. $count =
  8023. // count($chat) +
  8024. // count($chat_group) +
  8025. count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting)
  8026. // + count($job_apply)
  8027. // + count($job_resume)
  8028. + count($complany)
  8029. + count($project);
  8030. $result = [
  8031. 'apply_articale' => $apply_articale,
  8032. // 'chat' => $chat,
  8033. // 'chat_group' => $chat_group,
  8034. 'good' => $good,
  8035. 'notice' => $notice,
  8036. 'complaint' => $complaint,
  8037. 'book' => $book,
  8038. 'job_hunting' => $job_hunting,
  8039. 'job_recruiting' => $job_recruiting,
  8040. // 'job_apply' => $job_apply,
  8041. // 'job_resume' => $job_resume,
  8042. 'complany' => $complany,
  8043. 'project' => $project,
  8044. 'count' => $count,
  8045. ];
  8046. } elseif ($type_id == 20000) {
  8047. }
  8048. var_dump($type_id, '-----------------test---------');
  8049. return Result::success($result);
  8050. }
  8051. /**
  8052. * @param array $data
  8053. * @return array
  8054. */
  8055. public function getWebsiteProject(array $data): array
  8056. {
  8057. $categorys = json_decode($data['id'], true);
  8058. if (!empty($categorys)) {
  8059. $category_arr = $this->processArticlePro($data['website_id']);
  8060. $cat_1st_arr = $category_arr['cat_1st_arr'];
  8061. $catiall = $category_arr['catiall'];
  8062. // return Result::success($catiall);
  8063. foreach ($categorys as $key => $val) {
  8064. if (isset($val['level'][0]) && !empty($val['level'][0])) {
  8065. $level = explode(',', $val['level'])[0];
  8066. $imgnum = explode(',', $val['level'])[1] ?? null;
  8067. $textnum = explode(',', $val['level'])[2] ?? null;
  8068. if ($level == 1) {
  8069. if (!empty($textnum) && $textnum > 0) {
  8070. $text_num = Project::where('level', $level)
  8071. ->where('website_id', $data['website_id'])
  8072. ->where('status', 1)
  8073. ->select(
  8074. 'project.id',
  8075. 'project.title',
  8076. 'project.description',
  8077. 'project.updated_at',
  8078. 'project.category_id',
  8079. 'project.cat_arr_id'
  8080. )
  8081. ->orderBy('updated_at', 'desc')
  8082. ->limit($textnum)
  8083. ->get()->all();
  8084. }
  8085. if (!empty($imgnum) && $imgnum > 0) {
  8086. $img_num = Project::where('level', $level)
  8087. ->where('website_id', $data['website_id'])
  8088. ->where('status', 1)
  8089. ->where('imgurl', '!=', '')
  8090. ->whereNotNull('imgurl')
  8091. ->select(
  8092. 'project.id',
  8093. 'project.title',
  8094. 'project.description',
  8095. 'project.updated_at',
  8096. 'project.imgurl as imgs',
  8097. 'project.category_id',
  8098. 'project.cat_arr_id'
  8099. )
  8100. ->orderBy('updated_at', 'desc')
  8101. ->limit($imgnum)
  8102. ->get()->all();
  8103. }
  8104. } else {
  8105. if (!empty($textnum) && $textnum > 0) {
  8106. $text_num = Project::where('website_id', $data['website_id'])
  8107. ->where('status', 1)
  8108. ->select(
  8109. 'project.id',
  8110. 'project.title',
  8111. 'project.description',
  8112. 'project.updated_at',
  8113. 'project.category_id',
  8114. 'project.cat_arr_id',
  8115. 'project.website_id',
  8116. 'project.updated_at',
  8117. 'project.created_at'
  8118. )
  8119. ->orderBy('updated_at', 'desc')
  8120. ->limit($textnum)
  8121. ->get()->all();
  8122. }
  8123. if (!empty($imgnum) && $imgnum > 0) {
  8124. $img_num = Project::where('website_id', $data['website_id'])
  8125. ->where('status', 1)
  8126. ->where('imgurl', '!=', '')
  8127. ->whereNotNull('imgurl')
  8128. ->select(
  8129. 'project.id',
  8130. 'project.title',
  8131. 'project.description',
  8132. 'project.updated_at',
  8133. 'project.imgurl as imgs',
  8134. 'project.category_id',
  8135. 'project.cat_arr_id'
  8136. )
  8137. ->orderBy('updated_at', 'desc')
  8138. ->limit($imgnum)
  8139. ->get()->all();
  8140. }
  8141. }
  8142. }
  8143. if (isset($val['id'][0]) && !empty($val['id'][0])) {
  8144. $category_ids = explode(',', $val['id'])[0];
  8145. $cat_imgnum = explode(',', $val['id'])[1] ?? null;
  8146. $cat_textnum = explode(',', $val['id'])[2] ?? null;
  8147. $category_arr = array_merge([$category_ids], $cat_1st_arr[$category_ids] ?? [0]);
  8148. if (!empty($cat_textnum) && $cat_textnum > 0) {
  8149. $text_num = Project::whereIn('category_id', $category_arr)
  8150. ->where('website_id', $data['website_id'])
  8151. ->where('status', 1)
  8152. ->select(
  8153. 'project.id',
  8154. 'project.title',
  8155. 'project.description',
  8156. 'project.updated_at',
  8157. 'project.category_id',
  8158. 'project.cat_arr_id'
  8159. )
  8160. ->orderBy('updated_at', 'desc')
  8161. ->limit($cat_textnum)
  8162. ->get()->all();
  8163. }
  8164. if (!empty($cat_imgnum) && $cat_imgnum > 0) {
  8165. $img_num = Project::whereIn('category_id', $category_arr)
  8166. ->where('website_id', $data['website_id'])
  8167. ->where('status', 1)
  8168. ->where('imgurl', '!=', '')
  8169. ->whereNotNull('imgurl')
  8170. ->select(
  8171. 'project.id',
  8172. 'project.title',
  8173. 'project.description',
  8174. 'project.updated_at',
  8175. 'project.imgurl as imgs',
  8176. 'project.category_id',
  8177. 'project.cat_arr_id'
  8178. )
  8179. ->orderBy('updated_at', 'desc')
  8180. ->limit($cat_imgnum)
  8181. ->get()->all();
  8182. }
  8183. }
  8184. if (!empty($img_num)) {
  8185. foreach ($img_num as $k => $v) {
  8186. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8187. $imgurl = json_decode($v['imgs'], true);
  8188. if (!empty($imgurl)) {
  8189. $img_num[$k]->imgurl = $imgurl[0];
  8190. }
  8191. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8192. }
  8193. }
  8194. if (!empty($text_num)) {
  8195. foreach ($text_num as $k => $v) {
  8196. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  8197. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  8198. }
  8199. }
  8200. $project[$key]['img_num'] = $img_num ?? [];
  8201. $project[$key]['text_num'] = $text_num ?? [];
  8202. }
  8203. }
  8204. if (empty($project)) {
  8205. return Result::error("暂无相关项目信息", 0);
  8206. }
  8207. return Result::success($project);
  8208. }
  8209. /**
  8210. * @param array $data
  8211. * @return array
  8212. */
  8213. public function getWebsiteProjectInfo(array $data): array
  8214. {
  8215. $project = Project::where('id', $data['id'])
  8216. ->where('status', 1)
  8217. ->where('website_id', $data['website_id'])
  8218. ->select('project.*')
  8219. ->first();
  8220. if (empty($project)) {
  8221. return Result::error("暂无相关项目信息", 0);
  8222. }
  8223. return Result::success($project);
  8224. }
  8225. /**
  8226. * @param array $data
  8227. * @return array
  8228. */
  8229. public function getWebsiteProjectList(array $data): array
  8230. {
  8231. $where = [];
  8232. if (isset($data['category_id']) && !empty($data['category_id'])) {
  8233. $where['category_id'] = $data['category_id'];
  8234. }
  8235. if (isset($data['keyword']) && !empty($data['keyword'])) {
  8236. $where[] = ['title', 'like', '%' . $data['keyword'] . '%'];
  8237. }
  8238. $query = Project::where($where)
  8239. ->where('status', 1)
  8240. ->where('website_id', $data['website_id'])
  8241. ->select(
  8242. 'project.id',
  8243. 'project.title',
  8244. 'project.description',
  8245. 'project.imgurl as imgs',
  8246. 'project.category_id',
  8247. 'project.cat_arr_id'
  8248. )
  8249. ->orderBy('updated_at', 'desc');
  8250. $count = $query->count();
  8251. $project = $query->clone()
  8252. ->offset(($data['page'] - 1) * $data['pageSize'])
  8253. ->limit($data['pageSize'])
  8254. ->get()->all();
  8255. if (empty($project)) {
  8256. return Result::error("暂无相关项目信息", 0);
  8257. }
  8258. $categorys = $this->processArticlePro($data['website_id']);
  8259. $catiall = $categorys['catiall'];
  8260. foreach ($project as $key => $val) {
  8261. $project[$key]->category_name = $catiall[$val->category_id]['alias'];
  8262. if (!empty($val['imgs'])) {
  8263. $imgurl = json_decode($val['imgs'], true);
  8264. if (!empty($imgurl)) {
  8265. $project[$key]->imgurl = $imgurl[0];
  8266. }
  8267. } else {
  8268. $project[$key]->imgurl = '';
  8269. }
  8270. $project[$key]->pinyin = $catiall[$val->category_id]['pinyin'];
  8271. }
  8272. $result = [
  8273. 'rows' => $project,
  8274. 'count' => $count,
  8275. ];
  8276. return Result::success($result);
  8277. }
  8278. /**
  8279. * @param array $data
  8280. * @return array
  8281. */
  8282. public function getWebsiteCategoryJob(array $data): array
  8283. {
  8284. $categorys = json_decode($data['id'], true);
  8285. if (!empty($categorys)) {
  8286. $category_arr = $this->processArticlePro($data['website_id']);
  8287. $cat_1st_arr = $category_arr['cat_1st_arr'];
  8288. $catiall = $category_arr['catiall'];
  8289. foreach ($categorys as $key => $val) {
  8290. if (isset($val['id']) && !empty($val['id'])) {
  8291. $catid = explode(',', $val['id'])[0] ?? null;
  8292. $type = explode(',', $val['id'])[1] ?? null;
  8293. $textnum = explode(',', $val['id'])[2] ?? null;
  8294. }
  8295. // 4:招聘;5:求职;
  8296. if ($textnum > 0 && $type == 4 && !empty($catid)) {
  8297. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  8298. $job = JobRecruiting::WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($catid) . "') = 1")
  8299. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  8300. ->where('job_recruiting.status', 1)
  8301. ->where('job_recruiting.website_id', $data['website_id'])
  8302. ->select(
  8303. 'job_recruiting.id',
  8304. 'job_recruiting.title',
  8305. 'job_company.business_name',
  8306. 'job_recruiting.updated_at',
  8307. 'job_recruiting.cat_arr_id',
  8308. 'job_recruiting.keyword',
  8309. 'job_recruiting.description'
  8310. )
  8311. ->orderBy('job_recruiting.updated_at', 'desc')
  8312. ->limit($textnum)
  8313. ->get()->all();
  8314. } else if ($textnum > 0 && $type == 5 && !empty($catid)) {
  8315. // 状态 审核状态,1待审核2已审核3已拒绝
  8316. $job = JobHunting::WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($catid) . "') = 1")
  8317. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  8318. ->where('job_hunting.status', 2)
  8319. ->where('job_hunting.website_id', $data['website_id'])
  8320. ->select(
  8321. 'job_hunting.id',
  8322. 'job_hunting.name',
  8323. 'job_hunting.cat_arr_id',
  8324. 'job_position.zwname as job_name',
  8325. 'job_hunting.updated_at',
  8326. // 'job_hunting.keyword',
  8327. 'job_hunting.slelf_evaluation'
  8328. )
  8329. ->orderBy('updated_at', 'desc')
  8330. ->limit($textnum)
  8331. ->get()->all();
  8332. } else {
  8333. $job = [];
  8334. }
  8335. // var_dump($catid.'222uuuuuuu'.$key);
  8336. if (!empty($job)) {
  8337. foreach ($job as $k => $value) {
  8338. if (isset($value->cat_arr_id)) {
  8339. $catArr = json_decode($value->cat_arr_id, true);
  8340. $catId = end($catArr);
  8341. } else {
  8342. continue;
  8343. }
  8344. if (isset($catiall[$catId])) {
  8345. $job[$k]->pinyin = $catiall[$catId]['pinyin'];
  8346. }
  8347. }
  8348. }
  8349. // var_dump($catid.'xxxxx'.$key);
  8350. $result[$key] = $job ?? [];
  8351. }
  8352. }
  8353. if (empty($result)) {
  8354. return Result::error("暂无相关分类信息", 0);
  8355. }
  8356. return Result::success($result);
  8357. }
  8358. /**
  8359. * 发送消息
  8360. * @param array $messageData
  8361. * @return void
  8362. */
  8363. public function sendMessage($messageData)
  8364. {
  8365. $msg = [
  8366. 'talk_type' => $messageData['talk_type'],
  8367. 'title' => $messageData['title'],
  8368. 'content' => $messageData['content'],
  8369. 'messageType' => $messageData['messageType'],
  8370. 'user_id' => $messageData['user_id'] ?? '',
  8371. 'time' => microtime(),
  8372. ];
  8373. $message = new MqProducer($msg);
  8374. $producer = ContextApplicationContext::getContainer()->get(Producer::class);
  8375. $producer->produce($message);
  8376. }
  8377. /**
  8378. * 行业分类管理 ------1121
  8379. * @param array $data
  8380. * @return array
  8381. */
  8382. public function getJobIndustryList(array $data): array
  8383. {
  8384. $page = $data['page'] ?? 1;
  8385. $page_size = $data['page_size'] ?? 10;
  8386. if (isset($data['hyname']) && !empty($data['hyname'])) {
  8387. $where = ['hyname', 'like', '%' . $data['hyname'] . '%'];
  8388. } else {
  8389. $where = [];
  8390. }
  8391. $rs_query = JobIndustry::when(!empty($where), function ($query) use ($where) {
  8392. $query->where([$where]); // 修复:将条件包装成二维数组
  8393. })
  8394. ->orderBy('updated_at', 'desc');
  8395. $count = $rs_query->count();
  8396. $hy = $rs_query->offset(($page - 1) * $page_size)->limit($page_size)->get()->all();
  8397. $result = [
  8398. 'count' => $count,
  8399. 'list' => $hy,
  8400. ];
  8401. if (empty($hy)) {
  8402. return Result::success('暂无数据');
  8403. }
  8404. return Result::success($result);
  8405. }
  8406. /**
  8407. * 添加行业分类
  8408. * @param array $data
  8409. * @return array
  8410. */
  8411. public function addJobIndustry(array $data): array
  8412. {
  8413. $hy_name = JobIndustry::where('hyname', $data['hyname'])->first(['hyid']);
  8414. if (!empty($hy_name)) {
  8415. return Result::error('行业分类已存在');
  8416. }
  8417. $hy = JobIndustry::insertGetId($data);
  8418. if (empty($hy)) {
  8419. return Result::error('添加失败');
  8420. }
  8421. return Result::success($hy);
  8422. }
  8423. /**
  8424. * 更新行业分类
  8425. * @param array $data
  8426. * @return array
  8427. */
  8428. public function upJobIndustry(array $data): array
  8429. {
  8430. $hy_query = JobIndustry::get();
  8431. $hy_ids = $hy_query->pluck('hyid')->toArray();
  8432. $hy_names = $hy_query->pluck('hyname')->toArray();
  8433. if (!in_array($data['hyid'], $hy_ids)) {
  8434. return Result::error('行业分类不存在');
  8435. }
  8436. if (isset($data['hyname']) && !empty($data['hyname'])) {
  8437. $other_key_hy = array_search($data['hyid'], $hy_ids);
  8438. // return Result::success($other_key_hy);
  8439. unset($hy_names[$other_key_hy]);
  8440. if (in_array($data['hyname'], $hy_names)) {
  8441. return Result::error('行业分类名称已存在');
  8442. }
  8443. }
  8444. $hy = JobIndustry::where('hyid', $data['hyid'])->update($data);
  8445. if (empty($hy)) {
  8446. return Result::error('更新失败');
  8447. }
  8448. return Result::success($hy);
  8449. }
  8450. /**
  8451. * 删除行业分类
  8452. * @param array $data
  8453. * @return array
  8454. */
  8455. public function delJobIndustry(array $data): array
  8456. {
  8457. $hy_id = JobIndustry::where('hyid', $data['hyid'])->first(['hyid']);
  8458. if (empty($hy_id)) {
  8459. return Result::error('行业分类不存在');
  8460. }
  8461. $hy = JobIndustry::where('hyid', $data['hyid'])->delete();
  8462. if (empty($hy)) {
  8463. return Result::error('删除失败');
  8464. }
  8465. return Result::success($hy);
  8466. }
  8467. /**
  8468. * 职位分类-列表
  8469. * @param array $data
  8470. * @return array
  8471. */
  8472. public function getJobPositionList(array $data): array
  8473. {
  8474. $page = $data['page'] ?? 1;
  8475. $page_size = $data['page_size'] ?? 10;
  8476. $where = [];
  8477. if (isset($data['zwname']) && !empty($data['zwname'])) {
  8478. $zwids = JobPosition::where('zwpid', 0)
  8479. ->when(!empty($data['zwname']), function ($query) use ($data) {
  8480. $query->where('zwname', 'like', '%' . $data['zwname'] . '%');
  8481. })
  8482. ->orderBy('updated_at', 'desc')
  8483. ->pluck('zwid')
  8484. // ->get()
  8485. ->toArray();
  8486. }
  8487. if (isset($data['childname']) && !empty($data['childname'])) {
  8488. $child_zwids = JobPosition::where('zwpid', '!=', 0)
  8489. ->when(!empty($data['childname']), function ($query) use ($data) {
  8490. $query->where('zwname', 'like', '%' . $data['childname'] . '%');
  8491. })
  8492. ->orderBy('updated_at', 'desc')
  8493. ->pluck('zwpid')
  8494. // ->get()
  8495. ->toArray();
  8496. if (isset($zwids) && is_array($zwids) && is_array($child_zwids)) {
  8497. $child_zwids = array_intersect($zwids, $child_zwids);
  8498. }
  8499. $zwids = array_values(array_unique($child_zwids));
  8500. }
  8501. $zwids = $zwids ?? null;
  8502. $count = JobPosition::when(!empty($zwids), function ($query) use ($zwids) {
  8503. $query->whereIn('zwid', $zwids);
  8504. })
  8505. ->where('zwpid', 0)
  8506. ->count();
  8507. $position = JobPosition::when(!empty($zwids), function ($query) use ($zwids) {
  8508. $query->whereIn('zwid', $zwids);
  8509. })
  8510. ->where('zwpid', 0)
  8511. ->orderBy('updated_at', 'desc')
  8512. ->offset(($page - 1) * $page_size)
  8513. ->limit($page_size)->get()
  8514. ->map(function ($item) use ($data) {
  8515. $item->children = $item->where('zwpid', $item->zwid)
  8516. ->when(!empty($data['childname']), function ($query) use ($data) {
  8517. $query->where('zwname', 'like', '%' . $data['childname'] . '%');
  8518. })
  8519. ->orderBy('updated_at', 'desc')
  8520. ->get();
  8521. return $item;
  8522. })
  8523. ->all();
  8524. $result = [
  8525. 'count' => $count,
  8526. 'list' => $position,
  8527. ];
  8528. if (empty($result)) {
  8529. return Result::success('暂无数据');
  8530. }
  8531. return Result::success($result);
  8532. }
  8533. /**
  8534. * 职位分类-添加
  8535. * @param array $data
  8536. * @return array
  8537. */
  8538. public function addJobPosition(array $data): array
  8539. {
  8540. $zw_name = JobPosition::where('zwpid', $data['zwpid'])
  8541. ->where('zwname', $data['zwname'])->first(['zwid']);
  8542. if (!empty($zw_name)) {
  8543. return Result::error('职位分类已存在');
  8544. }
  8545. $zw = JobPosition::insertGetId($data);
  8546. if(empty($zw)){
  8547. return Result::error('添加失败');
  8548. }
  8549. return Result::success($zw);
  8550. }
  8551. /**
  8552. * 更新职位分类
  8553. * @param array $data
  8554. * @return array
  8555. */
  8556. public function upJobPosition(array $data): array
  8557. {
  8558. $zw_position = JobPosition::get();
  8559. if (!in_array($data['zwid'], $zw_position->pluck('zwid')->toArray())) {
  8560. return Result::error('职位分类不存在');
  8561. }
  8562. $zw_name = $zw_position->where('zwid', '!=', $data['zwid'])
  8563. ->where('zwpid', $data['zwpid'])
  8564. ->where('zwname', $data['zwname'])->first();
  8565. if (!empty($zw_name)) {
  8566. return Result::error('职位分类已存在');
  8567. }
  8568. $result = JobPosition::where('zwid', $data['zwid'])->update($data);
  8569. if (empty($result)) {
  8570. return Result::error('更新失败');
  8571. }
  8572. return Result::success($result);
  8573. }
  8574. /**
  8575. * 删除职位分类
  8576. * @param array $data
  8577. * @return array
  8578. */
  8579. public function delJobPosition(array $data): array
  8580. {
  8581. $zw_jobposition = JobPosition::get();
  8582. $zw_id = $zw_jobposition->where('zwid', $data['zwid'])->first();
  8583. if (empty($zw_id)) {
  8584. return Result::error('职位分类不存在');
  8585. }
  8586. if($zw_id->zwpid == 0){
  8587. $zw_job = JobPosition::where('zwpid', $zw_id->zwid)->first();
  8588. if(!empty($zw_job)){
  8589. return Result::error('请先删除子分类');
  8590. }
  8591. }
  8592. $result = JobPosition::where('zwid', $data['zwid'])->delete();
  8593. if (empty($result)) {
  8594. return Result::error('删除失败');
  8595. }
  8596. return Result::success($result);
  8597. }
  8598. }