NewsService.php 291 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042
  1. <?php
  2. namespace App\JsonRpc;
  3. use App\Model\Article;
  4. use App\Model\ArticleData;
  5. use App\Model\Category;
  6. use App\Model\HistoryToday;
  7. use App\Model\WebsiteCategory;
  8. use App\Model\ArticleSurvey;
  9. use App\Model\District;
  10. use App\Model\Good;
  11. use App\Model\JobCompany;
  12. use App\Model\Website;
  13. use App\Model\JobRecruiting;
  14. use App\Model\JobIndustry;
  15. use App\Model\Book;
  16. use App\Model\JobPosition;
  17. use App\Model\Notice;
  18. use App\Model\JobNature;
  19. use App\Model\JobEnum;
  20. use App\Model\User;
  21. use App\Model\UserRole;
  22. use App\Model\News;
  23. use App\Model\UserInfo;
  24. use App\Model\WebsiteGroup;;
  25. use App\Model\JobResume;
  26. use Hyperf\DbConnection\Db;
  27. use Hyperf\RpcServer\Annotation\RpcService;
  28. use App\Tools\Result;
  29. use Directory;
  30. use Ramsey\Uuid\Uuid;
  31. use Hyperf\Utils\Random;
  32. use Fukuball\Jieba\Jieba;
  33. use Fukuball\Jieba\Finalseg;
  34. use Hyperf\Utils\Collection;
  35. use function Hyperf\Support\retry;
  36. use App\Tools\PublicData;
  37. use App\Model\ChatGroups;
  38. use App\Model\ChatGroupsMember;
  39. use App\Model\ChatRecords;
  40. use App\Model\Complaint;
  41. use Hamcrest\Arrays\IsArray;
  42. use Hyperf\Codec\Json;
  43. use App\Tools\buildMenuTree;
  44. use App\Model\JobApply;
  45. use App\Model\JobHunting;
  46. use App\Model\JobRemuse;
  47. use Hyperf\Redis\Redis;
  48. use Hyperf\Di\Annotation\Inject;
  49. use App\Model\Festival;
  50. use App\Model\Character;
  51. use App\Model\Couplet;
  52. use App\Model\Riddle;
  53. use App\Model\Idiom;
  54. use App\Model\WhiteRouter;
  55. use Illuminate\Support\Facades\Cache;
  56. use App\Model\Company;
  57. use Hyperf\Paginator\Paginator;
  58. use App\Model\Project;
  59. use Hyperf\Context\Context;
  60. use Hyperf\Context\ApplicationContext as ContextApplicationContext;
  61. use Hyperf\Amqp\Producer;
  62. use App\Amqp\Producer\MqProducer;
  63. use App\Model\Web;
  64. use App\Model\GroupMemberImp;
  65. use App\Model\GroupImp;
  66. use App\Model\GroupTalkImp;
  67. use App\Model\GroupTalkMessagerImp;
  68. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  69. class NewsService implements NewsServiceInterface
  70. {
  71. #[Inject]
  72. protected Redis $redis;
  73. /**
  74. * 获取导航池列表
  75. * @param array $data
  76. * @return array
  77. */
  78. public function getCategoryList(array $data): array
  79. {
  80. $search = $data['name'] ?? '';
  81. $page = (int)($data['page'] ?? 1);
  82. $perPage = (int)($data['pageSize'] ?? 10);
  83. // 1. 查出所有匹配的分类id
  84. if ($search) {
  85. $matchedIds = Category::where('name', 'like', "%{$search}%")->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  86. if (empty($matchedIds)) {
  87. return Result::success(['rows' => [], 'total' => 0]);
  88. }
  89. // 2. 递归查所有父级,直到一级分类
  90. $idsStr = implode(',', $matchedIds);
  91. $sql = "
  92. WITH RECURSIVE parents AS (
  93. SELECT * FROM category WHERE id IN ($idsStr)
  94. UNION ALL
  95. SELECT c.* FROM category c
  96. INNER JOIN parents p ON c.id = p.pid
  97. )
  98. SELECT * FROM parents
  99. ";
  100. $parents = Db::select($sql);
  101. $parentIds = [];
  102. foreach ($parents as $row) {
  103. if ($row->pid == 0) {
  104. $parentIds[] = $row->id;
  105. }
  106. }
  107. $parentIds = array_unique($parentIds);
  108. } else {
  109. // 没有搜索,一级分类就是根
  110. $parentIds = Category::where('pid', 0)->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  111. }
  112. // 3. 一级分类分页
  113. $total = count($parentIds);
  114. $parentIds = array_slice($parentIds, ($page - 1) * $perPage, $perPage);
  115. if (empty($parentIds)) {
  116. return Result::success(['rows' => [], 'total' => $total]);
  117. }
  118. // 4. 递归查所有子孙
  119. $idsStr = implode(',', $parentIds);
  120. $sql = "
  121. WITH RECURSIVE subcategories AS (
  122. SELECT * FROM category WHERE id IN ($idsStr)
  123. UNION ALL
  124. SELECT c.* FROM category c
  125. INNER JOIN subcategories s ON c.pid = s.id
  126. )
  127. SELECT * FROM subcategories ORDER BY updated_at DESC
  128. ";
  129. $allCategories = Db::select($sql);
  130. // 5. 组装树结构
  131. $categoryMap = [];
  132. foreach ($allCategories as $cat) {
  133. $cat = (array)$cat;
  134. $cat['children'] = [];
  135. $categoryMap[$cat['id']] = $cat;
  136. }
  137. foreach ($categoryMap as $id => &$cat) {
  138. if ($cat['pid'] && isset($categoryMap[$cat['pid']])) {
  139. $categoryMap[$cat['pid']]['children'][] = &$cat;
  140. }
  141. }
  142. unset($cat);
  143. $categoryTree = [];
  144. foreach ($parentIds as $id) {
  145. if (isset($categoryMap[$id])) {
  146. $categoryTree[] = $categoryMap[$id];
  147. }
  148. }
  149. return Result::success([
  150. 'rows' => $categoryTree,
  151. 'total' => $total,
  152. ]);
  153. }
  154. private function findMatchedCategories($search)
  155. {
  156. if ($search) {
  157. return Category::where('name', 'like', "%{$search}%")
  158. ->orderBy('updated_at', 'desc')
  159. ->get();
  160. }
  161. return Category::orderBy('updated_at', 'desc') // 按 updated_at 字段倒序排序
  162. ->get();
  163. }
  164. private function findAllParents($categories)
  165. {
  166. $allCategories = [];
  167. foreach ($categories as $category) {
  168. $parentId = $category->pid;
  169. while ($parentId > 0) {
  170. $parent = Category::find($parentId);
  171. if ($parent) {
  172. $allCategories[$parent->id] = $parent;
  173. $parentId = $parent->pid;
  174. } else {
  175. break;
  176. }
  177. }
  178. $allCategories[$category->id] = $category;
  179. }
  180. return array_values($allCategories);
  181. }
  182. private function buildCategoryTree($category, $allRequiredCategories)
  183. {
  184. $categoryData = $category->toArray();
  185. $children = [];
  186. foreach ($allRequiredCategories as $c) {
  187. if ($c->pid === $category->id) {
  188. $children[] = $this->buildCategoryTree($c, $allRequiredCategories);
  189. }
  190. }
  191. if (!empty($children)) {
  192. $categoryData['children'] = $children;
  193. }
  194. return $categoryData;
  195. }
  196. public function myCategoryList(array $data): array
  197. {
  198. $sszq = $data['sszq'] ?? '';
  199. unset($data['sszq']);
  200. //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
  201. $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
  202. $where[] = [
  203. 'pid',
  204. '=',
  205. $data['pid'],
  206. ];
  207. if (isset($data['name'])) {
  208. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  209. }
  210. var_dump($where);
  211. //根据分类id,从category表中取出分类信息
  212. $result = Category::where($where)
  213. ->whereIn('category.id', $catorytids)
  214. ->select('category.*', 'category.id as category_id')->get();
  215. if (empty($result)) {
  216. return Result::error("没有栏目数据");
  217. }
  218. return Result::success($result);
  219. }
  220. /**
  221. * @param array $data
  222. * @return array
  223. */
  224. public function categoryList(array $data): array
  225. {
  226. $where[] = [
  227. 'pid',
  228. '=',
  229. $data['pid']
  230. ];
  231. if (isset($data['name'])) {
  232. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  233. }
  234. var_dump($where);
  235. $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
  236. if (empty($result)) {
  237. return Result::error("没有栏目数据");
  238. }
  239. return Result::success($result);
  240. }
  241. /**
  242. * @param array $data
  243. * @return array
  244. */
  245. public function addCategory(array $data): array
  246. {
  247. if (isset($data['id'])) {
  248. unset($data['id']);
  249. }
  250. $id = Category::insertGetId($data);
  251. if (empty($id)) {
  252. return Result::error("添加失败");
  253. }
  254. return Result::success(['id' => $id]);
  255. }
  256. /**
  257. * @param array $data
  258. * @return array
  259. */
  260. public function delCategory(array $data): array
  261. {
  262. Db::beginTransaction();
  263. try {
  264. $categoryList = Category::where(['pid' => $data['id']])->get();
  265. if ($categoryList->toArray()) {
  266. Db::rollBack();
  267. return Result::error("分类下面有子分类不能删除");
  268. }
  269. $articleList = Article::where(['catid' => $data['id']])->get();
  270. if ($articleList->toArray()) {
  271. Db::rollBack();
  272. return Result::error("分类下面有资讯不能删除");
  273. }
  274. $result = Category::where($data)->delete();
  275. WebsiteCategory::where(['category_id' => $data['id']])->delete();
  276. if (!$result) {
  277. Db::rollBack();
  278. return Result::error("删除失败");
  279. }
  280. Db::commit();
  281. return Result::success($result);
  282. } catch (\Exception $e) {
  283. Db::rollBack();
  284. return Result::error("删除失败" . $e->getMessage());
  285. }
  286. }
  287. /**
  288. * @param array $data
  289. * @return array
  290. */
  291. public function updateCategory(array $data): array
  292. {
  293. $where = [
  294. 'id' => $data['id'],
  295. ];
  296. $result = Category::where($where)->update($data);
  297. if ($result) {
  298. return Result::success($result);
  299. } else {
  300. return Result::error("更新失败");
  301. }
  302. }
  303. /**
  304. * 获取导航池信息
  305. * @param array $data
  306. * @return array
  307. */
  308. public function getCategoryInfo(array $data): array
  309. {
  310. $where = [
  311. 'id' => $data['id'],
  312. ];
  313. $result = Category::where($where)->first();
  314. if ($result) {
  315. return Result::success($result);
  316. } else {
  317. return Result::error("更新失败");
  318. }
  319. }
  320. public function getArticleCommend(array $data): array
  321. {
  322. $where = [
  323. 'website_id' => $data['website_id'],
  324. ];
  325. $ids = WebsiteCategory::where($where)->pluck('category_id')->toArray();
  326. var_dump($ids);
  327. if (empty($ids)) {
  328. return Result::error("没有推荐数据");
  329. }
  330. //id
  331. $whereArticle = [];
  332. if (isset($data['id'])) {
  333. $whereArticle['id'] = $data['id'];
  334. }
  335. //title like
  336. if (isset($data['title'])) {
  337. array_push($whereArticle, ['title', 'like', "%{$data['title']}%"]);
  338. }
  339. $article = Article::whereIn('catid', values: $ids)->where('status', 1)
  340. ->where($whereArticle)
  341. ->orderBy('id', 'desc')
  342. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  343. if ($article) {
  344. $data = [
  345. 'rows' => $article->items(),
  346. 'count' => $article->total(),
  347. ];
  348. return Result::success($data);
  349. } else {
  350. return Result::error("获取失败失败");
  351. }
  352. }
  353. /**
  354. * @param array $data
  355. * @return array
  356. */
  357. public function getArticleList(array $data): array
  358. {
  359. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  360. $type_id = $data['type_id'];
  361. unset($data['type_id']);
  362. $user_id = $data['user_id'];
  363. unset($data['user_id']);
  364. $where = [];
  365. $status1 = [];
  366. if (isset($data['id']) && $data['id']) {
  367. array_push($where, ['article.id', '=', $data['id']]);
  368. }
  369. if (isset($data['title']) && $data['title']) {
  370. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  371. }
  372. if (isset($data['category_name']) && $data['category_name']) {
  373. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  374. }
  375. if (isset($data['catid']) && $data['catid']) {
  376. array_push($where, ['article.catid', '=', $data['catid']]);
  377. }
  378. if (isset($data['author']) && $data['author']) {
  379. array_push($where, ['article.author', '=', $data['author']]);
  380. }
  381. if (isset($data['islink']) && $data['islink'] !== "") {
  382. array_push($where, ['article.islink', '=', $data['islink']]);
  383. }
  384. if (isset($data['status']) && $data['status'] !== "") {
  385. array_push($where, ['article.status', '=', $data['status']]);
  386. }
  387. if (isset($data['status1'])) {
  388. $status1 = json_decode(($data['status1']));
  389. }
  390. //不是管理员展示个人数据;
  391. if ($type_id != 10000) {
  392. $where[] = ['article.admin_user_id', '=', $user_id];
  393. }
  394. $rep = Article::where($where)
  395. ->whereNotIn('article.status', [404])
  396. ->when($status1, function ($query) use ($status1) {
  397. if (isset($status1) && $status1) {
  398. $query->whereIn('article.status', $status1);
  399. }
  400. })
  401. ->leftJoin('category', 'article.catid', 'category.id')
  402. ->leftJoin('website_category', function ($join) {
  403. $join->on('article.web_site_id', '=', 'website_category.website_id')
  404. ->on('article.catid', '=', 'website_category.category_id');
  405. })
  406. ->select("article.*", "category.name as category_name", "website_category.alias")
  407. ->orderBy("article.updated_at", "desc")
  408. ->limit($data['pageSize'])
  409. ->offset(($data['page'] - 1) * $data['pageSize'])->get();
  410. $count = Article::where($where)->whereNotIn('article.status', [404])
  411. ->when($status1, function ($query) use ($status1) {
  412. if (isset($status1) && $status1) {
  413. $query->whereIn('article.status', $status1);
  414. }
  415. })
  416. ->leftJoin('category', 'article.catid', 'category.id')->count();
  417. $data = [
  418. 'rows' => $rep->toArray(),
  419. 'count' => $count,
  420. ];
  421. if (empty($rep)) {
  422. return Result::error("没有信息数据");
  423. }
  424. return Result::success($data);
  425. }
  426. /**
  427. * @param array $data
  428. * @return array
  429. */
  430. public function addArticle(array $data): array
  431. {
  432. var_dump($data, '----------12-----------1');
  433. unset($data['user_type']);
  434. unset($data['nav_add_pool_id']);
  435. // unset($data['commend_id']);
  436. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  437. Db::beginTransaction();
  438. try {
  439. //处理投票
  440. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  441. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  442. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  443. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  444. unset($data['is_survey']);
  445. unset($data['survey_name']);
  446. unset($data['suvey_array']);
  447. // unset($data['website_id']);
  448. // unset($data['web_site_id']);
  449. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  450. if ($data['hits'] == '') {
  451. $data['hits'] = 0;
  452. }
  453. if ($data['is_original'] == '') {
  454. $data['is_original'] = 0;
  455. }
  456. if ($data['status'] == '') {
  457. $data['status'] = 0;
  458. }
  459. $articleData = $data;
  460. unset($articleData['content']);
  461. //自动处理缩略图、关键字、描述
  462. if ($articleData['imgurl'] == '') {
  463. //如果没有图,设置level=0
  464. $levelArr = json_decode($articleData['level'], true);
  465. var_dump($levelArr, '----------levelArr-----------1');
  466. //content中提取图片第一个图,正则提取
  467. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  468. preg_match_all($reg, $data['content'], $matches);
  469. if (isset($matches[1][0])) {
  470. //截取varchar240
  471. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  472. //如果有图,设置level=3
  473. if (!in_array(3, $levelArr)) {
  474. $levelArr[] = 3;
  475. }
  476. $articleData['level'] = json_encode($levelArr);
  477. } else {
  478. if (!in_array(0, $levelArr)) {
  479. $levelArr[] = 0;
  480. }
  481. $articleData['level'] = json_encode($levelArr);
  482. }
  483. }
  484. var_dump($articleData['level'], '----------$articleData[level]----------1');
  485. if ($articleData['keyword'] == '') {
  486. //提取标题+内容中的关键词
  487. $articleData['keyword'] = $data['title'];
  488. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  489. Jieba::init(); // 初始化 jieba-php
  490. Finalseg::init();
  491. $segList = Jieba::cut($articleData['keyword']);
  492. $segList1 = array_slice($segList, 0, 8);
  493. $articleData['keyword'] = implode(',', $segList1);
  494. }
  495. if ($articleData['introduce'] == '') {
  496. //提取内容中的描述
  497. $content = $data['content'];
  498. // 去除 <style> 和 <script> 标签及其内容
  499. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  500. // 去除所有 HTML 标签
  501. $content = strip_tags($content);
  502. // 去除 HTML 实体
  503. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  504. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  505. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  506. // 去除多余空白
  507. $content = preg_replace('/\s+/u', '', $content);
  508. // 截取 100 个字符
  509. $articleData['introduce'] = mb_substr($content, 0, 100);
  510. }
  511. if ($articleData['status'] == 0) {
  512. $this->sendMessage([
  513. 'talk_type' => 100,
  514. 'title' => $articleData['title'],
  515. 'content' => '提交了审核',
  516. 'messageType' => 2,
  517. ]);
  518. }
  519. $id = Article::insertGetId($articleData);
  520. $articleDataContent = [
  521. 'article_id' => $id,
  522. 'content' => $data['content'],
  523. ];
  524. ArticleData::insertGetId($articleDataContent);
  525. //处理投票
  526. if ($is_survey == 1) {
  527. //生成年月日时分秒+8位随机数
  528. $uuid = date('YmdHis') . rand(10000000, 99999999);
  529. var_dump($suvey_array, 'suvey_array________');
  530. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  531. var_dump($suveys_array, '---------------------1');
  532. var_dump($suvey_array, '---------------------2');
  533. $suvey_data = [];
  534. foreach ($suveys_array as $key => $value) {
  535. if ($value == '') {
  536. continue;
  537. }
  538. if (is_array($value)) {
  539. $suvey_data[] = [
  540. 'sur_id' => $uuid,
  541. 'art_id' => $id,
  542. 'website_id' => $website_id ?? 2,
  543. 'survey_name' => $survey_name,
  544. 'choice_name' => $value[1],
  545. 'is_other' => 1,
  546. 'other_id' => 0,
  547. 'results' => 0,
  548. ];
  549. } else {
  550. $suvey_data[] = [
  551. 'sur_id' => $uuid,
  552. 'art_id' => $id,
  553. 'website_id' => $website_id ?? 2,
  554. 'survey_name' => $survey_name,
  555. 'choice_name' => $value,
  556. 'is_other' => 0,
  557. 'other_id' => 0,
  558. 'results' => 0,
  559. ];
  560. }
  561. if (empty($suvey_data)) {
  562. throw new \Exception("投票数据为空");
  563. }
  564. }
  565. $result = ArticleSurvey::insert($suvey_data);
  566. if (!$result) {
  567. throw new \Exception("投票失败,ArticleSurvey插入失败");
  568. }
  569. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  570. if (!$result) {
  571. throw new \Exception("投票失败,更新主表失败");
  572. }
  573. }
  574. Db::commit();
  575. return Result::success(['id' => $id]);
  576. } catch (\Throwable $ex) {
  577. Db::rollBack();
  578. var_dump($ex->getMessage());
  579. return Result::error("创建失败", 0);
  580. }
  581. }
  582. /**
  583. * @param array $data
  584. * @return array
  585. */
  586. public function delArticle(array $data): array
  587. {
  588. $result = Article::where($data)->delete();
  589. //survey投票删除
  590. articleSurvey::where(['art_id' => $data['id']])->delete();
  591. if (!$result) {
  592. return Result::error("删除失败");
  593. }
  594. return Result::success($result);
  595. }
  596. /**
  597. * @param array $data
  598. * @return array
  599. */
  600. public function updateArticle(array $data): array
  601. {
  602. var_dump($data, '----------12-----------1');
  603. Db::beginTransaction();
  604. unset($data['user_type']);
  605. // unset($data['web_site_id']);
  606. unset($data['nav_add_pool_id']);
  607. try {
  608. //处理投票
  609. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  610. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  611. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  612. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  613. unset($data['is_survey']);
  614. unset($data['survey_name']);
  615. unset($data['suvey_array']);
  616. unset($data['website_id']);
  617. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  618. if ($data['hits'] == '') {
  619. $data['hits'] = 0;
  620. }
  621. if ($data['is_original'] == '') {
  622. $data['is_original'] = 0;
  623. }
  624. if ($data['status'] == '') {
  625. $data['status'] = 0;
  626. }
  627. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  628. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  629. $articleData = $data;
  630. unset($articleData['content']);
  631. unset($articleData['status_name']);
  632. unset($articleData['name']);
  633. unset($articleData['content']);
  634. unset($articleData['pid_arr']);
  635. unset($articleData['pid']);
  636. //自动处理缩略图、关键字、描述
  637. if ($articleData['imgurl'] == '') {
  638. //如果没有图,设置level=0
  639. $levelArr = json_decode($articleData['level'], true);
  640. var_dump($levelArr, '----------levelArr-----------1');
  641. //content中提取图片第一个图,正则提取
  642. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  643. preg_match_all($reg, $data['content'], $matches);
  644. if (isset($matches[1][0])) {
  645. //截取varchar240
  646. // 截取到第一个<
  647. $articleData['imgurl'] = $matches[1][0];
  648. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  649. $pos = strpos($articleData['imgurl'], '"');
  650. if ($pos !== false) {
  651. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  652. }
  653. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  654. //如果有图,设置level=3
  655. if (!in_array(3, $levelArr)) {
  656. $levelArr[] = 3;
  657. }
  658. $articleData['level'] = json_encode($levelArr);
  659. } else {
  660. if (!in_array(0, $levelArr)) {
  661. $levelArr[] = 0;
  662. }
  663. $articleData['level'] = json_encode($levelArr);
  664. }
  665. }
  666. var_dump($articleData['level'], '----------$articleData[level]----------1');
  667. if ($articleData['keyword'] == '') {
  668. //提取标题+内容中的关键词
  669. $articleData['keyword'] = $data['title'];
  670. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  671. Jieba::init(); // 初始化 jieba-php
  672. Finalseg::init();
  673. $segList = Jieba::cut($articleData['keyword']);
  674. $segList1 = array_slice($segList, 0, 8);
  675. $articleData['keyword'] = implode(',', $segList1);
  676. }
  677. if ($articleData['introduce'] == '') {
  678. //提取内容中的描述
  679. $content = $data['content'];
  680. // 去除 <style> 和 <script> 标签及其内容
  681. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  682. // 去除所有 HTML 标签
  683. $content = strip_tags($content);
  684. // 去除 HTML 实体
  685. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  686. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  687. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  688. // 去除多余空白
  689. $content = preg_replace('/\s+/u', '', $content);
  690. // 截取 100 个字符
  691. $articleData['introduce'] = mb_substr($content, 0, 100);
  692. }
  693. if ($articleData['status'] == 0) {
  694. $this->sendMessage([
  695. 'talk_type' => 100,
  696. 'title' => $articleData['title'],
  697. 'content' => '提交了审核',
  698. 'messageType' => 2,
  699. ]);
  700. }
  701. $id = Article::where(['id' => $data['id']])->update($articleData);
  702. $articleDataContent = [
  703. 'content' => $data['content'],
  704. ];
  705. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  706. //处理投票
  707. $id = $data['id'];
  708. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  709. var_dump($suvey_array, 'suvey_array________delete');
  710. //处理投票
  711. if ($is_survey == 1) {
  712. //生成年月日时分秒+8位随机数
  713. $uuid = date('YmdHis') . rand(10000000, 99999999);
  714. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  715. var_dump($suveys_array, '---------------------1');
  716. $suvey_data = [];
  717. if (is_array($suveys_array)) {
  718. foreach ($suveys_array as $key => $value) {
  719. if ($value == '') {
  720. continue;
  721. }
  722. if (is_array($value)) {
  723. $suvey_data[] = [
  724. 'sur_id' => $uuid,
  725. 'art_id' => $id,
  726. 'website_id' => $website_id ?? 2,
  727. 'survey_name' => $survey_name,
  728. 'choice_name' => $value[1],
  729. 'is_other' => 1,
  730. 'other_id' => 0,
  731. 'results' => 0,
  732. ];
  733. } else {
  734. $suvey_data[] = [
  735. 'sur_id' => $uuid,
  736. 'art_id' => $id,
  737. 'website_id' => $website_id ?? 2,
  738. 'survey_name' => $survey_name,
  739. 'choice_name' => $value,
  740. 'is_other' => 0,
  741. 'other_id' => 0,
  742. 'results' => 0,
  743. ];
  744. }
  745. if (empty($suvey_data)) {
  746. throw new \Exception("投票数据为空");
  747. }
  748. }
  749. }
  750. $result = ArticleSurvey::insert($suvey_data);
  751. if (!$result) {
  752. throw new \Exception("投票失败");
  753. }
  754. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  755. if (!$result) {
  756. throw new \Exception("投票失败");
  757. }
  758. } else {
  759. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  760. }
  761. Db::commit();
  762. return Result::success([]);
  763. } catch (\Throwable $ex) {
  764. Db::rollBack();
  765. var_dump($ex->getMessage());
  766. return Result::error("更新失败" . $ex->getMessage(), 0);
  767. }
  768. }
  769. /**
  770. * 更新资讯状态
  771. * @param array $data
  772. * @return array
  773. */
  774. public function upArticleStatus(array $data): array
  775. {
  776. $articleData = Article::where(['id' => $data['id']])->first();
  777. //发送10次
  778. for ($i = 0; $i < 10; $i++) {
  779. $this->sendMessage([
  780. 'talk_type' => 100,
  781. 'title' => $i . $articleData['title'],
  782. 'content' => '审核通过',
  783. 'messageType' => 2,
  784. 'user_id' => $articleData['admin_user_id'],
  785. ]);
  786. }
  787. var_dump($data['status'], 'status');
  788. return Result::success();
  789. if ($data['status'] == 1) {
  790. $this->sendMessage([
  791. 'talk_type' => 101,
  792. 'title' => $articleData['title'],
  793. 'content' => '审核通过',
  794. 'messageType' => 2,
  795. 'user_id' => $articleData['admin_user_id'],
  796. ]);
  797. }
  798. if ($data['status'] == 2) {
  799. $this->sendMessage([
  800. 'talk_type' => 101,
  801. 'title' => $articleData['title'],
  802. 'content' => '审核拒绝',
  803. 'messageType' => 2,
  804. 'user_id' => $articleData['admin_user_id'],
  805. ]);
  806. }
  807. if ($data['status'] == 0) {
  808. $this->sendMessage([
  809. 'talk_type' => 100,
  810. 'title' => $articleData['title'],
  811. 'content' => '提交了审核',
  812. 'messageType' => 2,
  813. ]);
  814. }
  815. $result = Article::where(['id' => $data['id']])->update($data);
  816. if (isset($data['ignore_ids']) && !empty($data['ignore_ids'])) {
  817. //article_ignore 表插入数据 db操作
  818. //转成数组
  819. //删掉数据重新写入
  820. DB::table('article_ignore')->where('article_id', $data['id'])->delete();
  821. $website_ids = is_array($data['ignore_ids']) ? $data['ignore_ids'] : json_decode($data['ignore_ids'], true);
  822. $insert_data = [];
  823. foreach ($website_ids as $key => $value) {
  824. $insert_data[] = [
  825. 'article_id' => $data['id'],
  826. 'website_id' => $value,
  827. ];
  828. }
  829. DB::table('article_ignore')->insert($insert_data);
  830. }
  831. if ($result) {
  832. return Result::success();
  833. } else {
  834. return Result::error("更新状态失败", 0);
  835. }
  836. }
  837. /**
  838. * 获取新闻详情
  839. * @param array $data
  840. * @return array
  841. */
  842. public function getArticleInfo(array $data): array
  843. {
  844. $where = [
  845. 'article.id' => $data['id'],
  846. // 'article.status' => 1,
  847. ];
  848. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  849. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  850. $info = $result;
  851. // var_dump($info, 'info');
  852. $info['survey_array'] = $articleSurvey;
  853. if ($result) {
  854. return Result::success($info);
  855. } else {
  856. return Result::error("查询失败", 0);
  857. }
  858. }
  859. /**
  860. * 获取头条新闻
  861. * @param array $data
  862. * @return array
  863. */
  864. public function getWebsiteArticlett(array $data): array
  865. {
  866. $website_id = $data['website_id'];
  867. $website = Website::where('id', $data['website_id'])->first();
  868. if(empty($website)){
  869. return Result::error("网站不存在",0);
  870. }
  871. $categorys = $this->processArticlePro($website_id);
  872. $catiall = $categorys['catiall'];
  873. $categoryIds = $categorys['categoryIds'];
  874. $where = [
  875. 'status' => 1
  876. ];
  877. // $website_column = $website['column'];
  878. if(!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]'){
  879. $website_column = json_decode($website['website_column_arr_id'],true);
  880. }
  881. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  882. // return Result::success($diff_pid_categoryIds);
  883. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  884. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  885. }
  886. // $website_id = $data['website_id'];
  887. $month = date("Y-m-d H:i:s", strtotime("-30 day"));
  888. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  889. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  890. switch ($data['level']) {
  891. case 1:
  892. case 2:
  893. case 3:
  894. case 6: //1.头条资讯;2.轮播图;3.推荐图;6.今日热点
  895. $query = Article::where($where)
  896. ->where('level', 'like', '%' . $data['level'] . '%')
  897. ->orderBy('updated_at', 'desc');
  898. break;
  899. case 4: //最新资讯
  900. $query = Article::where($where)->orderBy('updated_at', 'desc');
  901. break;
  902. case 5: //资讯推荐
  903. $query = Article::where($where)
  904. ->where('updated_at', '>', $month);
  905. break;
  906. case 7: //资讯分类
  907. if (isset($data['id']) && !empty($data['id'])) {
  908. $keyword = Article::where('id', $data['id'])->value('keyword');
  909. $keywordArray = explode(',', $keyword);
  910. $whereL7 = [];
  911. foreach ($keywordArray as $k => $v) {
  912. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  913. }
  914. $query = Article::where($where)->where($whereL7)->orderBy('updated_at', 'desc');;
  915. break;
  916. } else {
  917. return Result::error("请输入资讯ID", 0);
  918. break;
  919. }
  920. default:
  921. break;
  922. }
  923. // $whereL7 = [];
  924. // if(isset($data['id']) && !empty($data['id'])){
  925. // $keyword = Article::where('id', $data['id'])->value('keyword');
  926. // $keywordArray = explode(',', $keyword);
  927. // foreach ($keywordArray as $k => $v) {
  928. // $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  929. // }
  930. // }
  931. // $query = Article::where($where)
  932. // ->when(isset($data['level']) && !empty($data['level']), function ($query) use ($data,$whereL7) {
  933. // if($data['level'] == 1 || $data['level'] == 2 || $data['level'] == 3 || $data['level'] == 6){
  934. // $query = $query->where('article.level','like','%'.$data['level'].'%')->orderBy('updated_at','desc');
  935. // }
  936. // if($data['level'] == 7){
  937. // $query = $query->where($whereL7)->orderBy('updated_at','desc');
  938. // }
  939. // if($data['level'] == 4){
  940. // $query = $query->inRandomOrder()
  941. // ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  942. // }
  943. // if($data['level'] == 5){
  944. // $query = $query->orderBy('updated_at','desc');
  945. // }
  946. // });
  947. if ($data['textnum'] > 0) {
  948. $query = clone $query;
  949. $result['text'] = $query
  950. ->whereIn('catid', $categoryIds)
  951. ->leftJoinSub(function ($query) use ($website_id) {
  952. $query->from('article_ignore')
  953. ->where('website_id', $website_id);
  954. }, 'article_ignore', function ($join) {
  955. $join->on('article_ignore.article_id', '=', 'article.id');
  956. })
  957. ->where(function ($query) use ($website_id) {
  958. $query->whereNull('article_ignore.article_id')
  959. ->orWhere('article_ignore.website_id', '!=', $website_id);
  960. })
  961. ->select(
  962. 'article.id',
  963. 'article.title',
  964. 'article.author',
  965. 'article.updated_at',
  966. 'article.introduce',
  967. 'article.islink',
  968. 'article.linkurl',
  969. 'article.copyfrom',
  970. 'article.cat_arr_id',
  971. 'article.catid',
  972. 'article.level'
  973. )
  974. ->offset($data['placeid'])
  975. ->limit($data['textnum'])
  976. ->get()->all();
  977. foreach ($result['text'] as $k => $v) {
  978. $result['text'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  979. $result['text'][$k]->alias = $catiall[$v->catid]['alias'];
  980. }
  981. }
  982. if ($data['imgnum'] > 0) {
  983. $query = clone $query;
  984. $result['img'] = $query
  985. ->whereIn('catid', $categoryIds)
  986. ->where('article.imgurl', '!=', '')
  987. ->select(
  988. 'article.id',
  989. 'article.title',
  990. 'article.imgurl',
  991. 'article.author',
  992. 'article.updated_at',
  993. 'article.introduce',
  994. 'article.islink',
  995. 'article.linkurl',
  996. 'article.copyfrom',
  997. 'article.cat_arr_id',
  998. 'article.catid',
  999. 'article.level'
  1000. )
  1001. ->offset($data['placeid'])
  1002. ->limit($data['imgnum'])
  1003. ->get()->all();
  1004. foreach ($result['img'] as $k => $v) {
  1005. $result['img'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1006. $result['img'][$k]->alias = $catiall[$v->catid]['alias'];
  1007. }
  1008. }
  1009. if (empty($result)) {
  1010. return Result::error("暂无相关资讯", 0);
  1011. }
  1012. return Result::success($result);
  1013. }
  1014. /**
  1015. * 获取模块新闻
  1016. * @param array $data
  1017. * @return array
  1018. */
  1019. public function getWebsiteModelArticles(array $data): array
  1020. {
  1021. $catid = $data['catid'];
  1022. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  1023. $category = $category->toArray();
  1024. if (!empty($category)) {
  1025. $where = [
  1026. 'status' => 1,
  1027. 'catid' => $catid,
  1028. ];
  1029. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  1030. // 1:文字新闻;2:轮播图;3:图文;
  1031. // 级别:0:未分类
  1032. // 3:推荐图片
  1033. if ($data['level'] == 1) {
  1034. $data['level'] = 0;
  1035. }
  1036. $result = Article::where($where)
  1037. ->where(function ($query) use ($data) {
  1038. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  1039. ->orWhereNull("level")
  1040. ->orWhereRaw("level = '[]'");
  1041. })
  1042. ->where(function ($query) use ($data) {
  1043. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1044. ->orWhereNull("ignore_ids");
  1045. })
  1046. ->orderBy("updated_at", "desc")
  1047. ->offset($placeid)
  1048. ->limit($data['pagesize'])
  1049. ->get();
  1050. if (empty($result)) {
  1051. return Result::error("此栏目暂无相关新闻", 0);
  1052. }
  1053. } else {
  1054. return Result::error("此网站暂无此栏目", 0);
  1055. }
  1056. return Result::success($result);
  1057. }
  1058. /**
  1059. *获取新闻列表
  1060. * @param array $data
  1061. * @return array
  1062. */
  1063. public function getWebsiteArticleList(array $data): array
  1064. {
  1065. // return Result::success($data);
  1066. $where[] = ['status', '=', 1];
  1067. $website_id = $data['website_id'];
  1068. $website = Website::where('id', $data['website_id'])->first();
  1069. if(empty($website)){
  1070. return Result::error("网站不存在",0);
  1071. }
  1072. // $website_column = $website['column'];
  1073. if(!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]'){
  1074. $website_column = json_decode($website['website_column_arr_id'],true);
  1075. }
  1076. $categorys = $this->processArticlePro($website_id);
  1077. $cat_1st_arr = $categorys['cat_1st_arr'];
  1078. $catiall = $categorys['catiall'];
  1079. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1080. // return Result::success($diff_pid_categoryIds);
  1081. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1082. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1083. }
  1084. if (isset($data['catid']) && !empty($data['catid'])) {
  1085. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  1086. if (empty($category)) {
  1087. return Result::error("此网站暂无此栏目", 0);
  1088. }
  1089. array_push($where, ['catid', '=', $data['catid']]);
  1090. }
  1091. // return Result::success($where);
  1092. $query = Article::where($where)
  1093. ->leftJoinSub(function ($query) use ($website_id) {
  1094. $query->from('article_ignore')
  1095. ->where('website_id', $website_id);
  1096. }, 'article_ignore', function ($join) {
  1097. $join->on('article_ignore.article_id', '=', 'article.id');
  1098. })
  1099. ->where(function ($query) use ($website_id) {
  1100. $query->whereNull('article_ignore.article_id')
  1101. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1102. })
  1103. ->select(
  1104. 'article.id',
  1105. 'article.title',
  1106. 'article.imgurl',
  1107. 'article.author',
  1108. 'article.updated_at',
  1109. 'article.introduce',
  1110. 'article.islink',
  1111. 'article.linkurl',
  1112. 'article.copyfrom',
  1113. 'article.cat_arr_id',
  1114. 'article.catid'
  1115. );
  1116. $count = $query->count();
  1117. $rep = $query->orderBy("updated_at", "desc")
  1118. ->offset(($data['page'] - 1) * $data['pageSize'])
  1119. ->limit($data['pageSize'])
  1120. ->get()->all();
  1121. $categorys = $this->processArticlePro($website_id);
  1122. $cat_1st_arr = $categorys['cat_1st_arr'];
  1123. $catiall = $categorys['catiall'];
  1124. // $web['website_id'] = $data['website_id'];
  1125. foreach ($rep as $k => $v) {
  1126. $rep[$k]->category_name = $catiall[$v->catid]['alias'];
  1127. $rep[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1128. }
  1129. // $rep = $this->processArticles($rep,$web);
  1130. $data = [
  1131. 'rows' => $rep,
  1132. 'count' => $count,
  1133. ];
  1134. if (empty($rep)) {
  1135. return Result::error("没有信息数据");
  1136. }
  1137. return Result::success($data);
  1138. }
  1139. /**
  1140. * 前端-获取新闻详情
  1141. * @param array $data
  1142. * @return array
  1143. */
  1144. public function selectWebsiteArticleInfo(array $data): array
  1145. {
  1146. $where = [
  1147. 'article.id' => $data['id'],
  1148. 'article.status' => 1,
  1149. ];
  1150. $result = Article::where($where)
  1151. ->leftJoin("article_data", "article.id", "article_data.article_id")
  1152. ->leftJoin("article_extend", "article_extend.article_id", "article.id")
  1153. ->where(function ($query) use ($data) {
  1154. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1155. ->orWhereNull("ignore_ids");
  1156. })
  1157. ->select(
  1158. 'article.*',
  1159. 'article_data.content',
  1160. 'article_data.article_id',
  1161. 'article_extend.website_url',
  1162. 'article_extend.email',
  1163. 'article_extend.contacts',
  1164. 'article_extend.contacts_mobile',
  1165. 'article_extend.contacts_address',
  1166. 'article_extend.zip_code',
  1167. 'article_extend.enterprise_name'
  1168. )
  1169. ->first();
  1170. if (empty($result)) {
  1171. return Result::error("暂无此新闻!", 0);
  1172. }
  1173. if (!empty($result['publiced_at'])) {
  1174. $result['updated_at'] = $result['publiced_at'];
  1175. }
  1176. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  1177. ->select('website_category.*', 'website.website_name', 'website.suffix')
  1178. ->where('website_category.website_id', $data['website_id'])
  1179. ->where(['website_category.category_id' => $result['catid']])
  1180. ->first();
  1181. if (empty($category)) {
  1182. return Result::error("查询失败", 0);
  1183. }
  1184. //手动推荐文章
  1185. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  1186. if (empty($commend_ids)) {
  1187. $commendArticle = [];
  1188. } else {
  1189. //去除不存在的文章ID
  1190. $commendArticle = Article::whereIn('article.id', $commend_ids)
  1191. ->leftjoin('website_category', 'website_category.category_id', '=', 'article.catid')
  1192. ->where('article.status', 1)
  1193. ->where('website_category.website_id', $data['website_id'])
  1194. ->select('article.id', 'article.cat_arr_id', 'article.title', 'article.catid', 'article.imgurl', 'article.hits', 'article.created_at', 'website_category.alias', 'website_category.alias_pinyin', 'website_category.website_id')
  1195. ->orderByRaw("FIELD(article.id, " . implode(',', $commend_ids) . ")")
  1196. // ->orderBy('article.updated_at', 'desc')
  1197. ->limit(5)
  1198. ->get();
  1199. //循环数组,取出cat_arr_id中的不重复值,再从website_category取出alias_pinyin,再将cat_arr_id的json转成路径/隔开
  1200. foreach ($commendArticle as $k => $v) {
  1201. $cat_arr_id = json_decode($v->cat_arr_id, true);
  1202. if (!empty($cat_arr_id) && is_array($cat_arr_id)) {
  1203. $cat_arr_id = array_unique($cat_arr_id);
  1204. // 从website_category取出alias_pinyin
  1205. $cat_arr = WebsiteCategory::where('website_id', $data['website_id'])
  1206. ->whereIn('category_id', $cat_arr_id)
  1207. ->pluck('alias_pinyin', 'category_id')
  1208. ->toArray();
  1209. // 将cat_arr_id的json转成路径/隔开
  1210. $path_parts = [];
  1211. foreach ($cat_arr_id as $cat_id) {
  1212. if (isset($cat_arr[$cat_id])) {
  1213. $path_parts[] = $cat_arr[$cat_id];
  1214. }
  1215. }
  1216. $v->alias_pinyin = implode('/', $path_parts);
  1217. } else {
  1218. $v->alias_pinyin = '';
  1219. }
  1220. }
  1221. }
  1222. $result['category_id'] = $category['category_id'];
  1223. $result['cat_name'] = $category['alias'];
  1224. $result['website_name'] = $category['website_name'] ?? "";
  1225. $result['suffix'] = $category['suffix'] ?? "";
  1226. $result['commendArticle'] = $commendArticle;
  1227. $result['commend_ids'] = $commend_ids;
  1228. return Result::success($result);
  1229. }
  1230. /**
  1231. * 前端-获取网站调查问卷
  1232. * @param array $data
  1233. * @return array
  1234. */
  1235. public function getWebsiteSurvey(array $data): array
  1236. {
  1237. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1238. $website = Website::where('id', $data['website_id'])->first();
  1239. if (empty($website)) {
  1240. return Result::error("暂无此网站", 0);
  1241. }
  1242. }
  1243. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1244. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1245. if (empty($article)) {
  1246. return Result::error("暂无此文章", 0);
  1247. }
  1248. // return Result::error($data,0);
  1249. $where['art_id'] = $data['art_id'];
  1250. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1251. } else {
  1252. $survey = Article::where(function ($query) {
  1253. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1254. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1255. })
  1256. ->where('status', 1)
  1257. ->where('is_survey', 1)
  1258. ->select('survey_id')
  1259. ->orderBy('updated_at', 'desc')
  1260. ->first();
  1261. if (empty($survey)) {
  1262. return Result::error("暂无调查问卷", 0);
  1263. }
  1264. $where['sur_id'] = $survey['survey_id'];
  1265. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1266. }
  1267. // return Result::success($where);
  1268. $result = ArticleSurvey::where($where)
  1269. ->where(function ($query) {
  1270. $query->where('is_other', 0)
  1271. ->orWhere(function ($subQuery) {
  1272. $subQuery->where('is_other', 1)
  1273. ->where('other_id', 0);
  1274. });
  1275. })
  1276. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1277. ->select('article_survey.*', 'article.survey_type')
  1278. ->get()->all();
  1279. if (empty($result)) {
  1280. return Result::error("此文章暂无调查问卷", 0);
  1281. }
  1282. return Result::success($result);
  1283. }
  1284. /**
  1285. * 前端-添加网站调查问卷选项
  1286. * @param array $data
  1287. * @return array
  1288. */
  1289. public function addWebsiteSurveyOption(array $data): array
  1290. {
  1291. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1292. $website = Website::where('id', $data['website_id'])->first();
  1293. if (empty($website)) {
  1294. return Result::error("暂无此网站", 0);
  1295. }
  1296. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1297. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1298. if (empty($survey)) {
  1299. return Result::error("此调查问卷不可添加选项", 0);
  1300. }
  1301. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1302. $choice = [
  1303. 'art_id' => $survey['art_id'],
  1304. 'website_id' => $data['website_id'],
  1305. 'survey_name' => $survey['survey_name'],
  1306. 'choice_name' => $data['choice_name'],
  1307. 'sur_id' => $survey['sur_id'],
  1308. 'is_other' => 1,
  1309. 'other_id' => $survey['id'],
  1310. ];
  1311. $result = ArticleSurvey::insertGetId($choice);
  1312. if (empty($result)) {
  1313. return Result::error("添加失败", 0);
  1314. }
  1315. return Result::success($result);
  1316. }
  1317. }
  1318. return Result::error("添加失败", 0);
  1319. }
  1320. return Result::error("添加失败", 0);
  1321. }
  1322. /**
  1323. * 前端-调查问卷投票
  1324. * @param array $data
  1325. * @return array
  1326. */
  1327. public function addWebsiteSurveyVote(array $data): array
  1328. {
  1329. // return Result::success($data);
  1330. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1331. $website = Website::where('id', $data['website_id'])->first();
  1332. if (empty($website)) {
  1333. return Result::error("暂无此网站", 0);
  1334. }
  1335. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1336. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1337. // return Result::success($survey);
  1338. if (empty($is_survey)) {
  1339. return Result::error("此调查问卷不存在", 0);
  1340. }
  1341. // return Result::success($survey);
  1342. // 调查问卷类型
  1343. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1344. //多选 若是json型则转化成数组类型
  1345. if (strpos($data['choice_id'], '[') === 0) {
  1346. $data['choice_id'] = json_decode($data['choice_id'], true);
  1347. } else {
  1348. // 单选 也转换成数组
  1349. $data['choice_id'] = [$data['choice_id']];
  1350. }
  1351. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1352. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1353. // ->where('website_id',$data['website_id'])
  1354. ->where('is_other', 1)
  1355. ->where('other_id', 0)
  1356. ->first();
  1357. if (!empty($other)) {
  1358. return Result::error("请选择已有的选项!", 0);
  1359. }
  1360. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1361. // ->where('website_id',$data['website_id'])
  1362. ->where('is_other', 1)
  1363. ->where('other_id', '!=', 0)
  1364. ->first();
  1365. // return Result::success($choice['other']);
  1366. $choice_id = $data['choice_id'];
  1367. if (!empty($choice['other'])) {
  1368. // array_push($data['choice_id'],$choice['other']['other_id']);
  1369. if (!empty($choice_id)) {
  1370. $key = array_search($choice['other']['id'], $choice_id);
  1371. if ($key !== false) {
  1372. unset($choice_id[$key]);
  1373. $choice_id = array_values($choice_id);
  1374. }
  1375. array_push($choice_id, $choice['other']['other_id']);
  1376. } else {
  1377. $choice_id[0] = $choice['other']['other_id'];
  1378. }
  1379. array_push($data['choice_id'], $choice['other']['other_id']);
  1380. }
  1381. // return Result::success($data);
  1382. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1383. // ->where('website_id',$data['website_id'])
  1384. ->increment('results', 1);
  1385. if (empty($choice)) {
  1386. return Result::error("请选择已有的选项!", 0);
  1387. }
  1388. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1389. // ->where('website_id',$data['website_id'])
  1390. ->where('other_id', 0)
  1391. ->get();
  1392. $survey['choice'] = $choice_id;
  1393. return Result::success($survey);
  1394. }
  1395. return Result::error("参数必填!");
  1396. }
  1397. return Result::error("此调查问卷不存在", 0);
  1398. }
  1399. return Result::error("参数必填!");
  1400. }
  1401. /**
  1402. * 后端-获取网站调查问卷列表
  1403. * @param array $data
  1404. * @return array
  1405. */
  1406. public function getSurveyList(array $data): array
  1407. {
  1408. $where = [];
  1409. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1410. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1411. }
  1412. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  1413. array_push($where, ['survey_type', '=', $data['survey_type']]);
  1414. }
  1415. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  1416. array_push($where, ['is_survey', '=', $data['is_survey']]);
  1417. }
  1418. // return Result::success($where);
  1419. if (!empty($where)) {
  1420. $query = Article::where($where)->where(function ($q) {
  1421. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1422. });
  1423. } else {
  1424. $query = Article::where(function ($q) {
  1425. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1426. });
  1427. }
  1428. $count = $query->count();
  1429. $survey = $query->orderByDesc('id')
  1430. ->limit($data['pageSize'])
  1431. ->offset(($data['page'] - 1) * $data['pageSize'])
  1432. ->get();
  1433. if (empty($survey->toArray())) {
  1434. return Result::error("暂无调查问卷!", 0);
  1435. }
  1436. $result = [
  1437. 'rows' => $survey,
  1438. 'count' => $count,
  1439. ];
  1440. return Result::success($result);
  1441. }
  1442. /**
  1443. * 后端-获取网站调查问卷详情
  1444. * @param array $data
  1445. * @return array
  1446. */
  1447. public function getSurveyInfo(array $data): array
  1448. {
  1449. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1450. $where = ['sur_id' => $data['sur_id']];
  1451. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1452. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1453. ->select('article_survey.*', 'article.survey_type')
  1454. ->get()->all();
  1455. if (empty($choose)) {
  1456. return Result::error("此调查问卷不存在", 0);
  1457. }
  1458. $resultsArray = array_column($choose, 'results');
  1459. $total = array_sum($resultsArray);
  1460. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1461. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1462. // $total = 0;
  1463. if (!empty($other)) {
  1464. $total = $total + $other['results'];
  1465. $other['choice_name'] = '(其他)';
  1466. if (!empty($others)) {
  1467. $other['hasChildren'] = true;
  1468. // array_push($other,['hasChildren','=',true]);
  1469. $other['children'] = $others;
  1470. $other_choices = [$other->toArray()];
  1471. $mer_choice = array_merge($choose, $other_choices);
  1472. $value_choice = array_values($mer_choice);
  1473. } else {
  1474. // return Result::error('1111');
  1475. $other_choices = [$other->toArray()];
  1476. $other_choices = array_merge($choose, $other_choices);
  1477. $value_choice = array_values($other_choices);
  1478. // return Result::success($result);
  1479. }
  1480. } else {
  1481. $value_choice = $choose;
  1482. }
  1483. $result = [
  1484. 'choose' => $value_choice,
  1485. 'total' => $total,
  1486. ];
  1487. }
  1488. return Result::success($result);
  1489. }
  1490. /**
  1491. * 前端-搜索新闻列表
  1492. * @param array $data
  1493. * @return array
  1494. */
  1495. public function selectWebsiteArticle(array $data): array
  1496. {
  1497. $website = Website::where('id', $data['website_id'])->first();
  1498. if(empty($website)){
  1499. return Result::error("网站不存在",0);
  1500. }
  1501. // $website_column = $website['column'];
  1502. if(!empty($website['website_column_arr_id']) && $website['website_column_arr_id'] != '[]'){
  1503. $website_column = json_decode($website['website_column_arr_id'],true);
  1504. }
  1505. $website_id = $data['website_id'];
  1506. $categorys = $this->processArticlePro($website_id);
  1507. $diff_pid_categoryIds = array_values($categorys['diff_pid_categoryIds']);
  1508. // return Result::success($diff_pid_categoryIds);
  1509. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1510. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1511. }
  1512. // return Result::success(reset($diff_pid_categoryIds) == 0);
  1513. // $cat_1st_arr = $categorys['cat_1st_arr'];
  1514. $catiall = $categorys['catiall'];
  1515. $categoryIds = $categorys['categoryIds'];
  1516. // return Result::success($categoryIds);
  1517. $query = Article::where('status', 1)
  1518. ->whereIn('catid', $categoryIds)
  1519. ->leftJoinSub(function ($query) use ($website_id) {
  1520. $query->from('article_ignore')
  1521. ->where('website_id', $website_id);
  1522. }, 'article_ignore', function ($join) {
  1523. $join->on('article_ignore.article_id', '=', 'article.id');
  1524. })
  1525. ->where(function ($query) use ($website_id) {
  1526. $query->whereNull('article_ignore.article_id')
  1527. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1528. });
  1529. // ->get()->all();
  1530. // return Result::success($query);
  1531. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1532. $query->whereRaw("JSON_CONTAINS(city_arr_id, '" . intval($data['cityid']) . "')");
  1533. }
  1534. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1535. $query->whereRaw("JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "')");
  1536. }
  1537. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1538. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  1539. }
  1540. // 计算总数
  1541. $count = $query->count();
  1542. // return Result::success($count);
  1543. // 分页查询
  1544. $articles = $query
  1545. ->select(
  1546. 'article.id',
  1547. 'article.title',
  1548. 'article.imgurl',
  1549. 'article.author',
  1550. 'article.updated_at',
  1551. 'article.introduce',
  1552. 'article.islink',
  1553. 'article.linkurl',
  1554. 'article.copyfrom',
  1555. 'article.cat_arr_id',
  1556. 'article.catid',
  1557. 'article.department_arr_id',
  1558. 'article.city_arr_id',
  1559. )
  1560. ->orderBy("updated_at", "desc")
  1561. ->offset(($data['page'] - 1) * $data['pageSize'])
  1562. ->limit($data['pageSize'])
  1563. ->get();
  1564. // return Result::success($articles);
  1565. foreach ($articles as $k => $v) {
  1566. $articles[$k]->category_name = $catiall[$v->catid]['alias'];
  1567. $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1568. }
  1569. if (empty($articles)) {
  1570. return Result::error("没有符合条件的资讯数据");
  1571. }
  1572. $result = [
  1573. 'rows' => $articles,
  1574. 'count' => $count,
  1575. ];
  1576. return Result::success($result);
  1577. }
  1578. /**
  1579. * 模块新闻加强版
  1580. * @param array $data
  1581. * @return array
  1582. */
  1583. public function getWebsiteCatidArticle(array $data): array
  1584. {
  1585. $where = [
  1586. 'website_category.category_id' => $data['catid'],
  1587. 'website_category.website_id' => $data['website_id'],
  1588. ];
  1589. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  1590. $child_catnum = $data['child_catnum'] ?? 1;
  1591. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  1592. $childCategoryIds = array_column($category['child'], 'category_id');
  1593. if (empty($childCategoryIds)) {
  1594. return Result::error("暂无子栏目", 0);
  1595. }
  1596. $imgArticles = [];
  1597. $textArticles = [];
  1598. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  1599. // 初始化子分类图片新闻和文字新闻数组
  1600. // 查询所有子级栏目的图文新闻
  1601. $imgArticles = Article::where('catid', $childCategoryIds[0])
  1602. ->where(function ($query) use ($data) {
  1603. $query->where(function ($subQuery) use ($data) {
  1604. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1605. })->orWhereNull("ignore_ids");
  1606. })
  1607. ->where('status', 1)
  1608. ->where('imgurl', '!=', '')
  1609. ->select('*')
  1610. ->orderBy('updated_at', 'desc')
  1611. ->limit($data['child_imgnum'])
  1612. ->get();
  1613. }
  1614. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  1615. // 查询所有子级栏目的文字新闻
  1616. $textArticles = Article::where('catid', $childCategoryIds[0])
  1617. ->where('status', 1)
  1618. ->where(function ($query) use ($data) {
  1619. $query->where(function ($subQuery) use ($data) {
  1620. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1621. })->orWhereNull("ignore_ids");
  1622. })
  1623. ->select('*')
  1624. ->orderBy('updated_at', 'desc')
  1625. ->limit($data['child_textnum'])
  1626. ->get();
  1627. }
  1628. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  1629. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  1630. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  1631. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  1632. return $child;
  1633. }, $category['child']);
  1634. }
  1635. // }
  1636. if (isset($data['img_num']) && !empty($data['img_num'])) {
  1637. $category['img'] = WebsiteCategory::where($where)
  1638. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1639. ->where('article.status', 1)
  1640. ->where('article.imgurl', '!=', '')
  1641. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1642. ->orderBy('article.updated_at', 'desc')
  1643. ->limit($data['img_num'])
  1644. ->get();
  1645. }
  1646. if (isset($data['text_num']) && !empty($data['text_num'])) {
  1647. $category['text'] = WebsiteCategory::where($where)
  1648. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1649. ->where('article.status', 1)
  1650. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1651. ->orderBy('article.updated_at', 'desc')
  1652. ->limit($data['text_num'])
  1653. ->get();
  1654. }
  1655. // $category = $category->get();
  1656. if (empty($category)) {
  1657. return Result::error("查询失败", 0);
  1658. }
  1659. return Result::success($category);
  1660. }
  1661. /**
  1662. * 模块新闻加强plus版
  1663. * @param array $data
  1664. * @return array
  1665. */
  1666. public function getWebsiteAllArticle(array $data): array
  1667. {
  1668. // return Result::success($data);
  1669. $time1 = microtime(true);
  1670. $wetbsite_id = $data['website_id'] ?? 2;
  1671. $data = json_decode($data['id'], true);
  1672. $website = Website::where('id', $wetbsite_id)->first();
  1673. if(empty($website)){
  1674. return Result::error("网站不存在",0);
  1675. }
  1676. // return Result::success($website);
  1677. $website_column = $website['website_column_arr_id'] ?? '[]';
  1678. $website_column = json_decode($website_column,true);
  1679. $categorys = $this->processArticlePro($wetbsite_id);
  1680. $cat_1st_arr = $categorys['cat_1st_arr'];
  1681. $catiall = $categorys['catiall'];
  1682. // return Result::success($catiall);
  1683. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  1684. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1685. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1686. }
  1687. $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
  1688. // return Result::success($categorys);
  1689. $parent_category = array_column($data, 'parent');
  1690. $parent_cat = [];
  1691. $child_category = array_column($data, 'child');
  1692. if (!empty($parent_category)) {
  1693. foreach ($parent_category as $key => $value) {
  1694. $arr = array_map('intval', explode(',', $value));
  1695. $parent_cat[$key] = $arr[0] ?? 0;
  1696. $parent_category = $arr[0] ?? 0;
  1697. $article_imgnum = $arr[1] ?? 0;
  1698. $article_textnum = $arr[2] ?? 0;
  1699. if ($parent_category != 0) {
  1700. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  1701. // return Result::success($category_arr);
  1702. if ($article_imgnum != 0) {
  1703. $img_article = Article::whereIn('catid', $category_arr)
  1704. ->where('status', 1)
  1705. ->where('imgurl', '!=', '')
  1706. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1707. $query->from('article_ignore')
  1708. ->where('website_id', $wetbsite_id);
  1709. }, 'article_ignore', function ($join) {
  1710. $join->on('article_ignore.article_id', '=', 'article.id');
  1711. })
  1712. ->where(function ($query) use ($wetbsite_id) {
  1713. $query->whereNull('article_ignore.article_id')
  1714. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1715. })
  1716. ->select('article.id', 'article.title', 'article.imgurl', 'article.author', 'article.updated_at', 'article.introduce', 'article.islink', 'article.linkurl', 'article.copyfrom', 'article.cat_arr_id', 'article.catid')
  1717. ->orderBy('updated_at', 'desc')
  1718. ->limit($article_imgnum)
  1719. ->get()->all();
  1720. foreach ($img_article as $k => $v) {
  1721. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1722. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1723. }
  1724. } else {
  1725. $img_article = [];
  1726. }
  1727. if ($article_textnum != 0) {
  1728. $text_article = Article::whereIn('catid', $category_arr)
  1729. ->where('status', 1)
  1730. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1731. $query->from('article_ignore')
  1732. ->where('website_id', $wetbsite_id);
  1733. }, 'article_ignore', function ($join) {
  1734. $join->on('article_ignore.article_id', '=', 'article.id');
  1735. })
  1736. ->where(function ($query) use ($wetbsite_id) {
  1737. $query->whereNull('article_ignore.article_id')
  1738. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1739. })
  1740. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1741. ->orderBy('updated_at', 'desc')
  1742. ->limit($article_textnum)
  1743. ->get()->all();
  1744. foreach ($text_article as $k => $v) {
  1745. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1746. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1747. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  1748. }
  1749. } else {
  1750. $text_article = [];
  1751. }
  1752. $catiall[$parent_category]['imgnum'] = $img_article;
  1753. $catiall[$parent_category]['textnum'] = $text_article;
  1754. $parent[$key] = $catiall[$parent_category];
  1755. } else {
  1756. $parent[$key] = '';
  1757. }
  1758. }
  1759. }
  1760. if (!empty($child_category)) {
  1761. foreach ($child_category as $key => $value) {
  1762. $arr = array_map('intval', explode(',', $value));
  1763. $parent_category = $parent_cat[$key];
  1764. $child_category = $arr[0] ?? 0;
  1765. $article_imgnum = $arr[1] ?? 0;
  1766. $article_textnum = $arr[2] ?? 0;
  1767. if ($child_category != 0) {
  1768. $all_childcat = $cat_1st_arr[$parent_category];
  1769. $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
  1770. // 从 $websiteInfoIndexed 中获取对应的数据
  1771. $info = $websiteInfoIndexed[$v];
  1772. // 返回一个包含所需信息的数组
  1773. return [
  1774. 'alias' => $info->alias,
  1775. 'category_id' => $info->category_id,
  1776. 'aLIas_pinyin' => $info->aLIas_pinyin,
  1777. 'pid' => $info->pid,
  1778. 'type' => $info->type,
  1779. 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
  1780. 'pinyin' => $info->pinyin,
  1781. ];
  1782. }, $all_childcat);
  1783. if ($article_imgnum != 0) {
  1784. $img_article = Article::where('catid', $child_category)
  1785. ->where('status', 1)
  1786. ->where('imgurl', '!=', '')
  1787. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1788. $query->from('article_ignore')
  1789. ->where('website_id', $wetbsite_id);
  1790. }, 'article_ignore', function ($join) {
  1791. $join->on('article_ignore.article_id', '=', 'article.id');
  1792. })
  1793. ->where(function ($query) use ($wetbsite_id) {
  1794. $query->whereNull('article_ignore.article_id')
  1795. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1796. })
  1797. ->select('id', 'title', 'imgurl', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1798. ->orderBy('updated_at', 'desc')
  1799. ->limit($article_imgnum)
  1800. ->get()->all();
  1801. foreach ($img_article as $k => $v) {
  1802. // var_dump($v);
  1803. // var_dump($k);
  1804. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1805. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1806. }
  1807. } else {
  1808. $img_article = [];
  1809. }
  1810. if ($article_textnum != 0) {
  1811. $text_article = Article::where('catid', $child_category)
  1812. ->where('status', 1)
  1813. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1814. $query->from('article_ignore')
  1815. ->where('website_id', $wetbsite_id);
  1816. }, 'article_ignore', function ($join) {
  1817. $join->on('article_ignore.article_id', '=', 'article.id');
  1818. })
  1819. ->where(function ($query) use ($wetbsite_id) {
  1820. $query->whereNull('article_ignore.article_id')
  1821. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1822. })
  1823. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1824. ->orderBy('updated_at', 'desc')
  1825. ->limit($article_textnum)
  1826. ->get()->all();
  1827. foreach ($text_article as $k => $v) {
  1828. // var_dump($v);
  1829. // var_dump($k);
  1830. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1831. // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1832. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1833. }
  1834. } else {
  1835. $text_article = [];
  1836. }
  1837. $catiall[$child_category]['all_childcat'] = $processedChildCat;
  1838. $catiall[$child_category]['imgnum'] = $img_article;
  1839. $catiall[$child_category]['textnum'] = $text_article;
  1840. $child[$key] = $catiall[$child_category];
  1841. // var_dump($pids);
  1842. } else {
  1843. $child[$key] = '';
  1844. }
  1845. }
  1846. }
  1847. foreach ($parent as $key => $value) {
  1848. $result[$key] = $value;
  1849. if (!empty($child[$key])) {
  1850. // var_dump($child[$key]);
  1851. $result[$key]['child'] = $child[$key];
  1852. // $value[$key]['child'] = $child[$key];
  1853. } else {
  1854. $result[$key]['child'] = [
  1855. "alias" => null,
  1856. "category_id" => null,
  1857. "type" => null,
  1858. "pinyin" => null,
  1859. "all_childcat" => [],
  1860. "imgnum" => [],
  1861. "textnum" => []
  1862. ];
  1863. }
  1864. }
  1865. return Result::success($result);
  1866. }
  1867. /**
  1868. * 辅助方法:获取文章列表
  1869. */
  1870. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  1871. {
  1872. sleep(1);
  1873. $query = Article::where('article.status', 1)
  1874. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  1875. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  1876. ->where(function ($query) use ($website) {
  1877. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  1878. })
  1879. ->leftJoin('website_category', function ($join) use ($website) {
  1880. $join->on('article.catid', '=', 'website_category.category_id')
  1881. ->where('website_category.website_id', '=', $website['website_id']);
  1882. })
  1883. ->select(
  1884. 'article.id',
  1885. 'article.title',
  1886. 'article.imgurl',
  1887. 'article.author',
  1888. 'article.updated_at',
  1889. 'article.introduce',
  1890. 'article.islink',
  1891. 'article.linkurl',
  1892. 'article.copyfrom',
  1893. 'article.cat_arr_id',
  1894. 'article.catid',
  1895. 'website_category.alias as category_name'
  1896. )
  1897. ->orderBy('updated_at', 'desc')
  1898. ->limit($limit);
  1899. // 如果是图片文章,添加图片URL条件
  1900. if ($isImageArticle) {
  1901. $query->where('imgurl', '!=', '');
  1902. } else {
  1903. // 文字文章不需要imgurl字段
  1904. $query->addSelect('article.introduce');
  1905. }
  1906. $articles = $query->get();
  1907. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  1908. }
  1909. /**
  1910. * 乡村网-获取特殊新闻模块
  1911. * @param array $data
  1912. * @return array
  1913. */
  1914. public function getWebsiteArticles(array $data): array
  1915. {
  1916. $website_id = $data['website_id'];
  1917. $website = Website::where('id', $website_id)->first();
  1918. if(empty($website)){
  1919. return Result::error("网站不存在",0);
  1920. }
  1921. // return Result::success($website);
  1922. $website_column = $website['website_column_arr_id'] ?? '[]';
  1923. $website_column = json_decode($website_column, true);
  1924. $catids = json_decode($data['id'], true);
  1925. $parent_category = array_column($catids, 'parent');
  1926. if(!empty($parent_category) && is_array($parent_category)) {
  1927. $categorys = $this->processArticlePro($website_id);
  1928. $diff_pid_categoryIds = $categorys['diff_pid_categoryIds'];
  1929. if (in_array(3, $website_column) && !empty($diff_pid_categoryIds)) {
  1930. return Result::error("此为核心站,有父级导航" . implode(',', $diff_pid_categoryIds) . "未选择而选择了此子级!", 0);
  1931. }
  1932. $catiall = $categorys['catiall'];
  1933. $cat_1st_arr = $categorys['cat_1st_arr'];
  1934. // return Result::success($categorys);
  1935. foreach ($parent_category as $key => $value) {
  1936. $arr = array_map('intval', explode(',', $value));
  1937. $parent_category = $arr[0] ?? 0;
  1938. $article_imgnum = $arr[1] ?? 0;
  1939. $article_textnum = $arr[2] ?? 0;
  1940. if ($parent_category != 0) {
  1941. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  1942. // return Result::success($category_arr);
  1943. if ($article_imgnum != 0) {
  1944. $img_article = Article::whereIn('catid', $category_arr)
  1945. ->where('status', 1)
  1946. ->where('imgurl', '!=', '')
  1947. ->leftJoinSub(function ($query) use ($website_id) {
  1948. $query->from('article_ignore')
  1949. ->where('website_id', $website_id);
  1950. }, 'article_ignore', function ($join) {
  1951. $join->on('article_ignore.article_id', '=', 'article.id');
  1952. })
  1953. ->where(function ($query) use ($website_id) {
  1954. $query->whereNull('article_ignore.article_id')
  1955. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1956. })
  1957. ->select(
  1958. 'id',
  1959. 'title',
  1960. 'imgurl',
  1961. 'author',
  1962. 'updated_at',
  1963. 'introduce',
  1964. 'islink',
  1965. 'linkurl',
  1966. 'copyfrom',
  1967. 'cat_arr_id',
  1968. 'catid as category_id'
  1969. )
  1970. ->orderBy('updated_at', 'desc')
  1971. ->limit($article_imgnum)
  1972. ->get()->all();
  1973. foreach ($img_article as $k => $v) {
  1974. $img_article[$k]->alias = $catiall[$v->category_id]['alias'];
  1975. // return Result::success($v);
  1976. $img_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  1977. }
  1978. } else {
  1979. $img_article = [];
  1980. }
  1981. if ($article_textnum != 0) {
  1982. $text_article = Article::whereIn('catid', $category_arr)
  1983. ->where('status', 1)
  1984. ->leftJoinSub(function ($query) use ($website_id) {
  1985. $query->from('article_ignore')
  1986. ->where('website_id', $website_id);
  1987. }, 'article_ignore', function ($join) {
  1988. $join->on('article_ignore.article_id', '=', 'article.id');
  1989. })
  1990. ->where(function ($query) use ($website_id) {
  1991. $query->whereNull('article_ignore.article_id')
  1992. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1993. })
  1994. ->select(
  1995. 'id',
  1996. 'title',
  1997. 'author',
  1998. 'updated_at',
  1999. 'introduce',
  2000. 'islink',
  2001. 'linkurl',
  2002. 'copyfrom',
  2003. 'cat_arr_id',
  2004. 'catid as category_id'
  2005. )
  2006. ->orderBy('updated_at', 'desc')
  2007. ->limit($article_textnum)
  2008. ->get()->all();
  2009. foreach ($text_article as $k => $v) {
  2010. $text_article[$k]->alias = $catiall[$v->category_id]['alias'];
  2011. $text_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  2012. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  2013. }
  2014. } else {
  2015. $text_article = [];
  2016. }
  2017. $catiall[$parent_category]['imgnum'] = $img_article ?? [];
  2018. $catiall[$parent_category]['textnum'] = $text_article ?? [];
  2019. $parent[$key] = $catiall[$parent_category];
  2020. } else {
  2021. $parent[$key] = [];
  2022. }
  2023. }
  2024. }
  2025. return Result::success($parent);
  2026. }
  2027. // 封装处理商品的路由问题
  2028. function processGoods($goods, $data)
  2029. {
  2030. return $goods->map(function ($good) use ($data) {
  2031. $catid = $good->catid ?? 0;
  2032. // $pinyin = '';
  2033. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2034. if (!empty($category->pid) && $category->pid != 0) {
  2035. $level = json_decode($category->category_arr_id, true);
  2036. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  2037. ->whereIn('category_id', $level)
  2038. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2039. ->get(['aLIas_pinyin'])
  2040. ->pluck('aLIas_pinyin')
  2041. ->implode('/');
  2042. } else {
  2043. $pinyin = $category->aLIas_pinyin ?? '';
  2044. }
  2045. if (isset($good->city_id) && !empty($good->city_id)) {
  2046. $city = District::where('id', $good->city_id)->first(['name']);
  2047. $good->city_name = $city->name ?? '';
  2048. }
  2049. // 解析imgurl JSON并取第一条数据
  2050. $imgUrls = json_decode($good->imgurl, true);
  2051. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  2052. $good->pinyin = $pinyin;
  2053. return $good;
  2054. });
  2055. }
  2056. /**
  2057. * 获取商城首页-根据栏目id
  2058. * @param array $data
  2059. * @return array
  2060. * */
  2061. function getWebsiteCatidshop(array $data): array
  2062. {
  2063. $input['catid'] = $data['catid'];
  2064. $input['website_id'] = $data['website_id'];
  2065. $data = json_decode($input['catid'] ?? '', true) ?? [];
  2066. $result = array_map(function ($item) use ($input) {
  2067. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  2068. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  2069. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  2070. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  2071. if (empty($category) || $category->type != 2) {
  2072. return Result::error("暂无此栏目", 0);
  2073. } else {
  2074. $website['website_id'] = $input['website_id'];
  2075. $goods = Good::where('good.status', 2)
  2076. ->where('good.website_id', $website['website_id'])
  2077. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  2078. ->select(
  2079. 'good.id',
  2080. 'good.name',
  2081. 'good.imgurl',
  2082. 'good.description',
  2083. 'good.updated_at',
  2084. 'good.catid',
  2085. 'good.type_id',
  2086. 'good.price',
  2087. 'good.com',
  2088. 'good.level',
  2089. 'good.unit'
  2090. )
  2091. ->orderBy('updated_at', 'desc')
  2092. ->offset($goodStart)
  2093. ->limit($goodNum);
  2094. $all_goods = $goods->get();
  2095. $all_goods = $this->processGoods($all_goods, $website);
  2096. }
  2097. return $all_goods ?? [];
  2098. }
  2099. }, $data);
  2100. return Result::success($result);
  2101. }
  2102. /**
  2103. * 获取商品模块
  2104. * @param array $data
  2105. * @return array
  2106. * */
  2107. public function getWebsiteshop(array $data): array
  2108. {
  2109. $input['id'] = $data['id'];
  2110. $input['website_id'] = $data['website_id'];
  2111. $catid = $data['catid'];
  2112. $data = json_decode($input['id'] ?? '', true) ?? [];
  2113. $result['goods'] = array_map(function ($item) use ($input) {
  2114. // 检查parent元素是否存在且不是undefined
  2115. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  2116. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  2117. $website = $input['website_id'];
  2118. $query = Good::where('good.status', 2)
  2119. ->where('good.website_id', $website);
  2120. switch ($Levelid) {
  2121. case 1:
  2122. case 2:
  2123. case 3:
  2124. $goods = $query->where(function ($q) use ($Levelid) {
  2125. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  2126. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  2127. });
  2128. break;
  2129. case 4:
  2130. $goods = $query;
  2131. break;
  2132. case 5:
  2133. $goods = $query->where('type_id', 1);
  2134. break;
  2135. case 6:
  2136. $goods = $query->where('type_id', 2);
  2137. break;
  2138. default:
  2139. return [];
  2140. }
  2141. $all_goods = $goods
  2142. ->select(
  2143. 'good.id',
  2144. 'good.name',
  2145. 'good.imgurl',
  2146. 'good.description',
  2147. 'good.updated_at',
  2148. 'good.catid',
  2149. 'good.type_id',
  2150. 'good.price',
  2151. 'good.level',
  2152. 'good.website_id'
  2153. )
  2154. ->orderBy('updated_at', 'desc')
  2155. ->offset($goodStart)
  2156. ->limit($goodNum)
  2157. ->get();
  2158. $web['website_id'] = $website;
  2159. $all_goods = $this->processGoods($all_goods, $web);
  2160. }
  2161. return $all_goods;
  2162. }, $data);
  2163. $website = $input['website_id'];
  2164. $result['article'] = Article::where(function ($query) use ($website) {
  2165. $query->where(function ($subQuery) use ($website) {
  2166. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  2167. })->orWhereNull("ignore_ids");
  2168. })
  2169. ->where('catid', $catid)
  2170. ->where('article.status', 1)
  2171. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  2172. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  2173. ->orderBy('article.updated_at', 'desc')
  2174. ->first();
  2175. return Result::success($result);
  2176. }
  2177. /**
  2178. * 获取商品分类
  2179. * @param array $data
  2180. * @return array
  2181. * */
  2182. public function getWebsiteshopCat(array $data): array
  2183. {
  2184. $website = $data['website_id'];
  2185. $category = WebsiteCategory::where('website_id', $website)
  2186. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  2187. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  2188. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  2189. ->orderBy('sort')
  2190. ->get();
  2191. $cat = $category->map(function ($item) use ($website) {
  2192. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  2193. $pid = $item->pid ?? 0;
  2194. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  2195. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  2196. ->where('website_id', $website)
  2197. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  2198. ->get(['aLIas_pinyin'])
  2199. ->pluck('aLIas_pinyin')
  2200. ->implode('/');
  2201. } else {
  2202. $pinyin = $item->aLIas_pinyin ?? '';
  2203. }
  2204. $item->pinyin = $pinyin;
  2205. });
  2206. if (empty($category)) {
  2207. return Result::error("栏目查询失败", 0);
  2208. }
  2209. $cat_tree = Result::buildMenuTree($category);
  2210. $web['website_id'] = $website;
  2211. $goods = Good::where('website_id', $website)
  2212. ->where('status', 2)
  2213. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  2214. ->latest('updated_at')
  2215. ->offset(($data['page'] - 1) * $data['pageSize'])
  2216. ->limit($data['pageSize'])
  2217. ->get();
  2218. if (!empty($goods)) {
  2219. if ($goods->count() > 1 && !empty($goods)) {
  2220. $goods = $this->processGoods($goods, $web);
  2221. }
  2222. } else {
  2223. $goods = [];
  2224. }
  2225. $result = [
  2226. 'category' => $cat_tree,
  2227. 'goods' => $goods,
  2228. ];
  2229. // $resul['goods'] = $goods;
  2230. if (empty($result)) {
  2231. return Result::error("查询失败", 0);
  2232. }
  2233. return Result::success($result);
  2234. }
  2235. /*
  2236. * 获取商品列表
  2237. * @param array $data
  2238. * @return array
  2239. * */
  2240. public function getWebsiteshopList(array $data): array
  2241. {
  2242. // return Result::success($data);
  2243. $where = [
  2244. 'status' => 2,
  2245. 'website_id' => $data['website_id'],
  2246. ];
  2247. // if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  2248. // return Result::error("查询失败", 0);
  2249. // }
  2250. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  2251. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  2252. $data['catid'] = $category->category_id ?? 0;
  2253. }
  2254. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2255. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  2256. }
  2257. if (isset($data['type_id']) && !empty($data['type_id'])) {
  2258. array_push($where, ['type_id', $data['type_id']]);
  2259. }
  2260. $query = Good::where($where)
  2261. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2262. $query->where(function ($q) use ($data) {
  2263. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  2264. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  2265. });
  2266. })
  2267. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2268. $query->where(function ($q) use ($data) {
  2269. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  2270. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  2271. });
  2272. })
  2273. ->select(
  2274. 'good.id',
  2275. 'good.name',
  2276. 'good.imgurl',
  2277. 'good.description',
  2278. 'good.updated_at',
  2279. 'good.com',
  2280. 'good.catid',
  2281. 'good.type_id',
  2282. 'good.website_id',
  2283. 'good.cat_arr_id',
  2284. 'good.created_at',
  2285. 'good.city_id'
  2286. )
  2287. ->latest('updated_at');
  2288. if (isset($data['ismix']) && $data['ismix'] == 1) {
  2289. $result['count'] = $query->clone()->count();
  2290. $result['goods'] = $this->processGoods(
  2291. $query->clone()
  2292. ->offset(($data['page'] - 1) * $data['pageSize'])
  2293. ->limit($data['pageSize'])
  2294. ->get(),
  2295. $data
  2296. );
  2297. } else {
  2298. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  2299. // 获取 type_id 为 1 的数据
  2300. $result['type1'] = $this->processGoods(
  2301. $query->clone()
  2302. ->where('type_id', 1)
  2303. ->offset(($data['page'] - 1) * $data['pageSize'])
  2304. ->limit($data['pageSize'])
  2305. ->get(),
  2306. $data
  2307. );
  2308. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2309. // 获取 type_id 为 2 的数据
  2310. $result['type2'] = $this->processGoods(
  2311. $query->clone()
  2312. ->where('type_id', 2)
  2313. ->offset(($data['page'] - 1) * $data['pageSize'])
  2314. ->limit($data['pageSize'])
  2315. ->get(),
  2316. $data
  2317. );
  2318. }
  2319. if (empty($result)) {
  2320. return Result::error("查询失败", 0);
  2321. }
  2322. return Result::success($result);
  2323. }
  2324. /**
  2325. * 获取商品详情
  2326. * @param array $data
  2327. * @return array
  2328. * */
  2329. public function getWebsiteshopInfo(array $data): array
  2330. {
  2331. $where = [
  2332. 'good.status' => 2,
  2333. 'good.website_id' => $data['website_id'],
  2334. 'good.id' => $data['id'],
  2335. ];
  2336. $goods = Good::where($where)
  2337. ->where('good.id', $data['id'])
  2338. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2339. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2340. ->first();
  2341. if (empty($goods)) {
  2342. return Result::error("查询失败", 0);
  2343. }
  2344. $goods->imgurl = json_decode($goods->imgurl, true);
  2345. return Result::success($goods);
  2346. }
  2347. /**
  2348. * plus pro 处理文章路由问题
  2349. */
  2350. function processArticlePro($website_id)
  2351. {
  2352. // $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2353. // // $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2354. // // 取出category_id 对应的aLIas_pinyin
  2355. // $categoryIds = array_column($categorys, 'category_id');
  2356. // $categoryPIds = array_column($categorys, 'pid');
  2357. // $aliasPinyins = array_column($categorys, 'path');
  2358. // $alias = array_column($categorys, 'alias');
  2359. // $cat_arr = array_combine($categoryIds, $aliasPinyins);
  2360. // $cat_alias_arr = array_combine($categoryIds, $categoryPIds);
  2361. // // return Result::success($cat_arr);
  2362. // // $catiall = [];
  2363. // //一级所有子级的记录
  2364. // $cat_alias_arr = array_combine($categoryIds, $alias);
  2365. // return [
  2366. // 'cat_1st_arr' => $cat_alias_arr,
  2367. // 'catiall' => $cat_arr,
  2368. // // 'websiteInfoIndexed' => $websiteInfoIndexed,
  2369. // 'categoryIds' => $categoryIds,
  2370. // ];
  2371. $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2372. $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2373. // 取出category_id 对应的aLIas_pinyin
  2374. $categoryIds = array_column($categorys, 'category_id');
  2375. $categoryPIds = array_values(array_unique(array_filter(array_column($categorys, 'pid'), function($pid) {
  2376. return $pid != 0;
  2377. })));
  2378. $category_path = array_column($categorys, 'path');
  2379. $cat_arr = array_combine($categoryIds, $category_path);
  2380. // return Result::success(array_diff($categoryIds, $categoryPIds));
  2381. $catiall = [];
  2382. //一级所有子级的记录
  2383. $cat_1st_arr = [];
  2384. foreach ($categorys as $key => $value) {
  2385. // $category_arr_id = json_decode($value->category_arr_id);
  2386. // $pinyin_str = '';
  2387. // // 算出一级 并且算出子级
  2388. if ($value->pid != 0 && in_array($value->pid,$categoryIds)) {
  2389. $cat_1st_arr[$value->pid][] = $value->category_id;
  2390. }
  2391. // foreach ($category_arr_id as $k => $v) {
  2392. // $pinyin_str .= $cat_arr[$v] . '/';
  2393. // }
  2394. // $pinyin_str = rtrim($pinyin_str, '/');
  2395. $catiall[$value->category_id]['alias'] = $value->alias;
  2396. $catiall[$value->category_id]['category_id'] = $value->category_id;
  2397. $catiall[$value->category_id]['type'] = $value->type;
  2398. $catiall[$value->category_id]['pinyin'] = $cat_arr[$value->category_id];
  2399. $websiteInfoIndexed[$value->category_id]->pinyin = $cat_arr[$value->category_id];
  2400. }
  2401. return [
  2402. 'cat_1st_arr' => $cat_1st_arr,
  2403. 'catiall' => $catiall,
  2404. 'websiteInfoIndexed' => $websiteInfoIndexed,
  2405. 'categoryIds' => $categoryIds,
  2406. 'diff_pid_categoryIds' => array_diff($categoryPIds,$categoryIds),
  2407. 'categoryPIds' => $categoryPIds,
  2408. ];
  2409. }
  2410. /**
  2411. * 封装处理文章的路由问题
  2412. * */
  2413. function processArticles($articles, $data)
  2414. {
  2415. // 检查 $articles 是否为数组或可迭代对象
  2416. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  2417. return $articles->map(function ($article) use ($data) {
  2418. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  2419. $catid = $article->cat_arr_id ?? '';
  2420. }
  2421. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  2422. $catid = $article->category_arr_id ?? '';
  2423. }
  2424. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  2425. $level = json_decode($catid, true);
  2426. if (!is_array($level)) {
  2427. return $article;
  2428. } else {
  2429. $level = array_map('intval', $level);
  2430. }
  2431. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2432. ->where($data)
  2433. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2434. ->pluck('aLIas_pinyin')
  2435. ->implode('/');
  2436. $article->pinyin = $pinyin ?? '';
  2437. return $article;
  2438. });
  2439. } else {
  2440. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2441. $catid = $articles->cat_arr_id ?? '';
  2442. $level = json_decode($catid, true);
  2443. if (!is_array($level)) {
  2444. return $articles;
  2445. } else {
  2446. $level = array_map('intval', $level);
  2447. }
  2448. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2449. ->where($data)
  2450. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2451. ->pluck('aLIas_pinyin')
  2452. ->implode('/');
  2453. $articles->pinyin = $pinyin ?? '';
  2454. return $articles;
  2455. }
  2456. }
  2457. // 封装处理由问题
  2458. function processJob($job, $data)
  2459. {
  2460. return $job->map(function ($job) use ($data) {
  2461. $category = $job->cat_arr_id ?? '';
  2462. $cityid = $job->city_arr_id ?? '';
  2463. $city = json_decode($cityid, true);
  2464. $pinyin = '';
  2465. $level = json_decode($category, true);
  2466. // 路由
  2467. if (!empty($level) && is_array($level)) {
  2468. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2469. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2470. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2471. ->get(['aLIas_pinyin'])
  2472. ->pluck('aLIas_pinyin')
  2473. ->implode('/');
  2474. if (empty($pinyin)) {
  2475. $pinyin = $pinyin->aLIas_pinyin ?? '';
  2476. }
  2477. $job->pinyin = $pinyin;
  2478. }
  2479. // 取职位-城市 市??省
  2480. if (!empty($city) && is_array($city)) {
  2481. if (isset($city[1]) && !empty($city[1])) {
  2482. $city = District::where('id', $city[1])->first(['name']);
  2483. $job->city_name = $city->name ?? '';
  2484. } else if (isset($city[0]) && !empty($city[0])) {
  2485. $city = District::where('id', $city[0])->first(['name']);
  2486. $job->city_name = $city->name ?? '';
  2487. } else {
  2488. $job->city_name = '全国';
  2489. }
  2490. }
  2491. // 获取简历最后一级地区
  2492. if (isset($job->city_id) && !empty($job->city_id)) {
  2493. $city = District::where('id', $job->city_id)->first(['name']);
  2494. $job->hunt_cityname = $city->name ?? '';
  2495. }
  2496. // 组合详细地址
  2497. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  2498. $address_id = json_decode($job->address_arr_id, true) ?? [];
  2499. if (is_array($address_id) && !empty($address_id)) {
  2500. $address = District::whereIn('id', $address_id)
  2501. ->orderBy('level', 'asc')
  2502. ->get(['name'])
  2503. ->pluck('name')
  2504. ->implode('');
  2505. // $job->address_name = $address ?? '';
  2506. $job->address_name = ($address ?? '') . ($job->address ?? '');
  2507. }
  2508. }
  2509. // 取行业
  2510. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  2511. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  2512. if (!empty($job->industry)) {
  2513. $query->where('hyid', $job->industry);
  2514. } else if (!empty($job->hy_id)) {
  2515. $query->where('hyid', $job->hy_id);
  2516. } else if (!empty($job->company_hy_id)) {
  2517. $query->where('hyid', $job->company_hy_id);
  2518. } else {
  2519. $query->where('hyid', $job->job_industry);
  2520. }
  2521. })->first(['hyname']);
  2522. $job->hy_name = $hy_name->hyname ?? '';
  2523. }
  2524. // 取职位类别
  2525. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  2526. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  2527. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  2528. $job->zw_name = $zw_name->zwname ?? '';
  2529. }
  2530. // 取具体职位
  2531. if ((isset($job->jtzw_id) && !empty($job->jtzw_id)) || (isset($job->job_name_get) && !empty($job->job_name_get)) || (isset($job->job_name) && !empty($job->job_name))) {
  2532. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  2533. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  2534. $job->jtzw_name = $jtzw_name->zwname ?? '';
  2535. }
  2536. // 取工作经验
  2537. if (isset($job->experience) && !empty($job->experience)) {
  2538. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  2539. $job->experience_name = $experience->ename ?? '';
  2540. }
  2541. // 取学历
  2542. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  2543. $education = $job->educational ?? $job->school_education;
  2544. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  2545. $job->education_name = $education->ename ?? '';
  2546. }
  2547. // 语言
  2548. if (isset($job->language) && !empty($job->language)) {
  2549. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  2550. $job->language_name = $language->ename ?? '';
  2551. }
  2552. // 薪资
  2553. if (isset($job->salary) && !empty($job->salary)) {
  2554. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  2555. $job->salary_name = $salary->ename ?? '';
  2556. }
  2557. // 职位性质
  2558. if (isset($job->nature_id) && !empty($job->nature_id)) {
  2559. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  2560. $job->job_nature_name = $job_nature->ename ?? '';
  2561. }
  2562. // 公司规模
  2563. if (isset($job->company_size) && !empty($job->company_size)) {
  2564. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  2565. $job->company_size_name = $company_size->ename ?? '';
  2566. }
  2567. // 公司性质
  2568. if (isset($job->company_nature) && !empty($job->company_nature)) {
  2569. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  2570. $job->company_nature_name = $company_nature->nature_name ?? '';
  2571. }
  2572. // $job->pinyin = $pinyin;
  2573. return $job;
  2574. });
  2575. }
  2576. /**
  2577. * 获取书籍模块
  2578. * @param array $data
  2579. * @return array
  2580. * */
  2581. public function getWebsiteBook(array $data): array
  2582. {
  2583. $input['id'] = $data['id'];
  2584. $input['website_id'] = $data['website_id'];
  2585. // 将 JSON 字符串转换为 PHP 数组
  2586. $data = json_decode($input['id'], true);
  2587. // 使用 array_map 处理每个元素
  2588. $result = array_map(function ($item) use ($input) {
  2589. // 检查parent元素是否存在且不是undefined
  2590. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  2591. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2592. $website = [
  2593. 'website_id' => $input['website_id'],
  2594. ];
  2595. // 查询栏目名称
  2596. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2597. if (empty($category)) {
  2598. $parent_alias = '';
  2599. $parent_pinyin = null;
  2600. $imgBooks = [];
  2601. $textBooks = [];
  2602. } else {
  2603. $parent_alias = $category->alias ?? '';
  2604. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  2605. // 查找子分类ID数组
  2606. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  2607. array_push($childCategoryIds, $parentCatId);
  2608. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  2609. if ($parentImgNum != 0) {
  2610. // 查询图片新闻
  2611. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  2612. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2613. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2614. })
  2615. ->where('book.status', 2)
  2616. ->where('book.img_url', '!=', '')
  2617. ->leftJoin('website_category', function ($join) use ($website) {
  2618. $join->on('book.cat_id', '=', 'website_category.category_id')
  2619. ->where('website_category.website_id', '=', $website['website_id']);
  2620. })
  2621. ->select(
  2622. 'book.id',
  2623. 'book.title',
  2624. 'book.img_url',
  2625. 'book.price',
  2626. 'book.market_price',
  2627. 'book.description',
  2628. 'book.cat_id',
  2629. 'book.description',
  2630. 'book.updated_at',
  2631. 'website_category.alias as category_name',
  2632. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2633. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2634. )
  2635. ->orderBy('updated_at', 'desc')
  2636. ->limit($parentImgNum)
  2637. ->get()->all();
  2638. // 查询文字新闻
  2639. }
  2640. if ($parentTextNum != 0) {
  2641. $textBooks = [];
  2642. $textBooks = Book::where(function ($query) use ($parentCatId) {
  2643. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2644. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2645. })
  2646. ->where('book.status', 2)
  2647. ->leftJoin('website_category', function ($join) use ($website) {
  2648. $join->on('book.cat_id', '=', 'website_category.category_id')
  2649. ->where('website_category.website_id', '=', $website['website_id']);
  2650. })
  2651. ->select(
  2652. 'book.id',
  2653. 'book.title',
  2654. 'book.img_url',
  2655. 'book.price',
  2656. 'book.market_price',
  2657. 'book.description',
  2658. 'book.cat_id',
  2659. 'book.description',
  2660. 'book.updated_at',
  2661. 'website_category.alias as category_name',
  2662. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2663. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2664. )
  2665. ->orderBy('updated_at', 'desc')
  2666. ->limit($parentTextNum)
  2667. ->get()->all();
  2668. }
  2669. }
  2670. }
  2671. $resultItem = [
  2672. 'alias' => $parent_alias ?? '',
  2673. 'category_id' => $parentCatId ?? 0,
  2674. 'pinyin' => $parent_pinyin ?? null,
  2675. 'imgnum' => $imgBooks ?? [],
  2676. 'textnum' => $textBooks ?? [],
  2677. ];
  2678. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  2679. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  2680. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  2681. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2682. ->get()->all();
  2683. if (!empty($childCategory)) {
  2684. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  2685. // 查询子栏目名称
  2686. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  2687. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2688. ->first();
  2689. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  2690. $childImgArticles = [];
  2691. $childTextArticles = [];
  2692. $resultItem['child'] = [];
  2693. } else {
  2694. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  2695. // 查询子栏目图片新闻
  2696. $childImgArticles = Book::where('cat_id', $childCatId)
  2697. ->where('status', 2)
  2698. ->where('img_url', '!=', '')
  2699. ->leftJoin('website_category', function ($join) use ($website) {
  2700. $join->on('book.cat_id', '=', 'website_category.category_id')
  2701. ->where('website_category.website_id', '=', $website['website_id']);
  2702. })
  2703. ->select(
  2704. 'book.id',
  2705. 'book.title',
  2706. 'book.img_url',
  2707. 'book.price',
  2708. 'book.market_price',
  2709. 'book.description',
  2710. 'book.cat_id',
  2711. 'book.description',
  2712. 'book.updated_at',
  2713. DB::raw("'$child_pinyin' as pinyin")
  2714. )
  2715. ->orderBy('updated_at', 'desc')
  2716. ->limit($childImgNum)
  2717. ->get()->all();
  2718. // 查询子栏目文字新闻
  2719. $childTextArticles = Book::where('cat_id', $childCatId)
  2720. ->where('status', 2)
  2721. ->leftJoin('website_category', function ($join) use ($website) {
  2722. $join->on('book.cat_id', '=', 'website_category.category_id')
  2723. ->where('website_category.website_id', '=', $website['website_id']);
  2724. })
  2725. ->select(
  2726. 'book.id',
  2727. 'book.title',
  2728. 'book.img_url',
  2729. 'book.price',
  2730. 'book.market_price',
  2731. 'book.description',
  2732. 'book.cat_id',
  2733. 'book.description',
  2734. 'book.updated_at',
  2735. DB::raw("'$child_pinyin' as pinyin")
  2736. )
  2737. ->orderBy('updated_at', 'desc')
  2738. ->limit($childTextNum)
  2739. ->get()->all();
  2740. $resultItem['child'] = [
  2741. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  2742. 'category_id' => $childCatId,
  2743. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  2744. 'all_childcat' => $childCategory,
  2745. 'imgnum' => $childImgArticles,
  2746. 'textnum' => $childTextArticles,
  2747. ];
  2748. }
  2749. }
  2750. } else {
  2751. $resultItem['child'] = [];
  2752. }
  2753. return $resultItem;
  2754. }, $data);
  2755. return Result::success($result);
  2756. }
  2757. /**
  2758. * 获取书刊列表
  2759. * @param array $data
  2760. * @return array
  2761. * */
  2762. public function getWebsiteBookList(array $data): array
  2763. {
  2764. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2765. if (empty($web)) {
  2766. return Result::error("查询失败", 0);
  2767. }
  2768. $catid = $data['id'];
  2769. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  2770. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  2771. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  2772. $category_pinyin = $category ? $category->aLias_pinyin : '';
  2773. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  2774. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  2775. ->where('pid', $category['pid'])
  2776. ->select(
  2777. 'category_id',
  2778. 'alias',
  2779. 'aLIas_pinyin',
  2780. 'pid',
  2781. 'sort',
  2782. 'is_url',
  2783. 'web_url',
  2784. 'seo_title',
  2785. 'seo_keywords',
  2786. 'seo_description',
  2787. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  2788. )
  2789. ->orderBy('sort')
  2790. ->get()->all();
  2791. if (empty($category)) {
  2792. return Result::error("查询失败", 0);
  2793. }
  2794. $query = Book::where('book.status', 2)
  2795. ->where('book.website_id', $data['website_id'])
  2796. ->where('book.cat_id', $catid)
  2797. ->select(
  2798. 'book.id',
  2799. 'book.title',
  2800. 'book.img_url',
  2801. 'book.description',
  2802. 'book.updated_at',
  2803. 'book.cat_id',
  2804. DB::raw("'$pinyin' as pinyin")
  2805. )
  2806. ->orderBy('book.updated_at', 'desc');
  2807. $count = $query->count();
  2808. $query = clone $query;
  2809. $Book = $query
  2810. ->limit($data['pageSize'])
  2811. ->offset(($data['page'] - 1) * $data['pageSize'])
  2812. ->get()->all();
  2813. $result = [
  2814. 'category' => $categorys,
  2815. 'books' => $Book,
  2816. 'count' => $count,
  2817. ];
  2818. // if(empty($result)){
  2819. // return Result::error("查询失败", 0);
  2820. // }
  2821. return Result::success($result);
  2822. }
  2823. /**
  2824. * 获取书刊详情
  2825. * @param array $data
  2826. * @return array
  2827. * */
  2828. public function getWebsiteBookInfo(array $data): array
  2829. {
  2830. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2831. if (empty($web)) {
  2832. return Result::error("查询失败", 0);
  2833. }
  2834. $book = Book::where('status', 2)
  2835. ->where('website_id', $data['website_id'])
  2836. ->where('id', $data['id'])
  2837. ->select(
  2838. 'book.*',
  2839. )
  2840. ->orderBy('updated_at', 'desc')
  2841. ->first();
  2842. if (empty($book)) {
  2843. return Result::error("查询失败", 0);
  2844. }
  2845. // 先查询当前分类的 pid
  2846. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  2847. ->where('category_id', $book['cat_id'])
  2848. ->first(['pid', 'category_id']);
  2849. $query = WebsiteCategory::where('website_id', $data['website_id']);
  2850. if (!empty($carpid)) {
  2851. if ($carpid->pid != 0) {
  2852. $pid = $carpid['pid'];
  2853. // $parent_pinyin = '';
  2854. } else {
  2855. $pid = $carpid['category_id'];
  2856. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  2857. }
  2858. }
  2859. $categorys = $query->where('pid', $pid)
  2860. ->select(
  2861. 'category_id',
  2862. 'alias',
  2863. 'aLIas_pinyin',
  2864. 'pid',
  2865. 'sort',
  2866. 'is_url',
  2867. 'web_url',
  2868. 'category_arr_id as cat_arr_id',
  2869. )
  2870. ->orderBy('sort')
  2871. ->get();
  2872. $category = $this->processArticle($categorys, $data);
  2873. $result = [
  2874. 'category' => $category,
  2875. 'books' => $book,
  2876. ];
  2877. return Result::success($result);
  2878. }
  2879. /**
  2880. * 尝试
  2881. * @param array $data
  2882. * @return array
  2883. * */
  2884. public function test(array $data): array
  2885. {
  2886. $input['id'] = $data['id'];
  2887. $input['website_id'] = $data['website_id'];
  2888. // 将 JSON 字符串转换为 PHP 数组
  2889. $data = json_decode($input['id'], true);
  2890. $result = [];
  2891. $article = $data;
  2892. $result = array_map(function ($item) use ($input) {
  2893. $website = [
  2894. 'website_id' => $input['website_id'],
  2895. ];
  2896. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2897. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2898. $parent = [
  2899. 0 => $category['category_id'] ?? [],
  2900. 1 => $parentImgNum ?? [],
  2901. 2 => $parentTextNum ?? [],
  2902. ];
  2903. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  2904. $child = [];
  2905. $resultItem = [
  2906. // 'alias' => $parent_alias ?? '',
  2907. 'category_id' => $parentCatId ?? 0,
  2908. 'pinyin' => $parentImgNum ?? null,
  2909. 'imgnum' => $parentTextNum ?? [],
  2910. // 'textnum' => $textArticles ?? [],
  2911. ];
  2912. return $parent;
  2913. }, $data);
  2914. return Result::success($result);
  2915. // });
  2916. }
  2917. /**
  2918. * 封装处理文章的路由问题
  2919. * */
  2920. function processArticle($article, $data)
  2921. {
  2922. return $article->map(function ($article) use ($data) {
  2923. $catid = $article->cat_arr_id ?? '';
  2924. $level = json_decode($catid, true);
  2925. $pinyin = '';
  2926. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2927. if (!empty($level) && is_array($level)) {
  2928. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2929. ->where('website_id', $data['website_id'])
  2930. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2931. ->get(['aLIas_pinyin'])
  2932. ->pluck('aLIas_pinyin')
  2933. ->implode('/');
  2934. } else {
  2935. $pinyin = '';
  2936. }
  2937. $article->pinyin = $pinyin;
  2938. return $article;
  2939. });
  2940. }
  2941. /**
  2942. * c端-获取招工招聘下拉选框
  2943. * @param array $data
  2944. * @return array
  2945. * */
  2946. public function getWebsiteJobSelect(array $data): array
  2947. {
  2948. $web = Website::where('id', $data['website_id'])->first();
  2949. if (empty($web)) {
  2950. return Result::error("该网站不存在", 0);
  2951. }
  2952. $hy = JobIndustry::get()->all();
  2953. $zw = JobPosition::where('zwpid', 0)->get()->all();
  2954. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  2955. $result = [
  2956. 'hy' => $hy,
  2957. 'zw' => $zw,
  2958. 'jtzw' => $jtzw,
  2959. ];
  2960. if (empty($result)) {
  2961. return Result::error("查询失败", 0);
  2962. }
  2963. return Result::success($result);
  2964. }
  2965. /**
  2966. * c端-获取招工招聘
  2967. * @param array $data
  2968. * @return array
  2969. * */
  2970. public function getWebsiteJob(array $data): array
  2971. {
  2972. $web = Website::where('id', $data['website_id'])->first();
  2973. if (empty($web)) {
  2974. return Result::error("该网站不存在", 0);
  2975. }
  2976. $job_hunting = JobHunting::where('job_hunting.status', 2)
  2977. ->where('job_hunting.website_id', $data['website_id'])
  2978. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2979. $query->where(function ($q) use ($data) {
  2980. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2981. });
  2982. })
  2983. ->select(
  2984. 'job_hunting.id',
  2985. 'job_hunting.cat_arr_id',
  2986. 'job_hunting.job_name_get',
  2987. 'job_hunting.industry',
  2988. 'job_hunting.name',
  2989. 'job_hunting.sexy',
  2990. 'job_hunting.origin',
  2991. 'job_hunting.city_arr_id',
  2992. 'job_hunting.experience',
  2993. 'job_hunting.updated_at',
  2994. 'job_hunting.salary'
  2995. )
  2996. ->orderBy('updated_at', 'desc')
  2997. ->limit($data['job1_num'])
  2998. ->get();
  2999. $web['website_id'] = $data['website_id'];
  3000. if (empty($job_hunting)) {
  3001. $job_huntings = "未查询到相关简历信息";
  3002. } else {
  3003. $job_huntings = $this->processJob($job_hunting, $web);
  3004. }
  3005. // 0:待审核 1:已通过 2:已拒绝
  3006. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  3007. ->where('job_recruiting.website_id', $data['website_id'])
  3008. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3009. $query->where(function ($q) use ($data) {
  3010. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3011. });
  3012. })
  3013. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3014. ->select(
  3015. 'job_recruiting.id',
  3016. 'job_recruiting.cat_arr_id',
  3017. 'job_recruiting.title',
  3018. 'job_recruiting.jtzw_id',
  3019. 'job_recruiting.hy_id',
  3020. 'job_recruiting.city_arr_id',
  3021. 'job_recruiting.due_data',
  3022. 'job_recruiting.updated_at',
  3023. 'job_recruiting.experience',
  3024. 'job_recruiting.educational',
  3025. 'job_recruiting.salary',
  3026. 'job_recruiting.zw_id',
  3027. 'job_company.business_name'
  3028. )
  3029. ->orderBy('updated_at', 'desc')
  3030. ->limit($data['job2_num'])
  3031. ->get();
  3032. if (empty($job_recruiting->toArray())) {
  3033. $job_recruitings = "未查询到相关职位信息";
  3034. } else {
  3035. $job_recruitings = $this->processJob($job_recruiting, $web);
  3036. }
  3037. $result = [
  3038. 'job_hunting' => $job_huntings,
  3039. 'job_recuiting' => $job_recruitings,
  3040. ];
  3041. return Result::success($result);
  3042. }
  3043. /**
  3044. * c端-获取招工招聘列表
  3045. * @param array $data
  3046. * @return array
  3047. * */
  3048. public function getWebsiteJobList(array $data): array
  3049. {
  3050. $recruit_where = [];
  3051. $hunt_where = [];
  3052. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3053. if (empty($web)) {
  3054. return Result::error("此网站不存在", 0);
  3055. }
  3056. $website_id['website_id'] = $data['website_id'];
  3057. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  3058. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3059. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  3060. }
  3061. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3062. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  3063. }
  3064. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3065. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  3066. }
  3067. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3068. array_push($recruit_where, ['title', 'like', '%' . $data['keyword'] . '%']);
  3069. }
  3070. $query = JobRecruiting::where('job_recruiting.status', 1)
  3071. ->where('job_recruiting.website_id', $data['website_id'])
  3072. ->where($recruit_where)
  3073. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3074. $query->where(function ($q) use ($data) {
  3075. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3076. });
  3077. })
  3078. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  3079. $query->where(function ($q) use ($data) {
  3080. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  3081. });
  3082. })
  3083. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3084. ->select(
  3085. 'job_recruiting.id',
  3086. 'job_recruiting.hy_id',
  3087. 'job_recruiting.title',
  3088. 'job_recruiting.zw_id',
  3089. 'job_recruiting.educational',
  3090. 'job_recruiting.jtzw_id',
  3091. 'job_recruiting.city_arr_id',
  3092. 'job_recruiting.due_data',
  3093. 'job_recruiting.experience',
  3094. 'job_recruiting.cat_arr_id',
  3095. 'job_recruiting.updated_at',
  3096. 'job_company.business_name'
  3097. )
  3098. ->orderBy('job_recruiting.updated_at', 'desc');
  3099. $recruit_count = $query->count();
  3100. $query = clone $query;
  3101. $JobRecruiting = $query
  3102. ->offset(($data['page'] - 1) * $data['pageSize'])
  3103. ->limit($data['pageSize'])
  3104. ->get();
  3105. if (empty($JobRecruiting)) {
  3106. $JobRecruiting = "暂无相关职位信息";
  3107. } else {
  3108. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  3109. }
  3110. }
  3111. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  3112. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  3113. array_push($hunt_where, ['job_hunting.job', $data['zw_id']]);
  3114. }
  3115. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  3116. array_push($hunt_where, ['job_hunting.job_name_get', $data['jtzw_id']]);
  3117. }
  3118. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  3119. array_push($hunt_where, ['job_hunting.industry', $data['hy_id']]);
  3120. }
  3121. if (isset($data['keyword']) && !empty($data['keyword'])) {
  3122. array_push($hunt_where, ['job_position.zwname', 'like', '%' . $data['keyword'] . '%']);
  3123. }
  3124. $query = JobHunting::where('job_hunting.status', 2)
  3125. ->where('job_hunting.website_id', $data['website_id'])
  3126. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3127. ->where($hunt_where)
  3128. // ->when(isset($data['keyword']) &&!empty($data['keyword']), function ($query) use ($data) {
  3129. // $query->where('job_position.zwname','like','%'.$data['keyword'].'%');
  3130. // })
  3131. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  3132. $query->where(function ($q) use ($data) {
  3133. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3134. });
  3135. })
  3136. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  3137. $query->where(function ($q) use ($data) {
  3138. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  3139. });
  3140. })
  3141. ->select(
  3142. 'job_hunting.id',
  3143. 'job_hunting.sexy',
  3144. 'job_hunting.experience',
  3145. 'job_hunting.origin',
  3146. 'job_hunting.industry',
  3147. 'job_hunting.name',
  3148. 'job_hunting.job',
  3149. 'job_hunting.job_name_get',
  3150. 'job_hunting.city_arr_id',
  3151. 'job_hunting.cat_arr_id',
  3152. 'job_hunting.created_at',
  3153. 'job_hunting.updated_at',
  3154. 'job_position.zwname as job_name'
  3155. )
  3156. ->orderBy('job_hunting.updated_at', 'desc');
  3157. $hunt_count = $query->count();
  3158. $query = clone $query;
  3159. $JobHunting = $query
  3160. ->offset(($data['page'] - 1) * $data['pageSize'])
  3161. ->limit($data['pageSize'])
  3162. ->get();
  3163. if (empty($JobHunting)) {
  3164. $JobRecruiting = "暂无相关简历信息";
  3165. } else {
  3166. $JobHunting = $this->processJob($JobHunting, $website_id);
  3167. }
  3168. }
  3169. $result = [
  3170. 'JobRecruiting' => $JobRecruiting ?? [],
  3171. 'recruit_count' => $recruit_count ?? 0,
  3172. 'JobHunting' => $JobHunting ?? [],
  3173. 'hunt_count' => $hunt_count ?? 0,
  3174. ];
  3175. return Result::success($result);
  3176. }
  3177. /**
  3178. * c端-获取招工招聘详情
  3179. * @param array $data
  3180. * @return array
  3181. * */
  3182. public function getWebsiteJobInfo(array $data): array
  3183. {
  3184. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3185. if (empty($web)) {
  3186. return Result::error("该网站不存在", 0);
  3187. }
  3188. $webid = [
  3189. 'website_id' => $data['website_id'],
  3190. ];
  3191. // 职位相关信息
  3192. if ($data['type'] == 1) {
  3193. $query = JobRecruiting::where('status', 1)
  3194. ->where('website_id', $data['website_id'])
  3195. ->select('*');
  3196. $job = $query->where('job_recruiting.id', $data['id'])->get();
  3197. $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();
  3198. if (!empty($company)) {
  3199. $result['company'] = $this->processJob($company, $webid);
  3200. }
  3201. $other_job = JobRecruiting::where('status', 1)
  3202. ->where('website_id', $data['website_id'])
  3203. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  3204. ->where('id', '!=', $data['id'])
  3205. ->where('user_id', '=', $job[0]['user_id'])
  3206. ->limit($data['pageSize'])
  3207. ->get();
  3208. if (!empty($other_job)) {
  3209. $result['other_job'] = $this->processJob($other_job, $webid);
  3210. }
  3211. } else {
  3212. // 简历相关信息
  3213. $job = JobHunting::where('job_hunting.status', 2)
  3214. ->where('job_hunting.website_id', $data['website_id'])
  3215. ->where('job_hunting.id', $data['id'])
  3216. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3217. ->select('job_hunting.*', 'user_name')
  3218. ->get();
  3219. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  3220. if (!empty($resume->toArray())) {
  3221. $result['resume'] = 1;
  3222. } else {
  3223. $result['resume'] = 0;
  3224. }
  3225. }
  3226. if (empty($job->toArray())) {
  3227. return Result::error("id参数错误", 0);
  3228. }
  3229. if (!empty($job[0]['job_experience'])) {
  3230. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  3231. if (!empty($job_experience)) {
  3232. // $hy = [];
  3233. foreach ($job_experience as $key => $value) {
  3234. // $id = $value['id'];
  3235. $hy[$key] = $value['job_industry'];
  3236. $zw_id[$key] = $value['job_typename'];
  3237. $jtzw_id[$key] = $value['job_name'];
  3238. }
  3239. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  3240. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  3241. // 先将关联表转换为索引数组,提高查找效率
  3242. $hyLookup = [];
  3243. foreach ($hy_table as $item) {
  3244. $hyLookup[$item['hyid']] = $item['hyname'];
  3245. }
  3246. $zwLookup = [];
  3247. foreach ($zw_table as $item) {
  3248. $zwLookup[$item['zwid']] = $item['zwname'];
  3249. }
  3250. foreach ($job_experience as $key => &$value) {
  3251. // 处理行业名称
  3252. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  3253. $value['hy_name'] = $hyLookup[$hy[$key]];
  3254. }
  3255. // 处理职位名称
  3256. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  3257. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  3258. }
  3259. // 处理具体职位名称
  3260. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  3261. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  3262. }
  3263. }
  3264. // 释放引用,防止意外修改后续代码
  3265. unset($value);
  3266. }
  3267. $result['job_experience'] = $job_experience ?? [];
  3268. }
  3269. if (!empty($job[0]['education_experience'])) {
  3270. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  3271. if (!empty($education_experience)) {
  3272. foreach ($education_experience as $key => $value) {
  3273. // $id = $value['id'];
  3274. $education[$key] = $value['school_education'];
  3275. }
  3276. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  3277. // // 先将关联表转换为索引数组,提高查找效率
  3278. $educationLookup = [];
  3279. foreach ($education_table as $item) {
  3280. $educationLookup[$item['evalue']] = $item['ename'];
  3281. }
  3282. foreach ($education_experience as $key => &$value) {
  3283. // 处理学历名称
  3284. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  3285. $value['education_name'] = $educationLookup[$education[$key]];
  3286. }
  3287. }
  3288. }
  3289. $result['education_experience'] = $job_experience ?? [];
  3290. }
  3291. $result['job'] = $this->processJob($job, $webid);
  3292. // // 返现对应的栏目
  3293. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  3294. $category = WebsiteCategory::where('website_id', $data['website_id'])
  3295. ->whereIn('category_id', $catid)
  3296. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  3297. ->orderBy('pid')->get()->all();
  3298. if (!empty($category)) {
  3299. $result['category'] = $category;
  3300. }
  3301. $result['job'] = $job;
  3302. $result['job_experience'] = $job_experience ?? [];
  3303. $result['education_experience'] = $education_experience ?? [];
  3304. if (empty($result)) {
  3305. return Result::error("参数错误", 0);
  3306. }
  3307. return Result::success($result);
  3308. }
  3309. /**
  3310. * c端-申请职位
  3311. * @param array $data
  3312. * @return array
  3313. * */
  3314. public function getWebsiteJobApply(array $data): array
  3315. {
  3316. // 首先验证网站是否存在
  3317. // return Result::success($data);
  3318. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3319. if (empty($web)) {
  3320. return Result::error("该网站不存在", 0);
  3321. }
  3322. // 验证用户是否存在且为个人会员/管理员
  3323. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3324. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3325. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  3326. return Result::error("用户不存在", 0);
  3327. }
  3328. // 去除重复元素和空元素,并保持原始顺序
  3329. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  3330. return !empty($value);
  3331. }));
  3332. // 验证职位是否存在 1:审核通过
  3333. $recruiting = JobRecruiting::where('status', 1)
  3334. ->where('website_id', $data['website_id'])
  3335. ->whereIn('id', $data['recruit_id'])
  3336. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  3337. if (empty($recruiting)) {
  3338. return Result::error("该职位不存在", 0);
  3339. }
  3340. // 简历是否存在
  3341. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  3342. if (empty($hunt_id)) {
  3343. return Result::error("该简历不存在", 0);
  3344. }
  3345. $data['hunt_id'] = $hunt_id['hunt_id'];
  3346. // // 验证是否已投递过该职位
  3347. $apply = JobApply::where('user_id', $data['user_id'])
  3348. ->where('hunt_id', $data['hunt_id'])
  3349. ->where('website_id', $data['website_id'])
  3350. ->whereIn('recruit_id', $data['recruit_id'])
  3351. ->get(['recruit_id']);
  3352. if (!empty($apply->toArray())) {
  3353. return Result::error("您已投递过该职位!");
  3354. }
  3355. $insertData = array_map(function ($recruiting) use ($data) {
  3356. return [
  3357. 'user_id' => $data['user_id'],
  3358. 'hunt_id' => $data['hunt_id'],
  3359. 'website_id' => $data['website_id'],
  3360. 'recruit_id' => $recruiting['recruit_id'],
  3361. 'receiver_id' => $recruiting['receiver_id'],
  3362. 'status' => 1,
  3363. ];
  3364. }, $recruiting);
  3365. // 批量插入数据
  3366. $result = JobApply::insert($insertData);
  3367. if (empty($result)) {
  3368. return Result::error("投递失败", 0);
  3369. }
  3370. return Result::success($result);
  3371. }
  3372. /**
  3373. * 招工招聘-沟通简历
  3374. * @param array $data
  3375. * @return array
  3376. * */
  3377. public function getWebsiteJobResume(array $data): array
  3378. {
  3379. // 首先验证网站是否存在
  3380. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3381. if (empty($web)) {
  3382. return Result::error("该网站不存在", 0);
  3383. }
  3384. // return Result::success($data);
  3385. // 验证用户是否存在且为企业会员/管理员
  3386. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3387. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3388. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3389. return Result::error("用户不存在", 0);
  3390. }
  3391. // 去除重复元素和空元素,并保持原始顺序
  3392. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  3393. return !empty($value);
  3394. }));
  3395. // 验证简历是否存在
  3396. $hunting = JobHunting::where('status', 2)
  3397. ->where('website_id', $data['website_id'])
  3398. ->whereIn('id', $data['hunt_id'])
  3399. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  3400. if (empty($hunting)) {
  3401. return Result::error("该简历不存在", 0);
  3402. }
  3403. // 验证是否已沟通过该简历
  3404. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3405. ->where('recruit_id', $data['recruit_id'])
  3406. ->where('website_id', $data['website_id'])
  3407. ->whereIn('hunt_id', $data['hunt_id'])
  3408. ->get(['hunt_id']);
  3409. if (!empty($remuse->toArray())) {
  3410. return Result::error("您已沟通过该简历!");
  3411. }
  3412. // 准备要插入的数据数组
  3413. $insertData = array_map(function ($hunting) use ($data) {
  3414. return [
  3415. 'user_id' => $data['user_id'],
  3416. 'recruit_id' => $data['recruit_id'],
  3417. 'website_id' => $data['website_id'],
  3418. 'hunt_id' => $hunting['hunt_id'],
  3419. 'receiver_id' => $hunting['receiver_id'],
  3420. 'status' => 1,
  3421. ];
  3422. }, $hunting);
  3423. // 批量插入数据
  3424. $result = JobRemuse::insert($insertData);
  3425. if (empty($result)) {
  3426. return Result::error("沟通失败", 0);
  3427. }
  3428. return Result::success($result);
  3429. }
  3430. /**
  3431. * 招工招聘 -我的职位(企业会员)
  3432. * @param array $data
  3433. * @return array
  3434. */
  3435. public function getWebsiteJobRecruiting(array $data): array
  3436. {
  3437. $web = Website::where('id', $data['website_id'])->first('id');
  3438. if (empty($web)) {
  3439. return Result::error("该网站不存在", 0);
  3440. }
  3441. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3442. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3443. return Result::error("用户暂无权限!", 0);
  3444. }
  3445. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3446. $result = JobRecruiting::where('website_id', $data['website_id'])
  3447. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  3448. $query->where('user_id', $user['id']);
  3449. })
  3450. ->where('status', 1)
  3451. ->select('id', 'title', 'website_id', 'user_id', 'updated_at')
  3452. ->orderBy('updated_at', 'desc')
  3453. ->limit($data['pageSize'])
  3454. ->get();
  3455. if (empty($result)) {
  3456. return Result::error("暂无相关职位信息", 0);
  3457. }
  3458. return Result::success($result);
  3459. }
  3460. /**
  3461. * c端 - 验证路由
  3462. * @param array $data
  3463. * @return array
  3464. */
  3465. /**
  3466. * c端 - 验证路由
  3467. * @param array $data
  3468. * @return array
  3469. */
  3470. public function checkWebsiteRoute(array $data): array
  3471. {
  3472. // 测试001111111222
  3473. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name', 'status']);
  3474. if (empty($web)) {
  3475. return Result::error("该网站不存在", 0);
  3476. } elseif ($web['status'] != 1) {
  3477. return Result::error("网站已经关闭", 0);
  3478. }
  3479. if (isset($data['other_route']) && !empty($data['other_route'])) {
  3480. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  3481. // 验证路由是否存在
  3482. if (empty($whiteRouterInfo)) {
  3483. $whiteRouterInfo = WhiteRouter::where("router_type", 1)->where('router_url', $data['other_route'])->first();
  3484. }
  3485. if (!empty($whiteRouterInfo)) {
  3486. return Result::success($whiteRouterInfo->toArray());
  3487. }
  3488. }
  3489. // 验证栏目路由
  3490. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  3491. ->where('path', $data['all_route'])
  3492. ->get()->all();
  3493. if (count($last_category) == 0) {
  3494. return Result::error("该栏目不存在", 0);
  3495. }
  3496. if(count($last_category) > 1){
  3497. return Result::error("该栏目路由存在多个,路由验证失败!", 0);
  3498. }
  3499. if (count($last_category) == 1) {
  3500. $last_category = $last_category[0];
  3501. }
  3502. // return Result::success($last_category);
  3503. if (isset($data['id']) && !empty($data['id'])) {
  3504. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  3505. switch ($last_category['type']) {
  3506. case 1:
  3507. // 文章
  3508. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  3509. $article = Article::where('status', 1)
  3510. ->where('id', $data['id'])
  3511. ->where(function ($query) use ($data) {
  3512. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  3513. ->orWhereNull("ignore_ids");
  3514. })
  3515. ->first(['catid']);
  3516. if (empty($article)) {
  3517. return Result::error("该文章不存在", 0);
  3518. }
  3519. // return Result::success($article);
  3520. break;
  3521. case 2:
  3522. // 商品
  3523. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3524. $article = Good::where('website_id', $data['website_id'])
  3525. ->where('status', 2)
  3526. ->where('id', $data['id'])
  3527. ->first(['cat_arr_id']);
  3528. if (empty($article)) {
  3529. return Result::error("该商品不存在", 0);
  3530. }
  3531. break;
  3532. case 3:
  3533. // 书刊信息
  3534. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3535. $article = Book::where('website_id', $data['website_id'])
  3536. ->where('status', 2)
  3537. ->where('id', $data['id'])
  3538. ->first(['id', 'cat_arr_id']);
  3539. if (empty($article)) {
  3540. return Result::error("该书刊不存在", 0);
  3541. }
  3542. break;
  3543. case 4:
  3544. // 招聘
  3545. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核通过;(只有企业会员需要审核)',
  3546. $article = JobRecruiting::where('website_id', $data['website_id'])
  3547. ->where('status', 1)
  3548. ->where('id', $data['id'])
  3549. ->first(['cat_arr_id']);
  3550. if (empty($article)) {
  3551. return Result::error("该招聘不存在", 0);
  3552. }
  3553. break;
  3554. case 5:
  3555. // 求职
  3556. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3557. $article = JobHunting::where('website_id', $data['website_id'])
  3558. ->where('status', 2)
  3559. ->where('id', $data['id'])
  3560. ->first(['cat_arr_id']);
  3561. if (empty($article)) {
  3562. return Result::error("该求职不存在", 0);
  3563. }
  3564. break;
  3565. case 6:
  3566. // 企业
  3567. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3568. $article = Company::
  3569. // where('website_id', $data['website_id'])
  3570. // ->
  3571. where('status', 1)
  3572. ->where('id', $data['id'])
  3573. ->first(['cat_arr_id']);
  3574. if (empty($article)) {
  3575. return Result::error("该企业不存在", 0);
  3576. }
  3577. break;
  3578. case 7:
  3579. // 项目
  3580. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3581. $article = Project::where('website_id', $data['website_id'])
  3582. ->where('status', 1)
  3583. ->where('id', $data['id'])
  3584. ->first(['cat_arr_id']);
  3585. if (empty($article)) {
  3586. return Result::error("该项目不存在", 0);
  3587. }
  3588. break;
  3589. default:
  3590. return Result::error("该数据不存在", 0);
  3591. break;
  3592. }
  3593. // return Result::success($article);
  3594. // $catid =0 ;
  3595. // if(!isset($article['cat_arr_id'])){
  3596. // $catid = isset($article['catid']) ? $article['catid'] : (isset($article['category_id']) ? $article['category_id'] : null);
  3597. // }else{
  3598. // $catidArray = json_decode($article['cat_arr_id'], true);
  3599. // $catid = !empty($catidArray) ? end($catidArray) : null;
  3600. // }
  3601. // // return Result::success($catid);
  3602. // // return Result::success($article['cat_arr_id']);
  3603. // if (empty($catid)) {
  3604. // return Result::error("该数据不存在", 0);
  3605. // }
  3606. // $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3607. // ->where('category_id',$catid)
  3608. // ->first('path');
  3609. }
  3610. // else{
  3611. // // if ($last_category['pid'] != 0) {
  3612. // $cat_arr = json_decode($last_category['category_arr_id'], true);
  3613. // $catid = !empty($cat_arr) && is_array($cat_arr) ? end($cat_arr) : null;
  3614. // $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3615. // ->where('category_id',$catid)
  3616. // ->where('path',$data['all_route'])
  3617. // ->first('path');
  3618. // // } else {
  3619. // // $pinyin[0] = $last_category['aLIas_pinyin'];
  3620. // // }
  3621. // }
  3622. // return Result::success($pinyin);
  3623. // if (empty($pinyin)) {
  3624. // return Result::error('非法路径!');
  3625. // } else {
  3626. return Result::success( $last_category['path']);
  3627. // }
  3628. }
  3629. /**
  3630. * 招工招聘 - 获取推荐职位
  3631. * @param array $data
  3632. * @return array
  3633. */
  3634. public function getWebsiteLevelJob(array $data): array
  3635. {
  3636. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3637. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  3638. ->where('job_recruiting.status', 1)
  3639. ->where('job_level', $data['job_level'])
  3640. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3641. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  3642. ->orderBy('job_recruiting.updated_at', 'desc')
  3643. ->limit($data['pageSize'])
  3644. ->get();
  3645. $web = ['website_id' => $data['website_id']];
  3646. if (!empty($job)) {
  3647. $result = $this->processJob($job, $web);
  3648. }
  3649. if (empty($result)) {
  3650. return Result::error("暂无相关职位信息", 0);
  3651. }
  3652. return Result::success($result);
  3653. }
  3654. /**
  3655. * 验证导航名称是否重复
  3656. * @return void
  3657. */
  3658. //20250226 产品列表
  3659. public function getGoodList(array $data): array
  3660. {
  3661. var_dump($data, '---------1-2--');
  3662. $type_id = isset($data['user_type_id']) ? $data['user_type_id'] : '';
  3663. unset($data['user_type_id']);
  3664. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3665. $where = [];
  3666. if ($type_id != '10000') {
  3667. $where = [
  3668. 'good.user_id' => $user_id,
  3669. ];
  3670. }
  3671. //类型
  3672. if (isset($data['type_id']) && $data['type_id']) {
  3673. $where['good.type_id'] = $data['type_id'];
  3674. }
  3675. //名称
  3676. if (isset($data['name']) && $data['name']) {
  3677. $where[] = ['good.name', 'like', '%' . $data['name'] . '%'];
  3678. }
  3679. //status
  3680. if (isset($data['status']) && $data['status'] != '') {
  3681. $where['good.status'] = $data['status'];
  3682. }
  3683. //status1
  3684. // if (isset($data['status1']) && $data['status1'] == 1) {
  3685. // $status1 = 1;
  3686. // }
  3687. $where1 = [];
  3688. //website_id
  3689. // if (isset($data['website_id']) && $data['website_id']) {
  3690. // $where1 = [
  3691. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  3692. // ];
  3693. // }
  3694. // website_name
  3695. if (isset($data['website_name']) && $data['website_name']) {
  3696. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  3697. }
  3698. // catid
  3699. if (isset($data['category_name']) && $data['category_name']) {
  3700. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  3701. }
  3702. // $result = Good::where($where)
  3703. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  3704. var_dump($where, '---------1---');
  3705. $result = Good::where($where)
  3706. ->when(!empty($where1), function ($query) use ($where1) {
  3707. return $query->where($where1);
  3708. })
  3709. //status 1待审核2已审核3已拒绝
  3710. ->when(isset($data['status1']), function ($query) {
  3711. return $query->whereIn('good.status', [1, 3]);
  3712. })
  3713. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3714. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3715. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3716. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3717. ->orderBy("updated_at", "desc")
  3718. ->limit($data['page_size'])
  3719. ->offset(($data['page'] - 1) * $data['page_size'])
  3720. ->get();
  3721. $count = Good::where($where)
  3722. ->when(!empty($where1), function ($query) use ($where1) {
  3723. return $query->where($where1);
  3724. })
  3725. //status 1待审核2已审核3已拒绝
  3726. ->when(isset($data['status1']), function ($query) {
  3727. return $query->whereIn('good.status', [1, 3]);
  3728. })
  3729. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3730. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3731. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3732. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3733. ->orderBy("updated_at", "desc")->count();
  3734. $data = [
  3735. 'rows' => $result->toArray(),
  3736. 'count' => $count,
  3737. ];
  3738. if (empty($result)) {
  3739. return Result::error("此栏目暂无相关产品", 0);
  3740. }
  3741. return Result::success($data);
  3742. }
  3743. public function getGoodInfo(array $data): array
  3744. {
  3745. $result = Good::where('id', $data['id'])->first();
  3746. if (empty($result)) {
  3747. return Result::error("此产品不存在", 0);
  3748. }
  3749. return Result::success($result);
  3750. }
  3751. public function addGood(array $data): array
  3752. {
  3753. // unset($data['city_arr_id']);
  3754. // unset($data['cat_arr_id']);
  3755. $data['city_id'] = end($data['city_arr_id']);
  3756. $data['catid'] = end($data['cat_arr_id']);
  3757. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3758. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3759. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3760. unset($data['imgUrl']); //大小写
  3761. if (isset($data['price']) && $data['price'] == '') {
  3762. $data['price'] = 0;
  3763. }
  3764. if ($data['imgurl'] == '') {
  3765. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  3766. preg_match_all($reg, $data['detail'], $matches);
  3767. if (isset($matches[1][0])) {
  3768. //截取varchar240
  3769. $data['imgurl'] = substr($matches[1][0], 0, 240);
  3770. }
  3771. }
  3772. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  3773. //提取标题+内容中的关键词
  3774. $data['keyword'] = $data['name'];
  3775. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  3776. Jieba::init(); // 初始化 jieba-php
  3777. Finalseg::init();
  3778. $segList = Jieba::cut($data['keyword']);
  3779. $segList1 = array_slice($segList, 0, 8);
  3780. $data['keyword'] = implode(',', $segList1);
  3781. }
  3782. if ($data['description'] == '') {
  3783. //提取内容中的描述
  3784. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  3785. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  3786. // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  3787. }
  3788. if ($data['status'] == 1) {
  3789. $this->sendMessage([
  3790. 'talk_type' => 200,
  3791. 'title' => $data['name'],
  3792. 'content' => '提交了审核',
  3793. 'messageType' => 3,
  3794. ]);
  3795. }
  3796. $result = Good::insert($data);
  3797. if (empty($result)) {
  3798. return Result::error("添加失败", 0);
  3799. }
  3800. return Result::success($result);
  3801. }
  3802. public function updateGood(array $data): array
  3803. {
  3804. $data['city_id'] = end($data['city_arr_id']);
  3805. $data['catid'] = end($data['cat_arr_id']);
  3806. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3807. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3808. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3809. //设置东八区
  3810. date_default_timezone_set('Asia/Shanghai');
  3811. $data['updated_at'] = date('Y-m-d H:i:s');
  3812. if (isset($data['price']) && $data['price'] == '') {
  3813. $data['price'] = 0;
  3814. }
  3815. if ($data['imgurl'] == '') {
  3816. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  3817. preg_match_all($reg, $data['detail'], $matches);
  3818. if (isset($matches[1][0])) {
  3819. //截取varchar240
  3820. $data['imgurl'] = substr($matches[1][0], 0, 240);
  3821. }
  3822. }
  3823. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  3824. //提取标题+内容中的关键词
  3825. $data['keyword'] = $data['name'];
  3826. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  3827. Jieba::init(); // 初始化 jieba-php
  3828. Finalseg::init();
  3829. $segList = Jieba::cut($data['keyword']);
  3830. $segList1 = array_slice($segList, 0, 8);
  3831. $data['keyword'] = implode(',', $segList1);
  3832. }
  3833. if ($data['description'] == '') {
  3834. //提取内容中的描述
  3835. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  3836. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  3837. }
  3838. if ($data['status'] == 1) {
  3839. $this->sendMessage([
  3840. 'talk_type' => 200,
  3841. 'title' => $data['name'],
  3842. 'content' => '提交了审核',
  3843. 'messageType' => 3,
  3844. ]);
  3845. }
  3846. $result = Good::where('id', $data['id'])->update($data);
  3847. if (empty($result)) {
  3848. return Result::error("更新失败", 0);
  3849. }
  3850. return Result::success($result);
  3851. }
  3852. public function delGood(array $data): array
  3853. {
  3854. $result = Good::where('id', $data['id'])->delete();
  3855. if (empty($result)) {
  3856. return Result::error("删除失败", 0);
  3857. }
  3858. return Result::success($result);
  3859. }
  3860. //20250226 产品列表
  3861. //20250306 求职信息
  3862. public function getJobHuntingList(array $data): array
  3863. {
  3864. $where = [];
  3865. if (isset($data['username']) && !empty($data['username'])) {
  3866. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3867. }
  3868. //status 1待审核2已审核3已拒绝
  3869. if (isset($data['status']) && $data['status'] != '') {
  3870. $where = [
  3871. 'job_hunting.status' => $data['status'],
  3872. ];
  3873. }
  3874. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3875. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3876. unset($data['type_id']);
  3877. if ($type_id != '10000') {
  3878. $where[] = ['job_hunting.user_id', '=', $user_id];
  3879. }
  3880. $result = JobHunting::where($where)
  3881. ->when(!empty($data['status1']), function ($query) use ($data) {
  3882. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3883. })
  3884. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3885. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3886. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  3887. ->orderBy("updated_at", "desc")
  3888. ->limit($data['page_size'])
  3889. ->offset(($data['page'] - 1) * $data['page_size'])
  3890. ->get();
  3891. if (empty($result)) {
  3892. return Result::error("查询失败", 0);
  3893. }
  3894. $count = JobHunting::where($where)
  3895. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3896. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3897. ->count();
  3898. $data = [
  3899. 'rows' => $result->toArray(),
  3900. 'count' => $count,
  3901. ];
  3902. return Result::success($data);
  3903. }
  3904. public function getJobHuntingApply(array $data): array
  3905. {
  3906. var_dump($data, '-----------------test--------1-');
  3907. $where = [];
  3908. if (isset($data['username']) && !empty($data['username'])) {
  3909. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3910. }
  3911. if (isset($data['salary']) && !empty($data['salary'])) {
  3912. $where[] = [
  3913. 'job_hunting.salary',
  3914. '=',
  3915. $data['salary'],
  3916. ];
  3917. }
  3918. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3919. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3920. unset($data['type_id']);
  3921. if ($type_id != '10000') {
  3922. $where[] = ['job_apply.receiver_id', '=', $user_id];
  3923. }
  3924. var_dump($where, '-----------------test---------');
  3925. $result = jobApply::where($where)
  3926. // ->when(!empty($data['status1']), function ($query) use ($data) {
  3927. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3928. // })
  3929. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  3930. ->where('job_enum.egroup', '=', 'income')
  3931. ->where('job_hunting.status', 2) //已审核
  3932. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3933. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3934. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3935. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3936. //职位----是申请职位
  3937. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3938. ->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')
  3939. ->orderBy("job_hunting.updated_at", "desc")
  3940. ->limit($data['page_size'])
  3941. ->offset(($data['page'] - 1) * $data['page_size'])
  3942. ->get();
  3943. if (empty($result)) {
  3944. return Result::error("查询失败", 0);
  3945. }
  3946. $count = jobApply::where($where)
  3947. ->where('job_enum.egroup', '=', 'income')
  3948. ->where('job_hunting.status', 2) //已审核
  3949. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3950. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3951. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3952. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3953. //职位----是申请职位
  3954. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3955. ->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')
  3956. ->count();
  3957. $data = [
  3958. 'rows' => $result->toArray(),
  3959. 'count' => $count,
  3960. ];
  3961. return Result::success($data);
  3962. }
  3963. public function addJobHunting(array $data): array
  3964. {
  3965. date_default_timezone_set('Asia/Shanghai');
  3966. unset($data['company_name']);
  3967. unset($data['job_industry']);
  3968. unset($data['job_name']);
  3969. unset($data['department']);
  3970. unset($data['job_timeList']);
  3971. unset($data['job_content']);
  3972. unset($data['job_typename']); //不知道这是啥,
  3973. $data['created_at'] = date('Y-m-d H:i:s');
  3974. $data['updated_at'] = date('Y-m-d H:i:s');
  3975. //根据用户 user_id 只能添加一次
  3976. $result = JobHunting::where('user_id', $data['user_id'])->first();
  3977. if (!empty($result)) {
  3978. return Result::error("您已添加过求职信息", 0);
  3979. }
  3980. var_dump($result, '-----------------test---------');
  3981. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  3982. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  3983. $cityArr = json_decode($data['city_arr_id'], true);
  3984. $data['city_id'] = end($cityArr);
  3985. } else {
  3986. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  3987. $data['city_id'] = end($data['city_arr_id']);
  3988. }
  3989. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  3990. $this->sendMessage([
  3991. 'talk_type' => 600,
  3992. 'title' => $data['name'],
  3993. 'content' => '提交了审核',
  3994. 'messageType' => 11,
  3995. ]);
  3996. }
  3997. $result = JobHunting::create($data);
  3998. if (empty($result)) {
  3999. return Result::error("添加失败", 0);
  4000. }
  4001. return Result::success($result);
  4002. }
  4003. public function delJobHunting(array $data): array
  4004. {
  4005. $result = JobHunting::where('id', $data['id'])->delete();
  4006. if (empty($result)) {
  4007. return Result::error("删除失败", 0);
  4008. }
  4009. return Result::success($result);
  4010. }
  4011. public function updateJobHunting(array $data): array
  4012. {
  4013. //设置东八区
  4014. date_default_timezone_set('Asia/Shanghai');
  4015. unset($data['company_name']);
  4016. unset($data['job_industry']);
  4017. unset($data['job_name']);
  4018. unset($data['department']);
  4019. unset($data['job_timeList']);
  4020. unset($data['job_content']);
  4021. unset($data['job_typename']); //不知道这是啥,
  4022. $data['created_at'] = date('Y-m-d H:i:s');
  4023. $data['updated_at'] = date('Y-m-d H:i:s');
  4024. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  4025. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  4026. $cityArr = json_decode($data['city_arr_id'], true);
  4027. $data['city_id'] = end($cityArr);
  4028. } else {
  4029. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  4030. $data['city_id'] = end($data['city_arr_id']);
  4031. }
  4032. if ((isset($data['status']) && $data['status'] == 1) || !isset($data['status'])) {
  4033. $this->sendMessage([
  4034. 'talk_type' => 600,
  4035. 'title' => $data['name'],
  4036. 'content' => '提交了审核',
  4037. 'messageType' => 11,
  4038. ]);
  4039. }
  4040. $result = JobHunting::where('id', $data['id'])->update($data);
  4041. if (empty($result)) {
  4042. return Result::error("更新失败", 0);
  4043. }
  4044. return Result::success($result);
  4045. }
  4046. public function getJobHuntingInfo(array $data): array
  4047. {
  4048. $result = JobHunting::where('id', $data['id'])->first();
  4049. if (empty($result)) {
  4050. return Result::error("查询失败", 0);
  4051. }
  4052. return Result::success($result);
  4053. }
  4054. public function getJobHuntingData(array $data): array
  4055. {
  4056. $jobEnum = JobEnum::get();
  4057. $jobIndustry = JobIndustry::get();
  4058. $jobNature = JobNature::get();
  4059. $jobPosition = JobPosition::get();
  4060. $data = [
  4061. 'jobEnum' => $jobEnum,
  4062. 'jobIndustry' => $jobIndustry,
  4063. 'jobNature' => $jobNature,
  4064. 'jobPosition' => $jobPosition,
  4065. ];
  4066. return Result::success($data);
  4067. }
  4068. public function delJobHuntingInfo(array $data): array
  4069. {
  4070. $result = JobHunting::where('id', $data['id'])->delete();
  4071. return Result::success();
  4072. }
  4073. //20250324 通知,公告,消息
  4074. public function delNotice(array $data): array
  4075. {
  4076. $result = Notice::where('id', $data['id'])->delete();
  4077. if ($result) {
  4078. return Result::success();
  4079. } else {
  4080. return Result::error("删除失败", 0);
  4081. }
  4082. }
  4083. public function getNoticeInfo(array $data): array
  4084. {
  4085. $result = Notice::where('id', $data['id'])->first();
  4086. // var_dump($result['re_user_ids'], '--------------------');
  4087. if (empty($result)) {
  4088. return Result::error("查询失败", 0);
  4089. }
  4090. return Result::success($result);
  4091. }
  4092. public function readNotice(array $data): array
  4093. {
  4094. $result = Notice::where('id', $data['id'])->first();
  4095. // var_dump($result['re_user_ids'], '--------------------');
  4096. if (empty($result)) {
  4097. return Result::error("查询失败", 0);
  4098. }
  4099. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4100. $re_user_ids = json_decode($result['re_user_ids'], true);
  4101. var_dump($re_user_ids, '--------------1---test---------');
  4102. var_dump($data, '--------------1---test---------');
  4103. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4104. //如果已经存在,就不再添加
  4105. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4106. $read_id = json_decode($result['read_id'], true);
  4107. if (!is_array($read_id)) {
  4108. $read_id = [];
  4109. }
  4110. if (!in_array($data['user_id'], $read_id)) {
  4111. $read_id[] = $data['user_id'];
  4112. $result['read_id'] = json_encode($read_id);
  4113. Notice::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4114. }
  4115. } else {
  4116. //如果不存在,就添加
  4117. $result['read_id'] = json_encode([$data['user_id']]);
  4118. Notice::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4119. }
  4120. }
  4121. return Result::success($result);
  4122. }
  4123. public function addNotice(array $data): array
  4124. {
  4125. date_default_timezone_set('Asia/Shanghai');
  4126. $data['created_at'] = date('Y-m-d H:i:s');
  4127. $data['updated_at'] = date('Y-m-d H:i:s');
  4128. $user_id = UserInfo::
  4129. //city_id不是null
  4130. whereNotNull('city_id')
  4131. ->whereNotNull('department_id')
  4132. ->where(function ($query) use ($data) {
  4133. $query->where(function ($subQuery) use ($data) {
  4134. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4135. });
  4136. })
  4137. ->where(function ($query) use ($data) {
  4138. $query->where(function ($subQuery) use ($data) {
  4139. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4140. });
  4141. })
  4142. ->pluck('user_id')->toArray();
  4143. $user_id = array_unique($user_id);
  4144. $chat_ids = $user_id;
  4145. $user_id = json_encode($user_id);
  4146. $data['re_user_ids'] = $user_id;
  4147. $this->sendMessage([
  4148. 'talk_type' => 700,
  4149. 'title' => $data['title'],
  4150. 'content' => '提交了审核',
  4151. 'messageType' => 5,
  4152. ]);
  4153. $result = Notice::insertGetId($data);
  4154. if (empty($result)) {
  4155. return Result::error("添加失败", 0);
  4156. }
  4157. return Result::success($result);
  4158. }
  4159. public function updateNotice(array $data): array
  4160. {
  4161. date_default_timezone_set('Asia/Shanghai');
  4162. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  4163. $user_id = UserInfo::
  4164. //city_id不是null
  4165. whereNotNull('city_id')
  4166. ->whereNotNull('department_id')
  4167. ->where(function ($query) use ($data) {
  4168. $query->where(function ($subQuery) use ($data) {
  4169. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  4170. });
  4171. })
  4172. ->where(function ($query) use ($data) {
  4173. $query->where(function ($subQuery) use ($data) {
  4174. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  4175. });
  4176. })
  4177. ->pluck('user_id')->toArray();
  4178. $user_id = array_unique($user_id);
  4179. $user_id = json_encode($user_id);
  4180. $data['re_user_ids'] = $user_id;
  4181. $data['updated_at'] = date('Y-m-d H:i:s');
  4182. $this->sendMessage([
  4183. 'talk_type' => 700,
  4184. 'title' => $data['title'],
  4185. 'content' => '提交了审核',
  4186. 'messageType' => 5,
  4187. ]);
  4188. $result = Notice::where('id', $data['id'])->update($data);
  4189. return Result::success($result);
  4190. }
  4191. public function getNoticeList(array $data): array
  4192. {
  4193. $where = [];
  4194. //title
  4195. if (isset($data['title']) && !empty($data['title'])) {
  4196. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4197. }
  4198. //level
  4199. if (isset($data['level']) && !empty($data['level'])) {
  4200. $where[] = ['notice.level', '=', $data['level']];
  4201. }
  4202. //status
  4203. if (isset($data['status']) && !empty($data['status'])) {
  4204. $where[] = ['notice.status', '=', $data['status']];
  4205. }
  4206. //type
  4207. if (isset($data['type']) && !empty($data['type'])) {
  4208. $where[] = ['notice.type', '=', $data['type']];
  4209. }
  4210. var_dump($data, '------------11111-2----test---------');
  4211. if ($data['type_id'] == 10000) {
  4212. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4213. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4214. })
  4215. ->where($where)
  4216. ->orderBy('updated_at', 'desc')
  4217. ->limit($data['page_size'])
  4218. ->offset(($data['page'] - 1) * $data['page_size'])
  4219. ->get();
  4220. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4221. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4222. })
  4223. ->where($where)
  4224. ->orderBy('updated_at', 'desc')
  4225. ->count();
  4226. } else {
  4227. $result = Notice::where($where)
  4228. // ->where('user_id', $data['user_id'])
  4229. ->Where(function ($query) use ($data) {
  4230. $query->Where(function ($q) use ($data) {
  4231. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4232. ->orWhere('notice.user_id', $data['user_id']);
  4233. });
  4234. })
  4235. ->when(!empty($data['status1']), function ($query) use ($data) {
  4236. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4237. })
  4238. ->orderBy('updated_at', 'desc')
  4239. ->limit($data['page_size'])
  4240. ->offset(($data['page'] - 1) * $data['page_size'])
  4241. ->get();
  4242. $total = Notice::where($where)
  4243. ->when(!empty($data['status1']), function ($query) use ($data) {
  4244. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4245. })
  4246. // ->where('user_id', $data['user_id'])
  4247. ->Where(function ($query) use ($data) {
  4248. $query->Where(function ($q) use ($data) {
  4249. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4250. ->orWhere('notice.user_id', $data['user_id']);
  4251. });
  4252. })
  4253. ->count();
  4254. }
  4255. if (empty($result)) {
  4256. return Result::error("查询失败", 0);
  4257. }
  4258. $data = [
  4259. 'rows' => $result,
  4260. 'count' => $total,
  4261. ];
  4262. return Result::success($data);
  4263. }
  4264. public function noticeList(array $data): array
  4265. {
  4266. $where = [];
  4267. //title
  4268. if (isset($data['title']) && !empty($data['title'])) {
  4269. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  4270. }
  4271. //level
  4272. if (isset($data['level']) && !empty($data['level'])) {
  4273. $where[] = ['notice.level', '=', $data['level']];
  4274. }
  4275. //status
  4276. if (isset($data['status']) && !empty($data['status'])) {
  4277. $where[] = ['notice.status', '=', $data['status']];
  4278. }
  4279. //type
  4280. if (isset($data['type']) && !empty($data['type'])) {
  4281. $where[] = ['notice.type', '=', $data['type']];
  4282. }
  4283. var_dump($data, '------------11111-2----test---------');
  4284. if ($data['type_id'] == 10000) {
  4285. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4286. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4287. })
  4288. ->where($where)
  4289. ->orderBy('updated_at', 'desc')
  4290. ->limit($data['page_size'])
  4291. ->offset(($data['page'] - 1) * $data['page_size'])
  4292. ->get();
  4293. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4294. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4295. })
  4296. ->where($where)
  4297. ->orderBy('updated_at', 'desc')
  4298. ->count();
  4299. } else {
  4300. $result = Notice::where($where)
  4301. // ->where('user_id', $data['user_id'])
  4302. ->Where(function ($query) use ($data) {
  4303. $query->Where(function ($q) use ($data) {
  4304. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4305. ->orWhere('notice.user_id', $data['user_id']);
  4306. });
  4307. })
  4308. ->when(!empty($data['status1']), function ($query) use ($data) {
  4309. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4310. })
  4311. ->orderBy('updated_at', 'desc')
  4312. ->limit($data['page_size'])
  4313. ->offset(($data['page'] - 1) * $data['page_size'])
  4314. ->get();
  4315. $total = Notice::where($where)
  4316. ->when(!empty($data['status1']), function ($query) use ($data) {
  4317. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4318. })
  4319. // ->where('user_id', $data['user_id'])
  4320. ->Where(function ($query) use ($data) {
  4321. $query->Where(function ($q) use ($data) {
  4322. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4323. ->orWhere('notice.user_id', $data['user_id']);
  4324. });
  4325. })
  4326. ->count();
  4327. }
  4328. if (empty($result)) {
  4329. return Result::error("查询失败", 0);
  4330. }
  4331. $data = [
  4332. 'rows' => $result,
  4333. 'count' => $total,
  4334. ];
  4335. return Result::success($data);
  4336. }
  4337. public function getNoticeDetail(array $data): array
  4338. {
  4339. $result = Notice::where('id', $data['id'])->first();
  4340. if (empty($result)) {
  4341. return Result::error("查询失败", 0);
  4342. }
  4343. return Result::success($result);
  4344. }
  4345. public function deleteNotice(array $data): array
  4346. {
  4347. $notice = Notice::where('id', $data['id'])->first();
  4348. if (empty($notice)) {
  4349. return Result::error("删除失败", 0);
  4350. }
  4351. $chat_group_id = $notice->group_id;
  4352. if ($chat_group_id) {
  4353. //删除群聊
  4354. ChatGroups::where('id', $chat_group_id)->delete();
  4355. //删除群成员
  4356. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  4357. //删除群聊记录
  4358. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  4359. }
  4360. $result = Notice::where('id', $data['id'])->delete();
  4361. return Result::success($result);
  4362. }
  4363. public function complaintList(array $data): array
  4364. {
  4365. var_dump($data, '---------1---------');
  4366. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4367. unset($data['type_id']);
  4368. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4369. $where = [];
  4370. if ($type_id != 10000 && empty($data['deal_user'])) {
  4371. // $where['complaint.user_id'] = $user_id;
  4372. }
  4373. if (!empty($data['title'])) {
  4374. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4375. }
  4376. if (!empty($data['department_id'])) {
  4377. $where['complaint.department_id'] = $data['department_id'];
  4378. }
  4379. if (!empty($data['deal'])) {
  4380. $where['complaint.deal'] = $data['deal'];
  4381. }
  4382. if (!empty($data['status'])) {
  4383. $where['complaint.status'] = $data['status'];
  4384. }
  4385. var_dump(!empty($data['deal_user']), '----------1');
  4386. var_dump($where, '----------2');
  4387. $result = Complaint::where($where)
  4388. ->when(!empty($data['status1']), function ($query) use ($data) {
  4389. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4390. })
  4391. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4392. //json re_user_ids data[user_id]是不是在里面
  4393. $query->Where(function ($q) use ($data) {
  4394. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4395. ->where('complaint.status', 2);
  4396. });
  4397. })
  4398. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4399. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4400. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4401. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4402. ->orderBy('updated_at', 'desc')
  4403. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4404. //sql输出
  4405. if (empty($result)) {
  4406. return Result::error("暂无投诉信息", 0);
  4407. }
  4408. // 取出数据
  4409. $rows = $result->items();
  4410. $count = $result->total();
  4411. $responseData = [
  4412. 'rows' => $rows,
  4413. 'count' => $count,
  4414. ];
  4415. return Result::success($responseData);
  4416. }
  4417. public function getComplaintList(array $data): array
  4418. {
  4419. var_dump($data, '00000001000000000000');
  4420. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4421. unset($data['type_id']);
  4422. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4423. $where = [];
  4424. if ($type_id != 10000 && empty($data['deal_user'])) {
  4425. $where['complaint.user_id'] = $user_id;
  4426. }
  4427. if (!empty($data['title'])) {
  4428. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4429. }
  4430. if (!empty($data['department_id'])) {
  4431. $where['complaint.department_id'] = $data['department_id'];
  4432. }
  4433. if (!empty($data['deal'])) {
  4434. $where['complaint.deal'] = $data['deal'];
  4435. }
  4436. if (!empty($data['status'])) {
  4437. $where['complaint.status'] = $data['status'];
  4438. }
  4439. var_dump(!empty($data['deal_user']), '----------1');
  4440. var_dump($where, '----------2');
  4441. $result = Complaint::where($where)
  4442. ->when(!empty($data['status1']), function ($query) use ($data) {
  4443. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4444. })
  4445. // ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4446. // //json re_user_ids data[user_id]是不是在里面
  4447. // $query->Where(function ($q) use ($data) {
  4448. // $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4449. // ->where('complaint.status', 2);
  4450. // });
  4451. // })
  4452. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4453. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4454. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4455. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4456. ->orderBy('updated_at', 'desc')
  4457. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4458. //sql输出
  4459. if (empty($result)) {
  4460. return Result::error("暂无投诉信息", 0);
  4461. }
  4462. // 取出数据
  4463. $rows = $result->items();
  4464. $count = $result->total();
  4465. $responseData = [
  4466. 'rows' => $rows,
  4467. 'count' => $count,
  4468. ];
  4469. return Result::success($responseData);
  4470. }
  4471. public function getComplaintInfo(array $data): array
  4472. {
  4473. $result = Complaint::where('id', $data['id'])->first();
  4474. if (empty($result)) {
  4475. return Result::error("查询失败", 0);
  4476. }
  4477. return Result::success($result);
  4478. }
  4479. public function readComplaint(array $data): array
  4480. {
  4481. $result = Complaint::where('id', $data['id'])->first();
  4482. if (empty($result)) {
  4483. return Result::error("查询失败", 0);
  4484. }
  4485. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4486. $re_user_ids = json_decode($result['re_user_ids'], true);
  4487. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4488. //如果已经存在,就不再添加
  4489. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4490. $read_id = json_decode($result['read_id'], true);
  4491. if (!is_array($read_id)) {
  4492. $read_id = [];
  4493. }
  4494. if (!in_array($data['user_id'], $read_id)) {
  4495. $read_id[] = $data['user_id'];
  4496. $result['read_id'] = json_encode($read_id);
  4497. Complaint::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4498. }
  4499. } else {
  4500. //如果不存在,就添加
  4501. $result['read_id'] = json_encode([$data['user_id']]);
  4502. Complaint::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4503. }
  4504. }
  4505. return Result::success($result);
  4506. }
  4507. public function addComplaint(array $data): array
  4508. {
  4509. date_default_timezone_set('Asia/Shanghai');
  4510. $data['created_at'] = date('Y-m-d H:i:s');
  4511. $data['updated_at'] = date('Y-m-d H:i:s');
  4512. $this->sendMessage([
  4513. 'talk_type' => 800,
  4514. 'title' => $data['title'],
  4515. 'content' => '提交了审核',
  4516. 'messageType' => 6,
  4517. ]);
  4518. $result = Complaint::create($data);
  4519. return Result::success($result);
  4520. }
  4521. public function updateComplaint(array $data): array
  4522. {
  4523. date_default_timezone_set('Asia/Shanghai');
  4524. $data['updated_at'] = date('Y-m-d H:i:s');
  4525. $user_id = $data['user_id'] ?? 0;
  4526. $type_id = $data['type_id'] ?? 0;
  4527. unset($data['user_id']);
  4528. unset($data['type_id']);
  4529. $this->sendMessage([
  4530. 'talk_type' => 800,
  4531. 'title' => $data['title'],
  4532. 'content' => '提交了审核',
  4533. 'messageType' => 6,
  4534. ]);
  4535. $result = Complaint::where('id', $data['id'])->update($data);
  4536. return Result::success($result);
  4537. }
  4538. public function deleteComplaint(array $data): array
  4539. {
  4540. $result = Complaint::where('id', $data['id'])->delete();
  4541. return Result::success($result);
  4542. }
  4543. public function getComplainInfo(array $data): array
  4544. {
  4545. $result = Complaint::where('id', $data['id'])->first();
  4546. if (empty($result)) {
  4547. return Result::error("查询失败", 0);
  4548. }
  4549. return Result::success($result);
  4550. }
  4551. public function updateComplaintStatus(array $data): array
  4552. {
  4553. date_default_timezone_set('Asia/Shanghai');
  4554. $data['updated_at'] = date('Y-m-d H:i:s');
  4555. $user_id = $data['user_id'] ?? 0;
  4556. $type_id = $data['type_id'] ?? 0;
  4557. unset($data['user_id']);
  4558. unset($data['type_id']);
  4559. //处理, 写入处理人
  4560. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  4561. $data['real_deal_user'] = $user_id;
  4562. }
  4563. //如果是deal 23,则判断是不是处理人
  4564. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  4565. $complaintInof = Complaint::where('id', $data['id'])
  4566. ->where('real_deal_user', $user_id)
  4567. ->first();
  4568. if (empty($complaintInof)) {
  4569. return Result::error("处理人错误", 0);
  4570. }
  4571. }
  4572. $complaintInfo = Complaint::where('id', $data['id'])->first();
  4573. if ($data['status'] == 1) {
  4574. $this->sendMessage([
  4575. 'talk_type' => 800,
  4576. 'title' => $complaintInfo['title'],
  4577. 'content' => '提交了审核',
  4578. 'messageType' => 6,
  4579. ]);
  4580. }
  4581. if ($data['status'] == 2 && !isset($data['deal'])) {
  4582. $this->sendMessage([
  4583. 'talk_type' => 801,
  4584. 'title' => $complaintInfo['title'],
  4585. 'content' => '审核通过',
  4586. 'messageType' => 6,
  4587. 'user_id' => $complaintInfo['user_id'],
  4588. ]);
  4589. $this->sendMessage([
  4590. 'talk_type' => 802,
  4591. 'title' => $complaintInfo['title'],
  4592. 'content' => '待处理',
  4593. 'messageType' => 6,
  4594. 'user_id' => $complaintInfo['re_user_ids'],
  4595. ]);
  4596. }
  4597. if ($data['status'] == 3 && !isset($data['deal'])) {
  4598. $this->sendMessage([
  4599. 'talk_type' => 801,
  4600. 'title' => $complaintInfo['title'],
  4601. 'content' => '审核拒绝',
  4602. 'messageType' => 6,
  4603. 'user_id' => $complaintInfo['user_id'],
  4604. ]);
  4605. }
  4606. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 2) {
  4607. $this->sendMessage([
  4608. 'talk_type' => 802,
  4609. 'title' => $complaintInfo['title'],
  4610. 'content' => '处理中',
  4611. 'messageType' => 6,
  4612. 'user_id' => $complaintInfo['re_user_ids'],
  4613. ]);
  4614. }
  4615. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 4) {
  4616. $this->sendMessage([
  4617. 'talk_type' => 802,
  4618. 'title' => $complaintInfo['title'],
  4619. 'content' => '不予处理',
  4620. 'messageType' => 6,
  4621. 'user_id' => $complaintInfo['re_user_ids'],
  4622. ]);
  4623. }
  4624. if ($data['status'] == 2 && isset($data['deal']) && $data['deal'] == 3) {
  4625. $this->sendMessage([
  4626. 'talk_type' => 802,
  4627. 'title' => $complaintInfo['title'],
  4628. 'content' => '已完结',
  4629. 'messageType' => 6,
  4630. 'user_id' => $complaintInfo['re_user_ids'],
  4631. ]);
  4632. }
  4633. $result = complaint::where('id', $data['id'])->update($data);
  4634. return Result::success($result);
  4635. }
  4636. public function updateGoodStatus(array $data): array
  4637. {
  4638. $user_id = $data['user_id'] ?? 0;
  4639. $type_id = $data['type_id'] ?? 0;
  4640. unset($data['user_id']);
  4641. unset($data['type_id']);
  4642. $goodInfo = Good::where('id', $data['id'])->first();
  4643. if ($data['status'] == 2) {
  4644. $this->sendMessage([
  4645. 'talk_type' => 201,
  4646. 'title' => $goodInfo['name'],
  4647. 'content' => '审核通过',
  4648. 'messageType' => 3,
  4649. 'user_id' => $goodInfo['user_id'],
  4650. ]);
  4651. }
  4652. if ($data['status'] == 3) {
  4653. $this->sendMessage([
  4654. 'talk_type' => 201,
  4655. 'title' => $goodInfo['name'],
  4656. 'content' => '审核拒绝',
  4657. 'messageType' => 3,
  4658. 'user_id' => $goodInfo['user_id'],
  4659. ]);
  4660. }
  4661. if ($data['status'] == 1) {
  4662. $this->sendMessage([
  4663. 'talk_type' => 200,
  4664. 'title' => $goodInfo['name'],
  4665. 'content' => '提交了审核',
  4666. 'messageType' => 3,
  4667. ]);
  4668. }
  4669. $result = Good::where('id', $data['id'])->update($data);
  4670. return Result::success($result);
  4671. }
  4672. public function updateJobHuntingStatus(array $data): array
  4673. {
  4674. $user_id = $data['user_id'] ?? 0;
  4675. $type_id = $data['type_id'] ?? 0;
  4676. unset($data['user_id']);
  4677. unset($data['type_id']);
  4678. $jogHuntingInfo = JobHunting::where('id', $data['id'])->first();
  4679. if ($data['status'] == 2) {
  4680. $this->sendMessage([
  4681. 'talk_type' => 601,
  4682. 'title' => $jogHuntingInfo['name'],
  4683. 'content' => '审核通过',
  4684. 'messageType' => 11,
  4685. 'user_id' => $jogHuntingInfo['user_id'],
  4686. ]);
  4687. }
  4688. if ($data['status'] == 3) {
  4689. $this->sendMessage([
  4690. 'talk_type' => 601,
  4691. 'title' => $jogHuntingInfo['name'],
  4692. 'content' => '审核拒绝',
  4693. 'messageType' => 11,
  4694. 'user_id' => $jogHuntingInfo['user_id'],
  4695. ]);
  4696. }
  4697. if ($data['status'] == 1) {
  4698. $this->sendMessage([
  4699. 'talk_type' => 600,
  4700. 'title' => $jogHuntingInfo['name'],
  4701. 'content' => '提交了审核',
  4702. 'messageType' => 11,
  4703. ]);
  4704. }
  4705. $result = JobHunting::where('id', $data['id'])->update($data);
  4706. return Result::success($result);
  4707. }
  4708. public function updateNoticeStatus(array $data): array
  4709. {
  4710. $user_id = $data['user_id'] ?? 0;
  4711. $type_id = $data['type_id'] ?? 0;
  4712. unset($data['user_id']);
  4713. unset($data['type_id']);
  4714. //查询公告
  4715. $notice = Notice::where('id', $data['id'])->first();
  4716. if (empty($notice)) {
  4717. return Result::error("公告不存在", 0);
  4718. }
  4719. //$chat_ids 去除掉$data['user_id']
  4720. $chat_ids = json_decode($notice['re_user_ids'], true);
  4721. $chat_ids = array_diff($chat_ids, [$notice['user_id']]);
  4722. //如果公告的状态是2,且是群聊公告,且状态是1,则创建群聊,第一次审核通过的时候处理成群聊
  4723. if ($data['status'] == 2 && $notice['is_group'] == 1 && ($notice['status'] == 1 || $notice['status'] == 3) && empty($notice['group_id'])) {
  4724. //chat_group
  4725. $group_id = PublicData::uuid();
  4726. $groupData = [
  4727. 'id' => $group_id,
  4728. 'creator_id' => $notice['user_id'],
  4729. 'group_name' => $notice['group_name'] ?? '',
  4730. 'profile' => $notice['profile'] ?? 0,
  4731. ];
  4732. var_dump($groupData, '-----------------groupData-------');
  4733. $groupResult = ChatGroups::insertGetId($groupData);
  4734. var_dump($groupResult, '-----------------groupid-------');
  4735. $groupMemberData = [
  4736. 'id' => PublicData::uuid(),
  4737. 'user_id' => $notice['user_id'],
  4738. 'group_id' => $group_id,
  4739. 'leader' => 2,
  4740. ];
  4741. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  4742. //插入群成员表
  4743. $groupMemberDataUser = [];
  4744. $chatData = [];
  4745. foreach ($chat_ids as $key => $value) {
  4746. $groupMemberDataUser[] = [
  4747. 'id' => PublicData::uuid(),
  4748. 'user_id' => $value,
  4749. 'group_id' => $group_id,
  4750. 'leader' => 1,
  4751. ];
  4752. $chatData[] = [
  4753. 'user_id' => $value,
  4754. 'msg_type' => 1,
  4755. 'receiver_id' => $group_id,
  4756. 'content' => '通过通知创建群聊',
  4757. 'group_receiver_id' => $notice['user_id'],
  4758. 'action' => 'recieved',
  4759. 'created_at' => date('Y-m-d H:i:s'),
  4760. ];
  4761. }
  4762. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  4763. ChatGroupsMember::insert($groupMemberDataUser);
  4764. //插入一条管理员聊天记录
  4765. $chatData[] = [
  4766. 'user_id' => $notice['user_id'],
  4767. 'msg_type' => 1,
  4768. 'receiver_id' => $group_id,
  4769. 'content' => '通过通知创建群聊',
  4770. 'group_receiver_id' => $notice['user_id'],
  4771. 'action' => 'said',
  4772. 'created_at' => date('Y-m-d H:i:s'),
  4773. ];
  4774. var_dump($chatData, '-----------------chatData-------');
  4775. $chatResult = ChatRecords::insert($chatData);
  4776. //处理imp
  4777. $group = [
  4778. 'type' => 1,
  4779. 'name' => $notice['group_name'] ?? '',
  4780. 'profile' => '',
  4781. 'avatar' => '',
  4782. 'creator_id' => $notice['user_id'],
  4783. ];
  4784. $groupResult = GroupImp::insertGetId($group);
  4785. var_dump($groupResult, '获取imp group_id');
  4786. $groupMember = [
  4787. 'user_id' => $notice['user_id'],
  4788. 'group_id' => $groupResult,
  4789. 'leader' => 1,
  4790. 'join_time' => Date('Y-m-d H:i:s')
  4791. ];
  4792. $groupMemberResult = GroupMemberImp::insertGetId($groupMember);
  4793. $talk_session = [
  4794. 'user_id' => $notice['user_id'],
  4795. 'to_from_id' => $groupResult,
  4796. 'talk_mode' => 2,
  4797. 'created_at' => Date('Y-m-d H:i:s'),
  4798. 'updated_at' => Date('Y-m-d H:i:s'),
  4799. ];
  4800. $talk_session_result = GroupTalkImp::insertGetId($talk_session);
  4801. //被通知人员处理
  4802. foreach ($chat_ids as $key => $value) {
  4803. $groupMemberdata[] = [
  4804. 'user_id' => $value,
  4805. 'group_id' => $groupResult,
  4806. 'leader' => 3,
  4807. 'join_time' => Date('Y-m-d H:i:s')
  4808. ];
  4809. $talk_sessionData[] = [
  4810. 'user_id' => $value,
  4811. 'to_from_id' => $groupResult,
  4812. 'talk_mode' => 2,
  4813. 'created_at' => Date('Y-m-d H:i:s'),
  4814. 'updated_at' => Date('Y-m-d H:i:s'),
  4815. ];
  4816. }
  4817. $groupResult1 = GroupMemberImp::insert($groupMemberdata);
  4818. $talk_sessionResult = GroupTalkImp::insert($talk_sessionData);
  4819. $group_id = $groupResult;
  4820. //更新result的 group_id
  4821. $data['group_id'] = $group_id;
  4822. Notice::where(['id' => $data['id']])->update($data);
  4823. }
  4824. if (($data['status'] == 1 || $data['status'] == 3) && $notice['is_group'] == 1 && $notice['status'] == 2 && !empty($notice['group_id'])) {
  4825. //删除掉信息
  4826. GroupImp::where('id', $notice['group_id'])->delete();
  4827. GroupMemberImp::where('group_id', $notice['group_id'])->delete();
  4828. GroupTalkImp::where('to_from_id', $notice['group_id'])->delete();
  4829. foreach ($chat_ids as $key => $value) {
  4830. }
  4831. //聊天记录删除
  4832. //如果是群聊公告,且已经有群聊id,则更新公告的group_id
  4833. $data['group_id'] = null;
  4834. Notice::where(['id' => $data['id']])->update($data);
  4835. }
  4836. $result = Notice::where('id', $data['id'])->update($data);
  4837. $noticeInfo = Notice::where('id', $data['id'])->first();
  4838. if ($data['status'] == 2) {
  4839. $this->sendMessage([
  4840. 'talk_type' => 701,
  4841. 'title' => $noticeInfo['title'],
  4842. 'content' => '审核通过',
  4843. 'messageType' => 3,
  4844. 'user_id' => $noticeInfo['user_id'],
  4845. ]);
  4846. }
  4847. if ($data['status'] == 3) {
  4848. $this->sendMessage([
  4849. 'talk_type' => 701,
  4850. 'title' => $noticeInfo['title'],
  4851. 'content' => '审核拒绝',
  4852. 'messageType' => 3,
  4853. 'user_id' => $noticeInfo['user_id'],
  4854. ]);
  4855. }
  4856. if ($data['status'] == 1) {
  4857. $this->sendMessage([
  4858. 'talk_type' => 700,
  4859. 'title' => $noticeInfo['title'],
  4860. 'content' => '提交了审核',
  4861. 'messageType' => 3,
  4862. ]);
  4863. }
  4864. return Result::success($result);
  4865. }
  4866. public function getDUser(array $data): array
  4867. {
  4868. if (!empty($data['ids'])) {
  4869. $user = User::whereIn('id', $data['ids'])->getall();
  4870. if (empty($user)) {
  4871. return Result::error('无数据', 0);
  4872. }
  4873. return Result::success($user);
  4874. }
  4875. $where = [];
  4876. if (!empty($data['department_id'])) {
  4877. $where['department_id'] = $data['department_id'];
  4878. }
  4879. if (!empty($data['city_id'])) {
  4880. $where['city_id'] = $data['city_id'];
  4881. }
  4882. $result = User::where('type_id', 2)
  4883. ->where('status', 1)
  4884. ->where($where)
  4885. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  4886. ->get();
  4887. if (empty($result)) {
  4888. return Result::error("查询失败", 0);
  4889. }
  4890. return Result::success($result);
  4891. }
  4892. /**
  4893. * 验证导航名称是否重复
  4894. * @return void
  4895. */
  4896. public function checkCategoryName(array $data): array
  4897. {
  4898. $result = Category::when($data, function ($query) use ($data) {
  4899. if (isset($data['name']) && $data['name']) {
  4900. $query->where("name", $data['name']);
  4901. }
  4902. if (isset($data['id']) && $data['id']) {
  4903. $query->where("id", "!=", $data['id']);
  4904. }
  4905. })->first();
  4906. if ($result) {
  4907. return Result::error("已存在");
  4908. } else {
  4909. return Result::success();
  4910. }
  4911. }
  4912. //20250226 产品列表
  4913. // 20250306 -------招聘--------fr
  4914. /*
  4915. * 招聘列表
  4916. * */
  4917. public function getJobRecruitingList(array $data): array
  4918. {
  4919. $where = [];
  4920. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  4921. if ($data['checkout'] == 0) {
  4922. $job_status = [0, 2];
  4923. } else {
  4924. $job_status = [1];
  4925. }
  4926. if (isset($data['keyword']) && !empty($data['keyword'])) {
  4927. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  4928. }
  4929. $user = User::where('id', $data['user_id'])->first();
  4930. if (empty($user)) {
  4931. return Result::error("用户不存在", 0);
  4932. }
  4933. // 3:企业会员
  4934. if ($user['type_id'] == 3) {
  4935. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  4936. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  4937. }
  4938. // 如果 $where 为空,则不添加 where 条件
  4939. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4940. return $query->where($where);
  4941. })
  4942. ->whereIn('job_recruiting.status', $job_status)
  4943. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4944. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  4945. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  4946. ->orderBy("updated_at", "desc")
  4947. ->offset(($data['page'] - 1) * $data['page_size'])
  4948. ->limit($data['page_size'])
  4949. ->get()
  4950. ->all();
  4951. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4952. return $query->where($where);
  4953. })
  4954. ->whereIn('job_recruiting.status', $job_status)
  4955. ->count();
  4956. if (empty($result)) {
  4957. return Result::error("暂无招聘信息", 0);
  4958. }
  4959. return Result::success($result);
  4960. }
  4961. /*
  4962. * 招聘信息添加
  4963. * */
  4964. public function addJobRecruiting(array $data): array
  4965. {
  4966. // var_dump('添加招聘进入news------data',$data);
  4967. // return Result::success($data);
  4968. $user = User::where('user.id', $data['user_id'])
  4969. ->where('user.status', 1)
  4970. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  4971. ->select(
  4972. 'user.type_id',
  4973. 'user.mobile',
  4974. 'user.email',
  4975. 'user_info.business_name',
  4976. 'user_info.company_hy_id',
  4977. 'user_info.company_nature',
  4978. 'user_info.company_size',
  4979. 'user_info.introduction',
  4980. 'user_info.real_name',
  4981. 'user_info.company_url',
  4982. 'user_info.address_arr_id',
  4983. 'user_info.address'
  4984. )
  4985. ->first();
  4986. if (empty($user) || $user['type_id'] != $data['user_type']) {
  4987. return Result::error("用户不存在", 0);
  4988. }
  4989. $web = Website::where('id', $data['website_id'])->first();
  4990. if (empty($web)) {
  4991. return Result::error("网站不存在", 0);
  4992. }
  4993. // var_dump('添加招聘进入news---user---user',$user);
  4994. // return Result::success($user);
  4995. $data['action_id'] = $data['user_id'] ?? null;
  4996. $data['user_type'] = $user['type_id'] ?? null;
  4997. $data['cat_arr_id'] = isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) ? array_values(array_unique($data['cat_arr_id'])) : [];
  4998. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? array_values(array_unique($data['city_arr_id'])) : [];
  4999. $data['cat_arr_id'] = isset($data['cat_arr_id']) && $data['cat_arr_id'] != [] ? json_encode(array_map('intval', $data['cat_arr_id'])) : '[]';
  5000. $data['city_arr_id'] = isset($data['city_arr_id']) && !empty($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '[]';
  5001. // 公司地址 管理员必填
  5002. $data['address_arr_id'] = isset($data['address_arr_id']) && !empty($data['address_arr_id']) ? array_values(array_unique($data['address_arr_id'])) : [];
  5003. $data['address_arr_id'] = isset($data['address_arr_id']) && $data['address_arr_id'] != [] ? json_encode(array_map('intval', $data['address_arr_id'])) : '[]';
  5004. // 管理员-企业相关信息
  5005. $company = [
  5006. // 'user_id' => $data['user_id']?? null,
  5007. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5008. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5009. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5010. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5011. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5012. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5013. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5014. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5015. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5016. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5017. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5018. ];
  5019. //去掉相关企业信息
  5020. $job = array_diff_key($data, array_flip(array_keys($company)));
  5021. // var_dump('添加招聘进入news---job---user',$job);
  5022. Db::beginTransaction();
  5023. try {
  5024. // // 先添加职位相关信息
  5025. if ($user['type_id'] == 10000) {
  5026. $job['status'] = 1;
  5027. }
  5028. $job['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5029. $job['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5030. $job['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5031. $job['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5032. $job['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5033. $job['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5034. $job['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5035. // return Result::success($job);
  5036. $jobId = JobRecruiting::insertGetId($job);
  5037. if (empty($jobId)) {
  5038. Db::rollBack();
  5039. return Result::error("添加失败");
  5040. }
  5041. // 添加公司信息
  5042. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5043. $company['job_id'] = $jobId;
  5044. $company['user_type'] = isset($user['type_id']) && $user['type_id'] !== '' ? $user['type_id'] : null;
  5045. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5046. if ($user['type_id'] == 10000) {
  5047. // 管理员添加企业信息
  5048. $companyId = JobCompany::insertGetId($company);
  5049. if (empty($companyId)) {
  5050. Db::rollBack();
  5051. return Result::error("添加失败");
  5052. }
  5053. } else {
  5054. // 企业会员添加企业信息
  5055. $company['user_id'] = isset($data['user_id']) && $data['user_id'] !== '' ? $data['user_id'] : null;
  5056. $company['website_id'] = isset($data['website_id']) && $data['website_id'] !== '' ? $data['website_id'] : null;
  5057. $company['user_type'] = isset($data['user_type']) && $data['user_type'] !== '' ? $data['user_type'] : null;
  5058. $company['job_id'] = $jobId;
  5059. $companyId = JobCompany::insertGetId($company);
  5060. if (empty($companyId)) {
  5061. Db::rollBack();
  5062. return Result::error("添加失败");
  5063. }
  5064. }
  5065. Db::commit();
  5066. $result = [
  5067. 'job_id' => $jobId,
  5068. 'company_id' => $companyId,
  5069. ];
  5070. return Result::success($result);
  5071. } catch (\Exception $e) {
  5072. Db::rollBack();
  5073. return Result::error($e->getMessage(), 0);
  5074. }
  5075. // return Result::success($result);
  5076. }
  5077. /*
  5078. * 获取招聘信息详情
  5079. * */
  5080. public function getJobRecruitingInfo(array $data): array
  5081. {
  5082. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  5083. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  5084. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5085. ->select(
  5086. 'job_recruiting.*',
  5087. 'website.website_name as website_name',
  5088. 'job_company.business_name',
  5089. 'job_company.company_hy_id',
  5090. 'job_company.company_size',
  5091. 'job_company.company_nature',
  5092. 'job_company.introduction',
  5093. 'job_company.real_name',
  5094. 'job_company.mobile',
  5095. 'job_company.company_url',
  5096. 'job_company.address_arr_id',
  5097. 'job_company.address',
  5098. 'job_company.email'
  5099. )
  5100. ->first();
  5101. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  5102. if (!empty($cityId)) {
  5103. if (isset($cityId[1]) && $cityId[1] != null) {
  5104. $city = District::where('id', $cityId[1])->first(['name']);
  5105. } else {
  5106. $city = District::where('id', $cityId[0])->first(['name']);
  5107. }
  5108. $result['city'] = $city['name'] ?? '';
  5109. }
  5110. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  5111. if (is_array($addressId) && !empty($addressId)) {
  5112. $address = District::whereIn('id', $addressId)
  5113. ->orderBy('level', 'asc')
  5114. ->get(['name'])
  5115. ->pluck('name')
  5116. ->implode('');
  5117. // $job->address_name = $address ?? '';
  5118. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  5119. }
  5120. if (empty($result)) {
  5121. return Result::error("招聘信息不存在", 0);
  5122. }
  5123. // return Result::success($job);
  5124. return Result::success($result);
  5125. }
  5126. /*
  5127. * 修改招聘信息
  5128. * */
  5129. public function upJobRecruiting(array $data): array
  5130. {
  5131. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  5132. // return Result::success($job);
  5133. if (empty($job)) {
  5134. return Result::error("招聘信息不存在", 0);
  5135. }
  5136. $user = User::where('id', $data['user_id'])->first();
  5137. // return Result::success($user);
  5138. if (empty($user) || $user['type_id'] != $data['user_type']) {
  5139. return Result::error("用户不存在", 0);
  5140. }
  5141. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5142. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5143. }
  5144. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  5145. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  5146. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  5147. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  5148. // 公司地址 管理员必填
  5149. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  5150. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5151. // 管理员-企业相关信息
  5152. $company = [
  5153. // 'user_id' => $data['user_id']?? null,
  5154. 'business_name' => isset($data['business_name']) && $data['business_name'] !== '' ? $data['business_name'] : null,
  5155. 'company_hy_id' => isset($data['company_hy_id']) && $data['company_hy_id'] !== '' ? $data['company_hy_id'] : null,
  5156. 'company_size' => isset($data['company_size']) && $data['company_size'] !== '' ? $data['company_size'] : null,
  5157. 'company_nature' => isset($data['company_nature']) && $data['company_nature'] !== '' ? $data['company_nature'] : null,
  5158. 'introduction' => isset($data['introduction']) && $data['introduction'] !== '' ? $data['introduction'] : null,
  5159. 'real_name' => isset($data['real_name']) && $data['real_name'] !== '' ? $data['real_name'] : null,
  5160. 'mobile' => isset($data['mobile']) && $data['mobile'] !== '' ? $data['mobile'] : null,
  5161. 'company_url' => isset($data['company_url']) && $data['company_url'] !== '' ? $data['company_url'] : null,
  5162. 'address_arr_id' => isset($data['address_arr_id']) && $data['address_arr_id'] !== '' ? $data['address_arr_id'] : null,
  5163. 'address' => isset($data['address']) && $data['address'] !== '' ? $data['address'] : null,
  5164. 'email' => isset($data['email']) && $data['email'] !== '' ? $data['email'] : null,
  5165. ];
  5166. //去掉相关企业信息
  5167. $data = array_diff_key($data, array_flip(array_keys($company)));
  5168. $jobId = $data['id'];
  5169. $web = $data['website_id'];
  5170. $data['action_id'] = $data['user_id'];
  5171. unset($data['user_id']);
  5172. unset($data['user_type']);
  5173. unset($data['id']);
  5174. unset($data['website_id']);
  5175. // return Result::success($data);
  5176. Db::beginTransaction();
  5177. try {
  5178. // 管理员修改招聘信息
  5179. if ($user['type_id'] == 10000) {
  5180. $data['website_id'] = $web;
  5181. $company['website_id'] = $data['website_id'];
  5182. $data['status'] = 1;
  5183. } else {
  5184. $data['status'] = 0;
  5185. }
  5186. $data['experience'] = isset($data['experience']) && $data['experience'] !== '' ? $data['experience'] : null;
  5187. $data['salary'] = isset($data['salary']) && $data['salary'] !== '' ? $data['salary'] : null;
  5188. $data['number'] = isset($data['number']) && $data['number'] !== '' ? $data['number'] : null;
  5189. $data['language'] = isset($data['language']) && $data['language'] !== '' ? $data['language'] : null;
  5190. $data['level'] = isset($data['level']) && $data['level'] !== '' ? $data['level'] : null;
  5191. $data['job_level'] = isset($data['job_level']) && $data['job_level'] !== '' ? $data['job_level'] : null;
  5192. $data['educational'] = isset($data['educational']) && $data['educational'] !== '' ? $data['educational'] : null;
  5193. // return Result::success($job);
  5194. // Db::rollBack();
  5195. // return Result::success($company);
  5196. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  5197. $this->sendMessage([
  5198. 'talk_type' => 500,
  5199. 'title' => $data['title'],
  5200. 'content' => '提交了审核',
  5201. 'messageType' => 10,
  5202. ]);
  5203. }
  5204. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  5205. if (empty($result['job'])) {
  5206. Db::rollBack();
  5207. return Result::error("修改招聘信息失败");
  5208. }
  5209. // 管理员修改企业相关信息
  5210. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  5211. if (empty($result['company'])) {
  5212. Db::rollBack();
  5213. return Result::error("修改企业相关信息失败");
  5214. }
  5215. Db::commit();
  5216. // return Result::success($result);
  5217. } catch (\Exception $e) {
  5218. Db::rollBack();
  5219. return Result::error($e->getMessage(), 0);
  5220. }
  5221. return Result::success($result);
  5222. }
  5223. /*
  5224. * 招聘信息删除
  5225. * */
  5226. public function delJobRecruiting(array $data): array
  5227. {
  5228. $user = User::where('id', $data['user_id'])->first();
  5229. if (empty($user)) {
  5230. return Result::error("用户不存在", 0);
  5231. }
  5232. $job = JobRecruiting::where('id', $data['id'])->first();
  5233. if (empty($job)) {
  5234. return Result::error("招聘信息不存在", 0);
  5235. }
  5236. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  5237. return Result::error("用户暂无权限修改此招聘信息!", 0);
  5238. }
  5239. Db::beginTransaction();
  5240. try {
  5241. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  5242. if (empty($result['job'])) {
  5243. Db::rollBack();
  5244. return Result::error("删除招聘信息失败");
  5245. }
  5246. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  5247. if (empty($result['company'])) {
  5248. Db::rollBack();
  5249. return Result::error("删除企业相关信息失败");
  5250. }
  5251. Db::commit();
  5252. } catch (\Exception $e) {
  5253. Db::rollBack();
  5254. return Result::error($e->getMessage(), 0);
  5255. }
  5256. return Result::success($result);
  5257. }
  5258. /*
  5259. * 获取公司信息
  5260. * */
  5261. public function getJobCompany(array $data): array
  5262. {
  5263. $user = User::where('user.id', $data['user_id'])
  5264. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  5265. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  5266. ->first();
  5267. // return Result::success($user);
  5268. if (empty($user)) {
  5269. return Result::error("用户不存在", 0);
  5270. }
  5271. if ($user['type_id'] == 3) {
  5272. $result = [
  5273. // 'id' => 0,
  5274. 'user_id' => $data['user_id'],
  5275. 'website_id' => $data['website_id'],
  5276. 'business_name' => $user['business_name'], // 企业名称
  5277. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  5278. 'company_nature' => $user['company_nature'], // 公司性质
  5279. 'company_size' => $user['company_size'], // 公司规模
  5280. 'introduction' => $user['introduction'], // 公司简介
  5281. 'real_name' => $user['real_name'], // 企业联系人
  5282. 'mobile' => $user['mobile'], // 企业联系电话
  5283. 'company_url' => $user['company_url'], // 企业网址
  5284. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  5285. 'address' => $user['address'], // 企业地址
  5286. 'email' => $user['email'], // 企业邮箱
  5287. ];
  5288. } else {
  5289. return Result::error("用户类型错误", 0);
  5290. }
  5291. if (empty($result)) {
  5292. return Result::error("公司信息不存在", 0);
  5293. }
  5294. return Result::success($result);
  5295. }
  5296. /*
  5297. * 修改公司信息
  5298. * */
  5299. public function upJobCompany(array $data): array
  5300. {
  5301. // return Result::success($data);
  5302. $user = User::where('user.id', $data['user_id'])
  5303. ->where('user.status', 1)
  5304. ->select('user.user_name', 'user.type_id')
  5305. ->first();
  5306. if (empty($user)) {
  5307. return Result::error("用户不存在", 0);
  5308. }
  5309. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  5310. $job_company = JobCompany::where('user_id', $data['user_id'])->first();
  5311. $company = [
  5312. 'business_name' => $data['business_name'], // 企业名称
  5313. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5314. 'company_nature' => $data['company_nature'], // 公司性质
  5315. 'company_size' => $data['company_size'], // 公司规模
  5316. 'introduction' => $data['introduction'], // 公司简介
  5317. // 'real_name' => $data['real_name'], // 企业联系人
  5318. 'company_url' => $data['company_url'], // 企业网址
  5319. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5320. 'address' => $data['address'], // 企业详细地址
  5321. // 'email' => $data['email'], // 企业邮箱
  5322. ];
  5323. if ($user['type_id'] == 3) {
  5324. Db::beginTransaction();
  5325. try {
  5326. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  5327. 'business_name' => $data['business_name'], // 企业名称
  5328. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  5329. 'company_nature' => $data['company_nature'], // 公司性质
  5330. 'company_size' => $data['company_size'], // 公司规模
  5331. 'introduction' => $data['introduction'], // 公司简介
  5332. // 'real_name' => $data['real_name'], // 企业联系人
  5333. 'company_url' => $data['company_url'], // 企业网址
  5334. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  5335. 'address' => $data['address'], // 企业详细地址
  5336. ]);
  5337. if (empty($result['userinfo'])) {
  5338. Db::rollBack();
  5339. return Result::error('修改企业会员信息失败!');
  5340. }
  5341. $result['user'] = User::where('id', $data['user_id'])->update([
  5342. 'email' => $data['email'], // 企业邮箱
  5343. ]);
  5344. if (empty($result['user'])) {
  5345. Db::rollBack();
  5346. return Result::error('修改个人中心信息失败!');
  5347. }
  5348. // 该企业会员若是未发布招聘信息则暂无该企业会员的企业信息
  5349. if (!empty($job_company)) {
  5350. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  5351. if (empty($result['job_company'])) {
  5352. Db::rollBack();
  5353. return Result::error('修改企业会员信息失败!');
  5354. }
  5355. }
  5356. Db::commit();
  5357. return Result::success($result);
  5358. } catch (\Exception $e) {
  5359. Db::rollBack();
  5360. return Result::error($e->getMessage(), 0);
  5361. }
  5362. } else {
  5363. return Result::error("用户类型错误", 0);
  5364. }
  5365. }
  5366. /*
  5367. * 获取省-市
  5368. * */
  5369. public function getJobRecruitingArea(array $data): array
  5370. {
  5371. if (isset($data['pid']) && $data['pid'] != null) {
  5372. $result = District::where('pid', $data['pid'])->get()->all();
  5373. } else {
  5374. $result = District::where('level', 1)->get()->all();
  5375. }
  5376. if (empty($result)) {
  5377. return Result::error("暂无此省市", 0);
  5378. }
  5379. return Result::success($result);
  5380. }
  5381. /*
  5382. * 获取行业分类
  5383. * */
  5384. public function getIndustry(array $data): array
  5385. {
  5386. $result = JobIndustry::get()->all();
  5387. if (empty($result)) {
  5388. return Result::error("暂无行业分类", 0);
  5389. }
  5390. return Result::success($result);
  5391. }
  5392. /*
  5393. * 获取职位
  5394. * */
  5395. public function getPositionList(array $data): array
  5396. {
  5397. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  5398. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  5399. } else {
  5400. $result = JobPosition::where('zwpid', 0)->get()->all();
  5401. }
  5402. if (empty($result)) {
  5403. return Result::error("暂无此职位", 0);
  5404. }
  5405. return Result::success($result);
  5406. }
  5407. /*
  5408. * 获取工作性质-菜单
  5409. * */
  5410. public function getJobNature(array $data): array
  5411. {
  5412. $result = JobEnum::where('egroup', 'nature')->get()->all();
  5413. if (empty($result)) {
  5414. return Result::error("暂无工作性质", 0);
  5415. }
  5416. return Result::success($result);
  5417. }
  5418. /*
  5419. * 获取工作经验-菜单
  5420. * */
  5421. public function getExperience(array $data): array
  5422. {
  5423. $result = JobEnum::where('egroup', 'years')->get()->all();
  5424. if (empty($result)) {
  5425. return Result::error("暂无工作经验", 0);
  5426. }
  5427. return Result::success($result);
  5428. }
  5429. /*
  5430. * 获取学历-菜单
  5431. * */
  5432. public function getEducation(array $data): array
  5433. {
  5434. $result = JobEnum::where('egroup', 'education')->get()->all();
  5435. if (empty($result)) {
  5436. return Result::error("暂无学历", 0);
  5437. }
  5438. return Result::success($result);
  5439. }
  5440. /*
  5441. * 获取薪资-菜单
  5442. * */
  5443. public function getSalary(array $data): array
  5444. {
  5445. $result = JobEnum::where('egroup', 'income')->get()->all();
  5446. if (empty($result)) {
  5447. return Result::error("暂无薪资", 0);
  5448. }
  5449. return Result::success($result);
  5450. }
  5451. /*
  5452. * 获取语言-菜单
  5453. * */
  5454. public function getLanguage(array $data): array
  5455. {
  5456. $result = JobEnum::where('egroup', 'language')->get()->all();
  5457. if (empty($result)) {
  5458. return Result::error("暂无语言", 0);
  5459. }
  5460. return Result::success($result);
  5461. }
  5462. /*
  5463. * 获取掌握程度-菜单
  5464. * */
  5465. public function getLevel(array $data): array
  5466. {
  5467. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  5468. if (empty($result)) {
  5469. return Result::error("暂无工作性质", 0);
  5470. }
  5471. return Result::success($result);
  5472. }
  5473. // 公司信息
  5474. /*
  5475. * 获取公司性质-菜单
  5476. * */
  5477. public function getCompanyNature(array $data): array
  5478. {
  5479. $result = JobNature::get()->all();
  5480. if (empty($result)) {
  5481. return Result::error("暂无公司性质", 0);
  5482. }
  5483. return Result::success($result);
  5484. }
  5485. /*
  5486. * 获取公司规模-菜单
  5487. * */
  5488. public function getCompanySize(array $data): array
  5489. {
  5490. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  5491. if (empty($result)) {
  5492. return Result::error("暂无公司规模", 0);
  5493. }
  5494. return Result::success($result);
  5495. }
  5496. /*
  5497. * 招聘信息审核
  5498. * */
  5499. public function checkJobRecruiting(array $data): array
  5500. {
  5501. $user = User::where('id', $data['user_id'])->first();
  5502. if (empty($user)) {
  5503. return Result::error("用户不存在", 0);
  5504. }
  5505. $job = JobRecruiting::where('id', $data['id'])->first();
  5506. if (empty($job)) {
  5507. return Result::error("招聘信息不存在", 0);
  5508. }
  5509. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  5510. if ($user['type_id'] != 10000) {
  5511. return Result::error("用户暂无权限审核此招聘信息!", 0);
  5512. }
  5513. // 驳回原因
  5514. if ($data['status'] == 2) {
  5515. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  5516. }
  5517. $data['action_id'] = $data['user_id'];
  5518. unset($data['user_id']);
  5519. if ($data['status'] == 1) {
  5520. $this->sendMessage([
  5521. 'talk_type' => 501,
  5522. 'title' => $job['title'],
  5523. 'content' => '审核通过',
  5524. 'messageType' => 10,
  5525. 'user_id' => $job['user_id'],
  5526. ]);
  5527. }
  5528. if ($data['status'] == 2) {
  5529. $this->sendMessage([
  5530. 'talk_type' => 501,
  5531. 'title' => $job['title'],
  5532. 'content' => '审核拒绝',
  5533. 'messageType' => 10,
  5534. 'user_id' => $job['user_id'],
  5535. ]);
  5536. }
  5537. if ($data['status'] == 0) {
  5538. $this->sendMessage([
  5539. 'talk_type' => 500,
  5540. 'title' => $job['title'],
  5541. 'content' => '提交了审核',
  5542. 'messageType' => 10,
  5543. ]);
  5544. }
  5545. $result = JobRecruiting::where('id', $data['id'])->update($data);
  5546. if (empty($result)) {
  5547. return Result::error("审核失败", 0);
  5548. }
  5549. return Result::success($result);
  5550. }
  5551. public function myApplyList(array $data): array
  5552. {
  5553. var_dump($data, '------参数');
  5554. $user = User::where('id', $data['user_id'])->first();
  5555. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5556. return Result::error("用户不存在", 0);
  5557. }
  5558. // 1:个人会员 职场机会
  5559. if ($user['type_id'] == 1) {
  5560. $where['user_id'] = $user['id'];
  5561. }
  5562. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  5563. $query->where('user_id', $user['id']);
  5564. })
  5565. ->pluck('recruit_id');
  5566. $where = [];
  5567. if (isset($data['salary']) && $data['salary'] != null) {
  5568. $where['job_recruiting.salary'] = $data['salary'];
  5569. }
  5570. if (isset($data['experience']) && $data['experience'] != null) {
  5571. $where['job_recruiting.experience'] = $data['experience'];
  5572. }
  5573. if (isset($data['business_name']) && $data['business_name'] != null) {
  5574. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  5575. }
  5576. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  5577. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5578. ->where($where);
  5579. // ->count();
  5580. $count = $query->count();
  5581. $query = clone $query;
  5582. $job = $query
  5583. ->leftJoin('job_enum as income_enum', function ($join) {
  5584. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  5585. ->where('income_enum.egroup', 'income');
  5586. })
  5587. ->leftJoin('job_enum as years_enum', function ($join) {
  5588. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  5589. ->where('years_enum.egroup', 'years');
  5590. })
  5591. // ->where($where)
  5592. ->orderBy('job_recruiting.updated_at', 'desc')
  5593. ->select(
  5594. 'job_recruiting.id',
  5595. 'job_recruiting.title',
  5596. 'job_company.business_name',
  5597. 'income_enum.evalue as salary_evalue',
  5598. 'income_enum.ename as salary_ename',
  5599. 'years_enum.evalue as experience_evalue',
  5600. 'years_enum.ename as experience_ename',
  5601. 'job_recruiting.updated_at'
  5602. )
  5603. ->offset(($data['page'] - 1) * $data['pageSize'])
  5604. ->limit($data['pageSize'])
  5605. ->get()
  5606. ->all();
  5607. if (empty($job)) {
  5608. return Result::error("暂无招聘信息", 0);
  5609. }
  5610. $result = [
  5611. 'row' => $job,
  5612. 'count' => $count,
  5613. ];
  5614. return Result::success($result);
  5615. }
  5616. public function readJobApply(array $data): array
  5617. {
  5618. $result = JobApply::where('id', $data['id'])->first();
  5619. if (empty($result)) {
  5620. return Result::error("查询失败", 0);
  5621. }
  5622. $result = JobApply::where('id', $data['id'])->update([
  5623. 'status' => 2,
  5624. ]);
  5625. return Result::success($result);
  5626. }
  5627. /*
  5628. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  5629. * */
  5630. public function getRecruitingList(array $data): array
  5631. {
  5632. $user = User::where('id', $data['user_id'])->first();
  5633. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5634. return Result::error("用户不存在", 0);
  5635. }
  5636. // 1:个人会员 职场机会
  5637. if ($user['type_id'] == 1) {
  5638. $where['user_id'] = $user['id'];
  5639. }
  5640. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  5641. $query->where('receiver_id', $user['id']);
  5642. })
  5643. ->pluck('recruit_id');
  5644. // return Result::success($recruitingId);
  5645. $where = [];
  5646. if (isset($data['salary']) && $data['salary'] != null) {
  5647. $where['job_recruiting.salary'] = $data['salary'];
  5648. }
  5649. if (isset($data['experience']) && $data['experience'] != null) {
  5650. $where['job_recruiting.experience'] = $data['experience'];
  5651. }
  5652. if (isset($data['business_name']) && $data['business_name'] != null) {
  5653. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  5654. }
  5655. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  5656. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5657. ->where($where);
  5658. // ->count();
  5659. $count = $query->count();
  5660. $query = clone $query;
  5661. $job = $query
  5662. ->leftJoin('job_enum as income_enum', function ($join) {
  5663. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  5664. ->where('income_enum.egroup', 'income');
  5665. })
  5666. ->leftJoin('job_enum as years_enum', function ($join) {
  5667. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  5668. ->where('years_enum.egroup', 'years');
  5669. })
  5670. // ->where($where)
  5671. ->orderBy('job_recruiting.updated_at', 'desc')
  5672. ->select(
  5673. 'job_recruiting.id',
  5674. 'job_recruiting.title',
  5675. 'job_company.business_name',
  5676. 'income_enum.evalue as salary_evalue',
  5677. 'income_enum.ename as salary_ename',
  5678. 'years_enum.evalue as experience_evalue',
  5679. 'years_enum.ename as experience_ename',
  5680. 'job_recruiting.updated_at'
  5681. )
  5682. ->offset(($data['page'] - 1) * $data['pageSize'])
  5683. ->limit($data['pageSize'])
  5684. ->get()
  5685. ->all();
  5686. if (empty($job)) {
  5687. return Result::error("暂无招聘信息", 0);
  5688. }
  5689. $result = [
  5690. 'row' => $job,
  5691. 'count' => $count,
  5692. ];
  5693. return Result::success($result);
  5694. }
  5695. /*
  5696. * 获取企业会员-招聘信息列表
  5697. * */
  5698. public function getRecruitingInfo(array $data): array
  5699. {
  5700. $user = User::where('id', $data['user_id'])->first();
  5701. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5702. return Result::error("用户不存在", 0);
  5703. }
  5704. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  5705. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5706. ->select(
  5707. 'job_recruiting.*',
  5708. 'job_company.business_name',
  5709. 'job_company.company_hy_id',
  5710. 'job_company.company_size',
  5711. 'job_company.company_nature',
  5712. 'job_company.introduction',
  5713. 'job_company.real_name',
  5714. 'job_company.mobile',
  5715. 'job_company.company_url',
  5716. 'job_company.address_arr_id',
  5717. 'job_company.address',
  5718. 'job_company.email'
  5719. )
  5720. ->get();
  5721. if (empty($recruiting)) {
  5722. return Result::error("暂无招聘信息", 0);
  5723. }
  5724. return Result::success($recruiting);
  5725. }
  5726. /*
  5727. * 获取企业会员-我的沟通
  5728. * */
  5729. public function getJobResumeList(array $data): array
  5730. {
  5731. $user = User::where('id', $data['user_id'])->first();
  5732. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  5733. return Result::error("用户不存在", 0);
  5734. }
  5735. $where = [];
  5736. if (isset($data['salary']) && $data['salary'] != null) {
  5737. $where['job_hunting.salary'] = $data['salary'];
  5738. }
  5739. if (isset($data['user_name']) && $data['user_name'] != null) {
  5740. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  5741. }
  5742. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  5743. $query->where('job_resume.user_id', $user['id']);
  5744. })
  5745. ->when(!empty($where), function ($query) use ($where) {
  5746. $query->where($where);
  5747. })
  5748. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  5749. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  5750. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  5751. ->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');
  5752. $count = $job->count();
  5753. if ($count == 0) {
  5754. return Result::error("暂无沟通记录", 0);
  5755. }
  5756. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  5757. ->offset(($data['page'] - 1) * $data['pageSize'])
  5758. ->limit($data['pageSize'])
  5759. ->get();
  5760. if (empty($jobs)) {
  5761. return Result::error("暂无沟通记录", 0);
  5762. }
  5763. $result['row'] = $this->processJob($jobs, '');
  5764. $result['count'] = $count;
  5765. return Result::success($result);
  5766. }
  5767. public function readJobResume(array $data): array
  5768. {
  5769. $result = JobResume::where('id', $data['id'])->first();
  5770. if (empty($result)) {
  5771. return Result::error("查询失败", 0);
  5772. }
  5773. $result = JobResume::where('id', $data['id'])->update([
  5774. 'status' => 2,
  5775. ]);
  5776. return Result::success($result);
  5777. }
  5778. // 20250306 招聘
  5779. //20250422 书刊音像
  5780. public function addBook(array $data): array
  5781. {
  5782. $user_id = $data['user_id'] ?? 0;
  5783. $type_id = $data['type_id'] ?? 0;
  5784. // $website_id = $data['website_id'] ?? 0;
  5785. // unset($data['user_id']);
  5786. unset($data['type_id']);
  5787. // unset($data['website_id']);
  5788. //处理数组
  5789. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  5790. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  5791. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  5792. if ($data['img_url'] == '') {
  5793. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5794. preg_match_all($reg, $data['detail'], $matches);
  5795. if (isset($matches[1][0])) {
  5796. //截取varchar240
  5797. $data['img_url'] = substr($matches[1][0], 0, 240);
  5798. }
  5799. }
  5800. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  5801. //提取标题+内容中的关键词
  5802. $data['keyword'] = $data['title'];
  5803. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5804. Jieba::init(); // 初始化 jieba-php
  5805. Finalseg::init();
  5806. $segList = Jieba::cut($data['keyword']);
  5807. $segList1 = array_slice($segList, 0, 8);
  5808. $data['keyword'] = implode(',', $segList1);
  5809. }
  5810. if ($data['description'] == '') {
  5811. //提取内容中的描述
  5812. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  5813. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  5814. }
  5815. var_dump($data, '--');
  5816. if ($data['status'] == 1) {
  5817. $this->sendMessage([
  5818. 'talk_type' => 400,
  5819. 'title' => $data['title'],
  5820. 'content' => '提交了审核',
  5821. 'messageType' => 7,
  5822. ]);
  5823. }
  5824. $result = Book::insertGetId($data);
  5825. if (empty($result)) {
  5826. return Result::error("添加失败", 0);
  5827. }
  5828. return Result::success($result);
  5829. }
  5830. public function getBookList(array $data): array
  5831. {
  5832. $where = [];
  5833. if (!empty($data["title"])) {
  5834. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  5835. }
  5836. if (!empty($data['website_name'])) {
  5837. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  5838. }
  5839. if (!empty($data['status'])) {
  5840. $where[] = ['book.status', '=', $data['status']];
  5841. }
  5842. $user_id = $data['user_id'];
  5843. $type_id = $data['type_id'];
  5844. // $type_id = 4;
  5845. var_dump($type_id, '------1--------');
  5846. if ($type_id != 10000) {
  5847. $where[] = ['book.user_id', '=', $user_id];
  5848. }
  5849. var_dump(!empty($data['status1']), '=-===1');
  5850. $result = Book::where($where)
  5851. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  5852. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  5853. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  5854. ->when(isset($data['status1']), function ($query) use ($data) {
  5855. $query->whereIn('book.status', [1, 3]);
  5856. })
  5857. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  5858. ->orderBy("updated_at", "desc")
  5859. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  5860. if (empty($result)) {
  5861. return Result::error("暂无数据", 0);
  5862. }
  5863. // 取出数据
  5864. $rows = $result->items();
  5865. $count = $result->total();
  5866. $responseData = [
  5867. 'rows' => $rows,
  5868. 'count' => $count,
  5869. ];
  5870. return Result::success($responseData);
  5871. }
  5872. public function deleteBook(array $data): array
  5873. {
  5874. $result = Book::where('id', $data['id'])->delete();
  5875. if (empty($result)) {
  5876. return Result::error("删除失败", 0);
  5877. }
  5878. return Result::success($result);
  5879. }
  5880. public function updateBook(array $data): array
  5881. {
  5882. // $user_id = $data['user_id'] ?? 0;
  5883. $type_id = $data['type_id'] ?? 0;
  5884. // $website_id = $data['website_id'] ?? 0;
  5885. unset($data['user_id']);
  5886. unset($data['type_id']);
  5887. // unset($data['website_id']);
  5888. //处理数组
  5889. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  5890. if ($data['img_url'] == '') {
  5891. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5892. preg_match_all($reg, $data['detail'], $matches);
  5893. if (isset($matches[1][0])) {
  5894. //截取varchar240
  5895. $data['img_url'] = substr($matches[1][0], 0, 240);
  5896. }
  5897. }
  5898. if ($data['keyword'] == '') {
  5899. //提取标题+内容中的关键词
  5900. $data['keyword'] = $data['title'];
  5901. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5902. Jieba::init(); // 初始化 jieba-php
  5903. Finalseg::init();
  5904. $segList = Jieba::cut($data['keyword']);
  5905. $segList1 = array_slice($segList, 0, 8);
  5906. $data['keyword'] = implode(',', $segList1);
  5907. }
  5908. if ($data['description'] == '') {
  5909. //提取内容中的描述
  5910. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  5911. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  5912. }
  5913. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  5914. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  5915. if ($data['status'] == 1) {
  5916. $this->sendMessage([
  5917. 'talk_type' => 400,
  5918. 'title' => $data['title'],
  5919. 'content' => '提交了审核',
  5920. 'messageType' => 7,
  5921. ]);
  5922. }
  5923. $result = Book::where("id", $data["id"])->update($data);
  5924. if (empty($result)) {
  5925. return Result::error("更新失败", 0);
  5926. }
  5927. return Result::success($result);
  5928. }
  5929. public function getBookInfo(array $data): array
  5930. {
  5931. $result = Book::where("id", $data["id"])->first();
  5932. if (empty($result)) {
  5933. return Result::error("获取失败", 0);
  5934. }
  5935. return Result::success($result);
  5936. }
  5937. public function updateBookStatus(array $data): array
  5938. {
  5939. //审核
  5940. unset($data['user_id']);
  5941. $bookInfo = Book::where("id", $data["id"])->first();
  5942. var_dump($bookInfo, '----');
  5943. if ($data['status'] == 2) {
  5944. $this->sendMessage([
  5945. 'talk_type' => 401,
  5946. 'title' => $bookInfo['title'],
  5947. 'content' => '审核通过',
  5948. 'messageType' => 7,
  5949. 'user_id' => $bookInfo['user_id'],
  5950. ]);
  5951. }
  5952. if ($data['status'] == 3) {
  5953. $this->sendMessage([
  5954. 'talk_type' => 401,
  5955. 'title' => $bookInfo['title'],
  5956. 'content' => '审核拒绝',
  5957. 'messageType' => 7,
  5958. 'user_id' => $bookInfo['user_id'],
  5959. ]);
  5960. }
  5961. if ($data['status'] == 1) {
  5962. $this->sendMessage([
  5963. 'talk_type' => 400,
  5964. 'title' => $bookInfo['title'],
  5965. 'content' => '提交了审核',
  5966. 'messageType' => 7,
  5967. // 'user_id'=>$bookInfo['user_id'],
  5968. ]);
  5969. }
  5970. $result = Book::where("id", $data["id"])->update($data);
  5971. if (empty($result)) {
  5972. return Result::error("更新失败", 0);
  5973. }
  5974. return Result::success($result);
  5975. }
  5976. //20250422 书刊音像
  5977. /**
  5978. * 贴身宝贝
  5979. * @param array $data
  5980. * @return array
  5981. */
  5982. public function getWebsiteTsbb(array $data): array
  5983. {
  5984. $month = $data['month'] ?? date('m');
  5985. $day = $data['day'] ?? date('d');
  5986. // 使用缓存键
  5987. $cacheKey = "tsbb_data_{$month}_{$day}";
  5988. // 尝试从缓存获取数据
  5989. $container = \Hyperf\Context\ApplicationContext::getContainer();
  5990. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  5991. if ($cachedData = $cache->get($cacheKey)) {
  5992. return Result::success(unserialize($cachedData));
  5993. }
  5994. //查询老黄历
  5995. try {
  5996. $date = date('Y-m-d');
  5997. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  5998. // 使用 curl 替代 file_get_contents
  5999. $ch = curl_init();
  6000. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  6001. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  6002. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  6003. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  6004. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  6005. 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');
  6006. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  6007. 'Accept: application/json',
  6008. 'Content-Type: application/json',
  6009. 'Referer: https://www.36jxs.com/'
  6010. ]);
  6011. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  6012. curl_setopt($ch, CURLOPT_ENCODING, '');
  6013. $almanacResponse = curl_exec($ch);
  6014. var_dump("====:", $almanacResponse);
  6015. if (curl_errno($ch)) {
  6016. var_dump('Curl error:', curl_error($ch));
  6017. throw new \Exception('Curl error: ' . curl_error($ch));
  6018. }
  6019. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  6020. curl_close($ch);
  6021. if ($almanacResponse === false) {
  6022. throw new \Exception('Failed to fetch almanac data');
  6023. }
  6024. $almanacData = json_decode($almanacResponse, true);
  6025. if (json_last_error() !== JSON_ERROR_NONE) {
  6026. throw new \Exception('Failed to parse almanac data');
  6027. }
  6028. $almanacInfo = $almanacData['data'] ?? [];
  6029. } catch (\Exception $e) {
  6030. var_dump('Exception:', $e->getMessage());
  6031. $almanacInfo = [];
  6032. }
  6033. // 获取历史上的今天数据
  6034. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6035. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  6036. ->orderBy('year', 'asc')
  6037. ->select("title", "id", "year", DB::raw('1 as type'))
  6038. ->limit(16)
  6039. ->get();
  6040. // 获取节日数据 - 从今天开始获取未来4条
  6041. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  6042. ->orderBy('showtime', 'asc')
  6043. ->select("title", "id", "showtime", DB::raw('2 as type'))
  6044. ->limit(16)
  6045. ->get();
  6046. //说文解字
  6047. $chartacterList = Character::orderBy('updated_at', 'desc')
  6048. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  6049. ->limit(6)
  6050. ->get();
  6051. //谜语沙龙
  6052. $riddletList = Riddle::orderBy('updated_at', 'desc')
  6053. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  6054. ->limit(4)
  6055. ->get();
  6056. //成语欣赏
  6057. $idiomList = Idiom::orderBy('updated_at', 'desc')
  6058. ->select("id", "title", "duyin", DB::raw('5 as type'))
  6059. ->limit(32)
  6060. ->get();
  6061. //名联赏析
  6062. $coupletList = Couplet::orderBy('updated_at', 'desc')
  6063. ->select("id", "first", "second", DB::raw('6 as type'))
  6064. ->limit(6)
  6065. ->get();
  6066. // 获取分类文章数据
  6067. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  6068. ->pluck('category_id')
  6069. ->toArray();
  6070. $articlesList = [];
  6071. foreach ($categoryIds as $catid) {
  6072. // 先查有图片的
  6073. $withImg = DB::table('article')
  6074. ->where('status', 1)
  6075. ->where('catid', $catid)
  6076. ->whereNotNull('imgurl')
  6077. ->where('imgurl', '!=', '')
  6078. ->orderBy('updated_at', 'desc')
  6079. ->limit(6)
  6080. ->get();
  6081. $count = $withImg->count();
  6082. if ($count < 6) {
  6083. // 不足6条再查无图片的补足
  6084. $withoutImg = DB::table('article')
  6085. ->where('status', 1)
  6086. ->where('catid', $catid)
  6087. ->where(function ($q) {
  6088. $q->whereNull('imgurl')->orWhere('imgurl', '');
  6089. })
  6090. ->orderBy('updated_at', 'desc')
  6091. ->limit(6 - $count)
  6092. ->get();
  6093. $articles = $withImg->concat($withoutImg);
  6094. } else {
  6095. $articles = $withImg;
  6096. }
  6097. // 组装
  6098. $category = \App\Model\Category::find($catid);
  6099. $websiteCategory = WebsiteCategory::where('category_id', $catid)->first();
  6100. $articlesList[] = [
  6101. 'category_name' => $category ? $category->name : '',
  6102. 'catid' => $catid,
  6103. 'pinyin' => $websiteCategory ? $websiteCategory->aLIas_pinyin : '',
  6104. 'type' => 100,
  6105. 'list' => $articles->map(function ($item) {
  6106. return [
  6107. 'id' => $item->id,
  6108. 'title' => $item->title,
  6109. 'imgurl' => $item->imgurl,
  6110. 'created_at' => $item->created_at
  6111. ];
  6112. })->values()
  6113. ];
  6114. }
  6115. $result = [
  6116. 'almanac' => $almanacInfo,
  6117. 'historyTodayList' => [
  6118. 'category_name' => '历史上的今天',
  6119. 'list' => $historyTodayList,
  6120. 'type' => 1
  6121. ],
  6122. 'festivalList' => [
  6123. 'category_name' => '节日预告',
  6124. 'list' => $festivalList,
  6125. 'type' => 2
  6126. ],
  6127. 'chartacterList' => [
  6128. 'category_name' => '说文解字',
  6129. 'list' => $chartacterList,
  6130. 'type' => 3
  6131. ],
  6132. 'coupletList' => [
  6133. 'category_name' => '名联赏析',
  6134. 'list' => $coupletList,
  6135. 'type' => 6
  6136. ],
  6137. 'riddletList' => [
  6138. 'category_name' => '谜语沙龙',
  6139. 'list' => $riddletList,
  6140. 'type' => 4
  6141. ],
  6142. 'idiomList' => [
  6143. 'category_name' => '成语欣赏',
  6144. 'list' => $idiomList,
  6145. 'type' => 5
  6146. ],
  6147. 'articlesList' => $articlesList
  6148. ];
  6149. // 缓存结果,设置1小时过期
  6150. $cache->set($cacheKey, serialize($result), 3600);
  6151. return Result::success($result);
  6152. }
  6153. /**
  6154. * 获取资讯列表
  6155. */
  6156. public function getWebsiteTsbbList(array $data): array
  6157. {
  6158. $page = $data['page'] ?? 1;
  6159. $pageSize = $data['pageSize'] ?? 10;
  6160. // 如果没有传入月份和日期,则使用今天的日期
  6161. $month = $data['month'] ?? date('m');
  6162. $day = $data['day'] ?? date('d');
  6163. $total = 0;
  6164. $result = [];
  6165. $data['type'] = intval($data['type']);
  6166. var_dump("接收参数:", $data);
  6167. switch ($data['type']) {
  6168. case 1:
  6169. $query = HistoryToday::where(function ($q) use ($month, $day) {
  6170. // 当前月份之后的数据
  6171. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  6172. // 或者当前月份且日期大于等于当前日期的数据
  6173. ->orWhere(function ($q) use ($month, $day) {
  6174. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  6175. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  6176. });
  6177. })
  6178. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  6179. $total = $query->count();
  6180. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  6181. ->offset(($page - 1) * $pageSize)
  6182. ->limit($pageSize)
  6183. ->get();
  6184. break;
  6185. case 2:
  6186. $query = Festival::where(function ($q) use ($month, $day) {
  6187. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  6188. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  6189. ->orWhere(function ($q) use ($month, $day) {
  6190. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  6191. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  6192. });
  6193. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  6194. $total = $query->count();
  6195. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  6196. ->offset(($page - 1) * $pageSize)
  6197. ->limit($pageSize)
  6198. ->get();
  6199. break;
  6200. case 3:
  6201. $query = Character::orderBy("updated_at", "desc");
  6202. $total = $query->count();
  6203. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  6204. ->offset(($page - 1) * $pageSize)
  6205. ->limit($pageSize)
  6206. ->get();
  6207. break;
  6208. case 4:
  6209. $query = Riddle::orderBy("updated_at", "desc");
  6210. $total = $query->count();
  6211. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  6212. ->offset(($page - 1) * $pageSize)
  6213. ->limit($pageSize)
  6214. ->get();
  6215. break;
  6216. case 5:
  6217. $query = Idiom::orderBy("updated_at", "desc");
  6218. $total = $query->count();
  6219. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  6220. ->offset(($page - 1) * $pageSize)
  6221. ->limit($pageSize)
  6222. ->get();
  6223. break;
  6224. case 6:
  6225. $query = Couplet::orderBy("updated_at", "desc");
  6226. $total = $query->count();
  6227. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  6228. ->offset(($page - 1) * $pageSize)
  6229. ->limit($pageSize)
  6230. ->get();
  6231. break;
  6232. default:
  6233. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  6234. $total = $query->count();
  6235. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  6236. ->offset(($page - 1) * $pageSize)
  6237. ->limit($pageSize)
  6238. ->get();
  6239. }
  6240. return Result::success([
  6241. 'list' => $result,
  6242. 'total' => $total,
  6243. 'page' => (int)$page,
  6244. 'pageSize' => (int)$pageSize,
  6245. 'month' => $month,
  6246. 'day' => $day
  6247. ]);
  6248. }
  6249. /**
  6250. * 1:历史上的今天
  6251. * 2:节日
  6252. * 3:文章
  6253. *
  6254. * 资讯详情信息
  6255. */
  6256. public function getWebsiteTsbbDetail(array $data): array
  6257. {
  6258. $data['type'] = intval($data['type']);
  6259. switch ($data['type']) {
  6260. case 1:
  6261. $result = HistoryToday::where("id", $data['id'])->first();
  6262. break;
  6263. case 2:
  6264. $result = Festival::where("id", $data['id'])->first();
  6265. break;
  6266. case 3:
  6267. $result = Character::where("id", $data['id'])->first();
  6268. break;
  6269. case 4:
  6270. $result = Riddle::where("id", $data['id'])->first();
  6271. break;
  6272. case 5:
  6273. $result = Idiom::where("id", $data['id'])->first();
  6274. break;
  6275. case 6:
  6276. $result = Couplet::where("id", $data['id'])->first();
  6277. break;
  6278. default:
  6279. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  6280. break;
  6281. }
  6282. return Result::success($result);
  6283. }
  6284. /**
  6285. * 农网导航首页数据
  6286. */
  6287. public function getWebsiteNwHomeList(array $data): array
  6288. {
  6289. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  6290. ->pluck('category_id')
  6291. ->toArray();
  6292. // 使用子查询优化
  6293. $articlesList = DB::table('article')
  6294. ->select([
  6295. 'article.id',
  6296. 'article.title',
  6297. 'article.imgurl',
  6298. 'article.created_at',
  6299. 'category.name as category_name',
  6300. 'category.id as category_id',
  6301. 'website_category.aLIas_pinyin as pinyin',
  6302. 'parent_wc.aLIas_pinyin as parent_pinyin',
  6303. DB::raw('100 as type')
  6304. ])
  6305. ->join('category', 'article.catid', '=', 'category.id')
  6306. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  6307. ->leftJoin('website_category as parent_wc', function ($join) {
  6308. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  6309. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  6310. })
  6311. ->where('website_category.website_id', $data['website_id'])
  6312. ->where('article.status', 1)
  6313. ->whereIn('category.id', $categoryIds)
  6314. ->orderBy('article.created_at', 'desc')
  6315. ->get()
  6316. ->groupBy('category_id')
  6317. ->map(function ($group) {
  6318. // 确保第一条数据有图片
  6319. $firstWithImage = $group->first(function ($item) {
  6320. return !empty($item->imgurl);
  6321. });
  6322. if ($firstWithImage) {
  6323. // 如果有带图片的文章,将其放在第一位
  6324. $group = $group->filter(function ($item) use ($firstWithImage) {
  6325. return $item->id !== $firstWithImage->id;
  6326. })->prepend($firstWithImage);
  6327. }
  6328. return [
  6329. 'category_name' => $group->first()->category_name,
  6330. 'catid' => $group->first()->category_id,
  6331. 'pinyin' => $group->first()->pinyin,
  6332. 'parent_pinyin' => $group->first()->parent_pinyin,
  6333. 'list' => $group->take(4)->map(function ($item) {
  6334. return [
  6335. 'id' => $item->id,
  6336. 'title' => $item->title,
  6337. ];
  6338. })->values()
  6339. ];
  6340. })
  6341. ->values()
  6342. ->toArray();
  6343. return Result::success($articlesList);
  6344. }
  6345. /**
  6346. * 企业管理
  6347. * @param array $data
  6348. * @return array
  6349. */
  6350. public function getCompanyList(array $data): array
  6351. {
  6352. // return Result::success($data);
  6353. $where = [];
  6354. $user = User::where('id', $data['user_id'])->first();
  6355. if (empty($user)) {
  6356. return Result::error('用户不存在!');
  6357. }
  6358. if ($user['type_id'] != 10000) {
  6359. $where['user_id'] = $data['user_id'];
  6360. }
  6361. if (isset($data['title']) && !empty($data['title'])) {
  6362. array_push($where, ['company.title', 'like', '%' . $data['title'] . '%']);
  6363. }
  6364. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6365. array_push($where, ['website.id', $data['website_id']]);
  6366. }
  6367. if (isset($data['ischeck']) && !empty($data['ischeck'])) {
  6368. if ($data['ischeck'] == 1) {
  6369. if (isset($data['status']) && $data['status'] != '') {
  6370. array_push($where, ['company.status', $data['status']]);
  6371. $query = Company::where($where);
  6372. } else {
  6373. $query = Company::whereIn('company.status', [0, 2]);
  6374. }
  6375. } else {
  6376. $query = Company::where('company.status', 1);
  6377. }
  6378. }
  6379. $result = $query->where($where)
  6380. ->leftJoin('website_category', function ($query) {
  6381. $query->on('website_category.category_id', '=', 'company.category_id')
  6382. ->on('website_category.website_id', '=', 'company.website_id');
  6383. })
  6384. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  6385. ->select(
  6386. 'company.id',
  6387. 'company.title',
  6388. 'company.website_id',
  6389. 'company.category_id',
  6390. 'website.website_name',
  6391. 'website_category.alias as category_name',
  6392. 'company.status',
  6393. 'company.updated_at',
  6394. 'company.user_id'
  6395. )
  6396. ->orderBy('company.updated_at', 'desc')
  6397. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  6398. if ($result->isEmpty()) {
  6399. return Result::error("暂无企业", 0);
  6400. }
  6401. return Result::success($result);
  6402. }
  6403. /**
  6404. * 添加企业
  6405. * @param array $data
  6406. * @return array
  6407. */
  6408. public function addCompany(array $data): array
  6409. {
  6410. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  6411. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6412. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6413. $data['cat_arr_id'] = json_encode($car_arr_id);
  6414. } else {
  6415. $data['cat_arr_id'] = '';
  6416. }
  6417. if ($data['imgurl'] == '') {
  6418. //content中提取图片第一个图,正则提取
  6419. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6420. preg_match_all($reg, $data['content'], $matches);
  6421. if (isset($matches[1][0])) {
  6422. //截取varchar240
  6423. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6424. }
  6425. }
  6426. if ($data['keyword'] == '') {
  6427. //提取标题+内容中的关键词
  6428. $data['keyword'] = $data['title'];
  6429. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6430. Jieba::init(); // 初始化 jieba-php
  6431. Finalseg::init();
  6432. $segList = Jieba::cut($data['keyword']);
  6433. $segList1 = array_slice($segList, 0, 8);
  6434. $data['keyword'] = implode(',', $segList1);
  6435. }
  6436. if ($data['introduce'] == '' || empty($data['introduce'])) {
  6437. //提取内容中的描述
  6438. $content = $data['content'];
  6439. // 去除 <style> 和 <script> 标签及其内容
  6440. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6441. // 去除所有 HTML 标签
  6442. $content = strip_tags($content);
  6443. // 去除 HTML 实体
  6444. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6445. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6446. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6447. // 去除多余空白
  6448. $content = preg_replace('/\s+/u', '', $content);
  6449. // 截取 100 个字符
  6450. $data['introduce'] = mb_substr($content, 0, 100);
  6451. }
  6452. $user = User::where('id', $data['user_id'])->first();
  6453. if (empty($user)) {
  6454. return Result::error('用户不存在!');
  6455. }
  6456. if ($user['type_id'] == 10000) {
  6457. $data['status'] = 1;
  6458. }
  6459. if (isset($data['level']) && $data['level'] != null) {
  6460. $data['level'] = intval($data['level']);
  6461. } else {
  6462. $data['level'] = null;
  6463. }
  6464. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  6465. $this->sendMessage([
  6466. 'talk_type' => 900,
  6467. 'title' => $data['title'],
  6468. 'content' => '提交了审核',
  6469. 'messageType' => 8,
  6470. ]);
  6471. }
  6472. $result = Company::insertGetId($data);
  6473. if ($result) {
  6474. return Result::success($result);
  6475. } else {
  6476. return Result::error('添加失败');
  6477. }
  6478. }
  6479. /**
  6480. * 更新企业
  6481. * @param array $data
  6482. * @return array
  6483. */
  6484. public function upCompany(array $data): array
  6485. {
  6486. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  6487. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  6488. $data['cat_arr_id'] = json_encode($car_arr_id);
  6489. $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
  6490. } else {
  6491. $data['cat_arr_id'] = '';
  6492. }
  6493. if ($data['imgurl'] == '') {
  6494. //content中提取图片第一个图,正则提取
  6495. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  6496. preg_match_all($reg, $data['content'], $matches);
  6497. if (isset($matches[1][0])) {
  6498. //截取varchar
  6499. $data['imgurl'] = substr($matches[1][0], 0, 240);
  6500. }
  6501. }
  6502. if ($data['keyword'] == '') {
  6503. //提取标题+内容中的关键词
  6504. $data['keyword'] = $data['title'];
  6505. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6506. Jieba::init(); // 初始化 jieba-php
  6507. Finalseg::init();
  6508. $segList = Jieba::cut($data['keyword']);
  6509. $segList1 = array_slice($segList, 0, 8);
  6510. $data['keyword'] = implode(',', $segList1);
  6511. }
  6512. if ($data['introduce'] == '') {
  6513. //提取内容中的描述
  6514. $content = $data['content'];
  6515. // 去除 <style> 和 <script> 标签及其内容
  6516. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6517. // 去除所有 HTML 标签
  6518. $content = strip_tags($content);
  6519. // 去除 HTML 实体
  6520. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6521. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6522. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6523. // 去除多余空白
  6524. $content = preg_replace('/\s+/u', '', $content);
  6525. // 截取 100 个字符
  6526. $data['introduce'] = mb_substr($content, 0, 100);
  6527. }
  6528. if (isset($data['level']) && $data['level'] != null) {
  6529. $data['level'] = intval($data['level']);
  6530. } else {
  6531. $data['level'] = null;
  6532. }
  6533. $user = User::where('id', $data['user_id'])->first();
  6534. if (empty($user)) {
  6535. return Result::error('用户不存在!');
  6536. }
  6537. if ($user['type_id'] == 10000) {
  6538. $data['status'] = 1;
  6539. } else {
  6540. $data['status'] = 0;
  6541. }
  6542. if ((isset($data['status']) && $data['status'] == 0) || !isset($data['status'])) {
  6543. $this->sendMessage([
  6544. 'talk_type' => 900,
  6545. 'title' => $data['title'],
  6546. 'content' => '提交了审核',
  6547. 'messageType' => 8,
  6548. ]);
  6549. }
  6550. $result = Company::where('id', $data['id'])->update($data);
  6551. if ($result) {
  6552. return Result::success($result);
  6553. } else {
  6554. return Result::error('修改失败');
  6555. }
  6556. }
  6557. /**
  6558. * 删除企业
  6559. * @param array $data
  6560. * @return array
  6561. */
  6562. public function delCompany(array $data): array
  6563. {
  6564. $result = Company::where('id', $data['id'])->delete();
  6565. if ($result) {
  6566. return Result::success($result);
  6567. } else {
  6568. return Result::error('删除失败');
  6569. }
  6570. }
  6571. /**
  6572. * 审核企业
  6573. * @param array $data
  6574. * @return array
  6575. */
  6576. public function checkCompany(array $data): array
  6577. {
  6578. $user = User::where('id', $data['user_id'])->first();
  6579. if (empty($user)) {
  6580. return Result::error('用户不存在!');
  6581. }
  6582. $company = Company::where('id', $data['id'])->first();
  6583. if (empty($company)) {
  6584. return Result::error('企业不存在!');
  6585. }
  6586. // 状态:0:未审核 1:已审核 2:已拒绝
  6587. if ($data['status'] == 2 || $data['status'] == '2') {
  6588. $this->sendMessage([
  6589. 'talk_type' => 901,
  6590. 'title' => $company['title'],
  6591. 'content' => '审核拒绝',
  6592. 'messageType' => 8,
  6593. 'user_id' => $company['user_id'],
  6594. ]);
  6595. $result = Company::where('id', $data['id'])->update(['status' => $data['status'], 'reject_reason' => $data['reason']]);
  6596. } else {
  6597. if ($data['status'] == 1) {
  6598. $this->sendMessage([
  6599. 'talk_type' => 901,
  6600. 'title' => $company['title'],
  6601. 'content' => '审核通过',
  6602. 'messageType' => 8,
  6603. 'user_id' => $company['user_id'],
  6604. ]);
  6605. } else if ($data['status'] == 0) {
  6606. $this->sendMessage([
  6607. 'talk_type' => 900,
  6608. 'title' => $company['title'],
  6609. 'content' => '提交了审核',
  6610. 'messageType' => 8,
  6611. ]);
  6612. }
  6613. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  6614. }
  6615. if (empty($result)) {
  6616. return Result::error('审核失败!');
  6617. } else {
  6618. return Result::success($result);
  6619. }
  6620. }
  6621. /**
  6622. * 获取企业信息
  6623. * @param array $data
  6624. * @return array
  6625. */
  6626. public function getCompanyInfo(array $data): array
  6627. {
  6628. $result = Company::where('id', $data['id'])->first();
  6629. $city_arr = json_decode($result['city_arr_id']);
  6630. $result['city_name'] = District::whereIn('id', $city_arr)
  6631. ->pluck('name')
  6632. ->implode('-');
  6633. if (empty($result)) {
  6634. return Result::error('企业不存在!');
  6635. } else {
  6636. return Result::success($result);
  6637. }
  6638. }
  6639. /**
  6640. * @param array $data
  6641. * @return array
  6642. */
  6643. public function getWebsiteCompany(array $data): array
  6644. {
  6645. $categorys = json_decode($data['id'], true);
  6646. $category_arr = $this->processArticlePro($data['website_id']);
  6647. $cat_1st_arr = $category_arr['cat_1st_arr'];
  6648. $catiall = $category_arr['catiall'];
  6649. $categoryIds = $category_arr['categoryIds'];
  6650. // return Result::success($category_arr);
  6651. foreach ($categorys as $key => $value) {
  6652. if (array_key_exists('level', $value)) {
  6653. $parts = explode(',', $value['level']);
  6654. $level = $parts[0] ?? null;
  6655. $imgnum = $parts[1] ?? null;
  6656. $textnum = $parts[2] ?? null;
  6657. if (!empty($textnum) && $textnum > 0) {
  6658. $text_num = Company::where('level', $level)
  6659. ->whereIn('category_id', $categoryIds)
  6660. ->where('status', 1)
  6661. ->select(
  6662. 'company.id',
  6663. 'company.title',
  6664. 'company.description',
  6665. 'company.updated_at',
  6666. 'company.category_id',
  6667. 'company.cat_arr_id'
  6668. )
  6669. ->orderBy('updated_at', 'desc')
  6670. ->limit($textnum)
  6671. ->get()->all();
  6672. }
  6673. if (!empty($imgnum) && $imgnum > 0) {
  6674. $img_num = Company::where('level', $level)
  6675. ->whereIn('category_id', $categoryIds)
  6676. ->where('status', 1)
  6677. ->where('imgurl', '!=', '')
  6678. ->whereNotNull('imgurl')
  6679. ->select(
  6680. 'company.id',
  6681. 'company.title',
  6682. 'company.description',
  6683. 'company.updated_at',
  6684. 'company.imgurl as imgs',
  6685. 'company.category_id',
  6686. 'company.cat_arr_id'
  6687. )
  6688. ->orderBy('updated_at', 'desc')
  6689. ->limit($imgnum)
  6690. ->get()->all();
  6691. }
  6692. }
  6693. if (array_key_exists('id', $value)) {
  6694. $parts = explode(',', $value['id']);
  6695. $category_id = $parts[0] ?? null;
  6696. $imgnum = $parts[1] ?? null;
  6697. $textnum = $parts[2] ?? null;
  6698. $category_arr = array_merge([$category_id], $cat_1st_arr[$category_id] ?? [0]);
  6699. if (!empty($textnum) && $textnum > 0) {
  6700. $text_num = Company::whereIn('category_id', $category_arr)
  6701. // ->where('website_id', $data['website_id'])
  6702. ->where('status', 1)
  6703. ->select(
  6704. 'company.id',
  6705. 'company.title',
  6706. 'company.description',
  6707. 'company.updated_at',
  6708. 'company.category_id',
  6709. 'company.cat_arr_id'
  6710. )
  6711. ->orderBy('updated_at', 'desc')
  6712. ->limit($textnum)
  6713. ->get()->all();
  6714. }
  6715. if (!empty($imgnum) && $imgnum > 0) {
  6716. $img_num = Company::whereIn('category_id', $category_arr)
  6717. // ->where('website_id', $data['website_id'])
  6718. ->where('status', 1)
  6719. ->where('imgurl', '!=', '')
  6720. ->whereNotNull('imgurl')
  6721. ->select(
  6722. 'company.id',
  6723. 'company.title',
  6724. 'company.description',
  6725. 'company.updated_at',
  6726. 'company.imgurl as imgs',
  6727. 'company.category_id',
  6728. 'company.cat_arr_id'
  6729. )
  6730. ->orderBy('updated_at', 'desc')
  6731. ->limit($imgnum)
  6732. ->get()->all();
  6733. }
  6734. }
  6735. if (!empty($text_num)) {
  6736. foreach ($text_num as $k => $v) {
  6737. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  6738. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  6739. }
  6740. }
  6741. if (!empty($img_num)) {
  6742. foreach ($img_num as $k => $v) {
  6743. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  6744. $imgurl = json_decode($v['imgs'], true);
  6745. if (!empty($imgurl)) {
  6746. $img_num[$k]->imgurl = $imgurl[0];
  6747. }
  6748. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  6749. }
  6750. }
  6751. $company[$key]['img_num'] = $img_num ?? [];
  6752. $company[$key]['text_num'] = $text_num ?? [];
  6753. }
  6754. if (empty($company)) {
  6755. return Result::error("暂无相关企业信息", 0);
  6756. }
  6757. return Result::success($company);
  6758. }
  6759. /**
  6760. * @param array $data
  6761. * @return array
  6762. */
  6763. public function getWebsiteCompanyList(array $data): array
  6764. {
  6765. $where['website_id'] = $data['website_id'];
  6766. $where['status'] = 1;
  6767. $categoryIds = [];
  6768. if (isset($data['category_id']) && !empty($data['category_id'])) {
  6769. $category_id = $data['category_id'];
  6770. }
  6771. $category_arr = $this->processArticlePro($data['website_id']);
  6772. $categoryIds = $category_arr['categoryIds'];
  6773. // return Result::success($cat_1st_arr);
  6774. $company = Company::when(isset($data['keyword']) && !empty($data['keyword']), function ($query) use ($data) {
  6775. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  6776. })
  6777. ->when(!isset($category_id) || empty($category_id), function ($query) use ($categoryIds) {
  6778. $query->whereIn('category_id', $categoryIds);
  6779. })
  6780. ->when(isset($data['category_id']) && !empty($data['category_id']), function ($query) use ($category_id) {
  6781. $query->where('category_id', $category_id);
  6782. })
  6783. ->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id', 'updated_at')
  6784. ->orderBy('updated_at', 'desc')
  6785. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  6786. if (empty($company)) {
  6787. return Result::error("暂无相关公司信息", 0);
  6788. }
  6789. $result = [
  6790. 'count' => $company->total(),
  6791. 'data' => $company->items(), // 使用 items() 方法替代不存在的 data() 方法
  6792. ];
  6793. return Result::success($result);
  6794. }
  6795. /**
  6796. * 获取项目列表
  6797. * @param array $data
  6798. * @return array
  6799. */
  6800. public function getProjectList(array $data): array
  6801. {
  6802. $where = [];
  6803. $user = User::where('id', $data['user_id'])->first();
  6804. if (empty($user)) {
  6805. return Result::error('用户不存在!');
  6806. }
  6807. if ($user->type_id != 10000) {
  6808. array_push($where, ['project.user_id', $data['user_id']]);
  6809. }
  6810. $query = Project::query();
  6811. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6812. array_push($where, ['project.website_id', $data['website_id']]);
  6813. }
  6814. if (isset($data['title']) && !empty($data['title'])) {
  6815. array_push($where, ['project.title', 'like', '%' . $data['title'] . '%']);
  6816. }
  6817. if ($data['status'] != 3) {
  6818. array_push($where, ['project.status', $data['status']]);
  6819. }
  6820. $query = Project::where($where)
  6821. ->when($data['status'] == 3, function ($query) {
  6822. $query->whereIn('project.status', [0, 2]);
  6823. });
  6824. $count = $query->clone()
  6825. ->count();
  6826. $rows = $query->clone()
  6827. ->leftJoin('website', 'project.website_id', 'website.id')
  6828. ->leftJoin('website_category', function ($join) {
  6829. $join->on('project.website_id', '=', 'website_category.website_id')
  6830. ->on('project.category_id', '=', 'website_category.category_id');
  6831. })
  6832. ->select(
  6833. 'project.id',
  6834. 'project.title',
  6835. 'project.updated_at',
  6836. 'project.status',
  6837. 'website.website_name',
  6838. 'website_category.alias as category_name',
  6839. 'project.website_id',
  6840. 'project.user_id'
  6841. )
  6842. ->orderBy('project.updated_at', 'desc')
  6843. ->offset(($data['page'] - 1) * $data['pageSize'])
  6844. ->limit($data['pageSize'])
  6845. ->get();
  6846. if ($rows->isEmpty()) {
  6847. return Result::error("暂无相关项目信息", 0);
  6848. }
  6849. $result = [
  6850. 'count' => $count,
  6851. 'rows' => $rows,
  6852. ];
  6853. return Result::success($result);
  6854. }
  6855. /**
  6856. * 添加项目
  6857. * @param array $data
  6858. * @return array
  6859. */
  6860. public function addProject(array $data): array
  6861. {
  6862. $user = User::where('id', $data['user_id'])->first();
  6863. if (empty($user)) {
  6864. return Result::error("暂无相关用户信息", 0);
  6865. }
  6866. if ($user->type_id == 10000) {
  6867. $data['status'] = 1;
  6868. } else {
  6869. $data['status'] = 0;
  6870. }
  6871. if ($data['keyword'] == '') {
  6872. //提取标题+内容中的关键词
  6873. $data['keyword'] = $data['title'];
  6874. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6875. Jieba::init(); // 初始化 jieba-php
  6876. Finalseg::init();
  6877. $segList = Jieba::cut($data['keyword']);
  6878. $segList1 = array_slice($segList, 0, 8);
  6879. $data['keyword'] = implode(',', $segList1);
  6880. }
  6881. if ($data['description'] == '') {
  6882. //提取内容中的描述
  6883. // var_dump(11111);
  6884. //提取内容中的描述
  6885. $content = $data['introduce'];
  6886. // 去除 <style> 和 <script> 标签及其内容
  6887. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6888. // 去除所有 HTML 标签
  6889. $content = strip_tags($content);
  6890. // 去除 HTML 实体
  6891. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6892. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6893. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6894. // 去除多余空白
  6895. $content = preg_replace('/\s+/u', '', $content);
  6896. // 截取 100 个字符
  6897. $data['description'] = mb_substr($content, 0, 100);
  6898. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  6899. }
  6900. if ($data['status'] == 0) {
  6901. $this->sendMessage([
  6902. 'talk_type' => 1000,
  6903. 'title' => $data['title'],
  6904. 'content' => '提交了审核',
  6905. 'messageType' => 9,
  6906. ]);
  6907. }
  6908. $project = Project::insertGetId($data);
  6909. if (empty($project)) {
  6910. return Result::error("暂无相关项目信息", 0);
  6911. }
  6912. return Result::success($project);
  6913. }
  6914. /**
  6915. * 更新项目
  6916. * @param array $data
  6917. * @return array
  6918. */
  6919. public function upProject(array $data): array
  6920. {
  6921. $project = Project::where('id', $data['id'])->first();
  6922. if (empty($project)) {
  6923. return Result::error("暂无相关项目信息", 0);
  6924. }
  6925. $id = $data['id'];
  6926. unset($data['id']);
  6927. $user = User::where('id', $data['user_id'])->first();
  6928. if (empty($user)) {
  6929. return Result::error("暂无相关用户信息", 0);
  6930. }
  6931. if ($user->type_id == 10000) {
  6932. $data['status'] = 1;
  6933. } else {
  6934. $data['status'] = 0;
  6935. }
  6936. unset($data['user_id']);
  6937. if ($data['keyword'] == '') {
  6938. //提取标题+内容中的关键词
  6939. $data['keyword'] = $data['title'];
  6940. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6941. Jieba::init(); // 初始化 jieba-php
  6942. Finalseg::init();
  6943. $segList = Jieba::cut($data['keyword']);
  6944. $segList1 = array_slice($segList, 0, 8);
  6945. $data['keyword'] = implode(',', $segList1);
  6946. }
  6947. if ($data['description'] == '') {
  6948. //提取内容中的描述
  6949. // var_dump(11111);
  6950. //提取内容中的描述
  6951. $content = $data['introduce'];
  6952. // 去除 <style> 和 <script> 标签及其内容
  6953. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  6954. // 去除所有 HTML 标签
  6955. $content = strip_tags($content);
  6956. // 去除 HTML 实体
  6957. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  6958. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  6959. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  6960. // 去除多余空白
  6961. $content = preg_replace('/\s+/u', '', $content);
  6962. // 截取 100 个字符
  6963. $data['description'] = mb_substr($content, 0, 100);
  6964. // 过滤 HTML 标签并去除空格,然后截取前 100 个字符
  6965. }
  6966. if ($data['status'] == 0) {
  6967. $this->sendMessage([
  6968. 'talk_type' => 1000,
  6969. 'title' => $data['title'],
  6970. 'content' => '提交了审核',
  6971. 'messageType' => 9,
  6972. ]);
  6973. }
  6974. $result = Project::where('id', $id)->update($data);
  6975. if (empty($result)) {
  6976. return Result::error("更新失败", 0);
  6977. }
  6978. return Result::success($result);
  6979. }
  6980. /**
  6981. * 删除项目
  6982. * @param array $data
  6983. * @return array
  6984. */
  6985. public function delProject(array $data): array
  6986. {
  6987. $user = User::where('id', $data['user_id'])->first();
  6988. if (empty($user)) {
  6989. return Result::error("暂无相关用户信息", 0);
  6990. }
  6991. $project = Project::where('id', $data['id'])->first();
  6992. if (empty($project)) {
  6993. return Result::error("暂无相关项目信息", 0);
  6994. }
  6995. $result = Project::where('id', $data['id'])->delete();
  6996. if (empty($result)) {
  6997. return Result::error("删除失败", 0);
  6998. }
  6999. return Result::success($result);
  7000. }
  7001. /**
  7002. * 审核项目
  7003. * @param array $data
  7004. * @return array
  7005. */
  7006. public function checkProject(array $data): array
  7007. {
  7008. $user = User::where('id', $data['user_id'])->first();
  7009. if (empty($user)) {
  7010. return Result::error("暂无相关用户信息", 0);
  7011. }
  7012. // 0:未审核; 1:已审核; 2:已拒绝;
  7013. if ($user->type_id != 10000) {
  7014. if ($data['status'] == 1 || $data['status'] == 2) {
  7015. return Result::error("此用户权限不足", 0);
  7016. }
  7017. }
  7018. $project = Project::where('id', $data['id'])->first();
  7019. if (empty($project)) {
  7020. return Result::error("暂无相关项目信息", 0);
  7021. }
  7022. if ($data['status'] == 2) {
  7023. $this->sendMessage([
  7024. 'talk_type' => 1001,
  7025. 'title' => $project['title'],
  7026. 'content' => '审核拒绝',
  7027. 'messageType' => 9,
  7028. 'user_id' => $project['user_id'],
  7029. ]);
  7030. $result = Project::where('id', $data['id'])->update(['status' => $data['status'], 'refuse_reason' => $data['refuse_reason']]);
  7031. } else {
  7032. if ($data['status'] == 1) {
  7033. $this->sendMessage([
  7034. 'talk_type' => 1001,
  7035. 'title' => $project['title'],
  7036. 'content' => '审核通过',
  7037. 'messageType' => 9,
  7038. 'user_id' => $project['user_id'],
  7039. ]);
  7040. } else if ($data['status'] == 0) {
  7041. $this->sendMessage([
  7042. 'talk_type' => 1000,
  7043. 'title' => $project['title'],
  7044. 'content' => '提交了审核',
  7045. 'messageType' => 9,
  7046. ]);
  7047. }
  7048. $result = Project::where('id', $data['id'])->update(['status' => $data['status']]);
  7049. }
  7050. if (empty($result)) {
  7051. return Result::error("审核失败", 0);
  7052. }
  7053. return Result::success($result);
  7054. }
  7055. /**
  7056. * 获取项目详情
  7057. * @param array $data
  7058. * @return array
  7059. */
  7060. public function getProjectInfo(array $data): array
  7061. {
  7062. $project = Project::where('id', $data['id'])->first();
  7063. if (empty($project)) {
  7064. return Result::error("暂无相关项目信息", 0);
  7065. }
  7066. return Result::success($project);
  7067. }
  7068. public function getWebsiteCompanyInfo(array $data): array
  7069. {
  7070. $company = Company::where('id', $data['id'])
  7071. ->leftJoin('job_industry', 'job_industry.hyid', 'company.hy_id')
  7072. ->where('status', 1)
  7073. // ->where('website_id', $data['website_id'])
  7074. ->select('company.*', 'job_industry.hyname as hy_name')
  7075. ->first();
  7076. // 企业性质:0:市场监管;1:信访纪检;2:公检法司;3:高关注机构
  7077. switch ($company->jobnature_id) {
  7078. case null:
  7079. $company->jobnature_name = '';
  7080. break;
  7081. case 0:
  7082. $company->jobnature_name = '市场监督';
  7083. break;
  7084. case 1:
  7085. $company->jobnature_name = '信访纪检';
  7086. break;
  7087. case 2:
  7088. $company->jobnature_name = '公检法司';
  7089. break;
  7090. case 3:
  7091. $company->jobnature_name = '高关注机构';
  7092. break;
  7093. default:
  7094. $company->jobnature_name = '';
  7095. break;
  7096. }
  7097. $city_arr = $company->city_arr_id;
  7098. if (!empty($city_arr)) {
  7099. $city_arr = json_decode($city_arr, true);
  7100. $cityNames = District::whereIn('id', $city_arr)
  7101. ->pluck('name')
  7102. ->implode('-');
  7103. $company->city_name = $cityNames;
  7104. } else {
  7105. $company->city_name = '';
  7106. }
  7107. if (empty($company)) {
  7108. return Result::error("暂无相关公司信息", 0);
  7109. }
  7110. return Result::success($company);
  7111. }
  7112. public function getMSG(array $data): array
  7113. {
  7114. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  7115. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  7116. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  7117. $result = [];
  7118. if ($type_id == 1 or $type_id == 2 or $type_id == 3 or $type_id == 4) {
  7119. //最近的5篇已审的文章
  7120. $apply_articale = Article::where('status', 1)
  7121. ->where('admin_user_id', $user_id)
  7122. ->orderBy('updated_at', 'desc')
  7123. // ->limit(5)
  7124. ->get();
  7125. //获取5条用户的已审核商品
  7126. $good = Good::where('status', 2)
  7127. ->where('user_id', $user_id)
  7128. ->orderBy('updated_at', 'desc')
  7129. // ->limit(5)
  7130. ->get();
  7131. //获取5条用户待审核的公告
  7132. $notice = Notice::where('status', 2)
  7133. ->where('user_id', $user_id)
  7134. ->orderBy('updated_at', 'desc')
  7135. ->limit(5)->get();
  7136. //获取5条用户的待审核投诉
  7137. $complaint = Complaint::where('status', 2)
  7138. ->where('user_id', $user_id)
  7139. ->orderBy('updated_at', 'desc')
  7140. // ->limit(5)
  7141. ->get();
  7142. //获取5条用户的book
  7143. $book = Book::where('status', 2)
  7144. ->where('user_id', $user_id)
  7145. ->orderBy('updated_at', 'desc')
  7146. // ->limit(5)
  7147. ->get();
  7148. //获取5条用户的求职
  7149. //获取5条用户的求职 1
  7150. $job_hunting = JobHunting::where('job_hunting.status', 2)
  7151. ->where('job_hunting.user_id', $user_id)
  7152. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7153. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7154. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7155. ->orderBy('updated_at', 'desc')
  7156. // ->limit(5)
  7157. ->get();
  7158. //获取5条用户的求职 2
  7159. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  7160. ->where('job_recruiting.user_id', $user_id)
  7161. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7162. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7163. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7164. ->orderBy('updated_at', 'desc')
  7165. // ->limit(5)
  7166. ->get();
  7167. //人才库 1
  7168. $job_apply = JobApply::where('job_apply.status', 1)
  7169. ->where('job_apply.receiver_id', $user_id)
  7170. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7171. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7172. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7173. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7174. ->select('job_recruiting', 'job_recruiting.', '', '')
  7175. ->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')
  7176. ->orderBy('updated_at', 'desc')
  7177. // ->limit(5)
  7178. ->get();
  7179. // 职场机会 2
  7180. $job_resume = JobResume::where('job_resume.status', 1)
  7181. ->where('job_resume.receiver_id', $user_id)
  7182. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7183. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7184. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7185. ->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')
  7186. ->orderBy('updated_at', 'desc')
  7187. // ->limit(5)
  7188. ->get();
  7189. //获取5条用户待处理的投诉
  7190. $complaint_deal = Complaint::where('status', 2)
  7191. ->where('deal', 1)
  7192. ->whereJsonContains('re_user_ids', $user_id)
  7193. ->orderBy('updated_at', 'desc')
  7194. // ->limit(5)
  7195. ->get();
  7196. //获取 被通知者未读信息
  7197. $notice_unread = Notice::where('status', 2)
  7198. ->whereJsonContains('re_user_ids', $user_id)
  7199. //未读消息
  7200. ->where(function ($query) use ($user_id) {
  7201. $query->whereJsonDoesntContain('read_id', $user_id)
  7202. ->orWhereNull('read_id');
  7203. })
  7204. ->orderBy('updated_at', 'desc')
  7205. ->get();
  7206. $complaint_unread = Complaint::where('status', 2)
  7207. ->whereJsonContains('re_user_ids', $user_id)
  7208. //未读消息
  7209. ->where(function ($query) use ($user_id) {
  7210. $query->whereJsonDoesntContain('read_id', $user_id)
  7211. ->orWhereNull('read_id');
  7212. })
  7213. ->orderBy('updated_at', 'desc')
  7214. ->get();
  7215. //获取5条用户的yijing审核公司 :0:未审核;1:已审核;2:已拒绝
  7216. $complany = Company::where('status', 1)
  7217. ->where('user_id', $user_id)
  7218. ->orderBy('updated_at', 'desc')
  7219. // ->limit(5)
  7220. ->get();
  7221. //获取5条单聊未读聊天消息
  7222. // $chat = ChatRecords::where('is_read', 0)
  7223. // ->where('user_id', $user_id)
  7224. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7225. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7226. // ->where('action', 'recieved')
  7227. // ->where('talk_type', 1)
  7228. // ->orderBy('created_at', 'desc')
  7229. // // ->limit(5)
  7230. // ->get();
  7231. //获取5条未读群聊信息
  7232. // $chat_group = ChatRecords::where('is_read', 0)
  7233. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7234. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7235. // ->where('user_id', $user_id)
  7236. // ->where('talk_type', 2)
  7237. // ->orderBy('created_at', 'desc')
  7238. // // ->limit(5)
  7239. // ->get();
  7240. //获取5条用户的待审核项目
  7241. $project = Project::where('status', 1)
  7242. ->where('user_id', $user_id)
  7243. ->orderBy('updated_at', 'desc')
  7244. // ->limit(5)
  7245. ->get();
  7246. // count($chat) + count($chat_group) +
  7247. $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)
  7248. + count($complany)
  7249. + count($project)
  7250. + count($notice_unread)
  7251. + count($complaint_unread)
  7252. // + count($chat) + count($chat_group)
  7253. ;
  7254. $result = [
  7255. 'apply_articale' => $apply_articale,
  7256. // 'chat' => $chat,
  7257. // 'chat_group' => $chat_group,
  7258. 'good' => $good,
  7259. 'notice' => $notice,
  7260. 'complaint' => $complaint,
  7261. 'book' => $book,
  7262. 'job_hunting' => $job_hunting,
  7263. 'job_recruiting' => $job_recruiting,
  7264. 'job_apply' => $job_apply,
  7265. 'job_resume' => $job_resume,
  7266. 'complaint_deal' => $complaint_deal,
  7267. 'complany' => $complany,
  7268. 'project' => $project,
  7269. 'notice_unread' => $notice_unread,
  7270. 'complaint_unread' => $complaint_unread,
  7271. 'count' => $count,
  7272. ];
  7273. } elseif ($type_id == 12) {
  7274. //最近的5篇已审的文章
  7275. $apply_articale = Article::where('status', 1)
  7276. ->where('admin_user_id', $user_id)
  7277. ->limit(5)->get();
  7278. //获取5条单聊未读聊天消息
  7279. $chat = ChatRecords::where('is_read', 0)
  7280. ->where('user_id', $user_id)
  7281. ->where('talk_type', 1)
  7282. ->orderBy('created_at', 'desc')
  7283. ->limit(5)->get();
  7284. //获取5条未读群聊信息
  7285. $chat_group = ChatRecords::where('is_read', 0)
  7286. ->where('user_id', $user_id)
  7287. ->where('talk_type', 2)
  7288. ->orderBy('created_at', 'desc')
  7289. ->limit(5)->get();
  7290. //获取5条用户的已审核商品
  7291. $good = Good::where('status', 2)
  7292. ->where('user_id', $user_id)
  7293. ->orderBy('updated_at', 'desc')
  7294. ->limit(5)->get();
  7295. //获取5条用户的book
  7296. $book = Book::where('status', 2)
  7297. ->where('user_id', $user_id)
  7298. ->orderBy('updated_at', 'desc')
  7299. ->limit(5)->get();
  7300. //获取5条用户的求职
  7301. //获取5条用户的求职 1
  7302. //count($chat) + count($chat_group)
  7303. $count = count($apply_articale) + count($good);
  7304. $result = [
  7305. 'apply_articale' => $apply_articale,
  7306. 'chat' => $chat,
  7307. 'chat_group' => $chat_group,
  7308. 'good' => $good,
  7309. 'book' => $book,
  7310. 'count' => $count,
  7311. ];
  7312. } elseif ($type_id == 13) {
  7313. //最近的5篇已审的文章
  7314. $apply_articale = Article::where('status', 1)
  7315. ->where('admin_user_id', $user_id)
  7316. ->limit(5)->get();
  7317. //获取5条单聊未读聊天消息
  7318. $chat = ChatRecords::where('is_read', 0)
  7319. ->where('user_id', $user_id)
  7320. ->where('talk_type', 1)
  7321. ->orderBy('created_at', 'desc')
  7322. ->limit(5)->get();
  7323. //获取5条未读群聊信息
  7324. $chat_group = ChatRecords::where('is_read', 0)
  7325. ->where('user_id', $user_id)
  7326. ->where('talk_type', 2)
  7327. ->orderBy('created_at', 'desc')
  7328. ->limit(5)->get();
  7329. //获取5条用户的已审核商品
  7330. $good = Good::where('status', 2)
  7331. ->where('user_id', $user_id)
  7332. ->orderBy('updated_at', 'desc')
  7333. ->limit(5)->get();
  7334. //count($chat) + count($chat_group) +
  7335. $count = count($apply_articale) + count($good);
  7336. $result = [
  7337. 'apply_articale' => $apply_articale,
  7338. 'chat' => $chat,
  7339. 'chat_group' => $chat_group,
  7340. 'good' => $good,
  7341. 'count' => $count,
  7342. ];
  7343. } elseif ($type_id == 14) {
  7344. //最近的5篇已审的文章
  7345. $apply_articale = Article::where('status', 1)
  7346. ->where('admin_user_id', $user_id)
  7347. // ->limit(5)
  7348. ->get();
  7349. //获取5条用户的已审核商品
  7350. $good = Good::where('status', 2)
  7351. ->where('user_id', $user_id)
  7352. ->orderBy('updated_at', 'desc')
  7353. // ->limit(5)
  7354. ->get();
  7355. $count = count($apply_articale) + count($good);
  7356. $result = [
  7357. 'apply_articale' => $apply_articale,
  7358. 'chat' => '',
  7359. 'chat_group' => '',
  7360. 'good' => $good,
  7361. 'count' => $count,
  7362. ];
  7363. } elseif ($type_id == 10000) {
  7364. //获取未审核的5篇文章
  7365. $apply_articale = Article::where('status', 0)
  7366. ->orderBy('updated_at', 'desc')
  7367. // ->limit(5)
  7368. ->get();
  7369. //获取5条单聊未读聊天消息
  7370. //获取5条单聊未读聊天消息
  7371. // $chat = ChatRecords::where('is_read', 0)
  7372. // ->where('user_id', $user_id)
  7373. // ->leftJoin('user', 'chat_records.receiver_id', '=', 'user.id')
  7374. // ->select('chat_records.*', 'user.nickname as nickname', 'user.user_name as user_name')
  7375. // ->where('action', 'recieved')
  7376. // ->where('talk_type', 1)
  7377. // ->orderBy('created_at', 'desc')
  7378. // // ->limit(5)
  7379. // ->get();
  7380. // //获取5条未读群聊信息
  7381. // $chat_group = ChatRecords::where('is_read', 0)
  7382. // ->leftJoin('chat_groups', 'chat_records.receiver_id', '=', 'chat_groups.id')
  7383. // ->select('chat_records.*', 'chat_groups.group_name as user_name')
  7384. // ->where('user_id', $user_id)
  7385. // ->where('talk_type', 2)
  7386. // ->orderBy('created_at', 'desc')
  7387. // // ->limit(5)
  7388. // ->get();
  7389. //获取5条用户的已审核商品
  7390. $good = Good::where('status', 1)
  7391. // ->where('user_id', $user_id)
  7392. ->orderBy('updated_at', 'desc')
  7393. // ->limit(5)
  7394. ->get();
  7395. //获取5条用户待审核的公告
  7396. $notice = Notice::where('status', 1)
  7397. ->orderBy('updated_at', 'desc')
  7398. // ->limit(5)
  7399. ->get();
  7400. //获取5条用户的待审核投诉
  7401. $complaint = Complaint::where('status', 1)
  7402. ->orderBy('updated_at', 'desc')
  7403. // ->limit(5)
  7404. ->get();
  7405. //获取5条用户的book
  7406. $book = Book::where('status', 1)
  7407. ->orderBy('updated_at', 'desc')
  7408. // ->limit(5)
  7409. ->get();
  7410. //获取5条用户的求职 1
  7411. $job_hunting = JobHunting::where('job_hunting.status', 1)
  7412. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  7413. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  7414. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7415. ->orderBy('updated_at', 'desc')
  7416. // ->limit(5)
  7417. ->get();
  7418. //获取5条用户的求职 2
  7419. $job_recruiting = JobRecruiting::where('job_recruiting.status', 0)
  7420. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  7421. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  7422. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  7423. ->orderBy('updated_at', 'desc')
  7424. // ->limit(5)
  7425. ->get();
  7426. //人才库 1
  7427. $job_apply = JobApply::where('job_apply.status', 1)
  7428. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  7429. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  7430. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  7431. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  7432. ->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')
  7433. ->orderBy('updated_at', 'desc')
  7434. // ->limit(5)
  7435. ->get();
  7436. // 职场机会 2
  7437. $job_resume = JobResume::where('job_resume.status', 1)
  7438. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  7439. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  7440. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  7441. ->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')
  7442. ->orderBy('updated_at', 'desc')
  7443. // ->limit(5)
  7444. ->get();
  7445. //待审核数据com pro
  7446. $complany = Company::where('status', 0)
  7447. ->orderBy('updated_at', 'desc')
  7448. // ->limit(5)
  7449. ->get();
  7450. $project = Project::where('status', 0)
  7451. ->orderBy('updated_at', 'desc')
  7452. // ->limit(5)
  7453. ->get();
  7454. $count =
  7455. // count($chat) +
  7456. // count($chat_group) +
  7457. count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting)
  7458. // + count($job_apply)
  7459. // + count($job_resume)
  7460. + count($complany)
  7461. + count($project);
  7462. $result = [
  7463. 'apply_articale' => $apply_articale,
  7464. // 'chat' => $chat,
  7465. // 'chat_group' => $chat_group,
  7466. 'good' => $good,
  7467. 'notice' => $notice,
  7468. 'complaint' => $complaint,
  7469. 'book' => $book,
  7470. 'job_hunting' => $job_hunting,
  7471. 'job_recruiting' => $job_recruiting,
  7472. // 'job_apply' => $job_apply,
  7473. // 'job_resume' => $job_resume,
  7474. 'complany' => $complany,
  7475. 'project' => $project,
  7476. 'count' => $count,
  7477. ];
  7478. } elseif ($type_id == 20000) {
  7479. }
  7480. var_dump($type_id, '-----------------test---------');
  7481. return Result::success($result);
  7482. }
  7483. /**
  7484. * @param array $data
  7485. * @return array
  7486. */
  7487. public function getWebsiteProject(array $data): array
  7488. {
  7489. $categorys = json_decode($data['id'], true);
  7490. if (!empty($categorys)) {
  7491. $category_arr = $this->processArticlePro($data['website_id']);
  7492. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7493. $catiall = $category_arr['catiall'];
  7494. // return Result::success($catiall);
  7495. foreach ($categorys as $key => $val) {
  7496. if (isset($val['level'][0]) && !empty($val['level'][0])) {
  7497. $level = explode(',', $val['level'])[0];
  7498. $imgnum = explode(',', $val['level'])[1] ?? null;
  7499. $textnum = explode(',', $val['level'])[2] ?? null;
  7500. if ($level == 1) {
  7501. if (!empty($textnum) && $textnum > 0) {
  7502. $text_num = Project::where('level', $level)
  7503. ->where('website_id', $data['website_id'])
  7504. ->where('status', 1)
  7505. ->select(
  7506. 'project.id',
  7507. 'project.title',
  7508. 'project.description',
  7509. 'project.updated_at',
  7510. 'project.category_id',
  7511. 'project.cat_arr_id'
  7512. )
  7513. ->orderBy('updated_at', 'desc')
  7514. ->limit($textnum)
  7515. ->get()->all();
  7516. }
  7517. if (!empty($imgnum) && $imgnum > 0) {
  7518. $img_num = Project::where('level', $level)
  7519. ->where('website_id', $data['website_id'])
  7520. ->where('status', 1)
  7521. ->where('imgurl', '!=', '')
  7522. ->whereNotNull('imgurl')
  7523. ->select(
  7524. 'project.id',
  7525. 'project.title',
  7526. 'project.description',
  7527. 'project.updated_at',
  7528. 'project.imgurl as imgs',
  7529. 'project.category_id',
  7530. 'project.cat_arr_id'
  7531. )
  7532. ->orderBy('updated_at', 'desc')
  7533. ->limit($imgnum)
  7534. ->get()->all();
  7535. }
  7536. } else {
  7537. if (!empty($textnum) && $textnum > 0) {
  7538. $text_num = Project::where('website_id', $data['website_id'])
  7539. ->where('status', 1)
  7540. ->select(
  7541. 'project.id',
  7542. 'project.title',
  7543. 'project.description',
  7544. 'project.updated_at',
  7545. 'project.category_id',
  7546. 'project.cat_arr_id',
  7547. 'project.website_id',
  7548. 'project.updated_at',
  7549. 'project.created_at'
  7550. )
  7551. ->orderBy('updated_at', 'desc')
  7552. ->limit($textnum)
  7553. ->get()->all();
  7554. }
  7555. if (!empty($imgnum) && $imgnum > 0) {
  7556. $img_num = Project::where('website_id', $data['website_id'])
  7557. ->where('status', 1)
  7558. ->where('imgurl', '!=', '')
  7559. ->whereNotNull('imgurl')
  7560. ->select(
  7561. 'project.id',
  7562. 'project.title',
  7563. 'project.description',
  7564. 'project.updated_at',
  7565. 'project.imgurl as imgs',
  7566. 'project.category_id',
  7567. 'project.cat_arr_id'
  7568. )
  7569. ->orderBy('updated_at', 'desc')
  7570. ->limit($imgnum)
  7571. ->get()->all();
  7572. }
  7573. }
  7574. }
  7575. if (isset($val['id'][0]) && !empty($val['id'][0])) {
  7576. $category_ids = explode(',', $val['id'])[0];
  7577. $cat_imgnum = explode(',', $val['id'])[1] ?? null;
  7578. $cat_textnum = explode(',', $val['id'])[2] ?? null;
  7579. $category_arr = array_merge([$category_ids], $cat_1st_arr[$category_ids] ?? [0]);
  7580. if (!empty($cat_textnum) && $cat_textnum > 0) {
  7581. $text_num = Project::whereIn('category_id', $category_arr)
  7582. ->where('website_id', $data['website_id'])
  7583. ->where('status', 1)
  7584. ->select(
  7585. 'project.id',
  7586. 'project.title',
  7587. 'project.description',
  7588. 'project.updated_at',
  7589. 'project.category_id',
  7590. 'project.cat_arr_id'
  7591. )
  7592. ->orderBy('updated_at', 'desc')
  7593. ->limit($cat_textnum)
  7594. ->get()->all();
  7595. }
  7596. if (!empty($cat_imgnum) && $cat_imgnum > 0) {
  7597. $img_num = Project::whereIn('category_id', $category_arr)
  7598. ->where('website_id', $data['website_id'])
  7599. ->where('status', 1)
  7600. ->where('imgurl', '!=', '')
  7601. ->whereNotNull('imgurl')
  7602. ->select(
  7603. 'project.id',
  7604. 'project.title',
  7605. 'project.description',
  7606. 'project.updated_at',
  7607. 'project.imgurl as imgs',
  7608. 'project.category_id',
  7609. 'project.cat_arr_id'
  7610. )
  7611. ->orderBy('updated_at', 'desc')
  7612. ->limit($cat_imgnum)
  7613. ->get()->all();
  7614. }
  7615. }
  7616. if (!empty($img_num)) {
  7617. foreach ($img_num as $k => $v) {
  7618. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7619. $imgurl = json_decode($v['imgs'], true);
  7620. if (!empty($imgurl)) {
  7621. $img_num[$k]->imgurl = $imgurl[0];
  7622. }
  7623. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7624. }
  7625. }
  7626. if (!empty($text_num)) {
  7627. foreach ($text_num as $k => $v) {
  7628. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  7629. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  7630. }
  7631. }
  7632. $project[$key]['img_num'] = $img_num ?? [];
  7633. $project[$key]['text_num'] = $text_num ?? [];
  7634. }
  7635. }
  7636. if (empty($project)) {
  7637. return Result::error("暂无相关项目信息", 0);
  7638. }
  7639. return Result::success($project);
  7640. }
  7641. /**
  7642. * @param array $data
  7643. * @return array
  7644. */
  7645. public function getWebsiteProjectInfo(array $data): array
  7646. {
  7647. $project = Project::where('id', $data['id'])
  7648. ->where('status', 1)
  7649. ->where('website_id', $data['website_id'])
  7650. ->select('project.*')
  7651. ->first();
  7652. if (empty($project)) {
  7653. return Result::error("暂无相关项目信息", 0);
  7654. }
  7655. return Result::success($project);
  7656. }
  7657. /**
  7658. * @param array $data
  7659. * @return array
  7660. */
  7661. public function getWebsiteProjectList(array $data): array
  7662. {
  7663. $where = [];
  7664. if (isset($data['category_id']) && !empty($data['category_id'])) {
  7665. $where['category_id'] = $data['category_id'];
  7666. }
  7667. if (isset($data['keyword']) && !empty($data['keyword'])) {
  7668. $where[] = ['title', 'like', '%' . $data['keyword'] . '%'];
  7669. }
  7670. $query = Project::where($where)
  7671. ->where('status', 1)
  7672. ->where('website_id', $data['website_id'])
  7673. ->select(
  7674. 'project.id',
  7675. 'project.title',
  7676. 'project.description',
  7677. 'project.imgurl as imgs',
  7678. 'project.category_id',
  7679. 'project.cat_arr_id'
  7680. )
  7681. ->orderBy('updated_at', 'desc');
  7682. $count = $query->count();
  7683. $project = $query->clone()
  7684. ->offset(($data['page'] - 1) * $data['pageSize'])
  7685. ->limit($data['pageSize'])
  7686. ->get()->all();
  7687. if (empty($project)) {
  7688. return Result::error("暂无相关项目信息", 0);
  7689. }
  7690. $categorys = $this->processArticlePro($data['website_id']);
  7691. $catiall = $categorys['catiall'];
  7692. foreach ($project as $key => $val) {
  7693. $project[$key]->category_name = $catiall[$val->category_id]['alias'];
  7694. if (!empty($val['imgs'])) {
  7695. $imgurl = json_decode($val['imgs'], true);
  7696. if (!empty($imgurl)) {
  7697. $project[$key]->imgurl = $imgurl[0];
  7698. }
  7699. } else {
  7700. $project[$key]->imgurl = '';
  7701. }
  7702. $project[$key]->pinyin = $catiall[$val->category_id]['pinyin'];
  7703. }
  7704. $result = [
  7705. 'rows' => $project,
  7706. 'count' => $count,
  7707. ];
  7708. return Result::success($result);
  7709. }
  7710. /**
  7711. * @param array $data
  7712. * @return array
  7713. */
  7714. public function getWebsiteCategoryJob(array $data): array
  7715. {
  7716. $categorys = json_decode($data['id'], true);
  7717. if (!empty($categorys)) {
  7718. $category_arr = $this->processArticlePro($data['website_id']);
  7719. $cat_1st_arr = $category_arr['cat_1st_arr'];
  7720. $catiall = $category_arr['catiall'];
  7721. foreach ($categorys as $key => $val) {
  7722. if (isset($val['id']) && !empty($val['id'])) {
  7723. $catid = explode(',', $val['id'])[0] ?? null;
  7724. $type = explode(',', $val['id'])[1] ?? null;
  7725. $textnum = explode(',', $val['id'])[2] ?? null;
  7726. }
  7727. // 4:招聘;5:求职;
  7728. if ($textnum > 0 && $type == 4 && !empty($catid)) {
  7729. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  7730. $job = JobRecruiting::WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($catid) . "') = 1")
  7731. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  7732. ->where('job_recruiting.status', 1)
  7733. ->where('job_recruiting.website_id', $data['website_id'])
  7734. ->select(
  7735. 'job_recruiting.id',
  7736. 'job_recruiting.title',
  7737. 'job_company.business_name',
  7738. 'job_recruiting.updated_at',
  7739. 'job_recruiting.cat_arr_id'
  7740. )
  7741. ->orderBy('job_recruiting.updated_at', 'desc')
  7742. ->limit($textnum)
  7743. ->get()->all();
  7744. } else if ($textnum > 0 && $type == 5 && !empty($catid)) {
  7745. // 状态 审核状态,1待审核2已审核3已拒绝
  7746. $job = JobHunting::WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($catid) . "') = 1")
  7747. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  7748. ->where('job_hunting.status', 2)
  7749. ->where('job_hunting.website_id', $data['website_id'])
  7750. ->select(
  7751. 'job_hunting.id',
  7752. 'job_hunting.name',
  7753. 'job_hunting.cat_arr_id',
  7754. 'job_position.zwname as job_name',
  7755. 'job_hunting.updated_at'
  7756. )
  7757. ->orderBy('updated_at', 'desc')
  7758. ->limit($textnum)
  7759. ->get()->all();
  7760. } else {
  7761. $job = [];
  7762. }
  7763. // var_dump($catid.'222uuuuuuu'.$key);
  7764. if (!empty($job)) {
  7765. foreach ($job as $k => $value) {
  7766. if (isset($value->cat_arr_id)) {
  7767. $catArr = json_decode($value->cat_arr_id, true);
  7768. $catId = end($catArr);
  7769. } else {
  7770. continue;
  7771. }
  7772. if (isset($catiall[$catId])) {
  7773. $job[$k]->pinyin = $catiall[$catId]['pinyin'];
  7774. }
  7775. }
  7776. }
  7777. // var_dump($catid.'xxxxx'.$key);
  7778. $result[$key] = $job ?? [];
  7779. }
  7780. }
  7781. if (empty($result)) {
  7782. return Result::error("暂无相关分类信息", 0);
  7783. }
  7784. return Result::success($result);
  7785. }
  7786. /**
  7787. * 发送消息
  7788. * @param array $messageData
  7789. * @return void
  7790. */
  7791. public function sendMessage($messageData)
  7792. {
  7793. $msg = [
  7794. 'talk_type' => $messageData['talk_type'],
  7795. 'title' => $messageData['title'],
  7796. 'content' => $messageData['content'],
  7797. 'messageType' => $messageData['messageType'],
  7798. 'user_id' => $messageData['user_id'] ?? '',
  7799. 'time' => microtime(),
  7800. ];
  7801. $message = new MqProducer($msg);
  7802. $producer = ContextApplicationContext::getContainer()->get(Producer::class);
  7803. $producer->produce($message);
  7804. }
  7805. }