NewsService.php 253 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980
  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. #[RpcService(name: "NewsService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
  64. class NewsService implements NewsServiceInterface
  65. {
  66. #[Inject]
  67. protected Redis $redis;
  68. /**
  69. * 获取导航池列表
  70. * @param array $data
  71. * @return array
  72. */
  73. public function getCategoryList(array $data): array
  74. {
  75. $search = $data['name'] ?? '';
  76. $page = (int)($data['page'] ?? 1);
  77. $perPage = (int)($data['pageSize'] ?? 10);
  78. // 1. 查出所有匹配的分类id
  79. if ($search) {
  80. $matchedIds = Category::where('name', 'like', "%{$search}%")->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  81. if (empty($matchedIds)) {
  82. return Result::success(['rows' => [], 'total' => 0]);
  83. }
  84. // 2. 递归查所有父级,直到一级分类
  85. $idsStr = implode(',', $matchedIds);
  86. $sql = "
  87. WITH RECURSIVE parents AS (
  88. SELECT * FROM category WHERE id IN ($idsStr)
  89. UNION ALL
  90. SELECT c.* FROM category c
  91. INNER JOIN parents p ON c.id = p.pid
  92. )
  93. SELECT * FROM parents
  94. ";
  95. $parents = Db::select($sql);
  96. $parentIds = [];
  97. foreach ($parents as $row) {
  98. if ($row->pid == 0) {
  99. $parentIds[] = $row->id;
  100. }
  101. }
  102. $parentIds = array_unique($parentIds);
  103. } else {
  104. // 没有搜索,一级分类就是根
  105. $parentIds = Category::where('pid', 0)->orderBy('updated_at', 'desc')->pluck('id')->toArray();
  106. }
  107. // 3. 一级分类分页
  108. $total = count($parentIds);
  109. $parentIds = array_slice($parentIds, ($page - 1) * $perPage, $perPage);
  110. if (empty($parentIds)) {
  111. return Result::success(['rows' => [], 'total' => $total]);
  112. }
  113. // 4. 递归查所有子孙
  114. $idsStr = implode(',', $parentIds);
  115. $sql = "
  116. WITH RECURSIVE subcategories AS (
  117. SELECT * FROM category WHERE id IN ($idsStr)
  118. UNION ALL
  119. SELECT c.* FROM category c
  120. INNER JOIN subcategories s ON c.pid = s.id
  121. )
  122. SELECT * FROM subcategories ORDER BY updated_at DESC
  123. ";
  124. $allCategories = Db::select($sql);
  125. // 5. 组装树结构
  126. $categoryMap = [];
  127. foreach ($allCategories as $cat) {
  128. $cat = (array)$cat;
  129. $cat['children'] = [];
  130. $categoryMap[$cat['id']] = $cat;
  131. }
  132. foreach ($categoryMap as $id => &$cat) {
  133. if ($cat['pid'] && isset($categoryMap[$cat['pid']])) {
  134. $categoryMap[$cat['pid']]['children'][] = &$cat;
  135. }
  136. }
  137. unset($cat);
  138. $categoryTree = [];
  139. foreach ($parentIds as $id) {
  140. if (isset($categoryMap[$id])) {
  141. $categoryTree[] = $categoryMap[$id];
  142. }
  143. }
  144. return Result::success([
  145. 'rows' => $categoryTree,
  146. 'total' => $total,
  147. ]);
  148. }
  149. private function findMatchedCategories($search)
  150. {
  151. if ($search) {
  152. return Category::where('name', 'like', "%{$search}%")
  153. ->orderBy('updated_at', 'desc')
  154. ->get();
  155. }
  156. return Category::orderBy('updated_at', 'desc') // 按 updated_at 字段倒序排序
  157. ->get();
  158. }
  159. private function findAllParents($categories)
  160. {
  161. $allCategories = [];
  162. foreach ($categories as $category) {
  163. $parentId = $category->pid;
  164. while ($parentId > 0) {
  165. $parent = Category::find($parentId);
  166. if ($parent) {
  167. $allCategories[$parent->id] = $parent;
  168. $parentId = $parent->pid;
  169. } else {
  170. break;
  171. }
  172. }
  173. $allCategories[$category->id] = $category;
  174. }
  175. return array_values($allCategories);
  176. }
  177. private function buildCategoryTree($category, $allRequiredCategories)
  178. {
  179. $categoryData = $category->toArray();
  180. $children = [];
  181. foreach ($allRequiredCategories as $c) {
  182. if ($c->pid === $category->id) {
  183. $children[] = $this->buildCategoryTree($c, $allRequiredCategories);
  184. }
  185. }
  186. if (!empty($children)) {
  187. $categoryData['children'] = $children;
  188. }
  189. return $categoryData;
  190. }
  191. public function myCategoryList(array $data): array
  192. {
  193. $sszq = $data['sszq'] ?? '';
  194. unset($data['sszq']);
  195. //1,2,3 根据这些webid,。从website_category表中取出对应的分类id,然后从category表中取出分类信息
  196. $catorytids = WebsiteCategory::whereIn('website_id', explode(',', $sszq))->get()->pluck('category_id')->toArray();
  197. $where[] = [
  198. 'pid',
  199. '=',
  200. $data['pid'],
  201. ];
  202. if (isset($data['name'])) {
  203. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  204. }
  205. var_dump($where);
  206. //根据分类id,从category表中取出分类信息
  207. $result = Category::where($where)
  208. ->whereIn('category.id', $catorytids)
  209. ->select('category.*', 'category.id as category_id')->get();
  210. if (empty($result)) {
  211. return Result::error("没有栏目数据");
  212. }
  213. return Result::success($result);
  214. }
  215. /**
  216. * @param array $data
  217. * @return array
  218. */
  219. public function categoryList(array $data): array
  220. {
  221. $where[] = [
  222. 'pid',
  223. '=',
  224. $data['pid']
  225. ];
  226. if (isset($data['name'])) {
  227. array_push($where, ['category.name', 'like', '%' . $data['name'] . '%']);
  228. }
  229. var_dump($where);
  230. $result = Category::where($where)->select('category.*', 'category.id as category_id')->get();
  231. if (empty($result)) {
  232. return Result::error("没有栏目数据");
  233. }
  234. return Result::success($result);
  235. }
  236. /**
  237. * @param array $data
  238. * @return array
  239. */
  240. public function addCategory(array $data): array
  241. {
  242. if (isset($data['id'])) {
  243. unset($data['id']);
  244. }
  245. $id = Category::insertGetId($data);
  246. if (empty($id)) {
  247. return Result::error("添加失败");
  248. }
  249. return Result::success(['id' => $id]);
  250. }
  251. /**
  252. * @param array $data
  253. * @return array
  254. */
  255. public function delCategory(array $data): array
  256. {
  257. Db::beginTransaction();
  258. try {
  259. $categoryList = Category::where(['pid' => $data['id']])->get();
  260. if ($categoryList->toArray()) {
  261. Db::rollBack();
  262. return Result::error("分类下面有子分类不能删除");
  263. }
  264. $articleList = Article::where(['catid' => $data['id']])->get();
  265. if ($articleList->toArray()) {
  266. Db::rollBack();
  267. return Result::error("分类下面有资讯不能删除");
  268. }
  269. $result = Category::where($data)->delete();
  270. WebsiteCategory::where(['category_id' => $data['id']])->delete();
  271. if (!$result) {
  272. Db::rollBack();
  273. return Result::error("删除失败");
  274. }
  275. Db::commit();
  276. return Result::success($result);
  277. } catch (\Exception $e) {
  278. Db::rollBack();
  279. return Result::error("删除失败" . $e->getMessage());
  280. }
  281. }
  282. /**
  283. * @param array $data
  284. * @return array
  285. */
  286. public function updateCategory(array $data): array
  287. {
  288. $where = [
  289. 'id' => $data['id'],
  290. ];
  291. $result = Category::where($where)->update($data);
  292. if ($result) {
  293. return Result::success($result);
  294. } else {
  295. return Result::error("更新失败");
  296. }
  297. }
  298. /**
  299. * 获取导航池信息
  300. * @param array $data
  301. * @return array
  302. */
  303. public function getCategoryInfo(array $data): array
  304. {
  305. $where = [
  306. 'id' => $data['id'],
  307. ];
  308. $result = Category::where($where)->first();
  309. if ($result) {
  310. return Result::success($result);
  311. } else {
  312. return Result::error("更新失败");
  313. }
  314. }
  315. /**
  316. * @param array $data
  317. * @return array
  318. */
  319. public function getArticleList(array $data): array
  320. {
  321. //判断是否是管理员'1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)'
  322. $type_id = $data['type_id'];
  323. unset($data['type_id']);
  324. $user_id = $data['user_id'];
  325. unset($data['user_id']);
  326. $where = [];
  327. $status1 = [];
  328. if (isset($data['id']) && $data['id']) {
  329. array_push($where, ['article.id', '=', $data['id']]);
  330. }
  331. if (isset($data['title']) && $data['title']) {
  332. array_push($where, ['article.title', 'like', '%' . $data['title'] . '%']);
  333. }
  334. if (isset($data['category_name']) && $data['category_name']) {
  335. array_push($where, ['category.name', 'like', '%' . $data['category_name'] . '%']);
  336. }
  337. if (isset($data['author']) && $data['author']) {
  338. array_push($where, ['article.author', '=', $data['author']]);
  339. }
  340. if (isset($data['islink']) && $data['islink'] !== "") {
  341. array_push($where, ['article.islink', '=', $data['islink']]);
  342. }
  343. if (isset($data['status']) && $data['status'] !== "") {
  344. array_push($where, ['article.status', '=', $data['status']]);
  345. }
  346. if (isset($data['status1'])) {
  347. $status1 = json_decode(($data['status1']));
  348. }
  349. //不是管理员展示个人数据;
  350. if ($type_id != 10000) {
  351. $where[] = ['article.admin_user_id', '=', $user_id];
  352. }
  353. $rep = Article::where($where)
  354. ->whereNotIn('article.status', [404])
  355. ->when($status1, function ($query) use ($status1) {
  356. if (isset($status1) && $status1) {
  357. $query->whereIn('article.status', $status1);
  358. }
  359. })
  360. ->leftJoin('category', 'article.catid', 'category.id')
  361. ->leftJoin('website_category', function ($join) {
  362. $join->on('article.web_site_id', '=', 'website_category.website_id')
  363. ->on('article.catid', '=', 'website_category.category_id');
  364. })
  365. ->select("article.*", "category.name as category_name", "website_category.alias")
  366. ->orderBy("article.updated_at", "desc")
  367. ->limit($data['pageSize'])
  368. ->offset(($data['page'] - 1) * $data['pageSize'])->get();
  369. $count = Article::where($where)->whereNotIn('article.status', [404])
  370. ->when($status1, function ($query) use ($status1) {
  371. if (isset($status1) && $status1) {
  372. $query->whereIn('article.status', $status1);
  373. }
  374. })
  375. ->leftJoin('category', 'article.catid', 'category.id')->count();
  376. $data = [
  377. 'rows' => $rep->toArray(),
  378. 'count' => $count,
  379. ];
  380. if (empty($rep)) {
  381. return Result::error("没有信息数据");
  382. }
  383. return Result::success($data);
  384. }
  385. /**
  386. * @param array $data
  387. * @return array
  388. */
  389. public function addArticle(array $data): array
  390. {
  391. var_dump($data, '----------12-----------1');
  392. unset($data['user_type']);
  393. unset($data['nav_add_pool_id']);
  394. // unset($data['commend_id']);
  395. // $data['cat_arr_id'] = is_string($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  396. Db::beginTransaction();
  397. try {
  398. //处理投票
  399. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  400. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  401. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  402. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  403. unset($data['is_survey']);
  404. unset($data['survey_name']);
  405. unset($data['suvey_array']);
  406. // unset($data['website_id']);
  407. // unset($data['web_site_id']);
  408. // $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  409. if ($data['hits'] == '') {
  410. $data['hits'] = 0;
  411. }
  412. if ($data['is_original'] == '') {
  413. $data['is_original'] = 0;
  414. }
  415. if ($data['status'] == '') {
  416. $data['status'] = 0;
  417. }
  418. $articleData = $data;
  419. unset($articleData['content']);
  420. //自动处理缩略图、关键字、描述
  421. if ($articleData['imgurl'] == '') {
  422. //如果没有图,设置level=0
  423. $levelArr = json_decode($articleData['level'], true);
  424. var_dump($levelArr, '----------levelArr-----------1');
  425. //content中提取图片第一个图,正则提取
  426. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  427. preg_match_all($reg, $data['content'], $matches);
  428. if (isset($matches[1][0])) {
  429. //截取varchar240
  430. $articleData['imgurl'] = substr($matches[1][0], 0, 240);
  431. //如果有图,设置level=3
  432. if (!in_array(3, $levelArr)) {
  433. $levelArr[] = 3;
  434. }
  435. $articleData['level'] = json_encode($levelArr);
  436. } else {
  437. if (!in_array(0, $levelArr)) {
  438. $levelArr[] = 0;
  439. }
  440. $articleData['level'] = json_encode($levelArr);
  441. }
  442. }
  443. var_dump($articleData['level'], '----------$articleData[level]----------1');
  444. if ($articleData['keyword'] == '') {
  445. //提取标题+内容中的关键词
  446. $articleData['keyword'] = $data['title'];
  447. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  448. Jieba::init(); // 初始化 jieba-php
  449. Finalseg::init();
  450. $segList = Jieba::cut($articleData['keyword']);
  451. $segList1 = array_slice($segList, 0, 8);
  452. $articleData['keyword'] = implode(',', $segList1);
  453. }
  454. if ($articleData['introduce'] == '') {
  455. //提取内容中的描述
  456. $content = $data['content'];
  457. // 去除 <style> 和 <script> 标签及其内容
  458. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  459. // 去除所有 HTML 标签
  460. $content = strip_tags($content);
  461. // 去除 HTML 实体
  462. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  463. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  464. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  465. // 去除多余空白
  466. $content = preg_replace('/\s+/u', '', $content);
  467. // 截取 100 个字符
  468. $articleData['introduce'] = mb_substr($content, 0, 100);
  469. }
  470. if($articleData['status']==0){
  471. $this->sendMessage([
  472. 'talk_type'=>100,
  473. 'title'=>$articleData['title'],
  474. 'content'=>'提交了审核',
  475. 'messageType'=>2,
  476. ]);
  477. }
  478. $id = Article::insertGetId($articleData);
  479. $articleDataContent = [
  480. 'article_id' => $id,
  481. 'content' => $data['content'],
  482. ];
  483. ArticleData::insertGetId($articleDataContent);
  484. //处理投票
  485. if ($is_survey == 1) {
  486. //生成年月日时分秒+8位随机数
  487. $uuid = date('YmdHis') . rand(10000000, 99999999);
  488. var_dump($suvey_array, 'suvey_array________');
  489. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  490. var_dump($suveys_array, '---------------------1');
  491. var_dump($suvey_array, '---------------------2');
  492. $suvey_data = [];
  493. foreach ($suveys_array as $key => $value) {
  494. if ($value == '') {
  495. continue;
  496. }
  497. if (is_array($value)) {
  498. $suvey_data[] = [
  499. 'sur_id' => $uuid,
  500. 'art_id' => $id,
  501. 'website_id' => $website_id ?? 2,
  502. 'survey_name' => $survey_name,
  503. 'choice_name' => $value[1],
  504. 'is_other' => 1,
  505. 'other_id' => 0,
  506. 'results' => 0,
  507. ];
  508. } else {
  509. $suvey_data[] = [
  510. 'sur_id' => $uuid,
  511. 'art_id' => $id,
  512. 'website_id' => $website_id ?? 2,
  513. 'survey_name' => $survey_name,
  514. 'choice_name' => $value,
  515. 'is_other' => 0,
  516. 'other_id' => 0,
  517. 'results' => 0,
  518. ];
  519. }
  520. if (empty($suvey_data)) {
  521. throw new \Exception("投票数据为空");
  522. }
  523. }
  524. $result = ArticleSurvey::insert($suvey_data);
  525. if (!$result) {
  526. throw new \Exception("投票失败,ArticleSurvey插入失败");
  527. }
  528. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  529. if (!$result) {
  530. throw new \Exception("投票失败,更新主表失败");
  531. }
  532. }
  533. Db::commit();
  534. return Result::success(['id' => $id]);
  535. } catch (\Throwable $ex) {
  536. Db::rollBack();
  537. var_dump($ex->getMessage());
  538. return Result::error("创建失败", 0);
  539. }
  540. }
  541. /**
  542. * @param array $data
  543. * @return array
  544. */
  545. public function delArticle(array $data): array
  546. {
  547. $result = Article::where($data)->delete();
  548. //survey投票删除
  549. articleSurvey::where(['art_id' => $data['id']])->delete();
  550. if (!$result) {
  551. return Result::error("删除失败");
  552. }
  553. return Result::success($result);
  554. }
  555. /**
  556. * @param array $data
  557. * @return array
  558. */
  559. public function updateArticle(array $data): array
  560. {
  561. var_dump($data, '----------12-----------1');
  562. Db::beginTransaction();
  563. unset($data['user_type']);
  564. // unset($data['web_site_id']);
  565. unset($data['nav_add_pool_id']);
  566. try {
  567. //处理投票
  568. $is_survey = isset($data['is_survey']) ? $data['is_survey'] : 0;
  569. $survey_name = isset($data['survey_name']) ? $data['survey_name'] : '';
  570. $suvey_array = isset($data['suvey_array']) ? $data['suvey_array'] : '';
  571. $website_id = isset($data['website_id']) ? $data['website_id'] : 2;
  572. unset($data['is_survey']);
  573. unset($data['survey_name']);
  574. unset($data['suvey_array']);
  575. unset($data['website_id']);
  576. $data['web_site_id'] = is_array($data['web_site_id']) ? json_encode($data['web_site_id']) : ($data['web_site_id']);
  577. if ($data['hits'] == '') {
  578. $data['hits'] = 0;
  579. }
  580. if ($data['is_original'] == '') {
  581. $data['is_original'] = 0;
  582. }
  583. if ($data['status'] == '') {
  584. $data['status'] = 0;
  585. }
  586. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : $data['cat_arr_id'];
  587. $data['tag'] = isset($data['tag']) ? json_encode($data['tag']) : '';
  588. $articleData = $data;
  589. unset($articleData['content']);
  590. unset($articleData['status_name']);
  591. unset($articleData['name']);
  592. unset($articleData['content']);
  593. unset($articleData['pid_arr']);
  594. unset($articleData['pid']);
  595. //自动处理缩略图、关键字、描述
  596. if ($articleData['imgurl'] == '') {
  597. //如果没有图,设置level=0
  598. $levelArr = json_decode($articleData['level'], true);
  599. var_dump($levelArr, '----------levelArr-----------1');
  600. //content中提取图片第一个图,正则提取
  601. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  602. preg_match_all($reg, $data['content'], $matches);
  603. if (isset($matches[1][0])) {
  604. //截取varchar240
  605. // 截取到第一个<
  606. $articleData['imgurl'] = $matches[1][0];
  607. var_dump($articleData['imgurl'], '----------imgurl-----------1');
  608. $pos = strpos($articleData['imgurl'], '"');
  609. if ($pos !== false) {
  610. $articleData['imgurl'] = substr($articleData['imgurl'], 0, $pos);
  611. }
  612. //$articleData['imgurl'] = substr($matches[1][0], 0, 240);
  613. //如果有图,设置level=3
  614. if (!in_array(3, $levelArr)) {
  615. $levelArr[] = 3;
  616. }
  617. $articleData['level'] = json_encode($levelArr);
  618. } else {
  619. if (!in_array(0, $levelArr)) {
  620. $levelArr[] = 0;
  621. }
  622. $articleData['level'] = json_encode($levelArr);
  623. }
  624. }
  625. var_dump($articleData['level'], '----------$articleData[level]----------1');
  626. if ($articleData['keyword'] == '') {
  627. //提取标题+内容中的关键词
  628. $articleData['keyword'] = $data['title'];
  629. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  630. Jieba::init(); // 初始化 jieba-php
  631. Finalseg::init();
  632. $segList = Jieba::cut($articleData['keyword']);
  633. $segList1 = array_slice($segList, 0, 8);
  634. $articleData['keyword'] = implode(',', $segList1);
  635. }
  636. if ($articleData['introduce'] == '') {
  637. //提取内容中的描述
  638. $content = $data['content'];
  639. // 去除 <style> 和 <script> 标签及其内容
  640. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  641. // 去除所有 HTML 标签
  642. $content = strip_tags($content);
  643. // 去除 HTML 实体
  644. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  645. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  646. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  647. // 去除多余空白
  648. $content = preg_replace('/\s+/u', '', $content);
  649. // 截取 100 个字符
  650. $articleData['introduce'] = mb_substr($content, 0, 100);
  651. }
  652. if($articleData['status']==0){
  653. $this->sendMessage([
  654. 'talk_type'=>100,
  655. 'title'=>$articleData['title'],
  656. 'content'=>'提交了审核',
  657. 'messageType'=>2,]);
  658. }
  659. $id = Article::where(['id' => $data['id']])->update($articleData);
  660. $articleDataContent = [
  661. 'content' => $data['content'],
  662. ];
  663. ArticleData::where(['article_id' => $data['id']])->update($articleDataContent);
  664. //处理投票
  665. $id = $data['id'];
  666. $surveydata = ArticleSurvey::where(['art_id' => $data['id']])->delete();
  667. var_dump($suvey_array, 'suvey_array________delete');
  668. //处理投票
  669. if ($is_survey == 1) {
  670. //生成年月日时分秒+8位随机数
  671. $uuid = date('YmdHis') . rand(10000000, 99999999);
  672. $suveys_array = is_array($suvey_array) ? $suvey_array : json_decode($suvey_array);
  673. var_dump($suveys_array, '---------------------1');
  674. $suvey_data = [];
  675. if (is_array($suveys_array)) {
  676. foreach ($suveys_array as $key => $value) {
  677. if ($value == '') {
  678. continue;
  679. }
  680. if (is_array($value)) {
  681. $suvey_data[] = [
  682. 'sur_id' => $uuid,
  683. 'art_id' => $id,
  684. 'website_id' => $website_id ?? 2,
  685. 'survey_name' => $survey_name,
  686. 'choice_name' => $value[1],
  687. 'is_other' => 1,
  688. 'other_id' => 0,
  689. 'results' => 0,
  690. ];
  691. } else {
  692. $suvey_data[] = [
  693. 'sur_id' => $uuid,
  694. 'art_id' => $id,
  695. 'website_id' => $website_id ?? 2,
  696. 'survey_name' => $survey_name,
  697. 'choice_name' => $value,
  698. 'is_other' => 0,
  699. 'other_id' => 0,
  700. 'results' => 0,
  701. ];
  702. }
  703. if (empty($suvey_data)) {
  704. throw new \Exception("投票数据为空");
  705. }
  706. }
  707. }
  708. $result = ArticleSurvey::insert($suvey_data);
  709. if (!$result) {
  710. throw new \Exception("投票失败");
  711. }
  712. $result = Article::where('id', $id)->update(['survey_id' => $uuid, 'survey_name' => $survey_name, 'is_survey' => $is_survey]);
  713. if (!$result) {
  714. throw new \Exception("投票失败");
  715. }
  716. } else {
  717. $result = Article::where('id', $id)->update(['survey_id' => '', 'survey_name' => '', 'is_survey' => 0]);
  718. }
  719. Db::commit();
  720. return Result::success([]);
  721. } catch (\Throwable $ex) {
  722. Db::rollBack();
  723. var_dump($ex->getMessage());
  724. return Result::error("更新失败" . $ex->getMessage(), 0);
  725. }
  726. }
  727. /**
  728. * 更新资讯状态
  729. * @param array $data
  730. * @return array
  731. */
  732. public function upArticleStatus(array $data): array
  733. {
  734. $articleData = Article::where(['id' => $data['id']])->first();
  735. if($data['status']==1){
  736. $this->sendMessage([
  737. 'talk_type'=>101,
  738. 'title'=>$articleData['title'],
  739. 'content'=>'审核通过',
  740. 'messageType'=>2,
  741. 'user_id'=>$articleData['admin_user_id'],
  742. ]);
  743. }
  744. if($data['status']==2){
  745. $this->sendMessage([
  746. 'talk_type'=>101,
  747. 'title'=>$articleData['title'],
  748. 'content'=>'审核拒绝',
  749. 'messageType'=>2,
  750. 'user_id'=>$articleData['admin_user_id'],
  751. ]);
  752. }
  753. $result = Article::where(['id' => $data['id']])->update($data);
  754. if (isset($data['ignore_ids']) && !empty($data['ignore_ids'])) {
  755. //article_ignore 表插入数据 db操作
  756. //转成数组
  757. //删掉数据重新写入
  758. DB::table('article_ignore')->where('article_id', $data['id'])->delete();
  759. $website_ids = is_array($data['ignore_ids']) ? $data['ignore_ids'] : json_decode($data['ignore_ids'], true);
  760. $insert_data = [];
  761. foreach ($website_ids as $key => $value) {
  762. $insert_data[] = [
  763. 'article_id' => $data['id'],
  764. 'website_id' => $value,
  765. ];
  766. }
  767. DB::table('article_ignore')->insert($insert_data);
  768. }
  769. if ($result) {
  770. return Result::success();
  771. } else {
  772. return Result::error("更新状态失败", 0);
  773. }
  774. }
  775. /**
  776. * 获取新闻详情
  777. * @param array $data
  778. * @return array
  779. */
  780. public function getArticleInfo(array $data): array
  781. {
  782. $where = [
  783. 'article.id' => $data['id'],
  784. // 'article.status' => 1,
  785. ];
  786. $result = Article::where($where)->leftJoin("article_data", "article.id", "article_data.article_id")->first();
  787. $articleSurvey = ArticleSurvey::where(['art_id' => $data['id']])->get();
  788. $info = $result;
  789. // var_dump($info, 'info');
  790. $info['survey_array'] = $articleSurvey;
  791. if ($result) {
  792. return Result::success($info);
  793. } else {
  794. return Result::error("查询失败", 0);
  795. }
  796. }
  797. /**
  798. * 获取头条新闻
  799. * @param array $data
  800. * @return array
  801. */
  802. public function getWebsiteArticlett(array $data): array
  803. {
  804. $website_id = $data['website_id'];
  805. $categorys = $this->processArticlePro($website_id);
  806. $catiall = $categorys['catiall'];
  807. $categoryIds = $categorys['categoryIds'];
  808. $where = [
  809. 'status' => 1
  810. ];
  811. $website_id = $data['website_id'];
  812. $month = date("Y-m-d H:i:s", strtotime("-30 day"));
  813. //如果是4:最新资讯(数据库已不存在) 5:资讯推荐(数据库已不存在);
  814. // 1:头条资讯;2:轮播图;6:热点资讯;(数据库)
  815. switch ($data['level']) {
  816. case 1:
  817. case 2:
  818. case 3:
  819. case 6:
  820. $query = Article::where($where)
  821. ->where('level', 'like', '%' . $data['level'] . '%')
  822. ->orderBy('updated_at', 'desc');
  823. break;
  824. case 4:
  825. $query = Article::where($where)
  826. ->where('updated_at', '>', $month);
  827. break;
  828. case 5:
  829. $query = Article::where($where)->orderBy('updated_at', 'desc');;
  830. break;
  831. case 7:
  832. if (isset($data['id']) && !empty($data['id'])) {
  833. $keyword = Article::where('id', $data['id'])->value('keyword');
  834. $keywordArray = explode(',', $keyword);
  835. $whereL7 = [];
  836. foreach ($keywordArray as $k => $v) {
  837. $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  838. }
  839. $query = Article::where($where)->where($whereL7)->orderBy('updated_at', 'desc');;
  840. break;
  841. } else {
  842. return Result::error("请输入资讯ID", 0);
  843. break;
  844. }
  845. default:
  846. break;
  847. }
  848. // $whereL7 = [];
  849. // if(isset($data['id']) && !empty($data['id'])){
  850. // $keyword = Article::where('id', $data['id'])->value('keyword');
  851. // $keywordArray = explode(',', $keyword);
  852. // foreach ($keywordArray as $k => $v) {
  853. // $whereL7[] = ['keyword', 'like', '%' . $v . '%'];
  854. // }
  855. // }
  856. // $query = Article::where($where)
  857. // ->when(isset($data['level']) && !empty($data['level']), function ($query) use ($data,$whereL7) {
  858. // if($data['level'] == 1 || $data['level'] == 2 || $data['level'] == 3 || $data['level'] == 6){
  859. // $query = $query->where('article.level','like','%'.$data['level'].'%')->orderBy('updated_at','desc');
  860. // }
  861. // if($data['level'] == 7){
  862. // $query = $query->where($whereL7)->orderBy('updated_at','desc');
  863. // }
  864. // if($data['level'] == 4){
  865. // $query = $query->inRandomOrder()
  866. // ->where('updated_at', '>', date("Y-m-d H:i:s", strtotime("-30 day")));
  867. // }
  868. // if($data['level'] == 5){
  869. // $query = $query->orderBy('updated_at','desc');
  870. // }
  871. // });
  872. if ($data['textnum'] > 0) {
  873. $query = clone $query;
  874. $result['text'] = $query
  875. ->whereIn('catid', $categoryIds)
  876. ->leftJoinSub(function ($query) use ($website_id) {
  877. $query->from('article_ignore')
  878. ->where('website_id', $website_id);
  879. }, 'article_ignore', function ($join) {
  880. $join->on('article_ignore.article_id', '=', 'article.id');
  881. })
  882. ->where(function ($query) use ($website_id) {
  883. $query->whereNull('article_ignore.article_id')
  884. ->orWhere('article_ignore.website_id', '!=', $website_id);
  885. })
  886. ->select(
  887. 'article.id',
  888. 'article.title',
  889. 'article.author',
  890. 'article.updated_at',
  891. 'article.introduce',
  892. 'article.islink',
  893. 'article.linkurl',
  894. 'article.copyfrom',
  895. 'article.cat_arr_id',
  896. 'article.catid',
  897. 'article.level'
  898. )
  899. ->offset($data['placeid'])
  900. ->limit($data['textnum'])
  901. ->get()->all();
  902. foreach ($result['text'] as $k => $v) {
  903. $result['text'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  904. }
  905. }
  906. if ($data['imgnum'] > 0) {
  907. $query = clone $query;
  908. $result['img'] = $query
  909. ->whereIn('catid', $categoryIds)
  910. ->where('article.imgurl', '!=', '')
  911. ->select(
  912. 'article.id',
  913. 'article.title',
  914. 'article.imgurl',
  915. 'article.author',
  916. 'article.updated_at',
  917. 'article.introduce',
  918. 'article.islink',
  919. 'article.linkurl',
  920. 'article.copyfrom',
  921. 'article.cat_arr_id',
  922. 'article.catid',
  923. 'article.level'
  924. )
  925. ->offset($data['placeid'])
  926. ->limit($data['imgnum'])
  927. ->get()->all();
  928. foreach ($result['img'] as $k => $v) {
  929. $result['img'][$k]->pinyin = $catiall[$v->catid]['pinyin'];
  930. }
  931. }
  932. if (empty($result)) {
  933. return Result::error("暂无相关资讯", 0);
  934. }
  935. return Result::success($result);
  936. }
  937. /**
  938. * 获取模块新闻
  939. * @param array $data
  940. * @return array
  941. */
  942. public function getWebsiteModelArticles(array $data): array
  943. {
  944. $catid = $data['catid'];
  945. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->select('category_id')->get();
  946. $category = $category->toArray();
  947. if (!empty($category)) {
  948. $where = [
  949. 'status' => 1,
  950. 'catid' => $catid,
  951. ];
  952. $placeid = isset($data['placeid']) && !empty($data['placeid']) ? $data['placeid'] - 1 : 0;
  953. // 1:文字新闻;2:轮播图;3:图文;
  954. // 级别:0:未分类
  955. // 3:推荐图片
  956. if ($data['level'] == 1) {
  957. $data['level'] = 0;
  958. }
  959. $result = Article::where($where)
  960. ->where(function ($query) use ($data) {
  961. $query->whereRaw("JSON_CONTAINS(level, '" . intval($data['level']) . "') = 1")
  962. ->orWhereNull("level")
  963. ->orWhereRaw("level = '[]'");
  964. })
  965. ->where(function ($query) use ($data) {
  966. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  967. ->orWhereNull("ignore_ids");
  968. })
  969. ->orderBy("updated_at", "desc")
  970. ->offset($placeid)
  971. ->limit($data['pagesize'])
  972. ->get();
  973. if (empty($result)) {
  974. return Result::error("此栏目暂无相关新闻", 0);
  975. }
  976. } else {
  977. return Result::error("此网站暂无此栏目", 0);
  978. }
  979. return Result::success($result);
  980. }
  981. /**
  982. *获取新闻列表
  983. * @param array $data
  984. * @return array
  985. */
  986. public function getWebsiteArticleList(array $data): array
  987. {
  988. // return Result::success($data);
  989. $where[] = ['status', '=', 1];
  990. $website_id = $data['website_id'];
  991. if (isset($data['catid']) && !empty($data['catid'])) {
  992. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->pluck('category_id');
  993. if (empty($category)) {
  994. return Result::error("此网站暂无此栏目", 0);
  995. }
  996. array_push($where, ['catid', '=', $data['catid']]);
  997. }
  998. // return Result::success($where);
  999. $query = Article::where($where)
  1000. ->leftJoinSub(function ($query) use ($website_id) {
  1001. $query->from('article_ignore')
  1002. ->where('website_id', $website_id);
  1003. }, 'article_ignore', function ($join) {
  1004. $join->on('article_ignore.article_id', '=', 'article.id');
  1005. })
  1006. ->where(function ($query) use ($website_id) {
  1007. $query->whereNull('article_ignore.article_id')
  1008. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1009. })
  1010. ->select(
  1011. 'article.id',
  1012. 'article.title',
  1013. 'article.imgurl',
  1014. 'article.author',
  1015. 'article.updated_at',
  1016. 'article.introduce',
  1017. 'article.islink',
  1018. 'article.linkurl',
  1019. 'article.copyfrom',
  1020. 'article.cat_arr_id',
  1021. 'article.catid'
  1022. );
  1023. $count = $query->count();
  1024. $rep = $query->orderBy("updated_at", "desc")
  1025. ->offset(($data['page'] - 1) * $data['pageSize'])
  1026. ->limit($data['pageSize'])
  1027. ->get()->all();
  1028. $categorys = $this->processArticlePro($website_id);
  1029. $cat_1st_arr = $categorys['cat_1st_arr'];
  1030. $catiall = $categorys['catiall'];
  1031. // $web['website_id'] = $data['website_id'];
  1032. foreach ($rep as $k => $v) {
  1033. $rep[$k]->category_name = $catiall[$v->catid]['alias'];
  1034. $rep[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1035. }
  1036. // $rep = $this->processArticles($rep,$web);
  1037. $data = [
  1038. 'rows' => $rep,
  1039. 'count' => $count,
  1040. ];
  1041. if (empty($rep)) {
  1042. return Result::error("没有信息数据");
  1043. }
  1044. return Result::success($data);
  1045. }
  1046. /**
  1047. * 前端-获取新闻详情
  1048. * @param array $data
  1049. * @return array
  1050. */
  1051. public function selectWebsiteArticleInfo(array $data): array
  1052. {
  1053. $where = [
  1054. 'article.id' => $data['id'],
  1055. 'article.status' => 1,
  1056. ];
  1057. $result = Article::where($where)
  1058. ->leftJoin("article_data", "article.id", "article_data.article_id")
  1059. ->leftJoin("article_extend", "article_extend.article_id", "article.id")
  1060. ->where(function ($query) use ($data) {
  1061. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  1062. ->orWhereNull("ignore_ids");
  1063. })
  1064. ->first();
  1065. if (empty($result)) {
  1066. return Result::error("暂无此新闻!", 0);
  1067. }
  1068. $category = WebsiteCategory::leftJoin('website', 'website.id', '=', 'website_category.website_id')
  1069. ->select('website_category.*', 'website.website_name', 'website.suffix')
  1070. ->where('website_category.website_id', $data['website_id'])
  1071. ->where(['website_category.category_id' => $result['catid']])
  1072. ->first();
  1073. if (empty($category)) {
  1074. return Result::error("查询失败", 0);
  1075. }
  1076. //手动推荐文章
  1077. $commend_ids = $result['commend_id'] ? json_decode($result['commend_id']) : [];
  1078. $commendArticle = Article::whereIn('id', $commend_ids)
  1079. ->where('status', 1)
  1080. ->select('id', 'title', 'catid', 'imgurl', 'hits', 'created_at')
  1081. ->orderBy('updated_at', 'desc')
  1082. ->limit(5)
  1083. ->get();
  1084. $result['category_id'] = $category['category_id'];
  1085. $result['cat_name'] = $category['alias'];
  1086. $result['website_name'] = $category['website_name'] ?? "";
  1087. $result['suffix'] = $category['suffix'] ?? "";
  1088. $result['commendArticle'] = $commendArticle;
  1089. return Result::success($result);
  1090. }
  1091. /**
  1092. * 前端-获取网站调查问卷
  1093. * @param array $data
  1094. * @return array
  1095. */
  1096. public function getWebsiteSurvey(array $data): array
  1097. {
  1098. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1099. $website = Website::where('id', $data['website_id'])->first();
  1100. if (empty($website)) {
  1101. return Result::error("暂无此网站", 0);
  1102. }
  1103. }
  1104. if (isset($data['art_id']) && !empty($data['art_id'])) {
  1105. $article = Article::where('id', $data['art_id'])->where('status', 1)->first();
  1106. if (empty($article)) {
  1107. return Result::error("暂无此文章", 0);
  1108. }
  1109. // return Result::error($data,0);
  1110. $where['art_id'] = $data['art_id'];
  1111. // $query = ArticleSurvey::where('art_id',$data['art_id']);
  1112. } else {
  1113. $survey = Article::where(function ($query) {
  1114. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '28')")
  1115. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '\"28\"')");
  1116. })
  1117. ->where('status', 1)
  1118. ->where('is_survey', 1)
  1119. ->select('survey_id')
  1120. ->orderBy('updated_at', 'desc')
  1121. ->first();
  1122. if (empty($survey)) {
  1123. return Result::error("暂无调查问卷", 0);
  1124. }
  1125. $where['sur_id'] = $survey['survey_id'];
  1126. // $query = ArticleSurvey::where('sur_id',$survey['sur_id']);
  1127. }
  1128. // return Result::success($where);
  1129. $result = ArticleSurvey::where($where)
  1130. ->where(function ($query) {
  1131. $query->where('is_other', 0)
  1132. ->orWhere(function ($subQuery) {
  1133. $subQuery->where('is_other', 1)
  1134. ->where('other_id', 0);
  1135. });
  1136. })
  1137. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1138. ->select('article_survey.*', 'article.survey_type')
  1139. ->get()->all();
  1140. if (empty($result)) {
  1141. return Result::error("此文章暂无调查问卷", 0);
  1142. }
  1143. return Result::success($result);
  1144. }
  1145. /**
  1146. * 前端-添加网站调查问卷选项
  1147. * @param array $data
  1148. * @return array
  1149. */
  1150. public function addWebsiteSurveyOption(array $data): array
  1151. {
  1152. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1153. $website = Website::where('id', $data['website_id'])->first();
  1154. if (empty($website)) {
  1155. return Result::error("暂无此网站", 0);
  1156. }
  1157. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1158. $survey = ArticleSurvey::where('sur_id', $data['sur_id'])->where('is_other', 1)->where('other_id', 0)->first();
  1159. if (empty($survey)) {
  1160. return Result::error("此调查问卷不可添加选项", 0);
  1161. }
  1162. if (isset($data['choice_name']) && !empty($data['choice_name'])) {
  1163. $choice = [
  1164. 'art_id' => $survey['art_id'],
  1165. 'website_id' => $data['website_id'],
  1166. 'survey_name' => $survey['survey_name'],
  1167. 'choice_name' => $data['choice_name'],
  1168. 'sur_id' => $survey['sur_id'],
  1169. 'is_other' => 1,
  1170. 'other_id' => $survey['id'],
  1171. ];
  1172. $result = ArticleSurvey::insertGetId($choice);
  1173. if (empty($result)) {
  1174. return Result::error("添加失败", 0);
  1175. }
  1176. return Result::success($result);
  1177. }
  1178. }
  1179. return Result::error("添加失败", 0);
  1180. }
  1181. return Result::error("添加失败", 0);
  1182. }
  1183. /**
  1184. * 前端-调查问卷投票
  1185. * @param array $data
  1186. * @return array
  1187. */
  1188. public function addWebsiteSurveyVote(array $data): array
  1189. {
  1190. // return Result::success($data);
  1191. if (isset($data['website_id']) && !empty($data['website_id'])) {
  1192. $website = Website::where('id', $data['website_id'])->first();
  1193. if (empty($website)) {
  1194. return Result::error("暂无此网站", 0);
  1195. }
  1196. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1197. $is_survey = ArticleSurvey::where('sur_id', $data['sur_id'])->first();
  1198. // return Result::success($survey);
  1199. if (empty($is_survey)) {
  1200. return Result::error("此调查问卷不存在", 0);
  1201. }
  1202. // return Result::success($survey);
  1203. // 调查问卷类型
  1204. if (isset($data['choice_id']) && !empty($data['choice_id'])) {
  1205. //多选 若是json型则转化成数组类型
  1206. if (strpos($data['choice_id'], '[') === 0) {
  1207. $data['choice_id'] = json_decode($data['choice_id'], true);
  1208. } else {
  1209. // 单选 也转换成数组
  1210. $data['choice_id'] = [$data['choice_id']];
  1211. }
  1212. $data['choice_id'] = array_map('intval', $data['choice_id']);
  1213. $other = ArticleSurvey::whereIn('id', $data['choice_id'])
  1214. // ->where('website_id',$data['website_id'])
  1215. ->where('is_other', 1)
  1216. ->where('other_id', 0)
  1217. ->first();
  1218. if (!empty($other)) {
  1219. return Result::error("请选择已有的选项!", 0);
  1220. }
  1221. $choice['other'] = ArticleSurvey::whereIn('id', $data['choice_id'])
  1222. // ->where('website_id',$data['website_id'])
  1223. ->where('is_other', 1)
  1224. ->where('other_id', '!=', 0)
  1225. ->first();
  1226. // return Result::success($choice['other']);
  1227. $choice_id = $data['choice_id'];
  1228. if (!empty($choice['other'])) {
  1229. // array_push($data['choice_id'],$choice['other']['other_id']);
  1230. if (!empty($choice_id)) {
  1231. $key = array_search($choice['other']['id'], $choice_id);
  1232. if ($key !== false) {
  1233. unset($choice_id[$key]);
  1234. $choice_id = array_values($choice_id);
  1235. }
  1236. array_push($choice_id, $choice['other']['other_id']);
  1237. } else {
  1238. $choice_id[0] = $choice['other']['other_id'];
  1239. }
  1240. array_push($data['choice_id'], $choice['other']['other_id']);
  1241. }
  1242. // return Result::success($data);
  1243. $choice = ArticleSurvey::whereIn('id', $data['choice_id'])
  1244. // ->where('website_id',$data['website_id'])
  1245. ->increment('results', 1);
  1246. if (empty($choice)) {
  1247. return Result::error("请选择已有的选项!", 0);
  1248. }
  1249. $survey['data'] = ArticleSurvey::where('sur_id', $data['sur_id'])
  1250. // ->where('website_id',$data['website_id'])
  1251. ->where('other_id', 0)
  1252. ->get();
  1253. $survey['choice'] = $choice_id;
  1254. return Result::success($survey);
  1255. }
  1256. return Result::error("参数必填!");
  1257. }
  1258. return Result::error("此调查问卷不存在", 0);
  1259. }
  1260. return Result::error("参数必填!");
  1261. }
  1262. /**
  1263. * 后端-获取网站调查问卷列表
  1264. * @param array $data
  1265. * @return array
  1266. */
  1267. public function getSurveyList(array $data): array
  1268. {
  1269. $where = [];
  1270. if (isset($data['survey_name']) && !empty($data['survey_name'])) {
  1271. array_push($where, ['survey_name', 'like', '%' . $data['survey_name'] . '%']);
  1272. }
  1273. if (isset($data['survey_type']) && $data['survey_type'] != null) {
  1274. array_push($where, ['survey_type', '=', $data['survey_type']]);
  1275. }
  1276. if (isset($data['is_survey']) && $data['is_survey'] != null) {
  1277. array_push($where, ['is_survey', '=', $data['is_survey']]);
  1278. }
  1279. // return Result::success($where);
  1280. if (!empty($where)) {
  1281. $query = Article::where($where)->where(function ($q) {
  1282. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1283. });
  1284. } else {
  1285. $query = Article::where(function ($q) {
  1286. $q->whereNotNull('survey_name')->where('survey_name', '!=', '');
  1287. });
  1288. }
  1289. $count = $query->count();
  1290. $survey = $query->orderByDesc('id')
  1291. ->limit($data['pageSize'])
  1292. ->offset(($data['page'] - 1) * $data['pageSize'])
  1293. ->get();
  1294. if (empty($survey->toArray())) {
  1295. return Result::error("暂无调查问卷!", 0);
  1296. }
  1297. $result = [
  1298. 'rows' => $survey,
  1299. 'count' => $count,
  1300. ];
  1301. return Result::success($result);
  1302. }
  1303. /**
  1304. * 后端-获取网站调查问卷详情
  1305. * @param array $data
  1306. * @return array
  1307. */
  1308. public function getSurveyInfo(array $data): array
  1309. {
  1310. if (isset($data['sur_id']) && !empty($data['sur_id'])) {
  1311. $where = ['sur_id' => $data['sur_id']];
  1312. $choose = ArticleSurvey::where($where)->where('is_other', 0)
  1313. ->leftJoin('article', 'article_survey.art_id', 'article.id')
  1314. ->select('article_survey.*', 'article.survey_type')
  1315. ->get()->all();
  1316. if (empty($choose)) {
  1317. return Result::error("此调查问卷不存在", 0);
  1318. }
  1319. $resultsArray = array_column($choose, 'results');
  1320. $total = array_sum($resultsArray);
  1321. $other = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', 0)->first();
  1322. $others = ArticleSurvey::where($where)->where('is_other', 1)->where('other_id', '!=', 0)->orderByDesc('created_at')->get()->all();
  1323. // $total = 0;
  1324. if (!empty($other)) {
  1325. $total = $total + $other['results'];
  1326. $other['choice_name'] = '(其他)';
  1327. if (!empty($others)) {
  1328. $other['hasChildren'] = true;
  1329. // array_push($other,['hasChildren','=',true]);
  1330. $other['children'] = $others;
  1331. $other_choices = [$other->toArray()];
  1332. $mer_choice = array_merge($choose, $other_choices);
  1333. $value_choice = array_values($mer_choice);
  1334. } else {
  1335. // return Result::error('1111');
  1336. $other_choices = [$other->toArray()];
  1337. $other_choices = array_merge($choose, $other_choices);
  1338. $value_choice = array_values($other_choices);
  1339. // return Result::success($result);
  1340. }
  1341. } else {
  1342. $value_choice = $choose;
  1343. }
  1344. $result = [
  1345. 'choose' => $value_choice,
  1346. 'total' => $total,
  1347. ];
  1348. }
  1349. return Result::success($result);
  1350. }
  1351. /**
  1352. * 前端-搜索新闻列表
  1353. * @param array $data
  1354. * @return array
  1355. */
  1356. public function selectWebsiteArticle(array $data): array
  1357. {
  1358. $category = WebsiteCategory::where('website_id', $data['website_id'])->pluck('category_id');
  1359. $website_id = $data['website_id'];
  1360. $categorys = $this->processArticlePro($website_id);
  1361. $catiall = $categorys['catiall'];
  1362. $query = Article::where('status', 1)
  1363. ->whereIn('catid', $category)
  1364. ->leftJoinSub(function ($query) use ($website_id) {
  1365. $query->from('article_ignore')
  1366. ->where('website_id', $website_id);
  1367. }, 'article_ignore', function ($join) {
  1368. $join->on('article_ignore.article_id', '=', 'article.id');
  1369. })
  1370. ->where(function ($query) use ($website_id) {
  1371. $query->whereNull('article_ignore.article_id')
  1372. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1373. });
  1374. // return Result::success($all_articles);
  1375. if (isset($data['cityid']) && !empty($data['cityid'])) {
  1376. $query->whereRaw("JSON_CONTAINS(city_arr_id, '" . intval($data['cityid']) . "')");
  1377. }
  1378. if (isset($data['department_id']) && !empty($data['department_id'])) {
  1379. $query->whereRaw("JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "')");
  1380. }
  1381. if (isset($data['keyword']) && !empty($data['keyword'])) {
  1382. $query->where('title', 'like', '%' . $data['keyword'] . '%');
  1383. }
  1384. // 计算总数
  1385. $count = $query->count();
  1386. // 分页查询
  1387. $articles = $query
  1388. ->select(
  1389. 'article.id',
  1390. 'article.title',
  1391. 'article.imgurl',
  1392. 'article.author',
  1393. 'article.updated_at',
  1394. 'article.introduce',
  1395. 'article.islink',
  1396. 'article.linkurl',
  1397. 'article.copyfrom',
  1398. 'article.cat_arr_id',
  1399. 'article.catid',
  1400. 'article.department_arr_id',
  1401. 'article.city_arr_id',
  1402. )
  1403. ->orderBy("updated_at", "desc")
  1404. ->offset(($data['page'] - 1) * $data['pageSize'])
  1405. ->limit($data['pageSize'])
  1406. ->get();
  1407. foreach ($articles as $k => $v) {
  1408. $articles[$k]->category_name = $catiall[$v->catid]['alias'];
  1409. $articles[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1410. }
  1411. if (empty($articles)) {
  1412. return Result::error("没有符合条件的资讯数据");
  1413. }
  1414. $result = [
  1415. 'rows' => $articles,
  1416. 'count' => $count,
  1417. ];
  1418. return Result::success($result);
  1419. }
  1420. /**
  1421. * 模块新闻加强版
  1422. * @param array $data
  1423. * @return array
  1424. */
  1425. public function getWebsiteCatidArticle(array $data): array
  1426. {
  1427. $where = [
  1428. 'website_category.category_id' => $data['catid'],
  1429. 'website_category.website_id' => $data['website_id'],
  1430. ];
  1431. if (isset($data['child_catnum']) && !empty($data['child_catnum'])) {
  1432. $child_catnum = $data['child_catnum'] ?? 1;
  1433. $category['child'] = WebsiteCategory::where('pid', $data['catid'])->where('website_id', $data['website_id'])->select('category_id', 'alias')->limit($child_catnum)->get()->toArray();
  1434. $childCategoryIds = array_column($category['child'], 'category_id');
  1435. if (empty($childCategoryIds)) {
  1436. return Result::error("暂无子栏目", 0);
  1437. }
  1438. $imgArticles = [];
  1439. $textArticles = [];
  1440. if (isset($data['child_imgnum']) && !empty($data['child_imgnum']) && $data['child_imgnum'] != 0) {
  1441. // 初始化子分类图片新闻和文字新闻数组
  1442. // 查询所有子级栏目的图文新闻
  1443. $imgArticles = Article::where('catid', $childCategoryIds[0])
  1444. ->where(function ($query) use ($data) {
  1445. $query->where(function ($subQuery) use ($data) {
  1446. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1447. })->orWhereNull("ignore_ids");
  1448. })
  1449. ->where('status', 1)
  1450. ->where('imgurl', '!=', '')
  1451. ->select('*')
  1452. ->orderBy('updated_at', 'desc')
  1453. ->limit($data['child_imgnum'])
  1454. ->get();
  1455. }
  1456. if (isset($data['child_textnum']) && !empty($data['child_textnum']) && $data['child_textnum'] != 0) {
  1457. // 查询所有子级栏目的文字新闻
  1458. $textArticles = Article::where('catid', $childCategoryIds[0])
  1459. ->where('status', 1)
  1460. ->where(function ($query) use ($data) {
  1461. $query->where(function ($subQuery) use ($data) {
  1462. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0");
  1463. })->orWhereNull("ignore_ids");
  1464. })
  1465. ->select('*')
  1466. ->orderBy('updated_at', 'desc')
  1467. ->limit($data['child_textnum'])
  1468. ->get();
  1469. }
  1470. // 遍历子分类,将图文新闻和文字新闻分别添加到子分类中
  1471. $category['child'] = array_map(function ($child) use ($imgArticles, $textArticles) {
  1472. $child['img'] = $imgArticles ? $imgArticles->where('catid', $child['category_id']) : [];
  1473. $child['text'] = $textArticles ? $textArticles->where('catid', $child['category_id']) : [];
  1474. return $child;
  1475. }, $category['child']);
  1476. }
  1477. // }
  1478. if (isset($data['img_num']) && !empty($data['img_num'])) {
  1479. $category['img'] = WebsiteCategory::where($where)
  1480. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1481. ->where('article.status', 1)
  1482. ->where('article.imgurl', '!=', '')
  1483. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1484. ->orderBy('article.updated_at', 'desc')
  1485. ->limit($data['img_num'])
  1486. ->get();
  1487. }
  1488. if (isset($data['text_num']) && !empty($data['text_num'])) {
  1489. $category['text'] = WebsiteCategory::where($where)
  1490. ->leftJoin('article', 'article.catid', 'website_category.category_id')
  1491. ->where('article.status', 1)
  1492. ->select('article.*', 'website_category.category_id', 'website_category.alias')
  1493. ->orderBy('article.updated_at', 'desc')
  1494. ->limit($data['text_num'])
  1495. ->get();
  1496. }
  1497. // $category = $category->get();
  1498. if (empty($category)) {
  1499. return Result::error("查询失败", 0);
  1500. }
  1501. return Result::success($category);
  1502. }
  1503. /**
  1504. * 模块新闻加强plus版
  1505. * @param array $data
  1506. * @return array
  1507. */
  1508. public function getWebsiteAllArticle(array $data): array
  1509. {
  1510. $time1 = microtime(true);
  1511. $wetbsite_id = $data['website_id'] ?? 2;
  1512. $data = json_decode($data['id'], true);
  1513. $categorys = $this->processArticlePro($wetbsite_id);
  1514. $cat_1st_arr = $categorys['cat_1st_arr'];
  1515. $catiall = $categorys['catiall'];
  1516. $websiteInfoIndexed = $categorys['websiteInfoIndexed'];
  1517. $parent_category = array_column($data, 'parent');
  1518. $parent_cat = [];
  1519. $child_category = array_column($data, 'child');
  1520. if (!empty($parent_category)) {
  1521. foreach ($parent_category as $key => $value) {
  1522. $arr = array_map('intval', explode(',', $value));
  1523. $parent_cat[$key] = $arr[0] ?? 0;
  1524. $parent_category = $arr[0] ?? 0;
  1525. $article_imgnum = $arr[1] ?? 0;
  1526. $article_textnum = $arr[2] ?? 0;
  1527. if ($parent_category != 0) {
  1528. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  1529. // return Result::success($category_arr);
  1530. if ($article_imgnum != 0) {
  1531. $img_article = Article::whereIn('catid', $category_arr)
  1532. ->where('status', 1)
  1533. ->where('imgurl', '!=', '')
  1534. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1535. $query->from('article_ignore')
  1536. ->where('website_id', $wetbsite_id);
  1537. }, 'article_ignore', function ($join) {
  1538. $join->on('article_ignore.article_id', '=', 'article.id');
  1539. })
  1540. ->where(function ($query) use ($wetbsite_id) {
  1541. $query->whereNull('article_ignore.article_id')
  1542. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1543. })
  1544. ->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')
  1545. ->orderBy('updated_at', 'desc')
  1546. ->limit($article_imgnum)
  1547. ->get()->all();
  1548. foreach ($img_article as $k => $v) {
  1549. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1550. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1551. }
  1552. } else {
  1553. $img_article = [];
  1554. }
  1555. if ($article_textnum != 0) {
  1556. $text_article = Article::whereIn('catid', $category_arr)
  1557. ->where('status', 1)
  1558. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1559. $query->from('article_ignore')
  1560. ->where('website_id', $wetbsite_id);
  1561. }, 'article_ignore', function ($join) {
  1562. $join->on('article_ignore.article_id', '=', 'article.id');
  1563. })
  1564. ->where(function ($query) use ($wetbsite_id) {
  1565. $query->whereNull('article_ignore.article_id')
  1566. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1567. })
  1568. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1569. ->orderBy('updated_at', 'desc')
  1570. ->limit($article_textnum)
  1571. ->get()->all();
  1572. foreach ($text_article as $k => $v) {
  1573. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1574. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1575. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  1576. }
  1577. } else {
  1578. $text_article = [];
  1579. }
  1580. $catiall[$parent_category]['imgnum'] = $img_article;
  1581. $catiall[$parent_category]['textnum'] = $text_article;
  1582. $parent[$key] = $catiall[$parent_category];
  1583. } else {
  1584. $parent[$key] = '';
  1585. }
  1586. }
  1587. }
  1588. if (!empty($child_category)) {
  1589. foreach ($child_category as $key => $value) {
  1590. $arr = array_map('intval', explode(',', $value));
  1591. $parent_category = $parent_cat[$key];
  1592. $child_category = $arr[0] ?? 0;
  1593. $article_imgnum = $arr[1] ?? 0;
  1594. $article_textnum = $arr[2] ?? 0;
  1595. if ($child_category != 0) {
  1596. $all_childcat = $cat_1st_arr[$parent_category];
  1597. $processedChildCat = array_map(function ($v) use ($websiteInfoIndexed) {
  1598. // 从 $websiteInfoIndexed 中获取对应的数据
  1599. $info = $websiteInfoIndexed[$v];
  1600. // 返回一个包含所需信息的数组
  1601. return [
  1602. 'alias' => $info->alias,
  1603. 'category_id' => $info->category_id,
  1604. 'aLIas_pinyin' => $info->aLIas_pinyin,
  1605. 'pid' => $info->pid,
  1606. 'type' => $info->type,
  1607. 'cat_arr_id' => $info->category_arr_id ?? ['出错'],
  1608. 'pinyin' => $info->pinyin,
  1609. ];
  1610. }, $all_childcat);
  1611. if ($article_imgnum != 0) {
  1612. $img_article = Article::where('catid', $child_category)
  1613. ->where('status', 1)
  1614. ->where('imgurl', '!=', '')
  1615. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1616. $query->from('article_ignore')
  1617. ->where('website_id', $wetbsite_id);
  1618. }, 'article_ignore', function ($join) {
  1619. $join->on('article_ignore.article_id', '=', 'article.id');
  1620. })
  1621. ->where(function ($query) use ($wetbsite_id) {
  1622. $query->whereNull('article_ignore.article_id')
  1623. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1624. })
  1625. ->select('id', 'title', 'imgurl', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1626. ->orderBy('updated_at', 'desc')
  1627. ->limit($article_imgnum)
  1628. ->get()->all();
  1629. foreach ($img_article as $k => $v) {
  1630. // var_dump($v);
  1631. // var_dump($k);
  1632. $img_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1633. $img_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1634. }
  1635. } else {
  1636. $img_article = [];
  1637. }
  1638. if ($article_textnum != 0) {
  1639. $text_article = Article::where('catid', $child_category)
  1640. ->where('status', 1)
  1641. ->leftJoinSub(function ($query) use ($wetbsite_id) {
  1642. $query->from('article_ignore')
  1643. ->where('website_id', $wetbsite_id);
  1644. }, 'article_ignore', function ($join) {
  1645. $join->on('article_ignore.article_id', '=', 'article.id');
  1646. })
  1647. ->where(function ($query) use ($wetbsite_id) {
  1648. $query->whereNull('article_ignore.article_id')
  1649. ->orWhere('article_ignore.website_id', '!=', $wetbsite_id);
  1650. })
  1651. ->select('id', 'title', 'author', 'updated_at', 'introduce', 'islink', 'linkurl', 'copyfrom', 'cat_arr_id', 'catid')
  1652. ->orderBy('updated_at', 'desc')
  1653. ->limit($article_textnum)
  1654. ->get()->all();
  1655. foreach ($text_article as $k => $v) {
  1656. // var_dump($v);
  1657. // var_dump($k);
  1658. $text_article[$k]->category_name = $catiall[$v->catid]['alias'];
  1659. // $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1660. $text_article[$k]->pinyin = $catiall[$v->catid]['pinyin'];
  1661. }
  1662. } else {
  1663. $text_article = [];
  1664. }
  1665. $catiall[$child_category]['all_childcat'] = $processedChildCat;
  1666. $catiall[$child_category]['imgnum'] = $img_article;
  1667. $catiall[$child_category]['textnum'] = $text_article;
  1668. $child[$key] = $catiall[$child_category];
  1669. // var_dump($pids);
  1670. } else {
  1671. $child[$key] = '';
  1672. }
  1673. }
  1674. }
  1675. foreach ($parent as $key => $value) {
  1676. $result[$key] = $value;
  1677. if (!empty($child[$key])) {
  1678. // var_dump($child[$key]);
  1679. $result[$key]['child'] = $child[$key];
  1680. // $value[$key]['child'] = $child[$key];
  1681. } else {
  1682. $result[$key]['child'] = [
  1683. "alias" => null,
  1684. "category_id" => null,
  1685. "type" => null,
  1686. "pinyin" => null,
  1687. "all_childcat" => [],
  1688. "imgnum" => [],
  1689. "textnum" => []
  1690. ];
  1691. }
  1692. }
  1693. return Result::success($result);
  1694. }
  1695. /**
  1696. * 辅助方法:获取文章列表
  1697. */
  1698. private function fetchArticles($catId, $website, $limit, $isImageArticle = false)
  1699. {
  1700. sleep(1);
  1701. $query = Article::where('article.status', 1)
  1702. // 使用更高效的查询方式,避免使用 JSON_CONTAINS 函数,如果可能的话,将 cat_arr_id 拆分为单独的字段
  1703. ->whereRaw("(FIND_IN_SET('$catId', REPLACE(REPLACE(cat_arr_id, '[', ''), ']', '')))")
  1704. ->where(function ($query) use ($website) {
  1705. $query->whereRaw("(JSON_CONTAINS(ignore_ids, '" . intval($website['website_id']) . "') = 0 OR ignore_ids IS NULL)");
  1706. })
  1707. ->leftJoin('website_category', function ($join) use ($website) {
  1708. $join->on('article.catid', '=', 'website_category.category_id')
  1709. ->where('website_category.website_id', '=', $website['website_id']);
  1710. })
  1711. ->select(
  1712. 'article.id',
  1713. 'article.title',
  1714. 'article.imgurl',
  1715. 'article.author',
  1716. 'article.updated_at',
  1717. 'article.introduce',
  1718. 'article.islink',
  1719. 'article.linkurl',
  1720. 'article.copyfrom',
  1721. 'article.cat_arr_id',
  1722. 'article.catid',
  1723. 'website_category.alias as category_name'
  1724. )
  1725. ->orderBy('updated_at', 'desc')
  1726. ->limit($limit);
  1727. // 如果是图片文章,添加图片URL条件
  1728. if ($isImageArticle) {
  1729. $query->where('imgurl', '!=', '');
  1730. } else {
  1731. // 文字文章不需要imgurl字段
  1732. $query->addSelect('article.introduce');
  1733. }
  1734. $articles = $query->get();
  1735. return !empty($articles) ? $this->processArticles($articles, $website) : [];
  1736. }
  1737. /**
  1738. * 乡村网-获取特殊新闻模块
  1739. * @param array $data
  1740. * @return array
  1741. */
  1742. public function getWebsiteArticles(array $data): array
  1743. {
  1744. $website_id = $data['website_id'];
  1745. $catids = json_decode($data['id'], true);
  1746. $parent_category = array_column($catids, 'parent');
  1747. if (!empty($parent_category) && is_array($parent_category)) {
  1748. $categorys = $this->processArticlePro($website_id);
  1749. $catiall = $categorys['catiall'];
  1750. $cat_1st_arr = $categorys['cat_1st_arr'];
  1751. // return Result::success($categorys);
  1752. foreach ($parent_category as $key => $value) {
  1753. $arr = array_map('intval', explode(',', $value));
  1754. $parent_category = $arr[0] ?? 0;
  1755. $article_imgnum = $arr[1] ?? 0;
  1756. $article_textnum = $arr[2] ?? 0;
  1757. if ($parent_category != 0) {
  1758. $category_arr = array_merge([$parent_category], $cat_1st_arr[$parent_category] ?? [0]);
  1759. // return Result::success($category_arr);
  1760. if ($article_imgnum != 0) {
  1761. $img_article = Article::whereIn('catid', $category_arr)
  1762. ->where('status', 1)
  1763. ->where('imgurl', '!=', '')
  1764. ->leftJoinSub(function ($query) use ($website_id) {
  1765. $query->from('article_ignore')
  1766. ->where('website_id', $website_id);
  1767. }, 'article_ignore', function ($join) {
  1768. $join->on('article_ignore.article_id', '=', 'article.id');
  1769. })
  1770. ->where(function ($query) use ($website_id) {
  1771. $query->whereNull('article_ignore.article_id')
  1772. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1773. })
  1774. ->select(
  1775. 'id',
  1776. 'title',
  1777. 'imgurl',
  1778. 'author',
  1779. 'updated_at',
  1780. 'introduce',
  1781. 'islink',
  1782. 'linkurl',
  1783. 'copyfrom',
  1784. 'cat_arr_id',
  1785. 'catid as category_id'
  1786. )
  1787. ->orderBy('updated_at', 'desc')
  1788. ->limit($article_imgnum)
  1789. ->get()->all();
  1790. foreach ($img_article as $k => $v) {
  1791. $img_article[$k]->alias = $catiall[$v->category_id]['alias'];
  1792. // return Result::success($v);
  1793. $img_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  1794. }
  1795. } else {
  1796. $img_article = [];
  1797. }
  1798. if ($article_textnum != 0) {
  1799. $text_article = Article::whereIn('catid', $category_arr)
  1800. ->where('status', 1)
  1801. ->leftJoinSub(function ($query) use ($website_id) {
  1802. $query->from('article_ignore')
  1803. ->where('website_id', $website_id);
  1804. }, 'article_ignore', function ($join) {
  1805. $join->on('article_ignore.article_id', '=', 'article.id');
  1806. })
  1807. ->where(function ($query) use ($website_id) {
  1808. $query->whereNull('article_ignore.article_id')
  1809. ->orWhere('article_ignore.website_id', '!=', $website_id);
  1810. })
  1811. ->select(
  1812. 'id',
  1813. 'title',
  1814. 'author',
  1815. 'updated_at',
  1816. 'introduce',
  1817. 'islink',
  1818. 'linkurl',
  1819. 'copyfrom',
  1820. 'cat_arr_id',
  1821. 'catid as category_id'
  1822. )
  1823. ->orderBy('updated_at', 'desc')
  1824. ->limit($article_textnum)
  1825. ->get()->all();
  1826. foreach ($text_article as $k => $v) {
  1827. $text_article[$k]->alias = $catiall[$v->category_id]['alias'];
  1828. $text_article[$k]->aLIas_pinyin = $catiall[$v->category_id]['pinyin'];
  1829. // $text_article[$k]->alias = $catiall[$v->catid]['alias'];
  1830. }
  1831. } else {
  1832. $text_article = [];
  1833. }
  1834. $catiall[$parent_category]['imgnum'] = $img_article ?? [];
  1835. $catiall[$parent_category]['textnum'] = $text_article ?? [];
  1836. $parent[$key] = $catiall[$parent_category];
  1837. } else {
  1838. $parent[$key] = [];
  1839. }
  1840. }
  1841. }
  1842. return Result::success($parent);
  1843. }
  1844. // 封装处理商品的路由问题
  1845. function processGoods($goods, $data)
  1846. {
  1847. return $goods->map(function ($good) use ($data) {
  1848. $catid = $good->catid ?? 0;
  1849. // $pinyin = '';
  1850. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  1851. if (!empty($category->pid) && $category->pid != 0) {
  1852. $level = json_decode($category->category_arr_id, true);
  1853. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  1854. ->whereIn('category_id', $level)
  1855. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  1856. ->get(['aLIas_pinyin'])
  1857. ->pluck('aLIas_pinyin')
  1858. ->implode('/');
  1859. } else {
  1860. $pinyin = $category->aLIas_pinyin ?? '';
  1861. }
  1862. if (isset($good->city_id) && !empty($good->city_id)) {
  1863. $city = District::where('id', $good->city_id)->first(['name']);
  1864. $good->city_name = $city->name ?? '';
  1865. }
  1866. // 解析imgurl JSON并取第一条数据
  1867. $imgUrls = json_decode($good->imgurl, true);
  1868. $good->imgurl = !empty($imgUrls) ? $imgUrls[0] : null;
  1869. $good->pinyin = $pinyin;
  1870. return $good;
  1871. });
  1872. }
  1873. /**
  1874. * 获取商城首页-根据栏目id
  1875. * @param array $data
  1876. * @return array
  1877. * */
  1878. function getWebsiteCatidshop(array $data): array
  1879. {
  1880. $input['catid'] = $data['catid'];
  1881. $input['website_id'] = $data['website_id'];
  1882. $data = json_decode($input['catid'] ?? '', true) ?? [];
  1883. $result = array_map(function ($item) use ($input) {
  1884. if (isset($item['catid']) && $item['catid'] != 'undefined' && $item['catid'] != "") {
  1885. list($catid, $goodStart, $goodNum) = explode(',', $item['catid']);
  1886. $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $input['website_id'])->first(['type']);
  1887. // 类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘
  1888. if (empty($category) || $category->type != 2) {
  1889. return Result::error("暂无此栏目", 0);
  1890. } else {
  1891. $website['website_id'] = $input['website_id'];
  1892. $goods = Good::where('good.status', 2)
  1893. ->where('good.website_id', $website['website_id'])
  1894. ->whereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($catid) . "') = 1")
  1895. ->select(
  1896. 'good.id',
  1897. 'good.name',
  1898. 'good.imgurl',
  1899. 'good.description',
  1900. 'good.updated_at',
  1901. 'good.catid',
  1902. 'good.type_id',
  1903. 'good.price',
  1904. 'good.com',
  1905. 'good.level',
  1906. 'good.unit'
  1907. )
  1908. ->orderBy('updated_at', 'desc')
  1909. ->offset($goodStart)
  1910. ->limit($goodNum);
  1911. $all_goods = $goods->get();
  1912. $all_goods = $this->processGoods($all_goods, $website);
  1913. }
  1914. return $all_goods ?? [];
  1915. }
  1916. }, $data);
  1917. return Result::success($result);
  1918. }
  1919. /**
  1920. * 获取商品模块
  1921. * @param array $data
  1922. * @return array
  1923. * */
  1924. public function getWebsiteshop(array $data): array
  1925. {
  1926. $input['id'] = $data['id'];
  1927. $input['website_id'] = $data['website_id'];
  1928. $catid = $data['catid'];
  1929. $data = json_decode($input['id'] ?? '', true) ?? [];
  1930. $result['goods'] = array_map(function ($item) use ($input) {
  1931. // 检查parent元素是否存在且不是undefined
  1932. if (isset($item['level']) && $item['level'] != 'undefined' && $item['level'] != "") {
  1933. list($Levelid, $goodStart, $goodNum) = explode(',', $item['level']);
  1934. $website = $input['website_id'];
  1935. $query = Good::where('good.status', 2)
  1936. ->where('good.website_id', $website);
  1937. switch ($Levelid) {
  1938. case 1:
  1939. case 2:
  1940. case 3:
  1941. $goods = $query->where(function ($q) use ($Levelid) {
  1942. $q->whereRaw("JSON_CONTAINS(good.level, '" . intval($Levelid) . "') = 1")
  1943. ->orWhereRaw("JSON_CONTAINS(good.level, '\"" . intval($Levelid) . "\"') = 1");
  1944. });
  1945. break;
  1946. case 4:
  1947. $goods = $query;
  1948. break;
  1949. case 5:
  1950. $goods = $query->where('type_id', 1);
  1951. break;
  1952. case 6:
  1953. $goods = $query->where('type_id', 2);
  1954. break;
  1955. default:
  1956. return [];
  1957. }
  1958. $all_goods = $goods
  1959. ->select(
  1960. 'good.id',
  1961. 'good.name',
  1962. 'good.imgurl',
  1963. 'good.description',
  1964. 'good.updated_at',
  1965. 'good.catid',
  1966. 'good.type_id',
  1967. 'good.price',
  1968. 'good.level',
  1969. 'good.website_id'
  1970. )
  1971. ->orderBy('updated_at', 'desc')
  1972. ->offset($goodStart)
  1973. ->limit($goodNum)
  1974. ->get();
  1975. $web['website_id'] = $website;
  1976. $all_goods = $this->processGoods($all_goods, $web);
  1977. }
  1978. return $all_goods;
  1979. }, $data);
  1980. $website = $input['website_id'];
  1981. $result['article'] = Article::where(function ($query) use ($website) {
  1982. $query->where(function ($subQuery) use ($website) {
  1983. $subQuery->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($website) . "') = 0");
  1984. })->orWhereNull("ignore_ids");
  1985. })
  1986. ->where('catid', $catid)
  1987. ->where('article.status', 1)
  1988. ->leftJoin('article_data', 'article_data.article_id', 'article.id')
  1989. ->select('article.id', 'article.title', 'article.updated_at', 'introduce', 'islink', 'linkurl', 'article_data.content')
  1990. ->orderBy('article.updated_at', 'desc')
  1991. ->first();
  1992. return Result::success($result);
  1993. }
  1994. /**
  1995. * 获取商品分类
  1996. * @param array $data
  1997. * @return array
  1998. * */
  1999. public function getWebsiteshopCat(array $data): array
  2000. {
  2001. $website = $data['website_id'];
  2002. $category = WebsiteCategory::where('website_id', $website)
  2003. ->whereRaw("JSON_CONTAINS(category_arr_id, '" . intval($data['id']) . "') = 1")
  2004. ->orWhereRaw("JSON_CONTAINS(category_arr_id, '\"" . intval($data['id']) . "\"') = 1")
  2005. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid', 'category_arr_id', 'sort')
  2006. ->orderBy('sort')
  2007. ->get();
  2008. $cat = $category->map(function ($item) use ($website) {
  2009. $cat_arr_id = json_decode($item->category_arr_id, true) ?? [];
  2010. $pid = $item->pid ?? 0;
  2011. if (!empty($cat_arr_id) && is_array($cat_arr_id) && $pid != 0) {
  2012. $pinyin = WebsiteCategory::whereIn('category_id', $cat_arr_id)
  2013. ->where('website_id', $website)
  2014. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr_id) . ')')
  2015. ->get(['aLIas_pinyin'])
  2016. ->pluck('aLIas_pinyin')
  2017. ->implode('/');
  2018. } else {
  2019. $pinyin = $item->aLIas_pinyin ?? '';
  2020. }
  2021. $item->pinyin = $pinyin;
  2022. });
  2023. if (empty($category)) {
  2024. return Result::error("栏目查询失败", 0);
  2025. }
  2026. $cat_tree = Result::buildMenuTree($category);
  2027. $web['website_id'] = $website;
  2028. $goods = Good::where('website_id', $website)
  2029. ->where('status', 2)
  2030. ->select('good.id as good_id', 'name', 'imgurl', 'description', 'updated_at', 'catid', 'type_id', 'website_id')
  2031. ->latest('updated_at')
  2032. ->offset(($data['page'] - 1) * $data['pageSize'])
  2033. ->limit($data['pageSize'])
  2034. ->get();
  2035. if (!empty($goods)) {
  2036. if ($goods->count() > 1 && !empty($goods)) {
  2037. $goods = $this->processGoods($goods, $web);
  2038. }
  2039. } else {
  2040. $goods = [];
  2041. }
  2042. $result = [
  2043. 'category' => $cat_tree,
  2044. 'goods' => $goods,
  2045. ];
  2046. // $resul['goods'] = $goods;
  2047. if (empty($result)) {
  2048. return Result::error("查询失败", 0);
  2049. }
  2050. return Result::success($result);
  2051. }
  2052. /*
  2053. * 获取商品列表
  2054. * @param array $data
  2055. * @return array
  2056. * */
  2057. public function getWebsiteshopList(array $data): array
  2058. {
  2059. // return Result::success($data);
  2060. $where = [
  2061. 'status' => 2,
  2062. 'website_id' => $data['website_id'],
  2063. ];
  2064. if ((empty($data['catid']) || !isset($data['catid'])) && (empty($data['keyword']) || !isset($data['keyword'])) && (empty($data['city_id']) || !isset($data['city_id']))) {
  2065. return Result::error("查询失败", 0);
  2066. }
  2067. if ((empty($data['catid']) || !isset($data['catid'])) && (!empty($data['city_id']) || isset($data['city_id']))) {
  2068. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('pid', $data['id'])->orderBy('sort')->first(['category_id']);
  2069. $data['catid'] = $category->category_id ?? 0;
  2070. }
  2071. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2072. array_push($where, ['name', 'like', '%' . $data['keyword'] . '%']);
  2073. }
  2074. if (isset($data['type_id']) && !empty($data['type_id'])) {
  2075. array_push($where, ['type_id', $data['type_id']]);
  2076. }
  2077. $query = Good::where($where)
  2078. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2079. $query->where(function ($q) use ($data) {
  2080. $q->WhereRaw("JSON_CONTAINS(good.cat_arr_id, '" . intval($data['catid']) . "') = 1")
  2081. ->orWhereRaw("JSON_CONTAINS(good.cat_arr_id, '\"" . intval($data['catid']) . "\"') = 1");
  2082. });
  2083. })
  2084. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2085. $query->where(function ($q) use ($data) {
  2086. $q->WhereRaw("JSON_CONTAINS(good.city_arr_id, '" . intval($data['city_id']) . "') = 1")
  2087. ->orWhereRaw("JSON_CONTAINS(good.city_arr_id, '\"" . intval($data['city_id']) . "\"') = 1");
  2088. });
  2089. })
  2090. ->select(
  2091. 'good.id',
  2092. 'good.name',
  2093. 'good.imgurl',
  2094. 'good.description',
  2095. 'good.updated_at',
  2096. 'good.com',
  2097. 'good.catid',
  2098. 'good.type_id',
  2099. 'good.website_id',
  2100. 'good.cat_arr_id',
  2101. 'good.created_at',
  2102. 'good.city_id'
  2103. )
  2104. ->latest('updated_at');
  2105. if (isset($data['ismix']) && $data['ismix'] == 1) {
  2106. $result['count'] = $query->clone()->count();
  2107. $result['goods'] = $this->processGoods(
  2108. $query->clone()
  2109. ->offset(($data['page'] - 1) * $data['pageSize'])
  2110. ->limit($data['pageSize'])
  2111. ->get(),
  2112. $data
  2113. );
  2114. } else {
  2115. $result['type1_count'] = $query->clone()->where('type_id', 1)->count();
  2116. // 获取 type_id 为 1 的数据
  2117. $result['type1'] = $this->processGoods(
  2118. $query->clone()
  2119. ->where('type_id', 1)
  2120. ->offset(($data['page'] - 1) * $data['pageSize'])
  2121. ->limit($data['pageSize'])
  2122. ->get(),
  2123. $data
  2124. );
  2125. $result['type2_count'] = $query->clone()->where('type_id', 2)->count();
  2126. // 获取 type_id 为 2 的数据
  2127. $result['type2'] = $this->processGoods(
  2128. $query->clone()
  2129. ->where('type_id', 2)
  2130. ->offset(($data['page'] - 1) * $data['pageSize'])
  2131. ->limit($data['pageSize'])
  2132. ->get(),
  2133. $data
  2134. );
  2135. }
  2136. if (empty($result)) {
  2137. return Result::error("查询失败", 0);
  2138. }
  2139. return Result::success($result);
  2140. }
  2141. /**
  2142. * 获取商品详情
  2143. * @param array $data
  2144. * @return array
  2145. * */
  2146. public function getWebsiteshopInfo(array $data): array
  2147. {
  2148. $where = [
  2149. 'good.status' => 2,
  2150. 'good.website_id' => $data['website_id'],
  2151. 'good.id' => $data['id'],
  2152. ];
  2153. $goods = Good::where($where)
  2154. ->where('good.id', $data['id'])
  2155. ->leftJoin('website_category', 'website_category.category_id', 'good.catid')
  2156. ->select('good.*', 'website_category.alias', 'website_category.category_id')
  2157. ->first();
  2158. if (empty($goods)) {
  2159. return Result::error("查询失败", 0);
  2160. }
  2161. $goods->imgurl = json_decode($goods->imgurl, true);
  2162. return Result::success($goods);
  2163. }
  2164. /**
  2165. * plus pro 处理文章路由问题
  2166. */
  2167. function processArticlePro($website_id)
  2168. {
  2169. $categorys = WebsiteCategory::where('website_id', $website_id)->get()->all();
  2170. $websiteInfoIndexed = array_column($categorys, null, 'category_id');
  2171. // 取出category_id 对应的aLIas_pinyin
  2172. $categoryIds = array_column($categorys, 'category_id');
  2173. $categoryPIds = array_column($categorys, 'pid');
  2174. $aliasPinyins = array_column($categorys, 'aLIas_pinyin');
  2175. $cat_arr = array_combine($categoryIds, $aliasPinyins);
  2176. // return Result::success($categorys);
  2177. $catiall = [];
  2178. //一级所有子级的记录
  2179. $cat_1st_arr = [];
  2180. foreach ($categorys as $key => $value) {
  2181. $category_arr_id = json_decode($value->category_arr_id);
  2182. $pinyin_str = '';
  2183. // 算出一级 并且算出子级
  2184. if ($value->pid != 0) {
  2185. $cat_1st_arr[$value->pid][] = $value->category_id;
  2186. }
  2187. foreach ($category_arr_id as $k => $v) {
  2188. $pinyin_str .= $cat_arr[$v] . '/';
  2189. }
  2190. $pinyin_str = rtrim($pinyin_str, '/');
  2191. $catiall[$value->category_id]['alias'] = $value->alias;
  2192. $catiall[$value->category_id]['category_id'] = $value->category_id;
  2193. $catiall[$value->category_id]['type'] = $value->type;
  2194. $catiall[$value->category_id]['pinyin'] = $pinyin_str;
  2195. $websiteInfoIndexed[$value->category_id]->pinyin = $pinyin_str;
  2196. }
  2197. return [
  2198. 'cat_1st_arr' => $cat_1st_arr,
  2199. 'catiall' => $catiall,
  2200. 'websiteInfoIndexed' => $websiteInfoIndexed,
  2201. 'categoryIds' => $categoryIds,
  2202. ];
  2203. }
  2204. /**
  2205. * 封装处理文章的路由问题
  2206. * */
  2207. function processArticles($articles, $data)
  2208. {
  2209. // 检查 $articles 是否为数组或可迭代对象
  2210. if (is_array($articles) || is_iterable($articles) && !empty($articles)) {
  2211. return $articles->map(function ($article) use ($data) {
  2212. if (isset($article->cat_arr_id) && !empty($article->cat_arr_id)) {
  2213. $catid = $article->cat_arr_id ?? '';
  2214. }
  2215. if (isset($article->category_arr_id) && !empty($article->category_arr_id)) {
  2216. $catid = $article->category_arr_id ?? '';
  2217. }
  2218. // $catid = $article->cat_arr_id || $article->category_arr_id ?? '';
  2219. $level = json_decode($catid, true);
  2220. if (!is_array($level)) {
  2221. return $article;
  2222. } else {
  2223. $level = array_map('intval', $level);
  2224. }
  2225. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2226. ->where($data)
  2227. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2228. ->pluck('aLIas_pinyin')
  2229. ->implode('/');
  2230. $article->pinyin = $pinyin ?? '';
  2231. return $article;
  2232. });
  2233. } else {
  2234. // 若 $articles 不是数组或可迭代对象,直接处理单条数据
  2235. $catid = $articles->cat_arr_id ?? '';
  2236. $level = json_decode($catid, true);
  2237. if (!is_array($level)) {
  2238. return $articles;
  2239. } else {
  2240. $level = array_map('intval', $level);
  2241. }
  2242. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2243. ->where($data)
  2244. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2245. ->pluck('aLIas_pinyin')
  2246. ->implode('/');
  2247. $articles->pinyin = $pinyin ?? '';
  2248. return $articles;
  2249. }
  2250. }
  2251. // 封装处理由问题
  2252. function processJob($job, $data)
  2253. {
  2254. return $job->map(function ($job) use ($data) {
  2255. $category = $job->cat_arr_id ?? '';
  2256. $cityid = $job->city_arr_id ?? '';
  2257. $city = json_decode($cityid, true);
  2258. $pinyin = '';
  2259. $level = json_decode($category, true);
  2260. // 路由
  2261. if (!empty($level) && is_array($level)) {
  2262. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2263. ->where('website_id', $data['website_id']) // 添加网站ID条件
  2264. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2265. ->get(['aLIas_pinyin'])
  2266. ->pluck('aLIas_pinyin')
  2267. ->implode('/');
  2268. if (empty($pinyin)) {
  2269. $pinyin = $pinyin->aLIas_pinyin ?? '';
  2270. }
  2271. $job->pinyin = $pinyin;
  2272. }
  2273. // 取职位-城市 市??省
  2274. if (!empty($city) && is_array($city)) {
  2275. if (isset($city[1]) && !empty($city[1])) {
  2276. $city = District::where('id', $city[1])->first(['name']);
  2277. $job->city_name = $city->name ?? '';
  2278. } else if (isset($city[0]) && !empty($city[0])) {
  2279. $city = District::where('id', $city[0])->first(['name']);
  2280. $job->city_name = $city->name ?? '';
  2281. } else {
  2282. $job->city_name = '全国';
  2283. }
  2284. }
  2285. // 获取简历最后一级地区
  2286. if (isset($job->city_id) && !empty($job->city_id)) {
  2287. $city = District::where('id', $job->city_id)->first(['name']);
  2288. $job->hunt_cityname = $city->name ?? '';
  2289. }
  2290. // 组合详细地址
  2291. if (isset($job->address_arr_id) && !empty($job->address_arr_id)) {
  2292. $address_id = json_decode($job->address_arr_id, true) ?? [];
  2293. if (is_array($address_id) && !empty($address_id)) {
  2294. $address = District::whereIn('id', $address_id)
  2295. ->orderBy('level', 'asc')
  2296. ->get(['name'])
  2297. ->pluck('name')
  2298. ->implode('');
  2299. // $job->address_name = $address ?? '';
  2300. $job->address_name = ($address ?? '') . ($job->address ?? '');
  2301. }
  2302. }
  2303. // 取行业
  2304. if (!empty($job->hy_id) || !empty($job->industry) || !empty($job->company_hy_id || !empty($job->job_industry))) {
  2305. $hy_name = JobIndustry::when($job, function ($query) use ($job) {
  2306. if (!empty($job->industry)) {
  2307. $query->where('hyid', $job->industry);
  2308. } else if (!empty($job->hy_id)) {
  2309. $query->where('hyid', $job->hy_id);
  2310. } else if (!empty($job->company_hy_id)) {
  2311. $query->where('hyid', $job->company_hy_id);
  2312. } else {
  2313. $query->where('hyid', $job->job_industry);
  2314. }
  2315. })->first(['hyname']);
  2316. $job->hy_name = $hy_name->hyname ?? '';
  2317. }
  2318. // 取职位类别
  2319. if ((isset($job->zw_id) && !empty($job->zw_id)) || (isset($job->job) && !empty($job->job)) || (isset($job->job_typename) && !empty($job->job_typename))) {
  2320. $zwid = $job->job ?? $job->zw_id ?? $job->job_typename;
  2321. $zw_name = JobPosition::where('zwid', $zwid)->first(['zwname']);
  2322. $job->zw_name = $zw_name->zwname ?? '';
  2323. }
  2324. // 取具体职位
  2325. 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))) {
  2326. $jtzwid = $job->job_name_get ?? $job->jtzw_id ?? $job->job_name;
  2327. $jtzw_name = JobPosition::where('zwid', $jtzwid)->first(['zwname']);
  2328. $job->jtzw_name = $jtzw_name->zwname ?? '';
  2329. }
  2330. // 取工作经验
  2331. if (isset($job->experience) && !empty($job->experience)) {
  2332. $experience = JobEnum::where('egroup', 'years')->where('evalue', $job->experience)->first(['ename']);
  2333. $job->experience_name = $experience->ename ?? '';
  2334. }
  2335. // 取学历
  2336. if (isset($job->educational) && !empty($job->educational) || isset($job->school_education) && !empty($job->school_education)) {
  2337. $education = $job->educational ?? $job->school_education;
  2338. $education = JobEnum::where('egroup', 'education')->where('evalue', $education)->first(['ename']);
  2339. $job->education_name = $education->ename ?? '';
  2340. }
  2341. // 语言
  2342. if (isset($job->language) && !empty($job->language)) {
  2343. $language = JobEnum::where('egroup', 'language')->where('evalue', $job->language)->first(['ename']);
  2344. $job->language_name = $language->ename ?? '';
  2345. }
  2346. // 薪资
  2347. if (isset($job->salary) && !empty($job->salary)) {
  2348. $salary = JobEnum::where('egroup', 'income')->where('evalue', $job->salary)->first(['ename']);
  2349. $job->salary_name = $salary->ename ?? '';
  2350. }
  2351. // 职位性质
  2352. if (isset($job->nature_id) && !empty($job->nature_id)) {
  2353. $job_nature = JobEnum::where('egroup', 'nature')->where('evalue', $job->nature_id)->first(['ename']);
  2354. $job->job_nature_name = $job_nature->ename ?? '';
  2355. }
  2356. // 公司规模
  2357. if (isset($job->company_size) && !empty($job->company_size)) {
  2358. $company_size = JobEnum::where('egroup', 'cosize')->where('evalue', $job->company_size)->first(['ename']);
  2359. $job->company_size_name = $company_size->ename ?? '';
  2360. }
  2361. // 公司性质
  2362. if (isset($job->company_nature) && !empty($job->company_nature)) {
  2363. $company_nature = JobNature::where('id', $job->company_nature)->first(['nature_name']);
  2364. $job->company_nature_name = $company_nature->nature_name ?? '';
  2365. }
  2366. // $job->pinyin = $pinyin;
  2367. return $job;
  2368. });
  2369. }
  2370. /**
  2371. * 获取书籍模块
  2372. * @param array $data
  2373. * @return array
  2374. * */
  2375. public function getWebsiteBook(array $data): array
  2376. {
  2377. $input['id'] = $data['id'];
  2378. $input['website_id'] = $data['website_id'];
  2379. // 将 JSON 字符串转换为 PHP 数组
  2380. $data = json_decode($input['id'], true);
  2381. // 使用 array_map 处理每个元素
  2382. $result = array_map(function ($item) use ($input) {
  2383. // 检查parent元素是否存在且不是undefined
  2384. if (isset($item['parent']) && $item['parent'] != 'undefined' && $item['parent'] != "") {
  2385. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2386. $website = [
  2387. 'website_id' => $input['website_id'],
  2388. ];
  2389. // 查询栏目名称
  2390. $category = WebsiteCategory::where('category_id', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2391. if (empty($category)) {
  2392. $parent_alias = '';
  2393. $parent_pinyin = null;
  2394. $imgBooks = [];
  2395. $textBooks = [];
  2396. } else {
  2397. $parent_alias = $category->alias ?? '';
  2398. $parent_pinyin = $category->aLIas_pinyin ? $category->aLIas_pinyin : null;
  2399. // 查找子分类ID数组
  2400. $childCategoryIds = WebsiteCategory::where('pid', $parentCatId)->where($website)->pluck('category_id')->toArray();
  2401. array_push($childCategoryIds, $parentCatId);
  2402. $childCategoryIds = json_encode(array_values(array_unique($childCategoryIds)));
  2403. if ($parentImgNum != 0) {
  2404. // 查询图片新闻
  2405. $imgBooks = Book::where(function ($query) use ($parentCatId) {
  2406. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2407. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2408. })
  2409. ->where('book.status', 2)
  2410. ->where('book.img_url', '!=', '')
  2411. ->leftJoin('website_category', function ($join) use ($website) {
  2412. $join->on('book.cat_id', '=', 'website_category.category_id')
  2413. ->where('website_category.website_id', '=', $website['website_id']);
  2414. })
  2415. ->select(
  2416. 'book.id',
  2417. 'book.title',
  2418. 'book.img_url',
  2419. 'book.price',
  2420. 'book.market_price',
  2421. 'book.description',
  2422. 'book.cat_id',
  2423. 'book.description',
  2424. 'book.updated_at',
  2425. 'website_category.alias as category_name',
  2426. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2427. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2428. )
  2429. ->orderBy('updated_at', 'desc')
  2430. ->limit($parentImgNum)
  2431. ->get()->all();
  2432. // 查询文字新闻
  2433. }
  2434. if ($parentTextNum != 0) {
  2435. $textBooks = [];
  2436. $textBooks = Book::where(function ($query) use ($parentCatId) {
  2437. $query->whereRaw("JSON_CONTAINS(cat_arr_id, '\"$parentCatId\"')")
  2438. ->orWhereRaw("JSON_CONTAINS(cat_arr_id, '$parentCatId')");
  2439. })
  2440. ->where('book.status', 2)
  2441. ->leftJoin('website_category', function ($join) use ($website) {
  2442. $join->on('book.cat_id', '=', 'website_category.category_id')
  2443. ->where('website_category.website_id', '=', $website['website_id']);
  2444. })
  2445. ->select(
  2446. 'book.id',
  2447. 'book.title',
  2448. 'book.img_url',
  2449. 'book.price',
  2450. 'book.market_price',
  2451. 'book.description',
  2452. 'book.cat_id',
  2453. 'book.description',
  2454. 'book.updated_at',
  2455. 'website_category.alias as category_name',
  2456. DB::raw("CASE WHEN book.cat_id = $parentCatId THEN '$parent_pinyin'
  2457. ELSE CONCAT('$parent_pinyin', '/', website_category.aLIas_pinyin) END as pinyin")
  2458. )
  2459. ->orderBy('updated_at', 'desc')
  2460. ->limit($parentTextNum)
  2461. ->get()->all();
  2462. }
  2463. }
  2464. }
  2465. $resultItem = [
  2466. 'alias' => $parent_alias ?? '',
  2467. 'category_id' => $parentCatId ?? 0,
  2468. 'pinyin' => $parent_pinyin ?? null,
  2469. 'imgnum' => $imgBooks ?? [],
  2470. 'textnum' => $textBooks ?? [],
  2471. ];
  2472. if (isset($item['child']) && $item['child'] != 'undefined' && $item['child'] != "") {
  2473. $parent_pinyin_str = is_string($parent_pinyin) ? $parent_pinyin . '/' : '';
  2474. $childCategory = WebsiteCategory::where('pid', $parentCatId)->where($website)
  2475. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2476. ->get()->all();
  2477. if (!empty($childCategory)) {
  2478. list($childCatId, $childImgNum, $childTextNum) = explode(',', $item['child']);
  2479. // 查询子栏目名称
  2480. $childCategoryInfo = WebsiteCategory::where('category_id', $childCatId)->where($website)
  2481. ->selectRaw("category_id, alias, CONCAT( ?, aLIas_pinyin) as aLIas_pinyin", [$parent_pinyin_str])
  2482. ->first();
  2483. if (empty($childCategoryInfo) || ($childImgNum == 0 && $childTextNum == 0)) {
  2484. $childImgArticles = [];
  2485. $childTextArticles = [];
  2486. $resultItem['child'] = [];
  2487. } else {
  2488. $child_pinyin = $childCategoryInfo->aLIas_pinyin ? $childCategoryInfo->aLIas_pinyin : null;
  2489. // 查询子栏目图片新闻
  2490. $childImgArticles = Book::where('cat_id', $childCatId)
  2491. ->where('status', 2)
  2492. ->where('img_url', '!=', '')
  2493. ->leftJoin('website_category', function ($join) use ($website) {
  2494. $join->on('book.cat_id', '=', 'website_category.category_id')
  2495. ->where('website_category.website_id', '=', $website['website_id']);
  2496. })
  2497. ->select(
  2498. 'book.id',
  2499. 'book.title',
  2500. 'book.img_url',
  2501. 'book.price',
  2502. 'book.market_price',
  2503. 'book.description',
  2504. 'book.cat_id',
  2505. 'book.description',
  2506. 'book.updated_at',
  2507. DB::raw("'$child_pinyin' as pinyin")
  2508. )
  2509. ->orderBy('updated_at', 'desc')
  2510. ->limit($childImgNum)
  2511. ->get()->all();
  2512. // 查询子栏目文字新闻
  2513. $childTextArticles = Book::where('cat_id', $childCatId)
  2514. ->where('status', 2)
  2515. ->leftJoin('website_category', function ($join) use ($website) {
  2516. $join->on('book.cat_id', '=', 'website_category.category_id')
  2517. ->where('website_category.website_id', '=', $website['website_id']);
  2518. })
  2519. ->select(
  2520. 'book.id',
  2521. 'book.title',
  2522. 'book.img_url',
  2523. 'book.price',
  2524. 'book.market_price',
  2525. 'book.description',
  2526. 'book.cat_id',
  2527. 'book.description',
  2528. 'book.updated_at',
  2529. DB::raw("'$child_pinyin' as pinyin")
  2530. )
  2531. ->orderBy('updated_at', 'desc')
  2532. ->limit($childTextNum)
  2533. ->get()->all();
  2534. $resultItem['child'] = [
  2535. 'alias' => $childCategoryInfo ? $childCategoryInfo->alias : null,
  2536. 'category_id' => $childCatId,
  2537. 'pinyin' => $childCategoryInfo->aLIas_pinyin ?? '',
  2538. 'all_childcat' => $childCategory,
  2539. 'imgnum' => $childImgArticles,
  2540. 'textnum' => $childTextArticles,
  2541. ];
  2542. }
  2543. }
  2544. } else {
  2545. $resultItem['child'] = [];
  2546. }
  2547. return $resultItem;
  2548. }, $data);
  2549. return Result::success($result);
  2550. }
  2551. /**
  2552. * 获取书刊列表
  2553. * @param array $data
  2554. * @return array
  2555. * */
  2556. public function getWebsiteBookList(array $data): array
  2557. {
  2558. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2559. if (empty($web)) {
  2560. return Result::error("查询失败", 0);
  2561. }
  2562. $catid = $data['id'];
  2563. $category = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $catid)->orderBy('sort')->first(['pid', 'category_id', 'aLias_pinyin']);
  2564. $parent_categpory = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $category['pid'])->orderBy('sort')->first(['aLias_pinyin']);
  2565. $parent_pinyin = $parent_categpory ? $parent_categpory->aLias_pinyin ?? '' : '';
  2566. $category_pinyin = $category ? $category->aLias_pinyin : '';
  2567. $pinyin = $category_pinyin ? $parent_pinyin . '/' . $category_pinyin ?? '' : '';
  2568. $categorys = WebsiteCategory::where('website_id', $data['website_id'])
  2569. ->where('pid', $category['pid'])
  2570. ->select(
  2571. 'category_id',
  2572. 'alias',
  2573. 'aLIas_pinyin',
  2574. 'pid',
  2575. 'sort',
  2576. 'is_url',
  2577. 'web_url',
  2578. 'seo_title',
  2579. 'seo_keywords',
  2580. 'seo_description',
  2581. DB::raw("CONCAT('$parent_pinyin', '/', aLIas_pinyin) as pinyin")
  2582. )
  2583. ->orderBy('sort')
  2584. ->get()->all();
  2585. if (empty($category)) {
  2586. return Result::error("查询失败", 0);
  2587. }
  2588. $query = Book::where('book.status', 2)
  2589. ->where('book.website_id', $data['website_id'])
  2590. ->where('book.cat_id', $catid)
  2591. ->select(
  2592. 'book.id',
  2593. 'book.title',
  2594. 'book.img_url',
  2595. 'book.description',
  2596. 'book.updated_at',
  2597. 'book.cat_id',
  2598. DB::raw("'$pinyin' as pinyin")
  2599. )
  2600. ->orderBy('book.updated_at', 'desc');
  2601. $count = $query->count();
  2602. $query = clone $query;
  2603. $Book = $query
  2604. ->limit($data['pageSize'])
  2605. ->offset(($data['page'] - 1) * $data['pageSize'])
  2606. ->get()->all();
  2607. $result = [
  2608. 'category' => $categorys,
  2609. 'books' => $Book,
  2610. 'count' => $count,
  2611. ];
  2612. // if(empty($result)){
  2613. // return Result::error("查询失败", 0);
  2614. // }
  2615. return Result::success($result);
  2616. }
  2617. /**
  2618. * 获取书刊详情
  2619. * @param array $data
  2620. * @return array
  2621. * */
  2622. public function getWebsiteBookInfo(array $data): array
  2623. {
  2624. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2625. if (empty($web)) {
  2626. return Result::error("查询失败", 0);
  2627. }
  2628. $book = Book::where('status', 2)
  2629. ->where('website_id', $data['website_id'])
  2630. ->where('id', $data['id'])
  2631. ->select(
  2632. 'book.*',
  2633. )
  2634. ->orderBy('updated_at', 'desc')
  2635. ->first();
  2636. if (empty($book)) {
  2637. return Result::error("查询失败", 0);
  2638. }
  2639. // 先查询当前分类的 pid
  2640. $carpid = WebsiteCategory::where('website_id', $data['website_id'])
  2641. ->where('category_id', $book['cat_id'])
  2642. ->first(['pid', 'category_id']);
  2643. $query = WebsiteCategory::where('website_id', $data['website_id']);
  2644. if (!empty($carpid)) {
  2645. if ($carpid->pid != 0) {
  2646. $pid = $carpid['pid'];
  2647. // $parent_pinyin = '';
  2648. } else {
  2649. $pid = $carpid['category_id'];
  2650. // $parent_pinyin = $currentCategory->aLias_pinyin?? '';
  2651. }
  2652. }
  2653. $categorys = $query->where('pid', $pid)
  2654. ->select(
  2655. 'category_id',
  2656. 'alias',
  2657. 'aLIas_pinyin',
  2658. 'pid',
  2659. 'sort',
  2660. 'is_url',
  2661. 'web_url',
  2662. 'category_arr_id as cat_arr_id',
  2663. )
  2664. ->orderBy('sort')
  2665. ->get();
  2666. $category = $this->processArticle($categorys, $data);
  2667. $result = [
  2668. 'category' => $category,
  2669. 'books' => $book,
  2670. ];
  2671. return Result::success($result);
  2672. }
  2673. /**
  2674. * 尝试
  2675. * @param array $data
  2676. * @return array
  2677. * */
  2678. public function test(array $data): array
  2679. {
  2680. $input['id'] = $data['id'];
  2681. $input['website_id'] = $data['website_id'];
  2682. // 将 JSON 字符串转换为 PHP 数组
  2683. $data = json_decode($input['id'], true);
  2684. $result = [];
  2685. $article = $data;
  2686. $result = array_map(function ($item) use ($input) {
  2687. $website = [
  2688. 'website_id' => $input['website_id'],
  2689. ];
  2690. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['parent']);
  2691. $category = WebsiteCategory::where('pid', $parentCatId)->where($website)->first(['alias', 'category_id', 'aLIas_pinyin']);
  2692. $parent = [
  2693. 0 => $category['category_id'] ?? [],
  2694. 1 => $parentImgNum ?? [],
  2695. 2 => $parentTextNum ?? [],
  2696. ];
  2697. list($parentCatId, $parentImgNum, $parentTextNum) = explode(',', $item['child']);
  2698. $child = [];
  2699. $resultItem = [
  2700. // 'alias' => $parent_alias ?? '',
  2701. 'category_id' => $parentCatId ?? 0,
  2702. 'pinyin' => $parentImgNum ?? null,
  2703. 'imgnum' => $parentTextNum ?? [],
  2704. // 'textnum' => $textArticles ?? [],
  2705. ];
  2706. return $parent;
  2707. }, $data);
  2708. return Result::success($result);
  2709. // });
  2710. }
  2711. /**
  2712. * 封装处理文章的路由问题
  2713. * */
  2714. function processArticle($article, $data)
  2715. {
  2716. return $article->map(function ($article) use ($data) {
  2717. $catid = $article->cat_arr_id ?? '';
  2718. $level = json_decode($catid, true);
  2719. $pinyin = '';
  2720. // $category = WebsiteCategory::where('category_id', $catid)->where('website_id', $data['website_id'])->first();
  2721. if (!empty($level) && is_array($level)) {
  2722. $pinyin = WebsiteCategory::whereIn('category_id', $level)
  2723. ->where('website_id', $data['website_id'])
  2724. ->orderByRaw('FIELD(category_id, ' . implode(',', $level) . ')')
  2725. ->get(['aLIas_pinyin'])
  2726. ->pluck('aLIas_pinyin')
  2727. ->implode('/');
  2728. } else {
  2729. $pinyin = '';
  2730. }
  2731. $article->pinyin = $pinyin;
  2732. return $article;
  2733. });
  2734. }
  2735. /**
  2736. * c端-获取招工招聘下拉选框
  2737. * @param array $data
  2738. * @return array
  2739. * */
  2740. public function getWebsiteJobSelect(array $data): array
  2741. {
  2742. $web = Website::where('id', $data['website_id'])->first();
  2743. if (empty($web)) {
  2744. return Result::error("该网站不存在", 0);
  2745. }
  2746. $hy = JobIndustry::get()->all();
  2747. $zw = JobPosition::where('zwpid', 0)->get()->all();
  2748. $jtzw = JobPosition::where('zwpid', '!=', 0)->get()->all();
  2749. $result = [
  2750. 'hy' => $hy,
  2751. 'zw' => $zw,
  2752. 'jtzw' => $jtzw,
  2753. ];
  2754. if (empty($result)) {
  2755. return Result::error("查询失败", 0);
  2756. }
  2757. return Result::success($result);
  2758. }
  2759. /**
  2760. * c端-获取招工招聘
  2761. * @param array $data
  2762. * @return array
  2763. * */
  2764. public function getWebsiteJob(array $data): array
  2765. {
  2766. $web = Website::where('id', $data['website_id'])->first();
  2767. if (empty($web)) {
  2768. return Result::error("该网站不存在", 0);
  2769. }
  2770. $job_hunting = JobHunting::where('job_hunting.status', 2)
  2771. ->where('job_hunting.website_id', $data['website_id'])
  2772. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2773. $query->where(function ($q) use ($data) {
  2774. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2775. });
  2776. })
  2777. ->select(
  2778. 'job_hunting.id',
  2779. 'job_hunting.cat_arr_id',
  2780. 'job_hunting.job_name_get',
  2781. 'job_hunting.industry',
  2782. 'job_hunting.name',
  2783. 'job_hunting.sexy',
  2784. 'job_hunting.origin',
  2785. 'job_hunting.city_arr_id',
  2786. 'job_hunting.experience',
  2787. 'job_hunting.updated_at',
  2788. 'job_hunting.salary'
  2789. )
  2790. ->orderBy('updated_at', 'desc')
  2791. ->limit($data['job1_num'])
  2792. ->get();
  2793. $web['website_id'] = $data['website_id'];
  2794. if (empty($job_hunting)) {
  2795. $job_huntings = "未查询到相关简历信息";
  2796. } else {
  2797. $job_huntings = $this->processJob($job_hunting, $web);
  2798. }
  2799. // 0:待审核 1:已通过 2:已拒绝
  2800. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  2801. ->where('job_recruiting.website_id', $data['website_id'])
  2802. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2803. $query->where(function ($q) use ($data) {
  2804. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2805. });
  2806. })
  2807. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2808. ->select(
  2809. 'job_recruiting.id',
  2810. 'job_recruiting.cat_arr_id',
  2811. 'job_recruiting.title',
  2812. 'job_recruiting.jtzw_id',
  2813. 'job_recruiting.hy_id',
  2814. 'job_recruiting.city_arr_id',
  2815. 'job_recruiting.due_data',
  2816. 'job_recruiting.updated_at',
  2817. 'job_recruiting.experience',
  2818. 'job_recruiting.educational',
  2819. 'job_recruiting.salary',
  2820. 'job_recruiting.zw_id',
  2821. 'job_company.business_name'
  2822. )
  2823. ->orderBy('updated_at', 'desc')
  2824. ->limit($data['job2_num'])
  2825. ->get();
  2826. if (empty($job_recruiting->toArray())) {
  2827. $job_recruitings = "未查询到相关职位信息";
  2828. } else {
  2829. $job_recruitings = $this->processJob($job_recruiting, $web);
  2830. }
  2831. $result = [
  2832. 'job_hunting' => $job_huntings,
  2833. 'job_recuiting' => $job_recruitings,
  2834. ];
  2835. return Result::success($result);
  2836. }
  2837. /**
  2838. * c端-获取招工招聘列表
  2839. * @param array $data
  2840. * @return array
  2841. * */
  2842. public function getWebsiteJobList(array $data): array
  2843. {
  2844. $recruit_where = [];
  2845. $hunt_where = [];
  2846. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2847. if (empty($web)) {
  2848. return Result::error("此网站不存在", 0);
  2849. }
  2850. $website_id['website_id'] = $data['website_id'];
  2851. if ((isset($data['type']) && $data['type'] == 1) || !isset($data['type'])) {
  2852. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  2853. array_push($recruit_where, ['zw_id', $data['zw_id']]);
  2854. }
  2855. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  2856. array_push($recruit_where, ['jtzw_id', $data['jtzw_id']]);
  2857. }
  2858. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  2859. array_push($recruit_where, ['hy_id', $data['hy_id']]);
  2860. }
  2861. if (isset($data['keyword']) && !empty($data['keyword'])) {
  2862. array_push($recruit_where, ['title', 'like', '%' . $data['keyword'] . '%']);
  2863. }
  2864. $query = JobRecruiting::where('job_recruiting.status', 1)
  2865. ->where('job_recruiting.website_id', $data['website_id'])
  2866. ->where($recruit_where)
  2867. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2868. $query->where(function ($q) use ($data) {
  2869. $q->WhereRaw("JSON_CONTAINS(job_recruiting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2870. });
  2871. })
  2872. ->when(isset($data['catid']) && !empty($data['catid']), function ($query) use ($data) {
  2873. $query->where(function ($q) use ($data) {
  2874. $q->WhereRaw("JSON_CONTAINS(job_recruiting.cat_arr_id, '" . intval($data['catid']) . "') = 1");
  2875. });
  2876. })
  2877. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  2878. ->select(
  2879. 'job_recruiting.id',
  2880. 'job_recruiting.hy_id',
  2881. 'job_recruiting.title',
  2882. 'job_recruiting.zw_id',
  2883. 'job_recruiting.educational',
  2884. 'job_recruiting.jtzw_id',
  2885. 'job_recruiting.city_arr_id',
  2886. 'job_recruiting.due_data',
  2887. 'job_recruiting.experience',
  2888. 'job_recruiting.cat_arr_id',
  2889. 'job_recruiting.updated_at',
  2890. 'job_company.business_name'
  2891. )
  2892. ->orderBy('updated_at', 'desc');
  2893. $recruit_count = $query->count();
  2894. $query = clone $query;
  2895. $JobRecruiting = $query
  2896. ->offset(($data['page'] - 1) * $data['pageSize'])
  2897. ->limit($data['pageSize'])
  2898. ->get();
  2899. if (empty($JobRecruiting)) {
  2900. $JobRecruiting = "暂无相关职位信息";
  2901. } else {
  2902. $JobRecruiting = $this->processJob($JobRecruiting, $website_id);
  2903. }
  2904. }
  2905. if ((isset($data['type']) && $data['type'] == 2) || !isset($data['type'])) {
  2906. if (isset($data['zw_id']) && !empty($data['zw_id'])) {
  2907. array_push($hunt_where, ['job', $data['zw_id']]);
  2908. }
  2909. if (isset($data['jtzw_id']) && !empty($data['jtzw_id'])) {
  2910. array_push($hunt_where, ['job_name_get', $data['jtzw_id']]);
  2911. }
  2912. if (isset($data['hy_id']) && !empty($data['hy_id'])) {
  2913. array_push($hunt_where, ['industry', $data['hy_id']]);
  2914. }
  2915. $query = JobHunting::where('status', 2)
  2916. ->where('job_hunting.website_id', $data['website_id'])
  2917. ->where($hunt_where)
  2918. ->when(isset($data['keyword']) && !empty($data['keyword']), function ($query) use ($data) {
  2919. $query->where('job_position.zwname', 'like', '%' . $data['keyword'] . '%');
  2920. })
  2921. ->when(isset($data['city_id']) && !empty($data['city_id']), function ($query) use ($data) {
  2922. $query->where(function ($q) use ($data) {
  2923. $q->WhereRaw("JSON_CONTAINS(job_hunting.city_arr_id, '" . intval($data['city_id']) . "') = 1");
  2924. });
  2925. })
  2926. ->when(isset($data['catid_id']) && !empty($data['catid_id']), function ($query) use ($data) {
  2927. $query->where(function ($q) use ($data) {
  2928. $q->WhereRaw("JSON_CONTAINS(job_hunting.cat_arr_id, '" . intval($data['catid_id']) . "') = 1");
  2929. });
  2930. })
  2931. ->select('id', 'sexy', 'experience', 'origin', 'industry', 'name', 'job', 'job_name_get', 'city_arr_id', 'cat_arr_id', 'created_at', 'updated_at')
  2932. ->orderBy('updated_at', 'desc');
  2933. $hunt_count = $query->count();
  2934. $query = clone $query;
  2935. $JobHunting = $query
  2936. ->offset(($data['page'] - 1) * $data['pageSize'])
  2937. ->limit($data['pageSize'])
  2938. ->get();
  2939. if (empty($JobHunting)) {
  2940. $JobRecruiting = "暂无相关简历信息";
  2941. } else {
  2942. $JobHunting = $this->processJob($JobHunting, $website_id);
  2943. }
  2944. }
  2945. $result = [
  2946. 'JobRecruiting' => $JobRecruiting ?? [],
  2947. 'recruit_count' => $recruit_count ?? 0,
  2948. 'JobHunting' => $JobHunting ?? [],
  2949. 'hunt_count' => $hunt_count ?? 0,
  2950. ];
  2951. return Result::success($result);
  2952. }
  2953. /**
  2954. * c端-获取招工招聘详情
  2955. * @param array $data
  2956. * @return array
  2957. * */
  2958. public function getWebsiteJobInfo(array $data): array
  2959. {
  2960. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  2961. if (empty($web)) {
  2962. return Result::error("该网站不存在", 0);
  2963. }
  2964. $webid = [
  2965. 'website_id' => $data['website_id'],
  2966. ];
  2967. // 职位相关信息
  2968. if ($data['type'] == 1) {
  2969. $query = JobRecruiting::where('status', 1)
  2970. ->where('website_id', $data['website_id'])
  2971. ->select('*');
  2972. $job = $query->where('job_recruiting.id', $data['id'])->get();
  2973. $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();
  2974. if (!empty($company)) {
  2975. $result['company'] = $this->processJob($company, $webid);
  2976. }
  2977. $other_job = JobRecruiting::where('status', 1)
  2978. ->where('website_id', $data['website_id'])
  2979. ->select('title', 'id', 'updated_at', 'cat_arr_id', 'user_id')
  2980. ->where('id', '!=', $data['id'])
  2981. ->where('user_id', '=', $job[0]['user_id'])
  2982. ->limit($data['pageSize'])
  2983. ->get();
  2984. if (!empty($other_job)) {
  2985. $result['other_job'] = $this->processJob($other_job, $webid);
  2986. }
  2987. } else {
  2988. // 简历相关信息
  2989. $job = JobHunting::where('job_hunting.status', 2)
  2990. ->where('job_hunting.website_id', $data['website_id'])
  2991. ->where('job_hunting.id', $data['id'])
  2992. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  2993. ->select('job_hunting.*', 'user_name')
  2994. ->get();
  2995. $resume = JobRemuse::where('hunt_id', $data['id'])->get();
  2996. if (!empty($resume->toArray())) {
  2997. $result['resume'] = 1;
  2998. } else {
  2999. $result['resume'] = 0;
  3000. }
  3001. }
  3002. if (empty($job->toArray())) {
  3003. return Result::error("id参数错误", 0);
  3004. }
  3005. if (!empty($job[0]['job_experience'])) {
  3006. $job_experience = json_decode($job[0]['job_experience'], true) ?? [];
  3007. if (!empty($job_experience)) {
  3008. // $hy = [];
  3009. foreach ($job_experience as $key => $value) {
  3010. // $id = $value['id'];
  3011. $hy[$key] = $value['job_industry'];
  3012. $zw_id[$key] = $value['job_typename'];
  3013. $jtzw_id[$key] = $value['job_name'];
  3014. }
  3015. $hy_table = JobIndustry::whereIn('hyid', $hy)->select('hyid', 'hyname')->get();
  3016. $zw_table = JobPosition::select('zwid', 'zwname')->get();
  3017. // 先将关联表转换为索引数组,提高查找效率
  3018. $hyLookup = [];
  3019. foreach ($hy_table as $item) {
  3020. $hyLookup[$item['hyid']] = $item['hyname'];
  3021. }
  3022. $zwLookup = [];
  3023. foreach ($zw_table as $item) {
  3024. $zwLookup[$item['zwid']] = $item['zwname'];
  3025. }
  3026. foreach ($job_experience as $key => &$value) {
  3027. // 处理行业名称
  3028. if (isset($hy[$key]) && isset($hyLookup[$hy[$key]])) {
  3029. $value['hy_name'] = $hyLookup[$hy[$key]];
  3030. }
  3031. // 处理职位名称
  3032. if (isset($zw_id[$key]) && isset($zwLookup[$zw_id[$key]])) {
  3033. $value['zw_name'] = $zwLookup[$zw_id[$key]];
  3034. }
  3035. // 处理具体职位名称
  3036. if (isset($jtzw_id[$key]) && isset($zwLookup[$jtzw_id[$key]])) {
  3037. $value['jtzw_name'] = $zwLookup[$jtzw_id[$key]];
  3038. }
  3039. }
  3040. // 释放引用,防止意外修改后续代码
  3041. unset($value);
  3042. }
  3043. $result['job_experience'] = $job_experience ?? [];
  3044. }
  3045. if (!empty($job[0]['education_experience'])) {
  3046. $education_experience = json_decode($job[0]['education_experience'], true) ?? '';
  3047. if (!empty($education_experience)) {
  3048. foreach ($education_experience as $key => $value) {
  3049. // $id = $value['id'];
  3050. $education[$key] = $value['school_education'];
  3051. }
  3052. $education_table = JobEnum::where('egroup', 'education')->whereIn('evalue', $education)->select('evalue', 'ename')->get();
  3053. // // 先将关联表转换为索引数组,提高查找效率
  3054. $educationLookup = [];
  3055. foreach ($education_table as $item) {
  3056. $educationLookup[$item['evalue']] = $item['ename'];
  3057. }
  3058. foreach ($education_experience as $key => &$value) {
  3059. // 处理学历名称
  3060. if (isset($education[$key]) && isset($educationLookup[$education[$key]])) {
  3061. $value['education_name'] = $educationLookup[$education[$key]];
  3062. }
  3063. }
  3064. }
  3065. $result['education_experience'] = $job_experience ?? [];
  3066. }
  3067. $result['job'] = $this->processJob($job, $webid);
  3068. // // 返现对应的栏目
  3069. $catid = json_decode($job[0]['cat_arr_id'], true) ?? '';
  3070. $category = WebsiteCategory::where('website_id', $data['website_id'])
  3071. ->whereIn('category_id', $catid)
  3072. ->select('category_id', 'alias', 'aLIas_pinyin', 'pid')
  3073. ->orderBy('pid')->get()->all();
  3074. if (!empty($category)) {
  3075. $result['category'] = $category;
  3076. }
  3077. $result['job'] = $job;
  3078. $result['job_experience'] = $job_experience ?? [];
  3079. $result['education_experience'] = $education_experience ?? [];
  3080. if (empty($result)) {
  3081. return Result::error("参数错误", 0);
  3082. }
  3083. return Result::success($result);
  3084. }
  3085. /**
  3086. * c端-申请职位
  3087. * @param array $data
  3088. * @return array
  3089. * */
  3090. public function getWebsiteJobApply(array $data): array
  3091. {
  3092. // 首先验证网站是否存在
  3093. // return Result::success($data);
  3094. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3095. if (empty($web)) {
  3096. return Result::error("该网站不存在", 0);
  3097. }
  3098. // 验证用户是否存在且为个人会员/管理员
  3099. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3100. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3101. if (empty($user) || ($user['type_id'] != 1 && $user['type_id'] != 10000)) {
  3102. return Result::error("用户不存在", 0);
  3103. }
  3104. // 去除重复元素和空元素,并保持原始顺序
  3105. $data['recruit_id'] = array_values(array_filter(array_unique($data['recruit_id']), function ($value) {
  3106. return !empty($value);
  3107. }));
  3108. // 验证职位是否存在 1:审核通过
  3109. $recruiting = JobRecruiting::where('status', 1)
  3110. ->where('website_id', $data['website_id'])
  3111. ->whereIn('id', $data['recruit_id'])
  3112. ->get(['id as recruit_id', 'user_id as receiver_id'])->all();
  3113. if (empty($recruiting)) {
  3114. return Result::error("该职位不存在", 0);
  3115. }
  3116. // 简历是否存在
  3117. $hunt_id = JobHunting::where('user_id', $data['user_id'])->where('status', 2)->first(['id as hunt_id']);
  3118. if (empty($hunt_id)) {
  3119. return Result::error("该简历不存在", 0);
  3120. }
  3121. $data['hunt_id'] = $hunt_id['hunt_id'];
  3122. // // 验证是否已投递过该职位
  3123. $apply = JobApply::where('user_id', $data['user_id'])
  3124. ->where('hunt_id', $data['hunt_id'])
  3125. ->where('website_id', $data['website_id'])
  3126. ->whereIn('recruit_id', $data['recruit_id'])
  3127. ->get(['recruit_id']);
  3128. if (!empty($apply->toArray())) {
  3129. return Result::error("您已投递过该职位!");
  3130. }
  3131. $insertData = array_map(function ($recruiting) use ($data) {
  3132. return [
  3133. 'user_id' => $data['user_id'],
  3134. 'hunt_id' => $data['hunt_id'],
  3135. 'website_id' => $data['website_id'],
  3136. 'recruit_id' => $recruiting['recruit_id'],
  3137. 'receiver_id' => $recruiting['receiver_id'],
  3138. 'status' => 1,
  3139. ];
  3140. }, $recruiting);
  3141. // 批量插入数据
  3142. $result = JobApply::insert($insertData);
  3143. if (empty($result)) {
  3144. return Result::error("投递失败", 0);
  3145. }
  3146. return Result::success($result);
  3147. }
  3148. /**
  3149. * 招工招聘-沟通简历
  3150. * @param array $data
  3151. * @return array
  3152. * */
  3153. public function getWebsiteJobResume(array $data): array
  3154. {
  3155. // 首先验证网站是否存在
  3156. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name']);
  3157. if (empty($web)) {
  3158. return Result::error("该网站不存在", 0);
  3159. }
  3160. // return Result::success($data);
  3161. // 验证用户是否存在且为企业会员/管理员
  3162. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3163. // 1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  3164. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3165. return Result::error("用户不存在", 0);
  3166. }
  3167. // 去除重复元素和空元素,并保持原始顺序
  3168. $data['hunt_id'] = array_values(array_filter(array_unique($data['hunt_id']), function ($value) {
  3169. return !empty($value);
  3170. }));
  3171. // 验证简历是否存在
  3172. $hunting = JobHunting::where('status', 2)
  3173. ->where('website_id', $data['website_id'])
  3174. ->whereIn('id', $data['hunt_id'])
  3175. ->get(['id as hunt_id', 'user_id as receiver_id'])->all();
  3176. if (empty($hunting)) {
  3177. return Result::error("该简历不存在", 0);
  3178. }
  3179. // 验证是否已沟通过该简历
  3180. $remuse = JobRemuse::where('user_id', $data['user_id'])
  3181. ->where('recruit_id', $data['recruit_id'])
  3182. ->where('website_id', $data['website_id'])
  3183. ->whereIn('hunt_id', $data['hunt_id'])
  3184. ->get(['hunt_id']);
  3185. if (!empty($remuse->toArray())) {
  3186. return Result::error("您已沟通过该简历!");
  3187. }
  3188. // 准备要插入的数据数组
  3189. $insertData = array_map(function ($hunting) use ($data) {
  3190. return [
  3191. 'user_id' => $data['user_id'],
  3192. 'recruit_id' => $data['recruit_id'],
  3193. 'website_id' => $data['website_id'],
  3194. 'hunt_id' => $hunting['hunt_id'],
  3195. 'receiver_id' => $hunting['receiver_id'],
  3196. 'status' => 1,
  3197. ];
  3198. }, $hunting);
  3199. // 批量插入数据
  3200. $result = JobRemuse::insert($insertData);
  3201. if (empty($result)) {
  3202. return Result::error("沟通失败", 0);
  3203. }
  3204. return Result::success($result);
  3205. }
  3206. /**
  3207. * 招工招聘 -我的职位(企业会员)
  3208. * @param array $data
  3209. * @return array
  3210. */
  3211. public function getWebsiteJobRecruiting(array $data): array
  3212. {
  3213. $web = Website::where('id', $data['website_id'])->first('id');
  3214. if (empty($web)) {
  3215. return Result::error("该网站不存在", 0);
  3216. }
  3217. $user = User::where('id', $data['user_id'])->first(['id', 'type_id']);
  3218. if (empty($user) || ($user['type_id'] != 3 && $user['type_id'] != 10000)) {
  3219. return Result::error("用户暂无权限!", 0);
  3220. }
  3221. // '状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3222. $result = JobRecruiting::where('website_id', $data['website_id'])
  3223. ->when(isset($user['type_id']) && $user['type_id'] == 3, function ($query) use ($user) {
  3224. $query->where('user_id', $user['id']);
  3225. })
  3226. ->where('status', 1)
  3227. ->select('id', 'title', 'website_id', 'user_id', 'updated_at')
  3228. ->orderBy('updated_at', 'desc')
  3229. ->limit($data['pageSize'])
  3230. ->get();
  3231. if (empty($result)) {
  3232. return Result::error("暂无相关职位信息", 0);
  3233. }
  3234. return Result::success($result);
  3235. }
  3236. /**
  3237. * c端 - 验证路由
  3238. * @param array $data
  3239. * @return array
  3240. */
  3241. /**
  3242. * c端 - 验证路由
  3243. * @param array $data
  3244. * @return array
  3245. */
  3246. public function checkWebsiteRoute(array $data): array
  3247. {
  3248. $web = Website::where('id', $data['website_id'])->first(['id', 'website_name', 'status']);
  3249. if (empty($web)) {
  3250. return Result::error("该网站不存在", 0);
  3251. } elseif ($web['status'] != 1) {
  3252. return Result::error("网站已经关闭", 0);
  3253. }
  3254. if (isset($data['other_route']) && !empty($data['other_route'])) {
  3255. $whiteRouterInfo = WhiteRouter::whereJsonContains("website_id", $data['website_id'])->where('router_url', $data['other_route'])->first();
  3256. if (!empty($whiteRouterInfo)) {
  3257. return Result::success($whiteRouterInfo->toArray());
  3258. }
  3259. }
  3260. // 验证栏目路由
  3261. $last_category = WebsiteCategory::where('website_id', $data['website_id'])
  3262. ->where('aLIas_pinyin', $data['last_route'])
  3263. ->first();
  3264. if (empty($last_category)) {
  3265. return Result::error("该栏目不存在", 0);
  3266. }
  3267. if (isset($data['id']) && !empty($data['id'])) {
  3268. // `type` int unsigned DEFAULT '1' COMMENT '类型:1资讯(默认)2商品3书刊音像4招聘5求职类型:1资讯(默认)2商品3书刊音像4招聘5求职6招工招聘'
  3269. switch ($last_category['type']) {
  3270. case 1:
  3271. // 文章
  3272. // `status` int DEFAULT '1' COMMENT '状态: 2:已拒绝 ;1:已发布,0待发布 草稿箱 404删除(移除)
  3273. $article = Article::where('status', 1)
  3274. ->where('id', $data['id'])
  3275. ->where(function ($query) use ($data) {
  3276. $query->whereRaw("JSON_CONTAINS(ignore_ids, '" . intval($data['website_id']) . "') = 0")
  3277. ->orWhereNull("ignore_ids");
  3278. })
  3279. ->first(['cat_arr_id']);
  3280. if (empty($article)) {
  3281. return Result::error("该文章不存在", 0);
  3282. }
  3283. // return Result::success($article);
  3284. break;
  3285. case 2:
  3286. // 商品
  3287. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3288. $article = Good::where('website_id', $data['website_id'])
  3289. ->where('status', 2)
  3290. ->where('id', $data['id'])
  3291. ->first(['cat_arr_id']);
  3292. if (empty($article)) {
  3293. return Result::error("该商品不存在", 0);
  3294. }
  3295. break;
  3296. case 3:
  3297. // 书刊信息
  3298. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3299. $article = Book::where('website_id', $data['website_id'])
  3300. ->where('status', 2)
  3301. ->where('id', $data['id'])
  3302. ->first(['id', 'cat_arr_id']);
  3303. if (empty($article)) {
  3304. return Result::error("该书刊不存在", 0);
  3305. }
  3306. break;
  3307. case 4:
  3308. // 招聘
  3309. // `status` int DEFAULT '0' COMMENT '状态 0:待审核;1:已审核通过;(只有企业会员需要审核)',
  3310. $article = JobRecruiting::where('website_id', $data['website_id'])
  3311. ->where('status', 1)
  3312. ->where('id', $data['id'])
  3313. ->first(['cat_arr_id']);
  3314. if (empty($article)) {
  3315. return Result::error("该招聘不存在", 0);
  3316. }
  3317. break;
  3318. case 5:
  3319. // 求职
  3320. // `status` int DEFAULT '1' COMMENT '审核状态,1待审核2已审核3已拒绝',
  3321. $article = JobHunting::where('website_id', $data['website_id'])
  3322. ->where('status', 2)
  3323. ->where('id', $data['id'])
  3324. ->first(['cat_arr_id']);
  3325. if (empty($article)) {
  3326. return Result::error("该求职不存在", 0);
  3327. }
  3328. break;
  3329. case 6:
  3330. // 企业
  3331. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3332. $article = Company::where('website_id', $data['website_id'])
  3333. ->where('status', 1)
  3334. ->where('id', $data['id'])
  3335. ->first(['cat_arr_id']);
  3336. if (empty($article)) {
  3337. return Result::error("该企业不存在", 0);
  3338. }
  3339. break;
  3340. case 7:
  3341. // 项目
  3342. // `status` int DEFAULT '1' COMMENT '审核状态状态:0:未审核;1:已审核;2:已拒绝;',
  3343. $article = Project::where('website_id', $data['website_id'])
  3344. ->where('status', 1)
  3345. ->where('id', $data['id'])
  3346. ->first(['cat_arr_id']);
  3347. if (empty($article)) {
  3348. return Result::error("该项目不存在", 0);
  3349. }
  3350. break;
  3351. default:
  3352. return Result::error("该数据不存在", 0);
  3353. break;
  3354. }
  3355. $catid = json_decode($article['cat_arr_id'], true);
  3356. if (empty($catid)) {
  3357. return Result::error("该数据不存在", 0);
  3358. }
  3359. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3360. ->orderByRaw('FIELD(category_id, ' . implode(',', $catid) . ')')
  3361. ->whereIn('category_id', $catid)
  3362. ->pluck('aLIas_pinyin')
  3363. ->implode('/');
  3364. }
  3365. if ($last_category['pid'] != 0) {
  3366. $cat_arr = json_decode($last_category['category_arr_id'], true);
  3367. $pinyin = WebsiteCategory::where('website_id', $data['website_id'])
  3368. ->orderByRaw('FIELD(category_id, ' . implode(',', $cat_arr) . ')')
  3369. ->whereIn('category_id', $cat_arr)
  3370. ->pluck('aLIas_pinyin')
  3371. ->implode('/');
  3372. } else {
  3373. $pinyin = $last_category['aLIas_pinyin'];
  3374. }
  3375. if (empty($pinyin) || $pinyin != $data['all_route']) {
  3376. return Result::error('非法路径!');
  3377. } else {
  3378. return Result::success($pinyin);
  3379. }
  3380. }
  3381. /**
  3382. * 招工招聘 - 获取推荐职位
  3383. * @param array $data
  3384. * @return array
  3385. */
  3386. public function getWebsiteLevelJob(array $data): array
  3387. {
  3388. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;
  3389. $job = JobRecruiting::where('job_recruiting.website_id', $data['website_id'])
  3390. ->where('job_recruiting.status', 1)
  3391. ->where('job_level', $data['job_level'])
  3392. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  3393. ->select('job_recruiting.id', 'job_recruiting.title', 'job_recruiting.cat_arr_id', 'job_company.business_name', 'job_recruiting.updated_at')
  3394. ->orderBy('job_recruiting.updated_at', 'desc')
  3395. ->limit($data['pageSize'])
  3396. ->get();
  3397. $web = ['website_id' => $data['website_id']];
  3398. if (!empty($job)) {
  3399. $result = $this->processJob($job, $web);
  3400. }
  3401. if (empty($result)) {
  3402. return Result::error("暂无相关职位信息", 0);
  3403. }
  3404. return Result::success($result);
  3405. }
  3406. /**
  3407. * 验证导航名称是否重复
  3408. * @return void
  3409. */
  3410. //20250226 产品列表
  3411. public function getGoodList(array $data): array
  3412. {
  3413. var_dump($data, '---------1-2--');
  3414. $type_id = isset($data['user_type_id']) ? $data['user_type_id'] : '';
  3415. unset($data['user_type_id']);
  3416. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3417. $where = [];
  3418. if ($type_id != '10000') {
  3419. $where = [
  3420. 'good.user_id' => $user_id,
  3421. ];
  3422. }
  3423. //类型
  3424. if (isset($data['type_id']) && $data['type_id']) {
  3425. $where['good.type_id'] = $data['type_id'];
  3426. }
  3427. //名称
  3428. if (isset($data['name']) && $data['name']) {
  3429. $where[] = ['good.name', 'like', '%' . $data['name'] . '%'];
  3430. }
  3431. //status
  3432. if (isset($data['status']) && $data['status'] != '') {
  3433. $where['good.status'] = $data['status'];
  3434. }
  3435. //status1
  3436. // if (isset($data['status1']) && $data['status1'] == 1) {
  3437. // $status1 = 1;
  3438. // }
  3439. $where1 = [];
  3440. //website_id
  3441. // if (isset($data['website_id']) && $data['website_id']) {
  3442. // $where1 = [
  3443. // 'good.website_id', 'like', '%' . $data['website_id'] . '%',
  3444. // ];
  3445. // }
  3446. // website_name
  3447. if (isset($data['website_name']) && $data['website_name']) {
  3448. $where1[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  3449. }
  3450. // catid
  3451. if (isset($data['category_name']) && $data['category_name']) {
  3452. $where1[] = ['category.name', 'like', '%' . $data['category_name'] . '%'];
  3453. }
  3454. // $result = Good::where($where)
  3455. // ->orderBy("updated_at", "desc")->paginate($data['pige_size'], ['*'], 'page', $data['page']);
  3456. var_dump($where, '---------1---');
  3457. $result = Good::where($where)
  3458. ->when(!empty($where1), function ($query) use ($where1) {
  3459. return $query->where($where1);
  3460. })
  3461. //status 1待审核2已审核3已拒绝
  3462. ->when(isset($data['status1']), function ($query) {
  3463. return $query->whereIn('good.status', [1, 3]);
  3464. })
  3465. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3466. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3467. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3468. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3469. ->orderBy("updated_at", "desc")
  3470. ->limit($data['page_size'])
  3471. ->offset(($data['page'] - 1) * $data['page_size'])
  3472. ->get();
  3473. $count = Good::where($where)
  3474. ->when(!empty($where1), function ($query) use ($where1) {
  3475. return $query->where($where1);
  3476. })
  3477. //status 1待审核2已审核3已拒绝
  3478. ->when(isset($data['status1']), function ($query) {
  3479. return $query->whereIn('good.status', [1, 3]);
  3480. })
  3481. ->leftJoin('district', 'good.city_id', '=', 'district.id')
  3482. ->leftJoin('website', 'good.website_id', '=', 'website.id')
  3483. ->leftJoin('category', 'good.catid', '=', 'category.id')
  3484. ->select('good.*', 'district.name as cityname', 'website.website_name as website_name', 'category.name as category_name')
  3485. ->orderBy("updated_at", "desc")->count();
  3486. $data = [
  3487. 'rows' => $result->toArray(),
  3488. 'count' => $count,
  3489. ];
  3490. if (empty($result)) {
  3491. return Result::error("此栏目暂无相关产品", 0);
  3492. }
  3493. return Result::success($data);
  3494. }
  3495. public function getGoodInfo(array $data): array
  3496. {
  3497. $result = Good::where('id', $data['id'])->first();
  3498. if (empty($result)) {
  3499. return Result::error("此产品不存在", 0);
  3500. }
  3501. return Result::success($result);
  3502. }
  3503. public function addGood(array $data): array
  3504. {
  3505. // unset($data['city_arr_id']);
  3506. // unset($data['cat_arr_id']);
  3507. $data['city_id'] = end($data['city_arr_id']);
  3508. $data['catid'] = end($data['cat_arr_id']);
  3509. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3510. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3511. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3512. unset($data['imgUrl']); //大小写
  3513. if (isset($data['price']) && $data['price'] == '') {
  3514. $data['price'] = 0;
  3515. }
  3516. if ($data['imgurl'] == '') {
  3517. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  3518. preg_match_all($reg, $data['detail'], $matches);
  3519. if (isset($matches[1][0])) {
  3520. //截取varchar240
  3521. $data['imgurl'] = substr($matches[1][0], 0, 240);
  3522. }
  3523. }
  3524. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  3525. //提取标题+内容中的关键词
  3526. $data['keyword'] = $data['name'];
  3527. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  3528. Jieba::init(); // 初始化 jieba-php
  3529. Finalseg::init();
  3530. $segList = Jieba::cut($data['keyword']);
  3531. $segList1 = array_slice($segList, 0, 8);
  3532. $data['keyword'] = implode(',', $segList1);
  3533. }
  3534. if ($data['description'] == '') {
  3535. //提取内容中的描述
  3536. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  3537. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  3538. // $data['description'] = substr(preg_replace('/\s+/', '', strip_tags($data['detail'])), 0, 100);
  3539. }
  3540. if($data['status']==1){
  3541. $this->sendMessage([
  3542. 'talk_type'=>200,
  3543. 'title'=>$data['name'],
  3544. 'content'=>'提交了审核',
  3545. 'messageType'=>3,
  3546. ]);
  3547. }
  3548. $result = Good::insert($data);
  3549. if (empty($result)) {
  3550. return Result::error("添加失败", 0);
  3551. }
  3552. return Result::success($result);
  3553. }
  3554. public function updateGood(array $data): array
  3555. {
  3556. $data['city_id'] = end($data['city_arr_id']);
  3557. $data['catid'] = end($data['cat_arr_id']);
  3558. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode($data['city_arr_id']) : '';
  3559. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode($data['cat_arr_id']) : '';
  3560. $data['imgurl'] = isset($data['imgurl']) ? json_encode($data['imgurl']) : '';
  3561. //设置东八区
  3562. date_default_timezone_set('Asia/Shanghai');
  3563. $data['updated_at'] = date('Y-m-d H:i:s');
  3564. if (isset($data['price']) && $data['price'] == '') {
  3565. $data['price'] = 0;
  3566. }
  3567. if ($data['imgurl'] == '') {
  3568. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  3569. preg_match_all($reg, $data['detail'], $matches);
  3570. if (isset($matches[1][0])) {
  3571. //截取varchar240
  3572. $data['imgurl'] = substr($matches[1][0], 0, 240);
  3573. }
  3574. }
  3575. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  3576. //提取标题+内容中的关键词
  3577. $data['keyword'] = $data['name'];
  3578. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  3579. Jieba::init(); // 初始化 jieba-php
  3580. Finalseg::init();
  3581. $segList = Jieba::cut($data['keyword']);
  3582. $segList1 = array_slice($segList, 0, 8);
  3583. $data['keyword'] = implode(',', $segList1);
  3584. }
  3585. if ($data['description'] == '') {
  3586. //提取内容中的描述
  3587. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  3588. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  3589. }
  3590. if($data['status']==1){
  3591. $this->sendMessage([
  3592. 'talk_type'=>200,
  3593. 'title'=>$data['name'],
  3594. 'content'=>'提交了审核',
  3595. 'messageType'=>3,
  3596. ]);
  3597. }
  3598. $result = Good::where('id', $data['id'])->update($data);
  3599. if (empty($result)) {
  3600. return Result::error("更新失败", 0);
  3601. }
  3602. return Result::success($result);
  3603. }
  3604. public function delGood(array $data): array
  3605. {
  3606. $result = Good::where('id', $data['id'])->delete();
  3607. if (empty($result)) {
  3608. return Result::error("删除失败", 0);
  3609. }
  3610. return Result::success($result);
  3611. }
  3612. //20250226 产品列表
  3613. //20250306 求职信息
  3614. public function getJobHuntingList(array $data): array
  3615. {
  3616. $where = [];
  3617. if (isset($data['username']) && !empty($data['username'])) {
  3618. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3619. }
  3620. //status 1待审核2已审核3已拒绝
  3621. if (isset($data['status']) && $data['status'] != '') {
  3622. $where = [
  3623. 'job_hunting.status' => $data['status'],
  3624. ];
  3625. }
  3626. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3627. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3628. unset($data['type_id']);
  3629. if ($type_id != '10000') {
  3630. $where[] = ['job_hunting.user_id', '=', $user_id];
  3631. }
  3632. $result = JobHunting::where($where)
  3633. ->when(!empty($data['status1']), function ($query) use ($data) {
  3634. return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3635. })
  3636. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3637. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3638. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as username', 'website.website_name as website_name')
  3639. ->orderBy("updated_at", "desc")
  3640. ->limit($data['page_size'])
  3641. ->offset(($data['page'] - 1) * $data['page_size'])
  3642. ->get();
  3643. if (empty($result)) {
  3644. return Result::error("查询失败", 0);
  3645. }
  3646. $count = JobHunting::where($where)
  3647. ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id')
  3648. ->leftJoin('website', 'website.id', '=', 'job_hunting.website_id')
  3649. ->count();
  3650. $data = [
  3651. 'rows' => $result->toArray(),
  3652. 'count' => $count,
  3653. ];
  3654. return Result::success($data);
  3655. }
  3656. public function getJobHuntingApply(array $data): array
  3657. {
  3658. var_dump($data, '-----------------test--------1-');
  3659. $where = [];
  3660. if (isset($data['username']) && !empty($data['username'])) {
  3661. $where[] = ['user.user_name', 'like', '%' . $data['username'] . '%'];
  3662. }
  3663. if (isset($data['salary']) && !empty($data['salary'])) {
  3664. $where[] = [
  3665. 'job_hunting.salary',
  3666. '=',
  3667. $data['salary'],
  3668. ];
  3669. }
  3670. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  3671. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  3672. unset($data['type_id']);
  3673. if ($type_id != '10000') {
  3674. $where[] = ['job_apply.receiver_id', '=', $user_id];
  3675. }
  3676. var_dump($where, '-----------------test---------');
  3677. $result = jobApply::where($where)
  3678. // ->when(!empty($data['status1']), function ($query) use ($data) {
  3679. // return $query->whereIn('job_hunting.status', [1, 3]); //1待审核2已审核3已拒绝
  3680. // })
  3681. // ->leftJoin('user', 'user.id', '=', 'job_hunting.user_id') 'user.nickname as nickname', , 'user.user_name as username'
  3682. ->where('job_enum.egroup', '=', 'income')
  3683. ->where('job_hunting.status', 2) //已审核
  3684. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3685. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3686. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3687. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3688. //职位----是申请职位
  3689. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3690. ->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')
  3691. ->orderBy("job_hunting.updated_at", "desc")
  3692. ->limit($data['page_size'])
  3693. ->offset(($data['page'] - 1) * $data['page_size'])
  3694. ->get();
  3695. if (empty($result)) {
  3696. return Result::error("查询失败", 0);
  3697. }
  3698. $count = jobApply::where($where)
  3699. ->where('job_enum.egroup', '=', 'income')
  3700. ->where('job_hunting.status', 2) //已审核
  3701. ->leftJoin('job_hunting', 'job_hunting.id', '=', 'job_apply.hunt_id')
  3702. ->leftJoin('district', 'district.id', '=', 'job_hunting.city_id')
  3703. ->leftJoin('job_enum', 'job_enum.evalue', '=', 'job_hunting.salary')
  3704. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  3705. //职位----是申请职位
  3706. ->leftJoin('job_position', 'job_hunting.job_name_get', '=', 'job_position.zwid')
  3707. ->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')
  3708. ->count();
  3709. $data = [
  3710. 'rows' => $result->toArray(),
  3711. 'count' => $count,
  3712. ];
  3713. return Result::success($data);
  3714. }
  3715. public function addJobHunting(array $data): array
  3716. {
  3717. date_default_timezone_set('Asia/Shanghai');
  3718. unset($data['company_name']);
  3719. unset($data['job_industry']);
  3720. unset($data['job_name']);
  3721. unset($data['department']);
  3722. unset($data['job_timeList']);
  3723. unset($data['job_content']);
  3724. unset($data['job_typename']); //不知道这是啥,
  3725. $data['created_at'] = date('Y-m-d H:i:s');
  3726. $data['updated_at'] = date('Y-m-d H:i:s');
  3727. //根据用户 user_id 只能添加一次
  3728. $result = JobHunting::where('user_id', $data['user_id'])->first();
  3729. if (!empty($result)) {
  3730. return Result::error("您已添加过求职信息", 0);
  3731. }
  3732. var_dump($result, '-----------------test---------');
  3733. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  3734. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  3735. $cityArr = json_decode($data['city_arr_id'], true);
  3736. $data['city_id'] = end($cityArr);
  3737. } else {
  3738. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  3739. $data['city_id'] = end($data['city_arr_id']);
  3740. }
  3741. $result = JobHunting::create($data);
  3742. if (empty($result)) {
  3743. return Result::error("添加失败", 0);
  3744. }
  3745. return Result::success($result);
  3746. }
  3747. public function delJobHunting(array $data): array
  3748. {
  3749. $result = JobHunting::where('id', $data['id'])->delete();
  3750. if (empty($result)) {
  3751. return Result::error("删除失败", 0);
  3752. }
  3753. return Result::success($result);
  3754. }
  3755. public function updateJobHunting(array $data): array
  3756. {
  3757. //设置东八区
  3758. date_default_timezone_set('Asia/Shanghai');
  3759. unset($data['company_name']);
  3760. unset($data['job_industry']);
  3761. unset($data['job_name']);
  3762. unset($data['department']);
  3763. unset($data['job_timeList']);
  3764. unset($data['job_content']);
  3765. unset($data['job_typename']); //不知道这是啥,
  3766. $data['created_at'] = date('Y-m-d H:i:s');
  3767. $data['updated_at'] = date('Y-m-d H:i:s');
  3768. if (isset($data['city_arr_id']) && !empty($data['city_arr_id']) && is_string($data['city_arr_id'])) {
  3769. // 如果 city_arr_id 是字符串,尝试将其转换为数组,取最后一个数据
  3770. $cityArr = json_decode($data['city_arr_id'], true);
  3771. $data['city_id'] = end($cityArr);
  3772. } else {
  3773. // 如果 city_arr_id 不是字符串,直接取最后一个数据
  3774. $data['city_id'] = end($data['city_arr_id']);
  3775. }
  3776. $result = JobHunting::where('id', $data['id'])->update($data);
  3777. if (empty($result)) {
  3778. return Result::error("更新失败", 0);
  3779. }
  3780. return Result::success($result);
  3781. }
  3782. public function getJobHuntingInfo(array $data): array
  3783. {
  3784. $result = JobHunting::where('id', $data['id'])->first();
  3785. if (empty($result)) {
  3786. return Result::error("查询失败", 0);
  3787. }
  3788. return Result::success($result);
  3789. }
  3790. public function getJobHuntingData(array $data): array
  3791. {
  3792. $jobEnum = JobEnum::get();
  3793. $jobIndustry = JobIndustry::get();
  3794. $jobNature = JobNature::get();
  3795. $jobPosition = JobPosition::get();
  3796. $data = [
  3797. 'jobEnum' => $jobEnum,
  3798. 'jobIndustry' => $jobIndustry,
  3799. 'jobNature' => $jobNature,
  3800. 'jobPosition' => $jobPosition,
  3801. ];
  3802. return Result::success($data);
  3803. }
  3804. public function delJobHuntingInfo(array $data): array
  3805. {
  3806. $result = JobHunting::where('id', $data['id'])->delete();
  3807. return Result::success();
  3808. }
  3809. //20250324 通知,公告,消息
  3810. public function delNotice(array $data): array
  3811. {
  3812. $result = Notice::where('id', $data['id'])->delete();
  3813. if ($result) {
  3814. return Result::success();
  3815. } else {
  3816. return Result::error("删除失败", 0);
  3817. }
  3818. }
  3819. public function getNoticeInfo(array $data): array
  3820. {
  3821. $result = Notice::where('id', $data['id'])->first();
  3822. // var_dump($result['re_user_ids'], '--------------------');
  3823. if (empty($result)) {
  3824. return Result::error("查询失败", 0);
  3825. }
  3826. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  3827. $re_user_ids = json_decode($result['re_user_ids'], true);
  3828. var_dump($re_user_ids, '--------------1---test---------');
  3829. var_dump($data, '--------------1---test---------');
  3830. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  3831. //如果已经存在,就不再添加
  3832. if (isset($result['read_id']) && !empty($result['read_id'])) {
  3833. $read_id = json_decode($result['read_id'], true);
  3834. if (!is_array($read_id)) {
  3835. $read_id = [];
  3836. }
  3837. if (!in_array($data['user_id'], $read_id)) {
  3838. $read_id[] = $data['user_id'];
  3839. $result['read_id'] = json_encode($read_id);
  3840. Notice::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  3841. }
  3842. } else {
  3843. //如果不存在,就添加
  3844. $result['read_id'] = json_encode([$data['user_id']]);
  3845. Notice::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  3846. }
  3847. }
  3848. return Result::success($result);
  3849. }
  3850. public function addNotice(array $data): array
  3851. {
  3852. date_default_timezone_set('Asia/Shanghai');
  3853. $data['created_at'] = date('Y-m-d H:i:s');
  3854. $data['updated_at'] = date('Y-m-d H:i:s');
  3855. $user_id = UserInfo::
  3856. //city_id不是null
  3857. whereNotNull('city_id')
  3858. ->whereNotNull('department_id')
  3859. ->where(function ($query) use ($data) {
  3860. $query->where(function ($subQuery) use ($data) {
  3861. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3862. });
  3863. })
  3864. ->where(function ($query) use ($data) {
  3865. $query->where(function ($subQuery) use ($data) {
  3866. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  3867. });
  3868. })
  3869. ->pluck('user_id')->toArray();
  3870. $user_id = array_unique($user_id);
  3871. $chat_ids = $user_id;
  3872. $user_id = json_encode($user_id);
  3873. $data['re_user_ids'] = $user_id;
  3874. $this->sendMessage([
  3875. 'talk_type'=>700,
  3876. 'title'=>$data['title'],
  3877. 'content'=>'提交了审核',
  3878. 'messageType'=>5,
  3879. ]);
  3880. $result = Notice::insertGetId($data);
  3881. if ($result && $data['is_group'] == 1) {
  3882. //chat_group
  3883. $group_id = PublicData::uuid();
  3884. $groupData = [
  3885. 'id' => $group_id,
  3886. 'creator_id' => $data['user_id'],
  3887. 'group_name' => $data['group_name'] ?? '',
  3888. 'profile' => $data['profile'] ?? 0,
  3889. ];
  3890. var_dump($groupData, '-----------------groupData-------');
  3891. $groupResult = ChatGroups::insertGetId($groupData);
  3892. var_dump($groupResult, '-----------------groupid-------');
  3893. $groupMemberData = [
  3894. 'id' => PublicData::uuid(),
  3895. 'user_id' => $data['user_id'],
  3896. 'group_id' => $group_id,
  3897. 'leader' => 2,
  3898. ];
  3899. $groupMemberResult = ChatGroupsMember::insertGetId($groupMemberData);
  3900. //$chat_ids 去除掉$data['user_id']
  3901. $chat_ids = array_diff($chat_ids, [$data['user_id']]);
  3902. //插入群成员表
  3903. $groupMemberDataUser = [];
  3904. $chatData = [];
  3905. foreach ($chat_ids as $key => $value) {
  3906. $groupMemberDataUser[] = [
  3907. 'id' => PublicData::uuid(),
  3908. 'user_id' => $value,
  3909. 'group_id' => $group_id,
  3910. 'leader' => 1,
  3911. ];
  3912. $chatData[] = [
  3913. 'user_id' => $value,
  3914. 'msg_type' => 1,
  3915. 'receiver_id' => $group_id,
  3916. 'content' => '通过通知创建群聊',
  3917. 'group_receiver_id' => $data['user_id'],
  3918. 'action' => 'recieved',
  3919. 'created_at' => date('Y-m-d H:i:s'),
  3920. ];
  3921. }
  3922. var_dump($groupMemberDataUser, '-----------------groupMemberDataUser-------');
  3923. ChatGroupsMember::insert($groupMemberDataUser);
  3924. //插入一条管理员聊天记录
  3925. $chatData[] = [
  3926. 'user_id' => $data['user_id'],
  3927. 'msg_type' => 1,
  3928. 'receiver_id' => $group_id,
  3929. 'content' => '通过通知创建群聊',
  3930. 'group_receiver_id' => $data['user_id'],
  3931. 'action' => 'said',
  3932. 'created_at' => date('Y-m-d H:i:s'),
  3933. ];
  3934. var_dump($chatData, '-----------------chatData-------');
  3935. $chatResult = ChatRecords::insert($chatData);
  3936. //更新result的 group_id
  3937. $data['group_id'] = $group_id;
  3938. Notice::where(['id' => $result])->update($data);
  3939. }
  3940. if (empty($result)) {
  3941. return Result::error("添加失败", 0);
  3942. }
  3943. return Result::success($result);
  3944. }
  3945. public function updateNotice(array $data): array
  3946. {
  3947. date_default_timezone_set('Asia/Shanghai');
  3948. //根据city_id 和department_id 查询出对应的user_id,放到 re_user_ids
  3949. $user_id = UserInfo::
  3950. //city_id不是null
  3951. whereNotNull('city_id')
  3952. ->whereNotNull('department_id')
  3953. ->where(function ($query) use ($data) {
  3954. $query->where(function ($subQuery) use ($data) {
  3955. $subQuery->whereRaw("JSON_VALID(city_arr_id) AND JSON_CONTAINS(city_arr_id, '" . intval($data['city_id']) . "') = 1");
  3956. });
  3957. })
  3958. ->where(function ($query) use ($data) {
  3959. $query->where(function ($subQuery) use ($data) {
  3960. $subQuery->whereRaw("JSON_VALID(department_arr_id) AND JSON_CONTAINS(department_arr_id, '" . intval($data['department_id']) . "') = 1");
  3961. });
  3962. })
  3963. ->pluck('user_id')->toArray();
  3964. $user_id = array_unique($user_id);
  3965. $user_id = json_encode($user_id);
  3966. $data['re_user_ids'] = $user_id;
  3967. $data['updated_at'] = date('Y-m-d H:i:s');
  3968. $this->sendMessage([
  3969. 'talk_type'=>700,
  3970. 'title'=>$data['title'],
  3971. 'content'=>'提交了审核',
  3972. 'messageType'=>5,
  3973. ]);
  3974. $result = Notice::where('id', $data['id'])->update($data);
  3975. return Result::success($result);
  3976. }
  3977. public function getNoticeList(array $data): array
  3978. {
  3979. $where = [];
  3980. //title
  3981. if (isset($data['title']) && !empty($data['title'])) {
  3982. $where[] = ['notice.title', 'like', '%' . $data['title'] . '%'];
  3983. }
  3984. //level
  3985. if (isset($data['level']) && !empty($data['level'])) {
  3986. $where[] = ['notice.level', '=', $data['level']];
  3987. }
  3988. //status
  3989. if (isset($data['status']) && !empty($data['status'])) {
  3990. $where[] = ['notice.status', '=', $data['status']];
  3991. }
  3992. var_dump($data, '------------11111-2----test---------');
  3993. if ($data['type_id'] == 10000) {
  3994. $result = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  3995. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  3996. })
  3997. ->where($where)
  3998. ->orderBy('updated_at', 'desc')
  3999. ->limit($data['page_size'])
  4000. ->offset(($data['page'] - 1) * $data['page_size'])
  4001. ->get();
  4002. $total = Notice::when(!empty($data['status1']), function ($query) use ($data) {
  4003. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4004. })
  4005. ->where($where)
  4006. ->orderBy('updated_at', 'desc')
  4007. ->count();
  4008. } else {
  4009. $result = Notice::where($where)
  4010. // ->where('user_id', $data['user_id'])
  4011. ->Where(function ($query) use ($data) {
  4012. $query->Where(function ($q) use ($data) {
  4013. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4014. ->orWhere('notice.user_id', $data['user_id']);
  4015. });
  4016. })
  4017. ->when(!empty($data['status1']), function ($query) use ($data) {
  4018. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4019. })
  4020. ->orderBy('updated_at', 'desc')
  4021. ->limit($data['page_size'])
  4022. ->offset(($data['page'] - 1) * $data['page_size'])
  4023. ->get();
  4024. $total = Notice::where($where)
  4025. ->when(!empty($data['status1']), function ($query) use ($data) {
  4026. return $query->whereIn('notice.status', [1, 3]); //1待审核2已审核3已拒绝
  4027. })
  4028. // ->where('user_id', $data['user_id'])
  4029. ->Where(function ($query) use ($data) {
  4030. $query->Where(function ($q) use ($data) {
  4031. $q->whereRaw('JSON_CONTAINS(notice.re_user_ids, \'' . $data['user_id'] . '\')')
  4032. ->orWhere('notice.user_id', $data['user_id']);
  4033. });
  4034. })
  4035. ->count();
  4036. }
  4037. if (empty($result)) {
  4038. return Result::error("查询失败", 0);
  4039. }
  4040. $data = [
  4041. 'rows' => $result,
  4042. 'count' => $total,
  4043. ];
  4044. return Result::success($data);
  4045. }
  4046. public function getNoticeDetail(array $data): array
  4047. {
  4048. $result = Notice::where('id', $data['id'])->first();
  4049. if (empty($result)) {
  4050. return Result::error("查询失败", 0);
  4051. }
  4052. return Result::success($result);
  4053. }
  4054. public function deleteNotice(array $data): array
  4055. {
  4056. $notice = Notice::where('id', $data['id'])->first();
  4057. if (empty($notice)) {
  4058. return Result::error("删除失败", 0);
  4059. }
  4060. $chat_group_id = $notice->group_id;
  4061. if ($chat_group_id) {
  4062. //删除群聊
  4063. ChatGroups::where('id', $chat_group_id)->delete();
  4064. //删除群成员
  4065. ChatGroupsMember::where('group_id', $chat_group_id)->delete();
  4066. //删除群聊记录
  4067. ChatRecords::where('receiver_id', $chat_group_id)->delete();
  4068. }
  4069. $result = Notice::where('id', $data['id'])->delete();
  4070. return Result::success($result);
  4071. }
  4072. public function getComplaintList(array $data): array
  4073. {
  4074. var_dump($data, '00000001000000000000');
  4075. $type_id = isset($data['type_id']) ? $data['type_id'] : '';
  4076. unset($data['type_id']);
  4077. $user_id = isset($data['user_id']) ? $data['user_id'] : '';
  4078. $where = [];
  4079. if ($type_id != 10000 && empty($data['deal_user'])) {
  4080. $where['complaint.user_id'] = $user_id;
  4081. }
  4082. if (!empty($data['title'])) {
  4083. $where[] = ['complaint.title', 'like', '%' . $data['title'] . '%'];
  4084. }
  4085. if (!empty($data['department_id'])) {
  4086. $where['complaint.department_id'] = $data['department_id'];
  4087. }
  4088. if (!empty($data['deal'])) {
  4089. $where['complaint.deal'] = $data['deal'];
  4090. }
  4091. if (!empty($data['status'])) {
  4092. $where['complaint.status'] = $data['status'];
  4093. }
  4094. var_dump(!empty($data['deal_user']), '----------1');
  4095. var_dump($where, '----------2');
  4096. $result = Complaint::where($where)
  4097. ->when(!empty($data['status1']), function ($query) use ($data) {
  4098. $query->whereIn('complaint.status', [1, 3]); //1待审核2已审核3已拒绝
  4099. })
  4100. ->when(!empty($data['deal_user']) && $type_id != 10000, function ($query) use ($data) {
  4101. //json re_user_ids data[user_id]是不是在里面
  4102. $query->Where(function ($q) use ($data) {
  4103. $q->whereRaw('JSON_CONTAINS(complaint.re_user_ids, \'' . $data['user_id'] . '\')')
  4104. ->where('complaint.status', 2);
  4105. });
  4106. })
  4107. ->leftJoin('department', 'complaint.department_id', '=', 'department.id')
  4108. // ->leftJoin('user', 'complaint.user_id', '=', 'user.id')
  4109. ->leftJoin('district', 'district.id', '=', 'complaint.city_id')
  4110. ->select('complaint.*', 'department.name as department_name', 'district.name as cityname')
  4111. ->orderBy('updated_at', 'desc')
  4112. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  4113. //sql输出
  4114. if (empty($result)) {
  4115. return Result::error("暂无投诉信息", 0);
  4116. }
  4117. // 取出数据
  4118. $rows = $result->items();
  4119. $count = $result->total();
  4120. $responseData = [
  4121. 'rows' => $rows,
  4122. 'count' => $count,
  4123. ];
  4124. return Result::success($responseData);
  4125. }
  4126. public function getComplaintInfo(array $data): array
  4127. {
  4128. $result = Complaint::where('id', $data['id'])->first();
  4129. if (empty($result)) {
  4130. return Result::error("查询失败", 0);
  4131. }
  4132. //判断$requireData['user_id'] ; 是不是在 re_user_ids 中,如果在,就写入read_id,存成数组的json
  4133. $re_user_ids = json_decode($result['re_user_ids'], true);
  4134. if (is_array($re_user_ids) && in_array($data['user_id'], $re_user_ids)) {
  4135. //如果已经存在,就不再添加
  4136. if (isset($result['read_id']) && !empty($result['read_id'])) {
  4137. $read_id = json_decode($result['read_id'], true);
  4138. if (!is_array($read_id)) {
  4139. $read_id = [];
  4140. }
  4141. if (!in_array($data['user_id'], $read_id)) {
  4142. $read_id[] = $data['user_id'];
  4143. $result['read_id'] = json_encode($read_id);
  4144. Complaint::where('id', $data['id'])->update(['read_id' => json_encode($read_id)]);
  4145. }
  4146. } else {
  4147. //如果不存在,就添加
  4148. $result['read_id'] = json_encode([$data['user_id']]);
  4149. Complaint::where('id', $data['id'])->update(['read_id' => json_encode([$data['user_id']])]);
  4150. }
  4151. }
  4152. return Result::success($result);
  4153. }
  4154. public function addComplaint(array $data): array
  4155. {
  4156. date_default_timezone_set('Asia/Shanghai');
  4157. $data['created_at'] = date('Y-m-d H:i:s');
  4158. $data['updated_at'] = date('Y-m-d H:i:s');
  4159. $this->sendMessage([
  4160. 'talk_type'=>800,
  4161. 'title'=>$data['title'],
  4162. 'content'=>'提交了审核',
  4163. 'messageType'=>6,
  4164. ]);
  4165. $result = Complaint::create($data);
  4166. return Result::success($result);
  4167. }
  4168. public function updateComplaint(array $data): array
  4169. {
  4170. date_default_timezone_set('Asia/Shanghai');
  4171. $data['updated_at'] = date('Y-m-d H:i:s');
  4172. $user_id = $data['user_id'] ?? 0;
  4173. $type_id = $data['type_id'] ?? 0;
  4174. unset($data['user_id']);
  4175. unset($data['type_id']);
  4176. $this->sendMessage([
  4177. 'talk_type'=>800,
  4178. 'title'=>$data['title'],
  4179. 'content'=>'提交了审核',
  4180. 'messageType'=>6,
  4181. ]);
  4182. $result = Complaint::where('id', $data['id'])->update($data);
  4183. return Result::success($result);
  4184. }
  4185. public function deleteComplaint(array $data): array
  4186. {
  4187. $result = Complaint::where('id', $data['id'])->delete();
  4188. return Result::success($result);
  4189. }
  4190. public function getComplainInfo(array $data): array
  4191. {
  4192. $result = Complaint::where('id', $data['id'])->first();
  4193. if (empty($result)) {
  4194. return Result::error("查询失败", 0);
  4195. }
  4196. return Result::success($result);
  4197. }
  4198. public function updateComplaintStatus(array $data): array
  4199. {
  4200. date_default_timezone_set('Asia/Shanghai');
  4201. $data['updated_at'] = date('Y-m-d H:i:s');
  4202. $user_id = $data['user_id'] ?? 0;
  4203. $type_id = $data['type_id'] ?? 0;
  4204. unset($data['user_id']);
  4205. unset($data['type_id']);
  4206. //处理, 写入处理人
  4207. if (isset($data['deal']) && ($data['deal'] == 2 || $data['deal'] == 4)) {
  4208. $data['real_deal_user'] = $user_id;
  4209. }
  4210. //如果是deal 23,则判断是不是处理人
  4211. if (isset($data['deal']) && ($data['deal'] == 3) && $type_id != 10000) {
  4212. $complaintInof = Complaint::where('id', $data['id'])
  4213. ->where('real_deal_user', $user_id)
  4214. ->first();
  4215. if (empty($complaintInof)) {
  4216. return Result::error("处理人错误", 0);
  4217. }
  4218. }
  4219. $complaintInfo = Complaint::where('id', $data['id'])->first();
  4220. if($data['status']==2 && !isset($data['deal'])){
  4221. $this->sendMessage([
  4222. 'talk_type'=>801,
  4223. 'title'=>$complaintInfo['title'],
  4224. 'content'=>'审核通过',
  4225. 'messageType'=>6,
  4226. 'user_id'=>$complaintInfo['user_id'],
  4227. ]);
  4228. $this->sendMessage([
  4229. 'talk_type'=>802,
  4230. 'title'=>$complaintInfo['title'],
  4231. 'content'=>'待处理',
  4232. 'messageType'=>6,
  4233. 'user_id'=>$complaintInfo['re_user_ids'],
  4234. ]);
  4235. }
  4236. if($data['status']==3 && !isset($data['deal'])){
  4237. $this->sendMessage([
  4238. 'talk_type'=>801,
  4239. 'title'=>$complaintInfo['title'],
  4240. 'content'=>'审核拒绝',
  4241. 'messageType'=>6,
  4242. 'user_id'=>$complaintInfo['user_id'],
  4243. ]);
  4244. }
  4245. if($data['status']==2 && isset($data['deal']) && $data['deal']==2){
  4246. $this->sendMessage([
  4247. 'talk_type'=>802,
  4248. 'title'=>$complaintInfo['title'],
  4249. 'content'=>'处理中',
  4250. 'messageType'=>6,
  4251. 'user_id'=>$complaintInfo['re_user_ids'],
  4252. ]);
  4253. }
  4254. if($data['status']==2 && isset($data['deal']) && $data['deal']==4){
  4255. $this->sendMessage([
  4256. 'talk_type'=>802,
  4257. 'title'=>$complaintInfo['title'],
  4258. 'content'=>'不予处理',
  4259. 'messageType'=>6,
  4260. 'user_id'=>$complaintInfo['re_user_ids'],
  4261. ]);
  4262. }
  4263. if($data['status']==2 && isset($data['deal']) && $data['deal']==3){
  4264. $this->sendMessage([
  4265. 'talk_type'=>802,
  4266. 'title'=>$complaintInfo['title'],
  4267. 'content'=>'已完结',
  4268. 'messageType'=>6,
  4269. 'user_id'=>$complaintInfo['re_user_ids'],
  4270. ]);
  4271. }
  4272. $result = complaint::where('id', $data['id'])->update($data);
  4273. return Result::success($result);
  4274. }
  4275. public function updateGoodStatus(array $data): array
  4276. {
  4277. $user_id = $data['user_id'] ?? 0;
  4278. $type_id = $data['type_id'] ?? 0;
  4279. unset($data['user_id']);
  4280. unset($data['type_id']);
  4281. $goodInfo = Good::where('id', $data['id'])->first();
  4282. if($data['status']==2){
  4283. $this->sendMessage([
  4284. 'talk_type'=>201,
  4285. 'title'=>$goodInfo['name'],
  4286. 'content'=>'审核通过',
  4287. 'messageType'=>3,
  4288. 'user_id'=>$goodInfo['user_id'],
  4289. ]);
  4290. }
  4291. if($data['status']==3){
  4292. $this->sendMessage([
  4293. 'talk_type'=>201,
  4294. 'title'=>$goodInfo['name'],
  4295. 'content'=>'审核拒绝',
  4296. 'messageType'=>3,
  4297. 'user_id'=>$goodInfo['user_id'],
  4298. ]);
  4299. }
  4300. $result = Good::where('id', $data['id'])->update($data);
  4301. return Result::success($result);
  4302. }
  4303. public function updateJobHuntingStatus(array $data): array
  4304. {
  4305. $user_id = $data['user_id'] ?? 0;
  4306. $type_id = $data['type_id'] ?? 0;
  4307. unset($data['user_id']);
  4308. unset($data['type_id']);
  4309. $result = JobHunting::where('id', $data['id'])->update($data);
  4310. return Result::success($result);
  4311. }
  4312. public function updateNoticeStatus(array $data): array
  4313. {
  4314. $user_id = $data['user_id'] ?? 0;
  4315. $type_id = $data['type_id'] ?? 0;
  4316. unset($data['user_id']);
  4317. unset($data['type_id']);
  4318. $result = Notice::where('id', $data['id'])->update($data);
  4319. $noticeInfo = Notice::where('id', $data['id'])->first();
  4320. if($data['status']==2){
  4321. $this->sendMessage([
  4322. 'talk_type'=>701,
  4323. 'title'=>$noticeInfo['title'],
  4324. 'content'=>'审核通过',
  4325. 'messageType'=>3,
  4326. 'user_id'=>$noticeInfo['user_id'],
  4327. ]);
  4328. }
  4329. if($data['status']==3){
  4330. $this->sendMessage([
  4331. 'talk_type'=>701,
  4332. 'title'=>$noticeInfo['title'],
  4333. 'content'=>'审核拒绝',
  4334. 'messageType'=>3,
  4335. 'user_id'=>$noticeInfo['user_id'],
  4336. ]);
  4337. }
  4338. return Result::success($result);
  4339. }
  4340. public function getDUser(array $data): array
  4341. {
  4342. if (!empty($data['ids'])) {
  4343. $user = User::whereIn('id', $data['ids'])->getall();
  4344. if (empty($user)) {
  4345. return Result::error('无数据', 0);
  4346. }
  4347. return Result::success($user);
  4348. }
  4349. $where = [];
  4350. if (!empty($data['department_id'])) {
  4351. $where['department_id'] = $data['department_id'];
  4352. }
  4353. if (!empty($data['city_id'])) {
  4354. $where['city_id'] = $data['city_id'];
  4355. }
  4356. $result = User::where('type_id', 2)
  4357. ->where('status', 1)
  4358. ->where($where)
  4359. ->leftJoin('user_info', 'user.id', '=', 'user_info.user_id')
  4360. ->get();
  4361. if (empty($result)) {
  4362. return Result::error("查询失败", 0);
  4363. }
  4364. return Result::success($result);
  4365. }
  4366. /**
  4367. * 验证导航名称是否重复
  4368. * @return void
  4369. */
  4370. public function checkCategoryName(array $data): array
  4371. {
  4372. $result = Category::when($data, function ($query) use ($data) {
  4373. if (isset($data['name']) && $data['name']) {
  4374. $query->where("name", $data['name']);
  4375. }
  4376. if (isset($data['id']) && $data['id']) {
  4377. $query->where("id", "!=", $data['id']);
  4378. }
  4379. })->first();
  4380. if ($result) {
  4381. return Result::error("已存在");
  4382. } else {
  4383. return Result::success();
  4384. }
  4385. }
  4386. //20250226 产品列表
  4387. // 20250306 -------招聘--------fr
  4388. /*
  4389. * 招聘列表
  4390. * */
  4391. public function getJobRecruitingList(array $data): array
  4392. {
  4393. $where = [];
  4394. // 状态 0:待审核;1:已审核通过;(只有企业会员需要审核);2:已拒绝;3;已撤回;
  4395. if ($data['checkout'] == 0) {
  4396. $job_status = [0, 2];
  4397. } else {
  4398. $job_status = [1];
  4399. }
  4400. if (isset($data['keyword']) && !empty($data['keyword'])) {
  4401. array_push($where, ['job_recruiting.title', 'like', '%' . $data['keyword'] . '%']);
  4402. }
  4403. $user = User::where('id', $data['user_id'])->first();
  4404. if (empty($user)) {
  4405. return Result::error("用户不存在", 0);
  4406. }
  4407. // 3:企业会员
  4408. if ($user['type_id'] == 3) {
  4409. array_push($where, ['job_recruiting.user_id', $data['user_id']]);
  4410. array_push($where, ['job_recruiting.website_id', $data['website_id']]);
  4411. }
  4412. // 如果 $where 为空,则不添加 where 条件
  4413. $result['rows'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4414. return $query->where($where);
  4415. })
  4416. ->whereIn('job_recruiting.status', $job_status)
  4417. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4418. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  4419. ->select('job_recruiting.*', 'website.website_name as website_name', 'user.user_name as user_name')
  4420. ->orderBy("updated_at", "desc")
  4421. ->offset(($data['page'] - 1) * $data['page_size'])
  4422. ->limit($data['page_size'])
  4423. ->get()
  4424. ->all();
  4425. $result['count'] = JobRecruiting::when(!empty($where), function ($query) use ($where) {
  4426. return $query->where($where);
  4427. })
  4428. ->whereIn('job_recruiting.status', $job_status)
  4429. ->count();
  4430. if (empty($result)) {
  4431. return Result::error("暂无招聘信息", 0);
  4432. }
  4433. return Result::success($result);
  4434. }
  4435. /*
  4436. * 招聘信息添加
  4437. * */
  4438. public function addJobRecruiting(array $data): array
  4439. {
  4440. // return Result::success($data);
  4441. $user = User::where('user.id', $data['user_id'])
  4442. ->where('user.status', 1)
  4443. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  4444. ->select(
  4445. 'user.type_id',
  4446. 'user.mobile',
  4447. 'user.email',
  4448. 'user_info.business_name',
  4449. 'user_info.company_hy_id',
  4450. 'user_info.company_nature',
  4451. 'user_info.company_size',
  4452. 'user_info.introduction',
  4453. 'user_info.real_name',
  4454. 'user_info.company_url',
  4455. 'user_info.address_arr_id',
  4456. 'user_info.address'
  4457. )
  4458. ->first();
  4459. if (empty($user) || $user['type_id'] != $data['user_type']) {
  4460. return Result::error("用户不存在", 0);
  4461. }
  4462. $web = Website::where('id', $data['website_id'])->first();
  4463. if (empty($web)) {
  4464. return Result::error("网站不存在", 0);
  4465. }
  4466. // return Result::success($user);
  4467. $data['action_id'] = $data['user_id'];
  4468. $data['user_type'] = $user['type_id'];
  4469. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  4470. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  4471. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  4472. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  4473. // 公司地址 管理员必填
  4474. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  4475. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4476. // 管理员-企业相关信息
  4477. $company = [
  4478. // 'user_id' => $data['user_id']?? null,
  4479. 'business_name' => $data['business_name'] ?? null,
  4480. 'company_hy_id' => $data['company_hy_id'] ?? null,
  4481. 'company_size' => $data['company_size'] ?? null,
  4482. 'company_nature' => $data['company_nature'] ?? null,
  4483. 'introduction' => $data['introduction'] ?? null,
  4484. 'real_name' => $data['real_name'] ?? null,
  4485. 'mobile' => $data['mobile'] ?? null,
  4486. 'company_url' => $data['company_url'] ?? null,
  4487. 'address_arr_id' => $data['address_arr_id'] ?? null,
  4488. 'address' => $data['address'] ?? null,
  4489. 'email' => $data['email'] ?? null,
  4490. ];
  4491. //去掉相关企业信息
  4492. $job = array_diff_key($data, array_flip(array_keys($company)));
  4493. Db::beginTransaction();
  4494. try {
  4495. // 先添加职位相关信息
  4496. if ($user['type_id'] == 10000) {
  4497. $job['status'] = 1;
  4498. }
  4499. if (empty($data['experience']) || $data['experience'] == '') {
  4500. $job['experience'] = null;
  4501. } else {
  4502. $job['experience'] = $data['experience'];
  4503. }
  4504. $jobId = JobRecruiting::insertGetId($job);
  4505. if (empty($jobId)) {
  4506. Db::rollBack();
  4507. return Result::error("添加失败");
  4508. }
  4509. // 添加公司信息
  4510. $company['user_id'] = $data['user_id'] ?? null;
  4511. $company['job_id'] = $jobId;
  4512. $company['user_type'] = $user['type_id'] ?? null;
  4513. $company['website_id'] = $data['website_id'] ?? null;
  4514. if ($user['type_id'] == 10000) {
  4515. // 管理员添加企业信息
  4516. // return Result::success($company);
  4517. $companyId = JobCompany::insertGetId($company);
  4518. if (empty($companyId)) {
  4519. Db::rollBack();
  4520. return Result::error("添加失败");
  4521. }
  4522. } else {
  4523. // 企业会员添加企业信息
  4524. $company = [
  4525. 'user_id' => $data['user_id'] ?? null,
  4526. 'business_name' => $user['business_name'] ?? null,
  4527. 'company_hy_id' => $user['company_hy_id'] ?? null,
  4528. 'company_size' => $user['company_size'] ?? null,
  4529. 'company_nature' => $user['company_nature'] ?? null,
  4530. 'introduction' => $user['introduction'] ?? null,
  4531. 'real_name' => $user['real_name'] ?? null,
  4532. 'mobile' => $user['mobile'] ?? null,
  4533. 'company_url' => $user['company_url'] ?? null,
  4534. 'address_arr_id' => $user['address_arr_id'] ?? null,
  4535. 'address' => $user['address'] ?? null,
  4536. 'email' => $user['email'] ?? null,
  4537. 'website_id' => $data['website_id'] ?? null,
  4538. 'user_type' => $user['type_id'] ?? null,
  4539. 'job_id' => $jobId,
  4540. ];
  4541. $companyId = JobCompany::insertGetId($company);
  4542. if (empty($companyId)) {
  4543. Db::rollBack();
  4544. return Result::error("添加失败");
  4545. }
  4546. // return Result::success($company);
  4547. }
  4548. Db::commit();
  4549. } catch (\Exception $e) {
  4550. Db::rollBack();
  4551. return Result::error($e->getMessage(), 0);
  4552. }
  4553. $result = [
  4554. 'job_id' => $jobId,
  4555. 'company_id' => $companyId,
  4556. ];
  4557. if (empty($result)) {
  4558. return Result::error("添加失败", 0);
  4559. }
  4560. return Result::success($result);
  4561. }
  4562. /*
  4563. * 获取招聘信息详情
  4564. * */
  4565. public function getJobRecruitingInfo(array $data): array
  4566. {
  4567. $result = JobRecruiting::where('job_recruiting.id', $data['id'])
  4568. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  4569. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  4570. ->select(
  4571. 'job_recruiting.*',
  4572. 'website.website_name as website_name',
  4573. 'job_company.business_name',
  4574. 'job_company.company_hy_id',
  4575. 'job_company.company_size',
  4576. 'job_company.company_nature',
  4577. 'job_company.introduction',
  4578. 'job_company.real_name',
  4579. 'job_company.mobile',
  4580. 'job_company.company_url',
  4581. 'job_company.address_arr_id',
  4582. 'job_company.address',
  4583. 'job_company.email'
  4584. )
  4585. ->first();
  4586. $cityId = json_decode($result['city_arr_id'], true) ?? [];
  4587. if (!empty($cityId)) {
  4588. if (isset($cityId[1]) && $cityId[1] != null) {
  4589. $city = District::where('id', $cityId[1])->first(['name']);
  4590. } else {
  4591. $city = District::where('id', $cityId[0])->first(['name']);
  4592. }
  4593. $result['city'] = $city['name'] ?? '';
  4594. }
  4595. $addressId = json_decode($result['address_arr_id'], true) ?? [];
  4596. if (is_array($addressId) && !empty($addressId)) {
  4597. $address = District::whereIn('id', $addressId)
  4598. ->orderBy('level', 'asc')
  4599. ->get(['name'])
  4600. ->pluck('name')
  4601. ->implode('');
  4602. // $job->address_name = $address ?? '';
  4603. $result['address_name'] = ($address ?? '') . ($result['address'] ?? '');
  4604. }
  4605. if (empty($result)) {
  4606. return Result::error("招聘信息不存在", 0);
  4607. }
  4608. // return Result::success($job);
  4609. return Result::success($result);
  4610. }
  4611. /*
  4612. * 修改招聘信息
  4613. * */
  4614. public function upJobRecruiting(array $data): array
  4615. {
  4616. $job = JobRecruiting::where('job_recruiting.id', $data['id'])->first();
  4617. // return Result::success($job);
  4618. if (empty($job)) {
  4619. return Result::error("招聘信息不存在", 0);
  4620. }
  4621. $user = User::where('id', $data['user_id'])->first();
  4622. // return Result::success($user);
  4623. if (empty($user) || $user['type_id'] != $data['user_type']) {
  4624. return Result::error("用户不存在", 0);
  4625. }
  4626. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  4627. return Result::error("用户暂无权限修改此招聘信息!", 0);
  4628. }
  4629. $data['cat_arr_id'] = array_values(array_unique($data['cat_arr_id']));
  4630. $data['city_arr_id'] = array_values(array_unique($data['city_arr_id']));
  4631. $data['cat_arr_id'] = isset($data['cat_arr_id']) ? json_encode(array_map('intval', $data['cat_arr_id'])) : '';
  4632. $data['city_arr_id'] = isset($data['city_arr_id']) ? json_encode(array_map('intval', $data['city_arr_id'])) : '';
  4633. // 公司地址 管理员必填
  4634. $data['address_arr_id'] = array_values(array_unique($data['address_arr_id']));
  4635. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4636. // 管理员-企业相关信息
  4637. $company = [
  4638. 'business_name' => $data['business_name'] ?? null,
  4639. 'company_hy_id' => $data['hy_id'] ?? null,
  4640. 'company_size' => $data['company_size'] ?? null,
  4641. 'company_nature' => $data['company_nature'] ?? null,
  4642. 'introduction' => $data['introduction'] ?? null,
  4643. 'real_name' => $data['real_name'] ?? null,
  4644. 'mobile' => $data['mobile'] ?? null,
  4645. 'company_url' => $data['company_url'] ?? null,
  4646. 'address_arr_id' => $data['address_arr_id'] ?? null,
  4647. 'address' => $data['address'] ?? null,
  4648. 'email' => $data['email'] ?? null,
  4649. ];
  4650. //去掉相关企业信息
  4651. $data = array_diff_key($data, array_flip(array_keys($company)));
  4652. $jobId = $data['id'];
  4653. $web = $data['website_id'];
  4654. $data['action_id'] = $data['user_id'];
  4655. unset($data['user_id']);
  4656. unset($data['user_type']);
  4657. unset($data['id']);
  4658. unset($data['website_id']);
  4659. // return Result::success($data);
  4660. Db::beginTransaction();
  4661. try {
  4662. // 管理员修改招聘信息
  4663. if ($user['type_id'] == 10000) {
  4664. $data['website_id'] = $web;
  4665. $company['website_id'] = $data['website_id'];
  4666. $data['status'] = 1;
  4667. } else {
  4668. $data['status'] = 0;
  4669. }
  4670. if (empty($data['experience']) || $data['experience'] == '') {
  4671. $job['experience'] = null;
  4672. } else {
  4673. $job['experience'] = $data['experience'];
  4674. }
  4675. // Db::rollBack();
  4676. // return Result::success($company);
  4677. $result['job'] = JobRecruiting::where('id', $jobId)->update($data);
  4678. if (empty($result['job'])) {
  4679. Db::rollBack();
  4680. return Result::error("修改招聘信息失败");
  4681. }
  4682. // 管理员修改企业相关信息
  4683. $result['company'] = JobCompany::where('job_id', $jobId)->update($company);
  4684. if (empty($result['company'])) {
  4685. Db::rollBack();
  4686. return Result::error("修改企业相关信息失败");
  4687. }
  4688. Db::commit();
  4689. // return Result::success($result);
  4690. } catch (\Exception $e) {
  4691. Db::rollBack();
  4692. return Result::error($e->getMessage(), 0);
  4693. }
  4694. return Result::success($result);
  4695. }
  4696. /*
  4697. * 招聘信息删除
  4698. * */
  4699. public function delJobRecruiting(array $data): array
  4700. {
  4701. $user = User::where('id', $data['user_id'])->first();
  4702. if (empty($user)) {
  4703. return Result::error("用户不存在", 0);
  4704. }
  4705. $job = JobRecruiting::where('id', $data['id'])->first();
  4706. if (empty($job)) {
  4707. return Result::error("招聘信息不存在", 0);
  4708. }
  4709. if ($user['type_id'] == 3 && $job['user_id'] != $user['id']) {
  4710. return Result::error("用户暂无权限修改此招聘信息!", 0);
  4711. }
  4712. Db::beginTransaction();
  4713. try {
  4714. $result['job'] = JobRecruiting::where('id', $data['id'])->delete();
  4715. if (empty($result['job'])) {
  4716. Db::rollBack();
  4717. return Result::error("删除招聘信息失败");
  4718. }
  4719. $result['company'] = JobCompany::where('job_id', $data['id'])->delete();
  4720. if (empty($result['company'])) {
  4721. Db::rollBack();
  4722. return Result::error("删除企业相关信息失败");
  4723. }
  4724. Db::commit();
  4725. } catch (\Exception $e) {
  4726. Db::rollBack();
  4727. return Result::error($e->getMessage(), 0);
  4728. }
  4729. return Result::success($result);
  4730. }
  4731. /*
  4732. * 获取公司信息
  4733. * */
  4734. public function getJobCompany(array $data): array
  4735. {
  4736. $user = User::where('user.id', $data['user_id'])
  4737. ->leftJoin('user_info', 'user_info.user_id', 'user.id')
  4738. ->select('user.user_name', 'user.mobile', 'user.email', 'user.type_id', 'user_info.*')
  4739. ->first();
  4740. // return Result::success($user);
  4741. if (empty($user)) {
  4742. return Result::error("用户不存在", 0);
  4743. }
  4744. if ($user['type_id'] == 3) {
  4745. $result = [
  4746. // 'id' => 0,
  4747. 'user_id' => $data['user_id'],
  4748. 'website_id' => $data['website_id'],
  4749. 'business_name' => $user['business_name'], // 企业名称
  4750. 'company_hy_id' => $user['company_hy_id'], // 企业所属行业
  4751. 'company_nature' => $user['company_nature'], // 公司性质
  4752. 'company_size' => $user['company_size'], // 公司规模
  4753. 'introduction' => $user['introduction'], // 公司简介
  4754. 'real_name' => $user['real_name'], // 企业联系人
  4755. 'mobile' => $user['mobile'], // 企业联系电话
  4756. 'company_url' => $user['company_url'], // 企业网址
  4757. 'address_arr_id' => $user['address_arr_id'], // 企业网址
  4758. 'address' => $user['address'], // 企业地址
  4759. 'email' => $user['email'], // 企业邮箱
  4760. ];
  4761. } else {
  4762. return Result::error("用户类型错误", 0);
  4763. }
  4764. if (empty($result)) {
  4765. return Result::error("公司信息不存在", 0);
  4766. }
  4767. return Result::success($result);
  4768. }
  4769. /*
  4770. * 修改公司信息
  4771. * */
  4772. public function upJobCompany(array $data): array
  4773. {
  4774. // return Result::success($data);
  4775. $user = User::where('user.id', $data['user_id'])
  4776. ->where('user.status', 1)
  4777. ->select('user.user_name', 'user.type_id')
  4778. ->first();
  4779. if (empty($user)) {
  4780. return Result::error("用户不存在", 0);
  4781. }
  4782. $data['address_arr_id'] = isset($data['address_arr_id']) ? json_encode(array_map('intval', $data['address_arr_id'])) : '';
  4783. $company = [
  4784. 'business_name' => $data['business_name'], // 企业名称
  4785. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  4786. 'company_nature' => $data['company_nature'], // 公司性质
  4787. 'company_size' => $data['company_size'], // 公司规模
  4788. 'introduction' => $data['introduction'], // 公司简介
  4789. // 'real_name' => $data['real_name'], // 企业联系人
  4790. 'company_url' => $data['company_url'], // 企业网址
  4791. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  4792. 'address' => $data['address'], // 企业详细地址
  4793. ];
  4794. if ($user['type_id'] == 3) {
  4795. Db::beginTransaction();
  4796. try {
  4797. $result['userinfo'] = UserInfo::where('user_id', $data['user_id'])->update([
  4798. 'business_name' => $data['business_name'], // 企业名称
  4799. 'company_hy_id' => $data['company_hy_id'], // 企业所属行业
  4800. 'company_nature' => $data['company_nature'], // 公司性质
  4801. 'company_size' => $data['company_size'], // 公司规模
  4802. 'introduction' => $data['introduction'], // 公司简介
  4803. // 'real_name' => $data['real_name'], // 企业联系人
  4804. 'company_url' => $data['company_url'], // 企业网址
  4805. 'address_arr_id' => $data['address_arr_id'], // 企业地址
  4806. 'address' => $data['address'], // 企业详细地址
  4807. ]);
  4808. $result['job_company'] = JobCompany::where('user_id', $data['user_id'])->update($company);
  4809. Db::commit();
  4810. } catch (\Exception $e) {
  4811. Db::rollBack();
  4812. return Result::error($e->getMessage(), 0);
  4813. }
  4814. } else {
  4815. return Result::error("用户类型错误", 0);
  4816. }
  4817. if (empty($result)) {
  4818. return Result::error("修改失败", 0);
  4819. }
  4820. return Result::success($result);
  4821. }
  4822. /*
  4823. * 获取省-市
  4824. * */
  4825. public function getJobRecruitingArea(array $data): array
  4826. {
  4827. if (isset($data['pid']) && $data['pid'] != null) {
  4828. $result = District::where('pid', $data['pid'])->get()->all();
  4829. } else {
  4830. $result = District::where('level', 1)->get()->all();
  4831. }
  4832. if (empty($result)) {
  4833. return Result::error("暂无此省市", 0);
  4834. }
  4835. return Result::success($result);
  4836. }
  4837. /*
  4838. * 获取行业分类
  4839. * */
  4840. public function getIndustry(array $data): array
  4841. {
  4842. $result = JobIndustry::get()->all();
  4843. if (empty($result)) {
  4844. return Result::error("暂无行业分类", 0);
  4845. }
  4846. return Result::success($result);
  4847. }
  4848. /*
  4849. * 获取职位
  4850. * */
  4851. public function getPositionList(array $data): array
  4852. {
  4853. if (isset($data['zwpid']) && $data['zwpid'] != null) {
  4854. $result = JobPosition::where('zwpid', $data['zwpid'])->get()->all();
  4855. } else {
  4856. $result = JobPosition::where('zwpid', 0)->get()->all();
  4857. }
  4858. if (empty($result)) {
  4859. return Result::error("暂无此职位", 0);
  4860. }
  4861. return Result::success($result);
  4862. }
  4863. /*
  4864. * 获取工作性质-菜单
  4865. * */
  4866. public function getJobNature(array $data): array
  4867. {
  4868. $result = JobEnum::where('egroup', 'nature')->get()->all();
  4869. if (empty($result)) {
  4870. return Result::error("暂无工作性质", 0);
  4871. }
  4872. return Result::success($result);
  4873. }
  4874. /*
  4875. * 获取工作经验-菜单
  4876. * */
  4877. public function getExperience(array $data): array
  4878. {
  4879. $result = JobEnum::where('egroup', 'years')->get()->all();
  4880. if (empty($result)) {
  4881. return Result::error("暂无工作经验", 0);
  4882. }
  4883. return Result::success($result);
  4884. }
  4885. /*
  4886. * 获取学历-菜单
  4887. * */
  4888. public function getEducation(array $data): array
  4889. {
  4890. $result = JobEnum::where('egroup', 'education')->get()->all();
  4891. if (empty($result)) {
  4892. return Result::error("暂无学历", 0);
  4893. }
  4894. return Result::success($result);
  4895. }
  4896. /*
  4897. * 获取薪资-菜单
  4898. * */
  4899. public function getSalary(array $data): array
  4900. {
  4901. $result = JobEnum::where('egroup', 'income')->get()->all();
  4902. if (empty($result)) {
  4903. return Result::error("暂无薪资", 0);
  4904. }
  4905. return Result::success($result);
  4906. }
  4907. /*
  4908. * 获取语言-菜单
  4909. * */
  4910. public function getLanguage(array $data): array
  4911. {
  4912. $result = JobEnum::where('egroup', 'language')->get()->all();
  4913. if (empty($result)) {
  4914. return Result::error("暂无语言", 0);
  4915. }
  4916. return Result::success($result);
  4917. }
  4918. /*
  4919. * 获取掌握程度-菜单
  4920. * */
  4921. public function getLevel(array $data): array
  4922. {
  4923. $result = JobEnum::where('egroup', 'languagetype')->get()->all();
  4924. if (empty($result)) {
  4925. return Result::error("暂无工作性质", 0);
  4926. }
  4927. return Result::success($result);
  4928. }
  4929. // 公司信息
  4930. /*
  4931. * 获取公司性质-菜单
  4932. * */
  4933. public function getCompanyNature(array $data): array
  4934. {
  4935. $result = JobNature::get()->all();
  4936. if (empty($result)) {
  4937. return Result::error("暂无公司性质", 0);
  4938. }
  4939. return Result::success($result);
  4940. }
  4941. /*
  4942. * 获取公司规模-菜单
  4943. * */
  4944. public function getCompanySize(array $data): array
  4945. {
  4946. $result = JobEnum::where('egroup', 'cosize')->get()->all();
  4947. if (empty($result)) {
  4948. return Result::error("暂无公司规模", 0);
  4949. }
  4950. return Result::success($result);
  4951. }
  4952. /*
  4953. * 招聘信息审核
  4954. * */
  4955. public function checkJobRecruiting(array $data): array
  4956. {
  4957. $user = User::where('id', $data['user_id'])->first();
  4958. if (empty($user)) {
  4959. return Result::error("用户不存在", 0);
  4960. }
  4961. $job = JobRecruiting::where('id', $data['id'])->first();
  4962. if (empty($job)) {
  4963. return Result::error("招聘信息不存在", 0);
  4964. }
  4965. // 状态 0:待审核;1:已审核通过;;2:已驳回;
  4966. if ($user['type_id'] != 10000) {
  4967. return Result::error("用户暂无权限审核此招聘信息!", 0);
  4968. }
  4969. // 驳回原因
  4970. if ($data['status'] == 2) {
  4971. $data['refuse_reason'] = $data['refuse_reason'] ?? null;
  4972. }
  4973. $data['action_id'] = $data['user_id'];
  4974. unset($data['user_id']);
  4975. $result = JobRecruiting::where('id', $data['id'])->update($data);
  4976. if (empty($result)) {
  4977. return Result::error("审核失败", 0);
  4978. }
  4979. return Result::success($result);
  4980. }
  4981. public function myApplyList(array $data): array
  4982. {
  4983. var_dump($data, '------参数');
  4984. $user = User::where('id', $data['user_id'])->first();
  4985. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  4986. return Result::error("用户不存在", 0);
  4987. }
  4988. // 1:个人会员 职场机会
  4989. if ($user['type_id'] == 1) {
  4990. $where['user_id'] = $user['id'];
  4991. }
  4992. $recruitingId = JobApply::when($user['type_id'] == 1, function ($query) use ($user) {
  4993. $query->where('user_id', $user['id']);
  4994. })
  4995. ->pluck('recruit_id');
  4996. $where = [];
  4997. if (isset($data['salary']) && $data['salary'] != null) {
  4998. $where['job_recruiting.salary'] = $data['salary'];
  4999. }
  5000. if (isset($data['experience']) && $data['experience'] != null) {
  5001. $where['job_recruiting.experience'] = $data['experience'];
  5002. }
  5003. if (isset($data['business_name']) && $data['business_name'] != null) {
  5004. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  5005. }
  5006. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  5007. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5008. ->where($where);
  5009. // ->count();
  5010. $count = $query->count();
  5011. $query = clone $query;
  5012. $job = $query
  5013. ->leftJoin('job_enum as income_enum', function ($join) {
  5014. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  5015. ->where('income_enum.egroup', 'income');
  5016. })
  5017. ->leftJoin('job_enum as years_enum', function ($join) {
  5018. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  5019. ->where('years_enum.egroup', 'years');
  5020. })
  5021. // ->where($where)
  5022. ->orderBy('job_recruiting.updated_at', 'desc')
  5023. ->select(
  5024. 'job_recruiting.id',
  5025. 'job_recruiting.title',
  5026. 'job_company.business_name',
  5027. 'income_enum.evalue as salary_evalue',
  5028. 'income_enum.ename as salary_ename',
  5029. 'years_enum.evalue as experience_evalue',
  5030. 'years_enum.ename as experience_ename',
  5031. 'job_recruiting.updated_at'
  5032. )
  5033. ->offset(($data['page'] - 1) * $data['pageSize'])
  5034. ->limit($data['pageSize'])
  5035. ->get()
  5036. ->all();
  5037. if (empty($job)) {
  5038. return Result::error("暂无招聘信息", 0);
  5039. }
  5040. $result = [
  5041. 'row' => $job,
  5042. 'count' => $count,
  5043. ];
  5044. return Result::success($result);
  5045. }
  5046. /*
  5047. * 获取招聘信息列表-职场机会(个人会员收到企业推送岗位)
  5048. * */
  5049. public function getRecruitingList(array $data): array
  5050. {
  5051. $user = User::where('id', $data['user_id'])->first();
  5052. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5053. return Result::error("用户不存在", 0);
  5054. }
  5055. // 1:个人会员 职场机会
  5056. if ($user['type_id'] == 1) {
  5057. $where['user_id'] = $user['id'];
  5058. }
  5059. $recruitingId = JobResume::when($user['type_id'] == 1, function ($query) use ($user) {
  5060. $query->where('receiver_id', $user['id']);
  5061. })
  5062. ->pluck('recruit_id');
  5063. // return Result::success($recruitingId);
  5064. $where = [];
  5065. if (isset($data['salary']) && $data['salary'] != null) {
  5066. $where['job_recruiting.salary'] = $data['salary'];
  5067. }
  5068. if (isset($data['experience']) && $data['experience'] != null) {
  5069. $where['job_recruiting.experience'] = $data['experience'];
  5070. }
  5071. if (isset($data['business_name']) && $data['business_name'] != null) {
  5072. array_push($where, ['job_company.business_name', 'like', '%' . $data['business_name'] . '%']);
  5073. }
  5074. $query = JobRecruiting::whereIn('job_recruiting.id', $recruitingId)
  5075. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5076. ->where($where);
  5077. // ->count();
  5078. $count = $query->count();
  5079. $query = clone $query;
  5080. $job = $query
  5081. ->leftJoin('job_enum as income_enum', function ($join) {
  5082. $join->on('job_recruiting.salary', '=', 'income_enum.evalue')
  5083. ->where('income_enum.egroup', 'income');
  5084. })
  5085. ->leftJoin('job_enum as years_enum', function ($join) {
  5086. $join->on('job_recruiting.experience', '=', 'years_enum.evalue')
  5087. ->where('years_enum.egroup', 'years');
  5088. })
  5089. // ->where($where)
  5090. ->orderBy('job_recruiting.updated_at', 'desc')
  5091. ->select(
  5092. 'job_recruiting.id',
  5093. 'job_recruiting.title',
  5094. 'job_company.business_name',
  5095. 'income_enum.evalue as salary_evalue',
  5096. 'income_enum.ename as salary_ename',
  5097. 'years_enum.evalue as experience_evalue',
  5098. 'years_enum.ename as experience_ename',
  5099. 'job_recruiting.updated_at'
  5100. )
  5101. ->offset(($data['page'] - 1) * $data['pageSize'])
  5102. ->limit($data['pageSize'])
  5103. ->get()
  5104. ->all();
  5105. if (empty($job)) {
  5106. return Result::error("暂无招聘信息", 0);
  5107. }
  5108. $result = [
  5109. 'row' => $job,
  5110. 'count' => $count,
  5111. ];
  5112. return Result::success($result);
  5113. }
  5114. /*
  5115. * 获取企业会员-招聘信息列表
  5116. * */
  5117. public function getRecruitingInfo(array $data): array
  5118. {
  5119. $user = User::where('id', $data['user_id'])->first();
  5120. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 1)) {
  5121. return Result::error("用户不存在", 0);
  5122. }
  5123. $recruiting = JobRecruiting::where('job_recruiting.id', $data['id'])
  5124. ->leftJoin('job_company', 'job_recruiting.id', '=', 'job_company.job_id')
  5125. ->select(
  5126. 'job_recruiting.*',
  5127. 'job_company.business_name',
  5128. 'job_company.company_hy_id',
  5129. 'job_company.company_size',
  5130. 'job_company.company_nature',
  5131. 'job_company.introduction',
  5132. 'job_company.real_name',
  5133. 'job_company.mobile',
  5134. 'job_company.company_url',
  5135. 'job_company.address_arr_id',
  5136. 'job_company.address',
  5137. 'job_company.email'
  5138. )
  5139. ->get();
  5140. if (empty($recruiting)) {
  5141. return Result::error("暂无招聘信息", 0);
  5142. }
  5143. return Result::success($recruiting);
  5144. }
  5145. /*
  5146. * 获取企业会员-我的沟通
  5147. * */
  5148. public function getJobResumeList(array $data): array
  5149. {
  5150. $user = User::where('id', $data['user_id'])->first();
  5151. if (empty($user) || ($user['type_id'] != 10000 && $user['type_id'] != 3)) {
  5152. return Result::error("用户不存在", 0);
  5153. }
  5154. $where = [];
  5155. if (isset($data['salary']) && $data['salary'] != null) {
  5156. $where['job_hunting.salary'] = $data['salary'];
  5157. }
  5158. if (isset($data['user_name']) && $data['user_name'] != null) {
  5159. array_push($where, ['user.user_name', 'like', '%' . $data['user_name'] . '%']);
  5160. }
  5161. $job = JobResume::when($user['type_id'] == 3, function ($query) use ($user) {
  5162. $query->where('job_resume.user_id', $user['id']);
  5163. })
  5164. ->when(!empty($where), function ($query) use ($where) {
  5165. $query->where($where);
  5166. })
  5167. ->leftJoin('job_hunting', 'job_hunting.id', 'job_resume.hunt_id')
  5168. ->leftJoin('job_recruiting', 'job_recruiting.id', 'job_resume.recruit_id')
  5169. ->leftJoin('user', 'user.id', 'job_resume.receiver_id')
  5170. ->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');
  5171. $count = $job->count();
  5172. if ($count == 0) {
  5173. return Result::error("暂无沟通记录", 0);
  5174. }
  5175. $jobs = $job->orderBy('job_hunting.updated_at', 'desc')
  5176. ->offset(($data['page'] - 1) * $data['pageSize'])
  5177. ->limit($data['pageSize'])
  5178. ->get();
  5179. if (empty($jobs)) {
  5180. return Result::error("暂无沟通记录", 0);
  5181. }
  5182. $result['row'] = $this->processJob($jobs, '');
  5183. $result['count'] = $count;
  5184. return Result::success($result);
  5185. }
  5186. // 20250306 招聘
  5187. //20250422 书刊音像
  5188. public function addBook(array $data): array
  5189. {
  5190. $user_id = $data['user_id'] ?? 0;
  5191. $type_id = $data['type_id'] ?? 0;
  5192. // $website_id = $data['website_id'] ?? 0;
  5193. // unset($data['user_id']);
  5194. unset($data['type_id']);
  5195. // unset($data['website_id']);
  5196. //处理数组
  5197. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  5198. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  5199. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  5200. if ($data['img_url'] == '') {
  5201. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5202. preg_match_all($reg, $data['detail'], $matches);
  5203. if (isset($matches[1][0])) {
  5204. //截取varchar240
  5205. $data['img_url'] = substr($matches[1][0], 0, 240);
  5206. }
  5207. }
  5208. if ($data['keyword'] == '' || $data['keyword'] == array()) {
  5209. //提取标题+内容中的关键词
  5210. $data['keyword'] = $data['title'];
  5211. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5212. Jieba::init(); // 初始化 jieba-php
  5213. Finalseg::init();
  5214. $segList = Jieba::cut($data['keyword']);
  5215. $segList1 = array_slice($segList, 0, 8);
  5216. $data['keyword'] = implode(',', $segList1);
  5217. }
  5218. if ($data['description'] == '') {
  5219. //提取内容中的描述
  5220. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  5221. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  5222. }
  5223. var_dump($data, '--');
  5224. $result = Book::insertGetId($data);
  5225. if (empty($result)) {
  5226. return Result::error("添加失败", 0);
  5227. }
  5228. return Result::success($result);
  5229. }
  5230. public function getBookList(array $data): array
  5231. {
  5232. $where = [];
  5233. if (!empty($data["title"])) {
  5234. $where[] = ['book.title', 'like', '%' . $data["title"] . '%'];
  5235. }
  5236. if (!empty($data['website_name'])) {
  5237. $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
  5238. }
  5239. if (!empty($data['status'])) {
  5240. $where[] = ['book.status', '=', $data['status']];
  5241. }
  5242. $user_id = $data['user_id'];
  5243. $type_id = $data['type_id'];
  5244. // $type_id = 4;
  5245. var_dump($type_id, '------1--------');
  5246. if ($type_id != 10000) {
  5247. $where[] = ['book.user_id', '=', $user_id];
  5248. }
  5249. var_dump(!empty($data['status1']), '=-===1');
  5250. $result = Book::where($where)
  5251. ->leftJoin('website', 'book.website_id', '=', 'website.id')
  5252. ->leftJoin('category', 'book.cat_id', '=', 'category.id')
  5253. ->leftJoin('district', 'book.city_id', '=', 'district.id')
  5254. ->when(isset($data['status1']), function ($query) use ($data) {
  5255. $query->whereIn('book.status', [1, 3]);
  5256. })
  5257. ->select('book.*', 'website.website_name', 'category.name as cat_name', 'district.name as city_name')
  5258. ->orderBy("updated_at", "desc")
  5259. ->paginate($data['page_size'], ['*'], 'page', $data['page']);
  5260. if (empty($result)) {
  5261. return Result::error("暂无数据", 0);
  5262. }
  5263. // 取出数据
  5264. $rows = $result->items();
  5265. $count = $result->total();
  5266. $responseData = [
  5267. 'rows' => $rows,
  5268. 'count' => $count,
  5269. ];
  5270. return Result::success($responseData);
  5271. }
  5272. public function deleteBook(array $data): array
  5273. {
  5274. $result = Book::where('id', $data['id'])->delete();
  5275. if (empty($result)) {
  5276. return Result::error("删除失败", 0);
  5277. }
  5278. return Result::success($result);
  5279. }
  5280. public function updateBook(array $data): array
  5281. {
  5282. // $user_id = $data['user_id'] ?? 0;
  5283. $type_id = $data['type_id'] ?? 0;
  5284. // $website_id = $data['website_id'] ?? 0;
  5285. unset($data['user_id']);
  5286. unset($data['type_id']);
  5287. // unset($data['website_id']);
  5288. //处理数组
  5289. // $data['department_arr_id'] = is_array($data['department_arr_id']) ? Json::encode($data['department_arr_id']) : '[]';
  5290. if ($data['img_url'] == '') {
  5291. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5292. preg_match_all($reg, $data['detail'], $matches);
  5293. if (isset($matches[1][0])) {
  5294. //截取varchar240
  5295. $data['img_url'] = substr($matches[1][0], 0, 240);
  5296. }
  5297. }
  5298. if ($data['keyword'] == '') {
  5299. //提取标题+内容中的关键词
  5300. $data['keyword'] = $data['title'];
  5301. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5302. Jieba::init(); // 初始化 jieba-php
  5303. Finalseg::init();
  5304. $segList = Jieba::cut($data['keyword']);
  5305. $segList1 = array_slice($segList, 0, 8);
  5306. $data['keyword'] = implode(',', $segList1);
  5307. }
  5308. if ($data['description'] == '') {
  5309. //提取内容中的描述
  5310. $cleaned = preg_replace('/\s+/', '', strip_tags(html_entity_decode($data['detail'], ENT_QUOTES, 'UTF-8')));
  5311. $data['description'] = mb_substr($cleaned, 0, 100, 'UTF-8');
  5312. }
  5313. $data['city_arr_id'] = is_array($data['city_arr_id']) ? Json::encode($data['city_arr_id']) : '[]';
  5314. $data['cat_arr_id'] = is_array($data['cat_arr_id']) ? Json::encode($data['cat_arr_id']) : '[]';
  5315. $result = Book::where("id", $data["id"])->update($data);
  5316. if (empty($result)) {
  5317. return Result::error("更新失败", 0);
  5318. }
  5319. return Result::success($result);
  5320. }
  5321. public function getBookInfo(array $data): array
  5322. {
  5323. $result = Book::where("id", $data["id"])->first();
  5324. if (empty($result)) {
  5325. return Result::error("获取失败", 0);
  5326. }
  5327. return Result::success($result);
  5328. }
  5329. public function updateBookStatus(array $data): array
  5330. {
  5331. //审核
  5332. unset($data['user_id']);
  5333. $result = Book::where("id", $data["id"])->update($data);
  5334. if (empty($result)) {
  5335. return Result::error("更新失败", 0);
  5336. }
  5337. return Result::success($result);
  5338. }
  5339. //20250422 书刊音像
  5340. /**
  5341. * 贴身宝贝
  5342. * @param array $data
  5343. * @return array
  5344. */
  5345. public function getWebsiteTsbb(array $data): array
  5346. {
  5347. $month = $data['month'] ?? date('m');
  5348. $day = $data['day'] ?? date('d');
  5349. // 使用缓存键
  5350. $cacheKey = "tsbb_data_{$month}_{$day}";
  5351. // 尝试从缓存获取数据
  5352. $container = \Hyperf\Context\ApplicationContext::getContainer();
  5353. $cache = $container->get(\Psr\SimpleCache\CacheInterface::class);
  5354. if ($cachedData = $cache->get($cacheKey)) {
  5355. return Result::success(unserialize($cachedData));
  5356. }
  5357. //查询老黄历
  5358. try {
  5359. $date = date('Y-m-d');
  5360. $almanacUrl = "https://www.36jxs.com/api/Commonweal/almanac?sun=" . $date;
  5361. // 使用 curl 替代 file_get_contents
  5362. $ch = curl_init();
  5363. curl_setopt($ch, CURLOPT_URL, $almanacUrl);
  5364. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  5365. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  5366. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  5367. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  5368. 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');
  5369. curl_setopt($ch, CURLOPT_HTTPHEADER, [
  5370. 'Accept: application/json',
  5371. 'Content-Type: application/json',
  5372. 'Referer: https://www.36jxs.com/'
  5373. ]);
  5374. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  5375. curl_setopt($ch, CURLOPT_ENCODING, '');
  5376. $almanacResponse = curl_exec($ch);
  5377. var_dump("====:", $almanacResponse);
  5378. if (curl_errno($ch)) {
  5379. var_dump('Curl error:', curl_error($ch));
  5380. throw new \Exception('Curl error: ' . curl_error($ch));
  5381. }
  5382. // $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  5383. curl_close($ch);
  5384. if ($almanacResponse === false) {
  5385. throw new \Exception('Failed to fetch almanac data');
  5386. }
  5387. $almanacData = json_decode($almanacResponse, true);
  5388. if (json_last_error() !== JSON_ERROR_NONE) {
  5389. throw new \Exception('Failed to parse almanac data');
  5390. }
  5391. $almanacInfo = $almanacData['data'] ?? [];
  5392. } catch (\Exception $e) {
  5393. var_dump('Exception:', $e->getMessage());
  5394. $almanacInfo = [];
  5395. }
  5396. // 获取历史上的今天数据
  5397. $historyTodayList = HistoryToday::whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  5398. ->whereRaw("DATE_FORMAT(year, '%d') = ?", [$day])
  5399. ->orderBy('year', 'asc')
  5400. ->select("title", "id", "year", DB::raw('1 as type'))
  5401. ->limit(16)
  5402. ->get();
  5403. // 获取节日数据 - 从今天开始获取未来4条
  5404. $festivalList = Festival::whereRaw("DATE_FORMAT(showtime, '%m-%d') >= ?", [$month . '-' . $day])
  5405. ->orderBy('showtime', 'asc')
  5406. ->select("title", "id", "showtime", DB::raw('2 as type'))
  5407. ->limit(16)
  5408. ->get();
  5409. //说文解字
  5410. $chartacterList = Character::orderBy('updated_at', 'desc')
  5411. ->select("id", "title", "duyin", "bushou", "bihua", DB::raw('3 as type'))
  5412. ->limit(6)
  5413. ->get();
  5414. //谜语沙龙
  5415. $riddletList = Riddle::orderBy('updated_at', 'desc')
  5416. ->select("id", "riddle_title", "riddle_bottom", "prompt", DB::raw('4 as type'))
  5417. ->limit(4)
  5418. ->get();
  5419. //成语欣赏
  5420. $idiomList = Idiom::orderBy('updated_at', 'desc')
  5421. ->select("id", "title", "duyin", DB::raw('5 as type'))
  5422. ->limit(32)
  5423. ->get();
  5424. //名联赏析
  5425. $coupletList = Couplet::orderBy('updated_at', 'desc')
  5426. ->select("id", "first", "second", DB::raw('6 as type'))
  5427. ->limit(6)
  5428. ->get();
  5429. // 获取分类文章数据
  5430. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id'], 'pid' => 0])
  5431. ->pluck('category_id')
  5432. ->toArray();
  5433. $articlesList = [];
  5434. foreach ($categoryIds as $catid) {
  5435. // 先查有图片的
  5436. $withImg = DB::table('article')
  5437. ->where('status', 1)
  5438. ->where('catid', $catid)
  5439. ->whereNotNull('imgurl')
  5440. ->where('imgurl', '!=', '')
  5441. ->orderBy('updated_at', 'desc')
  5442. ->limit(6)
  5443. ->get();
  5444. $count = $withImg->count();
  5445. if ($count < 6) {
  5446. // 不足6条再查无图片的补足
  5447. $withoutImg = DB::table('article')
  5448. ->where('status', 1)
  5449. ->where('catid', $catid)
  5450. ->where(function ($q) {
  5451. $q->whereNull('imgurl')->orWhere('imgurl', '');
  5452. })
  5453. ->orderBy('updated_at', 'desc')
  5454. ->limit(6 - $count)
  5455. ->get();
  5456. $articles = $withImg->concat($withoutImg);
  5457. } else {
  5458. $articles = $withImg;
  5459. }
  5460. // 组装
  5461. $category = \App\Model\Category::find($catid);
  5462. $websiteCategory = WebsiteCategory::where('category_id', $catid)->first();
  5463. $articlesList[] = [
  5464. 'category_name' => $category ? $category->name : '',
  5465. 'catid' => $catid,
  5466. 'pinyin' => $websiteCategory ? $websiteCategory->aLIas_pinyin : '',
  5467. 'type' => 100,
  5468. 'list' => $articles->map(function ($item) {
  5469. return [
  5470. 'id' => $item->id,
  5471. 'title' => $item->title,
  5472. 'imgurl' => $item->imgurl,
  5473. 'created_at' => $item->created_at
  5474. ];
  5475. })->values()
  5476. ];
  5477. }
  5478. $result = [
  5479. 'almanac' => $almanacInfo,
  5480. 'historyTodayList' => [
  5481. 'category_name' => '历史上的今天',
  5482. 'list' => $historyTodayList,
  5483. 'type' => 1
  5484. ],
  5485. 'festivalList' => [
  5486. 'category_name' => '节日预告',
  5487. 'list' => $festivalList,
  5488. 'type' => 2
  5489. ],
  5490. 'chartacterList' => [
  5491. 'category_name' => '说文解字',
  5492. 'list' => $chartacterList,
  5493. 'type' => 3
  5494. ],
  5495. 'coupletList' => [
  5496. 'category_name' => '名联赏析',
  5497. 'list' => $coupletList,
  5498. 'type' => 6
  5499. ],
  5500. 'riddletList' => [
  5501. 'category_name' => '谜语沙龙',
  5502. 'list' => $riddletList,
  5503. 'type' => 4
  5504. ],
  5505. 'idiomList' => [
  5506. 'category_name' => '成语欣赏',
  5507. 'list' => $idiomList,
  5508. 'type' => 5
  5509. ],
  5510. 'articlesList' => $articlesList
  5511. ];
  5512. // 缓存结果,设置1小时过期
  5513. $cache->set($cacheKey, serialize($result), 3600);
  5514. return Result::success($result);
  5515. }
  5516. /**
  5517. * 获取资讯列表
  5518. */
  5519. public function getWebsiteTsbbList(array $data): array
  5520. {
  5521. $page = $data['page'] ?? 1;
  5522. $pageSize = $data['pageSize'] ?? 10;
  5523. // 如果没有传入月份和日期,则使用今天的日期
  5524. $month = $data['month'] ?? date('m');
  5525. $day = $data['day'] ?? date('d');
  5526. $total = 0;
  5527. $result = [];
  5528. $data['type'] = intval($data['type']);
  5529. var_dump("接收参数:", $data);
  5530. switch ($data['type']) {
  5531. case 1:
  5532. $query = HistoryToday::where(function ($q) use ($month, $day) {
  5533. // 当前月份之后的数据
  5534. $q->whereRaw("DATE_FORMAT(year, '%m') > ?", [$month])
  5535. // 或者当前月份且日期大于等于当前日期的数据
  5536. ->orWhere(function ($q) use ($month, $day) {
  5537. $q->whereRaw("DATE_FORMAT(year, '%m') = ?", [$month])
  5538. ->whereRaw("DATE_FORMAT(year, '%d') >= ?", [$day]);
  5539. });
  5540. })
  5541. ->orderByRaw("DATE_FORMAT(year, '%m') ASC, DATE_FORMAT(year, '%d') ASC, year ASC");
  5542. $total = $query->count();
  5543. $result = $query->select("title", "id", "year", "updated_at", DB::raw('1 as type'))
  5544. ->offset(($page - 1) * $pageSize)
  5545. ->limit($pageSize)
  5546. ->get();
  5547. break;
  5548. case 2:
  5549. $query = Festival::where(function ($q) use ($month, $day) {
  5550. // 当前月份之后或者当前月份且日期大于等于当前日期的数据
  5551. $q->whereRaw("DATE_FORMAT(showtime, '%m') > ?", [$month])
  5552. ->orWhere(function ($q) use ($month, $day) {
  5553. $q->whereRaw("DATE_FORMAT(showtime, '%m') = ?", [$month])
  5554. ->whereRaw("DATE_FORMAT(showtime, '%d') >= ?", [$day]);
  5555. });
  5556. })->orderByRaw("DATE_FORMAT(showtime, '%m') ASC, DATE_FORMAT(showtime, '%d') ASC, showtime ASC");
  5557. $total = $query->count();
  5558. $result = $query->select("title", "id", "updated_at", "showtime", DB::raw('2 as type'))
  5559. ->offset(($page - 1) * $pageSize)
  5560. ->limit($pageSize)
  5561. ->get();
  5562. break;
  5563. case 3:
  5564. $query = Character::orderBy("updated_at", "desc");
  5565. $total = $query->count();
  5566. $result = $query->select("title", "id", "updated_at", DB::raw('3 as type'))
  5567. ->offset(($page - 1) * $pageSize)
  5568. ->limit($pageSize)
  5569. ->get();
  5570. break;
  5571. case 4:
  5572. $query = Riddle::orderBy("updated_at", "desc");
  5573. $total = $query->count();
  5574. $result = $query->select("riddle_title as title", "updated_at", "id", DB::raw('4 as type'))
  5575. ->offset(($page - 1) * $pageSize)
  5576. ->limit($pageSize)
  5577. ->get();
  5578. break;
  5579. case 5:
  5580. $query = Idiom::orderBy("updated_at", "desc");
  5581. $total = $query->count();
  5582. $result = $query->select("title", "id", "updated_at", DB::raw('5 as type'))
  5583. ->offset(($page - 1) * $pageSize)
  5584. ->limit($pageSize)
  5585. ->get();
  5586. break;
  5587. case 6:
  5588. $query = Couplet::orderBy("updated_at", "desc");
  5589. $total = $query->count();
  5590. $result = $query->select("first as title", "updated_at", "id", DB::raw('6 as type'))
  5591. ->offset(($page - 1) * $pageSize)
  5592. ->limit($pageSize)
  5593. ->get();
  5594. break;
  5595. default:
  5596. $query = Article::where(['catid' => $data['catid']])->orderBy("updated_at", "desc");
  5597. $total = $query->count();
  5598. $result = $query->select("title", "id", "updated_at", DB::raw('100 as type'))
  5599. ->offset(($page - 1) * $pageSize)
  5600. ->limit($pageSize)
  5601. ->get();
  5602. }
  5603. return Result::success([
  5604. 'list' => $result,
  5605. 'total' => $total,
  5606. 'page' => (int)$page,
  5607. 'pageSize' => (int)$pageSize,
  5608. 'month' => $month,
  5609. 'day' => $day
  5610. ]);
  5611. }
  5612. /**
  5613. * 1:历史上的今天
  5614. * 2:节日
  5615. * 3:文章
  5616. *
  5617. * 资讯详情信息
  5618. */
  5619. public function getWebsiteTsbbDetail(array $data): array
  5620. {
  5621. $data['type'] = intval($data['type']);
  5622. switch ($data['type']) {
  5623. case 1:
  5624. $result = HistoryToday::where("id", $data['id'])->first();
  5625. break;
  5626. case 2:
  5627. $result = Festival::where("id", $data['id'])->first();
  5628. break;
  5629. case 3:
  5630. $result = Character::where("id", $data['id'])->first();
  5631. break;
  5632. case 4:
  5633. $result = Riddle::where("id", $data['id'])->first();
  5634. break;
  5635. case 5:
  5636. $result = Idiom::where("id", $data['id'])->first();
  5637. break;
  5638. case 6:
  5639. $result = Couplet::where("id", $data['id'])->first();
  5640. break;
  5641. default:
  5642. $result = Article::where("id", $data['id'])->select("article.*", "article_data.content")->leftJoin("article_data", "article.id", "=", "article_data.article_id")->first();
  5643. break;
  5644. }
  5645. return Result::success($result);
  5646. }
  5647. /**
  5648. * 农网导航首页数据
  5649. */
  5650. public function getWebsiteNwHomeList(array $data): array
  5651. {
  5652. $categoryIds = WebsiteCategory::where(['website_id' => $data['website_id']])->where("pid", "!=", 0)
  5653. ->pluck('category_id')
  5654. ->toArray();
  5655. // 使用子查询优化
  5656. $articlesList = DB::table('article')
  5657. ->select([
  5658. 'article.id',
  5659. 'article.title',
  5660. 'article.imgurl',
  5661. 'article.created_at',
  5662. 'category.name as category_name',
  5663. 'category.id as category_id',
  5664. 'website_category.aLIas_pinyin as pinyin',
  5665. 'parent_wc.aLIas_pinyin as parent_pinyin',
  5666. DB::raw('100 as type')
  5667. ])
  5668. ->join('category', 'article.catid', '=', 'category.id')
  5669. ->leftJoin('website_category', 'website_category.category_id', '=', 'category.id')
  5670. ->leftJoin('website_category as parent_wc', function ($join) {
  5671. $join->on('parent_wc.category_id', '=', 'website_category.pid')
  5672. ->where('parent_wc.website_id', '=', DB::raw('website_category.website_id'));
  5673. })
  5674. ->where('website_category.website_id', $data['website_id'])
  5675. ->where('article.status', 1)
  5676. ->whereIn('category.id', $categoryIds)
  5677. ->orderBy('article.created_at', 'desc')
  5678. ->get()
  5679. ->groupBy('category_id')
  5680. ->map(function ($group) {
  5681. // 确保第一条数据有图片
  5682. $firstWithImage = $group->first(function ($item) {
  5683. return !empty($item->imgurl);
  5684. });
  5685. if ($firstWithImage) {
  5686. // 如果有带图片的文章,将其放在第一位
  5687. $group = $group->filter(function ($item) use ($firstWithImage) {
  5688. return $item->id !== $firstWithImage->id;
  5689. })->prepend($firstWithImage);
  5690. }
  5691. return [
  5692. 'category_name' => $group->first()->category_name,
  5693. 'catid' => $group->first()->category_id,
  5694. 'pinyin' => $group->first()->pinyin,
  5695. 'parent_pinyin' => $group->first()->parent_pinyin,
  5696. 'list' => $group->take(4)->map(function ($item) {
  5697. return [
  5698. 'id' => $item->id,
  5699. 'title' => $item->title,
  5700. ];
  5701. })->values()
  5702. ];
  5703. })
  5704. ->values()
  5705. ->toArray();
  5706. return Result::success($articlesList);
  5707. }
  5708. /**
  5709. * 企业管理
  5710. * @param array $data
  5711. * @return array
  5712. */
  5713. public function getCompanyList(array $data): array
  5714. {
  5715. // return Result::success($data);
  5716. $where = [];
  5717. $user = User::where('id', $data['user_id'])->first();
  5718. if(empty($user)){
  5719. return Result::error('用户不存在!');
  5720. }
  5721. if($user['type_id']!= 10000){
  5722. $where['user_id'] = $data['user_id'];
  5723. }
  5724. if(isset($data['title']) && !empty($data['title'])){
  5725. array_push($where, ['company.title', 'like', '%'. $data['title']. '%']);
  5726. }
  5727. if(isset($data['website_id']) && !empty($data['website_id'])){
  5728. array_push($where, ['website.id', $data['website_id']]);
  5729. }
  5730. if(isset($data['ischeck']) && !empty($data['ischeck'])){
  5731. if($data['ischeck'] == 1){
  5732. if(isset($data['status']) && $data['status'] != ''){
  5733. array_push($where, ['company.status', $data['status']]);
  5734. $query = Company::where($where);
  5735. }else{
  5736. $query = Company::whereIn('company.status', [0,2]);
  5737. }
  5738. }else{
  5739. $query = Company::where('company.status', 1);
  5740. }
  5741. }
  5742. $result = $query->where($where)
  5743. ->leftJoin('website_category', function ($query) {
  5744. $query->on('website_category.category_id', '=', 'company.category_id')
  5745. ->on('website_category.website_id', '=', 'company.website_id');
  5746. })
  5747. ->leftJoin('website', 'company.website_id', '=', 'website.id')
  5748. ->select(
  5749. 'company.id',
  5750. 'company.title',
  5751. 'company.website_id',
  5752. 'company.category_id',
  5753. 'website.website_name',
  5754. 'website_category.alias as category_name',
  5755. 'company.status',
  5756. 'company.updated_at',
  5757. )
  5758. ->orderBy('company.updated_at', 'desc')
  5759. ->paginate($data['pageSize'], ['*'], 'page', $data['page']);
  5760. if($result->isEmpty()){
  5761. return Result::error("暂无企业", 0);
  5762. }
  5763. return Result::success($result);
  5764. }
  5765. /**
  5766. * 添加企业
  5767. * @param array $data
  5768. * @return array
  5769. */
  5770. public function addCompany(array $data): array
  5771. {
  5772. $data['category_id'] = isset($data['cat_arr_id']) ? end($data['cat_arr_id']) : '';
  5773. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5774. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  5775. $data['cat_arr_id'] = json_encode($car_arr_id);
  5776. } else {
  5777. $data['cat_arr_id'] = '';
  5778. }
  5779. if ($data['imgurl'] == '') {
  5780. //content中提取图片第一个图,正则提取
  5781. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5782. preg_match_all($reg, $data['content'], $matches);
  5783. if (isset($matches[1][0])) {
  5784. //截取varchar240
  5785. $data['imgurl'] = substr($matches[1][0], 0, 240);
  5786. }
  5787. }
  5788. if ($data['keyword'] == '') {
  5789. //提取标题+内容中的关键词
  5790. $data['keyword'] = $data['title'];
  5791. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5792. Jieba::init(); // 初始化 jieba-php
  5793. Finalseg::init();
  5794. $segList = Jieba::cut($data['keyword']);
  5795. $segList1 = array_slice($segList, 0, 8);
  5796. $data['keyword'] = implode(',', $segList1);
  5797. }
  5798. if ($data['introduce'] == '' || empty($data['introduce'])) {
  5799. //提取内容中的描述
  5800. $content = $data['content'];
  5801. // 去除 <style> 和 <script> 标签及其内容
  5802. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5803. // 去除所有 HTML 标签
  5804. $content = strip_tags($content);
  5805. // 去除 HTML 实体
  5806. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5807. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5808. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5809. // 去除多余空白
  5810. $content = preg_replace('/\s+/u', '', $content);
  5811. // 截取 100 个字符
  5812. $data['introduce'] = mb_substr($content, 0, 100);
  5813. }
  5814. $user = User::where('id', $data['user_id'])->first();
  5815. if (empty($user)) {
  5816. return Result::error('用户不存在!');
  5817. }
  5818. if ($user['type_id'] == 10000) {
  5819. $data['status'] = 1;
  5820. }
  5821. if (isset($data['level']) && $data['level'] != null) {
  5822. $data['level'] = intval($data['level']);
  5823. } else {
  5824. $data['level'] = null;
  5825. }
  5826. $result = Company::insertGetId($data);
  5827. if ($result) {
  5828. return Result::success($result);
  5829. } else {
  5830. return Result::error('添加失败');
  5831. }
  5832. }
  5833. /**
  5834. * 更新企业
  5835. * @param array $data
  5836. * @return array
  5837. */
  5838. public function upCompany(array $data): array
  5839. {
  5840. if (isset($data['cat_arr_id']) && !empty($data['cat_arr_id']) && is_array($data['cat_arr_id'])) {
  5841. $car_arr_id = array_values(array_unique(array_map('intval', $data['cat_arr_id'])));
  5842. $data['cat_arr_id'] = json_encode($car_arr_id);
  5843. $data['category_id'] = isset($data['cat_arr_id']) ? end($car_arr_id) : '';
  5844. } else {
  5845. $data['cat_arr_id'] = '';
  5846. }
  5847. if ($data['imgurl'] == '') {
  5848. //content中提取图片第一个图,正则提取
  5849. $reg = '/<img.*?src=[\"|\']?(.*?)[\"|\']?\s.*?>/i';
  5850. preg_match_all($reg, $data['content'], $matches);
  5851. if (isset($matches[1][0])) {
  5852. //截取varchar
  5853. $data['imgurl'] = substr($matches[1][0], 0, 240);
  5854. }
  5855. }
  5856. if ($data['keyword'] == '') {
  5857. //提取标题+内容中的关键词
  5858. $data['keyword'] = $data['title'];
  5859. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  5860. Jieba::init(); // 初始化 jieba-php
  5861. Finalseg::init();
  5862. $segList = Jieba::cut($data['keyword']);
  5863. $segList1 = array_slice($segList, 0, 8);
  5864. $data['keyword'] = implode(',', $segList1);
  5865. }
  5866. if ($data['introduce'] == '') {
  5867. //提取内容中的描述
  5868. $content = $data['content'];
  5869. // 去除 <style> 和 <script> 标签及其内容
  5870. $content = preg_replace('/<(style|script)[^>]*>.*?<\/\1>/is', '', $content);
  5871. // 去除所有 HTML 标签
  5872. $content = strip_tags($content);
  5873. // 去除 HTML 实体
  5874. $content = html_entity_decode($content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
  5875. // 只保留文本和标点符号(去除所有字母数字以外的特殊符号,可根据需要调整正则)
  5876. $content = preg_replace('/[^\p{L}\p{N}\p{P}\p{Zs}]+/u', '', $content);
  5877. // 去除多余空白
  5878. $content = preg_replace('/\s+/u', '', $content);
  5879. // 截取 100 个字符
  5880. $data['introduce'] = mb_substr($content, 0, 100);
  5881. }
  5882. if (isset($data['level']) && $data['level'] != null) {
  5883. $data['level'] = intval($data['level']);
  5884. } else {
  5885. $data['level'] = null;
  5886. }
  5887. $user = User::where('id', $data['user_id'])->first();
  5888. if (empty($user)) {
  5889. return Result::error('用户不存在!');
  5890. }
  5891. if ($user['type_id'] == 10000) {
  5892. $data['status'] = 1;
  5893. } else {
  5894. $data['status'] = 0;
  5895. }
  5896. $result = Company::where('id', $data['id'])->update($data);
  5897. if ($result) {
  5898. return Result::success($result);
  5899. } else {
  5900. return Result::error('修改失败');
  5901. }
  5902. }
  5903. /**
  5904. * 删除企业
  5905. * @param array $data
  5906. * @return array
  5907. */
  5908. public function delCompany(array $data): array
  5909. {
  5910. $result = Company::where('id', $data['id'])->delete();
  5911. if ($result) {
  5912. return Result::success($result);
  5913. } else {
  5914. return Result::error('删除失败');
  5915. }
  5916. }
  5917. /**
  5918. * 审核企业
  5919. * @param array $data
  5920. * @return array
  5921. */
  5922. public function checkCompany(array $data): array
  5923. {
  5924. $user = User::where('id', $data['user_id'])->first();
  5925. if (empty($user)) {
  5926. return Result::error('用户不存在!');
  5927. }
  5928. $company = Company::where('id', $data['id'])->first();
  5929. if (empty($company)) {
  5930. return Result::error('企业不存在!');
  5931. }
  5932. // 状态:0:未审核 1:已审核 2:已拒绝
  5933. if ($data['status'] == 2 || $data['status'] == '2') {
  5934. $result = Company::where('id', $data['id'])->update(['status' => $data['status'], 'reject_reason' => $data['reason']]);
  5935. } else {
  5936. $result = Company::where('id', $data['id'])->update(['status' => $data['status']]);
  5937. }
  5938. if (empty($result)) {
  5939. return Result::error('审核失败!');
  5940. } else {
  5941. return Result::success($result);
  5942. }
  5943. }
  5944. /**
  5945. * 获取企业信息
  5946. * @param array $data
  5947. * @return array
  5948. */
  5949. public function getCompanyInfo(array $data): array
  5950. {
  5951. $result = Company::where('id', $data['id'])->first();
  5952. if (empty($result)) {
  5953. return Result::error('企业不存在!');
  5954. } else {
  5955. return Result::success($result);
  5956. }
  5957. }
  5958. /**
  5959. * @param array $data
  5960. * @return array
  5961. */
  5962. public function getWebsiteCompany(array $data): array
  5963. {
  5964. $categorys = json_decode($data['id'], true);
  5965. $category_arr = $this->processArticlePro($data['website_id']);
  5966. $cat_1st_arr = $category_arr['cat_1st_arr'];
  5967. $catiall = $category_arr['catiall'];
  5968. foreach($categorys as $key => $value){
  5969. if(array_key_exists('level',$value)){
  5970. $parts = explode(',', $value['level']);
  5971. $level = $parts[0] ?? null;
  5972. $imgnum = $parts[1] ?? null;
  5973. $textnum = $parts[2] ?? null;
  5974. if(!empty($textnum) && $textnum > 0){
  5975. $text_num = Company::where('level', $level)
  5976. ->where('website_id',$data['website_id'])
  5977. ->where('status',1)
  5978. ->select('company.id','company.title','company.description','company.updated_at',
  5979. 'company.category_id','company.cat_arr_id')
  5980. ->orderBy('updated_at', 'desc')
  5981. ->limit($textnum)
  5982. ->get()->all();
  5983. }
  5984. if(!empty($imgnum) && $imgnum > 0){
  5985. $img_num = Company::where('level', $level)
  5986. ->where('website_id',$data['website_id'])
  5987. ->where('status',1)
  5988. ->where('imgurl','!=', '')
  5989. ->whereNotNull('imgurl')
  5990. ->select('company.id','company.title','company.description','company.updated_at',
  5991. 'company.imgurl as imgs','company.category_id','company.cat_arr_id')
  5992. ->orderBy('updated_at', 'desc')
  5993. ->limit($imgnum)
  5994. ->get()->all();
  5995. }
  5996. }
  5997. if(array_key_exists('id',$value)){
  5998. $parts = explode(',', $value['id']);
  5999. $category_id = $parts[0] ?? null;
  6000. $imgnum = $parts[1] ?? null;
  6001. $textnum = $parts[2] ?? null;
  6002. $category_arr = array_merge([$category_id], $cat_1st_arr[$category_id] ?? [0]);
  6003. if(!empty($textnum) && $textnum > 0){
  6004. $text_num = Company::whereIn('category_id', $category_arr)
  6005. ->where('website_id',$data['website_id'])
  6006. ->where('status',1)
  6007. ->select('company.id','company.title','company.description','company.updated_at',
  6008. 'company.category_id','company.cat_arr_id')
  6009. ->orderBy('updated_at', 'desc')
  6010. ->limit($textnum)
  6011. ->get()->all();
  6012. }
  6013. if(!empty($imgnum) && $imgnum > 0){
  6014. $img_num = Company::whereIn('category_id', $category_arr)
  6015. ->where('website_id',$data['website_id'])
  6016. ->where('status',1)
  6017. ->where('imgurl','!=', '')
  6018. ->whereNotNull('imgurl')
  6019. ->select('company.id','company.title','company.description','company.updated_at',
  6020. 'company.imgurl as imgs','company.category_id','company.cat_arr_id')
  6021. ->orderBy('updated_at', 'desc')
  6022. ->limit($imgnum)
  6023. ->get()->all();
  6024. }
  6025. }
  6026. if(!empty($text_num)){
  6027. foreach ($text_num as $k => $v) {
  6028. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  6029. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  6030. }
  6031. }
  6032. if(!empty($img_num)){
  6033. foreach ($img_num as $k => $v) {
  6034. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  6035. $imgurl = json_decode($v['imgs'], true);
  6036. if(!empty($imgurl)){
  6037. $img_num[$k]->imgurl = $imgurl[0];
  6038. }
  6039. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  6040. }
  6041. }
  6042. $company[$key]['img_num'] = $img_num ?? [];
  6043. $company[$key]['text_num'] = $text_num ?? [];
  6044. }
  6045. if(empty($company)){
  6046. return Result::error("暂无相关企业信息", 0);
  6047. }
  6048. return Result::success($company);
  6049. }
  6050. /**
  6051. * @param array $data
  6052. * @return array
  6053. */
  6054. public function getWebsiteCompanyList(array $data): array
  6055. {
  6056. $where['website_id'] = $data['website_id'];
  6057. $where['status'] = 1;
  6058. if (isset($data['category_id']) && !empty($data['category_id'])) {
  6059. $where['category_id'] = $data['category_id'];
  6060. }
  6061. if (isset($data['keyword']) && !empty($data['keyword'])) {
  6062. array_push($where, ['title', 'like', '%' . $data['keyword'] . '%']);
  6063. }
  6064. $query = Company::where($where);
  6065. $company = $this->processArticle(
  6066. $query->select('id', 'title', 'introduce', 'description', 'content', 'category_id', 'cat_arr_id','updated_at')
  6067. ->orderBy('updated_at', 'desc')
  6068. ->offset(($data['page'] - 1) * $data['pageSize'])
  6069. ->limit($data['pageSize'])
  6070. ->get(),
  6071. $data
  6072. );
  6073. if (empty($company)) {
  6074. return Result::error("暂无相关公司信息", 0);
  6075. }
  6076. $result = [
  6077. 'count' => $query->clone()->count(),
  6078. 'data' => $company,
  6079. ];
  6080. return Result::success($result);
  6081. }
  6082. /**
  6083. * 获取项目列表
  6084. * @param array $data
  6085. * @return array
  6086. */
  6087. public function getProjectList(array $data): array
  6088. {
  6089. $where = [];
  6090. $user = User::where('id', $data['user_id'])->first();
  6091. if (empty($user)) {
  6092. return Result::error('用户不存在!');
  6093. }
  6094. if ($user->type_id != 10000) {
  6095. array_push($where, ['project.user_id', $data['user_id']]);
  6096. }
  6097. $query = Project::query();
  6098. if (isset($data['website_id']) && !empty($data['website_id'])) {
  6099. array_push($where, ['project.website_id', $data['website_id']]);
  6100. }
  6101. if (isset($data['title']) && !empty($data['title'])) {
  6102. array_push($where, ['project.title', 'like', '%' . $data['title'] . '%']);
  6103. }
  6104. if ($data['status'] != 3) {
  6105. array_push($where, ['project.status', $data['status']]);
  6106. }
  6107. $query = Project::where($where)
  6108. ->when($data['status'] == 3, function ($query) {
  6109. $query->whereIn('project.status', [0, 2]);
  6110. });
  6111. $count = $query->clone()
  6112. ->count();
  6113. $rows = $query->clone()
  6114. ->leftJoin('website', 'project.website_id', 'website.id')
  6115. ->leftJoin('website_category', function ($join) {
  6116. $join->on('project.website_id', '=', 'website_category.website_id')
  6117. ->on('project.category_id', '=', 'website_category.category_id');
  6118. })
  6119. ->select(
  6120. 'project.id',
  6121. 'project.title',
  6122. 'project.updated_at',
  6123. 'project.status',
  6124. 'website.website_name',
  6125. 'website_category.alias as category_name'
  6126. )
  6127. ->orderBy('project.updated_at', 'desc')
  6128. ->offset(($data['page'] - 1) * $data['pageSize'])
  6129. ->limit($data['pageSize'])
  6130. ->get();
  6131. if ($rows->isEmpty()) {
  6132. return Result::error("暂无相关项目信息", 0);
  6133. }
  6134. $result = [
  6135. 'count' => $count,
  6136. 'rows' => $rows,
  6137. ];
  6138. return Result::success($result);
  6139. }
  6140. /**
  6141. * 添加项目
  6142. * @param array $data
  6143. * @return array
  6144. */
  6145. public function addProject(array $data): array
  6146. {
  6147. $user = User::where('id', $data['user_id'])->first();
  6148. if (empty($user)) {
  6149. return Result::error("暂无相关用户信息", 0);
  6150. }
  6151. if ($user->type_id == 10000) {
  6152. $data['status'] = 1;
  6153. } else {
  6154. $data['status'] = 0;
  6155. }
  6156. if ($data['keyword'] == '') {
  6157. //提取标题+内容中的关键词
  6158. $data['keyword'] = $data['title'];
  6159. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6160. Jieba::init(); // 初始化 jieba-php
  6161. Finalseg::init();
  6162. $segList = Jieba::cut($data['keyword']);
  6163. $segList1 = array_slice($segList, 0, 8);
  6164. $data['keyword'] = implode(',', $segList1);
  6165. }
  6166. if ($data['description'] == '') {
  6167. //提取内容中的描述
  6168. // var_dump(11111);
  6169. $data['description'] = mb_substr(str_replace(' ', '', strip_tags($data['introduce'])), 0, 100);
  6170. }
  6171. $project = Project::insertGetId($data);
  6172. if (empty($project)) {
  6173. return Result::error("暂无相关项目信息", 0);
  6174. }
  6175. return Result::success($project);
  6176. }
  6177. /**
  6178. * 更新项目
  6179. * @param array $data
  6180. * @return array
  6181. */
  6182. public function upProject(array $data): array
  6183. {
  6184. $project = Project::where('id', $data['id'])->first();
  6185. if (empty($project)) {
  6186. return Result::error("暂无相关项目信息", 0);
  6187. }
  6188. $id = $data['id'];
  6189. unset($data['id']);
  6190. $user = User::where('id', $data['user_id'])->first();
  6191. if (empty($user)) {
  6192. return Result::error("暂无相关用户信息", 0);
  6193. }
  6194. if ($user->type_id == 10000) {
  6195. $data['status'] = 1;
  6196. } else {
  6197. $data['status'] = 0;
  6198. }
  6199. unset($data['user_id']);
  6200. if ($data['keyword'] == '') {
  6201. //提取标题+内容中的关键词
  6202. $data['keyword'] = $data['title'];
  6203. // . substr(str_replace(' ', '', strip_tags($data['content'])), 0, 20);
  6204. Jieba::init(); // 初始化 jieba-php
  6205. Finalseg::init();
  6206. $segList = Jieba::cut($data['keyword']);
  6207. $segList1 = array_slice($segList, 0, 8);
  6208. $data['keyword'] = implode(',', $segList1);
  6209. }
  6210. if ($data['description'] == '') {
  6211. //提取内容中的描述
  6212. // var_dump(11111);
  6213. $data['description'] = mb_substr(str_replace(' ', '', strip_tags($data['introduce'])), 0, 100);
  6214. }
  6215. $result = Project::where('id', $id)->update($data);
  6216. if (empty($result)) {
  6217. return Result::error("更新失败", 0);
  6218. }
  6219. return Result::success($result);
  6220. }
  6221. /**
  6222. * 删除项目
  6223. * @param array $data
  6224. * @return array
  6225. */
  6226. public function delProject(array $data): array
  6227. {
  6228. $user = User::where('id', $data['user_id'])->first();
  6229. if (empty($user)) {
  6230. return Result::error("暂无相关用户信息", 0);
  6231. }
  6232. $project = Project::where('id', $data['id'])->first();
  6233. if (empty($project)) {
  6234. return Result::error("暂无相关项目信息", 0);
  6235. }
  6236. $result = Project::where('id', $data['id'])->delete();
  6237. if (empty($result)) {
  6238. return Result::error("删除失败", 0);
  6239. }
  6240. return Result::success($result);
  6241. }
  6242. /**
  6243. * 审核项目
  6244. * @param array $data
  6245. * @return array
  6246. */
  6247. public function checkProject(array $data): array
  6248. {
  6249. $user = User::where('id', $data['user_id'])->first();
  6250. if (empty($user)) {
  6251. return Result::error("暂无相关用户信息", 0);
  6252. }
  6253. // 0:未审核; 1:已审核; 2:已拒绝;
  6254. if ($user->type_id != 10000) {
  6255. if ($data['status'] == 1 || $data['status'] == 2) {
  6256. return Result::error("此用户权限不足", 0);
  6257. }
  6258. }
  6259. $project = Project::where('id', $data['id'])->first();
  6260. if (empty($project)) {
  6261. return Result::error("暂无相关项目信息", 0);
  6262. }
  6263. if ($data['status'] == 2) {
  6264. $result = Project::where('id', $data['id'])->update(['status' => $data['status'], 'refuse_reason' => $data['refuse_reason']]);
  6265. } else {
  6266. $result = Project::where('id', $data['id'])->update(['status' => $data['status']]);
  6267. }
  6268. if (empty($result)) {
  6269. return Result::error("审核失败", 0);
  6270. }
  6271. return Result::success($result);
  6272. }
  6273. /**
  6274. * 获取项目详情
  6275. * @param array $data
  6276. * @return array
  6277. */
  6278. public function getProjectInfo(array $data): array
  6279. {
  6280. $project = Project::where('id', $data['id'])->first();
  6281. if (empty($project)) {
  6282. return Result::error("暂无相关项目信息", 0);
  6283. }
  6284. return Result::success($project);
  6285. }
  6286. public function getWebsiteCompanyInfo(array $data): array
  6287. {
  6288. $company = Company::where('id', $data['id'])
  6289. ->leftJoin('job_industry','job_industry.hyid','company.hy_id')
  6290. ->where('status', 1)
  6291. ->where('website_id', $data['website_id'])
  6292. ->select('company.*','job_industry.hyname as hy_name')
  6293. ->first();
  6294. // 企业性质:0:市场监管;1:信访纪检;2:公检法司;3:高关注机构
  6295. switch($company->jobnature_id){
  6296. case null:
  6297. $company->jobnature_name = '';
  6298. break;
  6299. case 0:
  6300. $company->jobnature_name = '市场监督';
  6301. break;
  6302. case 1:
  6303. $company->jobnature_name = '信访纪检';
  6304. break;
  6305. case 2:
  6306. $company->jobnature_name = '公检法司';
  6307. break;
  6308. case 3:
  6309. $company->jobnature_name = '高关注机构';
  6310. break;
  6311. default:
  6312. $company->jobnature_name = '';
  6313. break;
  6314. }
  6315. $city_arr = $company->city_arr_id;
  6316. if(!empty($city_arr)){
  6317. $city_arr = json_decode($city_arr, true);
  6318. $cityNames = District::whereIn('id', $city_arr)
  6319. ->pluck('name')
  6320. ->implode('-');
  6321. $company->city_name = $cityNames;
  6322. }else{
  6323. $company->city_name = '';
  6324. }
  6325. if(empty($company)){
  6326. return Result::error("暂无相关公司信息", 0);
  6327. }
  6328. return Result::success($company);
  6329. }
  6330. public function getMSG(array $data): array
  6331. {
  6332. $type_id = isset($data['type_id']) ? $data['type_id'] : 1;
  6333. // '1:个人会员 2:政务会员 3:企业会员 4:调研员 10000:管理员 20000:游客(小程序)
  6334. $user_id = isset($data['user_id']) ? $data['user_id'] : 0; //用户id
  6335. $result = [];
  6336. if ($type_id == 1) {
  6337. //最近的5篇已审的文章
  6338. $apply_articale = Article::where('status', 1)
  6339. ->where('admin_user_id', $user_id)
  6340. ->orderBy('updated_at', 'desc')
  6341. ->limit(5)->get();
  6342. //获取5条单聊未读聊天消息
  6343. $chat = ChatRecords::where('is_read', 0)
  6344. ->where('user_id', $user_id)
  6345. ->where('talk_type', 1)
  6346. ->orderBy('created_at', 'desc')
  6347. ->limit(5)->get();
  6348. //获取5条未读群聊信息
  6349. $chat_group = ChatRecords::where('is_read', 0)
  6350. ->where('user_id', $user_id)
  6351. ->where('talk_type', 2)
  6352. ->orderBy('created_at', 'desc')
  6353. ->limit(5)->get();
  6354. //获取5条用户的已审核商品
  6355. $good = Good::where('status', 2)
  6356. ->where('user_id', $user_id)
  6357. ->orderBy('updated_at', 'desc')
  6358. ->limit(5)->get();
  6359. //获取5条用户待审核的公告
  6360. $notice = Notice::where('status', 2)
  6361. ->where('user_id', $user_id)
  6362. ->orderBy('updated_at', 'desc')
  6363. ->limit(5)->get();
  6364. //获取5条用户的待审核投诉
  6365. $complaint = Complaint::where('status', 2)
  6366. ->where('user_id', $user_id)
  6367. ->orderBy('updated_at', 'desc')
  6368. ->limit(5)->get();
  6369. //获取5条用户的book
  6370. $book = Book::where('status', 2)
  6371. ->where('user_id', $user_id)
  6372. ->orderBy('updated_at', 'desc')
  6373. ->limit(5)->get();
  6374. //获取5条用户的求职
  6375. //获取5条用户的求职 1
  6376. $job_hunting = JobHunting::where('job_hunting.status', 1)
  6377. ->where('job_hunting.user_id', $user_id)
  6378. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  6379. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  6380. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  6381. ->orderBy('updated_at', 'desc')
  6382. ->limit(5)->get();
  6383. //获取5条用户的求职 2
  6384. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  6385. ->where('job_recruiting.user_id', $user_id)
  6386. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  6387. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  6388. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  6389. ->orderBy('updated_at', 'desc')
  6390. ->limit(5)->get();
  6391. //人才库 1
  6392. $job_apply = JobApply::where('job_apply.status', 1)
  6393. ->where('job_apply.receiver_id', $user_id)
  6394. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  6395. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  6396. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  6397. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  6398. ->select('job_recruiting', 'job_recruiting.', '', '')
  6399. ->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')
  6400. ->orderBy('updated_at', 'desc')
  6401. ->limit(5)->get();
  6402. // 职场机会 2
  6403. $job_resume = JobResume::where('job_resume.status', 1)
  6404. ->where('job_resume.receiver_id', $user_id)
  6405. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  6406. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  6407. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  6408. ->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')
  6409. ->orderBy('updated_at', 'desc')
  6410. ->limit(5)->get();
  6411. // count($chat) + count($chat_group) +
  6412. $count = count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting) + count($job_apply) + count($job_resume);
  6413. $result = [
  6414. 'apply_articale' => $apply_articale,
  6415. 'chat' => $chat,
  6416. 'chat_group' => $chat_group,
  6417. 'good' => $good,
  6418. 'notice' => $notice,
  6419. 'complaint' => $complaint,
  6420. 'book' => $book,
  6421. 'job_hunting' => $job_hunting,
  6422. 'job_recruiting' => $job_recruiting,
  6423. 'job_apply' => $job_apply,
  6424. 'job_resume' => $job_resume,
  6425. 'count' => $count,
  6426. ];
  6427. } elseif ($type_id == 2) {
  6428. //最近的5篇已审的文章
  6429. $apply_articale = Article::where('status', 1)
  6430. ->where('admin_user_id', $user_id)
  6431. ->limit(5)->get();
  6432. //获取5条单聊未读聊天消息
  6433. $chat = ChatRecords::where('is_read', 0)
  6434. ->where('user_id', $user_id)
  6435. ->where('talk_type', 1)
  6436. ->orderBy('created_at', 'desc')
  6437. ->limit(5)->get();
  6438. //获取5条未读群聊信息
  6439. $chat_group = ChatRecords::where('is_read', 0)
  6440. ->where('user_id', $user_id)
  6441. ->where('talk_type', 2)
  6442. ->orderBy('created_at', 'desc')
  6443. ->limit(5)->get();
  6444. //获取5条用户的已审核商品
  6445. $good = Good::where('status', 2)
  6446. ->where('user_id', $user_id)
  6447. ->orderBy('updated_at', 'desc')
  6448. ->limit(5)->get();
  6449. //count($chat) + count($chat_group)
  6450. $count = count($apply_articale) + count($good);
  6451. $result = [
  6452. 'apply_articale' => $apply_articale,
  6453. 'chat' => $chat,
  6454. 'chat_group' => $chat_group,
  6455. 'good' => $good,
  6456. 'count' => $count,
  6457. ];
  6458. } elseif ($type_id == 3) {
  6459. //最近的5篇已审的文章
  6460. $apply_articale = Article::where('status', 1)
  6461. ->where('admin_user_id', $user_id)
  6462. ->limit(5)->get();
  6463. //获取5条单聊未读聊天消息
  6464. $chat = ChatRecords::where('is_read', 0)
  6465. ->where('user_id', $user_id)
  6466. ->where('talk_type', 1)
  6467. ->orderBy('created_at', 'desc')
  6468. ->limit(5)->get();
  6469. //获取5条未读群聊信息
  6470. $chat_group = ChatRecords::where('is_read', 0)
  6471. ->where('user_id', $user_id)
  6472. ->where('talk_type', 2)
  6473. ->orderBy('created_at', 'desc')
  6474. ->limit(5)->get();
  6475. //获取5条用户的已审核商品
  6476. $good = Good::where('status', 2)
  6477. ->where('user_id', $user_id)
  6478. ->orderBy('updated_at', 'desc')
  6479. ->limit(5)->get();
  6480. //count($chat) + count($chat_group) +
  6481. $count = count($apply_articale) + count($good);
  6482. $result = [
  6483. 'apply_articale' => $apply_articale,
  6484. 'chat' => $chat,
  6485. 'chat_group' => $chat_group,
  6486. 'good' => $good,
  6487. 'count' => $count,
  6488. ];
  6489. } elseif ($type_id == 4) {
  6490. //最近的5篇已审的文章
  6491. $apply_articale = Article::where('status', 1)
  6492. ->where('admin_user_id', $user_id)
  6493. ->limit(5)->get();
  6494. //获取5条用户的已审核商品
  6495. $good = Good::where('status', 2)
  6496. ->where('user_id', $user_id)
  6497. ->orderBy('updated_at', 'desc')
  6498. ->limit(5)->get();
  6499. $count = count($apply_articale) + count($good);
  6500. $result = [
  6501. 'apply_articale' => $apply_articale,
  6502. 'chat' => '',
  6503. 'chat_group' => '',
  6504. 'good' => $good,
  6505. 'count' => $count,
  6506. ];
  6507. } elseif ($type_id == 10000) {
  6508. //获取未审核的5篇文章
  6509. $apply_articale = Article::where('status', 0)
  6510. ->orderBy('updated_at', 'desc')
  6511. ->limit(5)->get();
  6512. //获取5条单聊未读聊天消息
  6513. $chat = ChatRecords::where('is_read', 0)
  6514. ->where('user_id', $user_id)
  6515. ->where('talk_type', 1)
  6516. ->orderBy('created_at', 'desc')
  6517. ->limit(5)->get();
  6518. //获取5条未读群聊信息
  6519. $chat_group = ChatRecords::where('is_read', 0)
  6520. ->where('user_id', $user_id)
  6521. ->where('talk_type', 2)
  6522. ->orderBy('created_at', 'desc')
  6523. ->limit(5)->get();
  6524. //获取5条用户的已审核商品
  6525. $good = Good::where('status', 1)
  6526. // ->where('user_id', $user_id)
  6527. ->orderBy('updated_at', 'desc')
  6528. ->limit(5)->get();
  6529. //获取5条用户待审核的公告
  6530. $notice = Notice::where('status', 1)
  6531. ->orderBy('updated_at', 'desc')
  6532. ->limit(5)->get();
  6533. //获取5条用户的待审核投诉
  6534. $complaint = Complaint::where('status', 1)
  6535. ->orderBy('updated_at', 'desc')
  6536. ->limit(5)->get();
  6537. //获取5条用户的book
  6538. $book = Book::where('status', 1)
  6539. ->orderBy('updated_at', 'desc')
  6540. ->limit(5)->get();
  6541. //获取5条用户的求职 1
  6542. $job_hunting = JobHunting::where('job_hunting.status', 1)
  6543. ->leftJoin('user', 'job_hunting.user_id', '=', 'user.id')
  6544. ->leftJoin('website', 'job_hunting.website_id', '=', 'website.id')
  6545. ->select('job_hunting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  6546. ->orderBy('updated_at', 'desc')
  6547. ->limit(5)->get();
  6548. //获取5条用户的求职 2
  6549. $job_recruiting = JobRecruiting::where('job_recruiting.status', 1)
  6550. ->leftJoin('user', 'job_recruiting.user_id', '=', 'user.id')
  6551. ->leftJoin('website', 'job_recruiting.website_id', '=', 'website.id')
  6552. ->select('job_recruiting.*', 'user.nickname as nickname', 'user.user_name as user_name', 'website.website_name as website_name')
  6553. ->orderBy('updated_at', 'desc')
  6554. ->limit(5)->get();
  6555. //人才库 1
  6556. $job_apply = JobApply::where('job_apply.status', 1)
  6557. ->leftJoin('user', 'job_apply.user_id', '=', 'user.id')
  6558. ->leftJoin('website', 'job_apply.website_id', '=', 'website.id')
  6559. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_apply.recruit_id')
  6560. ->leftJoin('job_recruiting', 'job_recruiting.id', '=', 'job_apply.recruit_id')
  6561. ->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')
  6562. ->orderBy('updated_at', 'desc')
  6563. ->limit(5)->get();
  6564. // 职场机会 2
  6565. $job_resume = JobResume::where('job_resume.status', 1)
  6566. ->leftJoin('user', 'job_resume.receiver_id', '=', 'user.id')
  6567. ->leftJoin('website', 'job_resume.website_id', '=', 'website.id')
  6568. ->leftJoin('job_company', 'job_company.job_id', '=', 'job_resume.recruit_id')
  6569. ->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')
  6570. ->orderBy('updated_at', 'desc')
  6571. ->limit(5)->get();
  6572. $count = count($chat) + count($chat_group) + count($apply_articale) + count($good) + count($notice) + count($complaint) + count($book) + count($job_hunting) + count($job_recruiting) + count($job_apply) + count($job_resume);
  6573. $result = [
  6574. 'apply_articale' => $apply_articale,
  6575. 'chat' => $chat,
  6576. 'chat_group' => $chat_group,
  6577. 'good' => $good,
  6578. 'notice' => $notice,
  6579. 'complaint' => $complaint,
  6580. 'book' => $book,
  6581. 'job_hunting' => $job_hunting,
  6582. 'job_recruiting' => $job_recruiting,
  6583. 'job_apply' => $job_apply,
  6584. 'job_resume' => $job_resume,
  6585. 'count' => $count,
  6586. ];
  6587. } elseif ($type_id == 20000) {
  6588. }
  6589. var_dump($type_id, '-----------------test---------');
  6590. return Result::success($result);
  6591. }
  6592. /**
  6593. * @param array $data
  6594. * @return array
  6595. */
  6596. public function getWebsiteProject(array $data): array
  6597. {
  6598. $categorys = json_decode($data['id'], true);
  6599. if(!empty($categorys)){
  6600. $category_arr = $this->processArticlePro($data['website_id']);
  6601. $cat_1st_arr = $category_arr['cat_1st_arr'];
  6602. $catiall = $category_arr['catiall'];
  6603. // return Result::success($catiall);
  6604. foreach($categorys as $key => $val){
  6605. if(isset($val['level'][0]) && !empty($val['level'][0])){
  6606. $level = explode(',', $val['level'])[0];
  6607. $imgnum = explode(',', $val['level'])[1] ?? null;
  6608. $textnum = explode(',', $val['level'])[2] ?? null;
  6609. if($level == 1){
  6610. if(!empty($textnum) && $textnum > 0){
  6611. $text_num = Project::where('level', $level)
  6612. ->where('website_id',$data['website_id'])
  6613. ->where('status',1)
  6614. ->select('project.id','project.title','project.description','project.updated_at',
  6615. 'project.category_id','project.cat_arr_id')
  6616. ->orderBy('updated_at', 'desc')
  6617. ->limit($textnum)
  6618. ->get()->all();
  6619. }
  6620. if(!empty($imgnum) && $imgnum > 0){
  6621. $img_num = Project::where('level', $level)
  6622. ->where('website_id',$data['website_id'])
  6623. ->where('status',1)
  6624. ->where('imgurl','!=', '')
  6625. ->whereNotNull('imgurl')
  6626. ->select('project.id','project.title','project.description','project.updated_at',
  6627. 'project.imgurl as imgs','project.category_id','project.cat_arr_id')
  6628. ->orderBy('updated_at', 'desc')
  6629. ->limit($imgnum)
  6630. ->get()->all();
  6631. }
  6632. }else{
  6633. if(!empty($textnum) && $textnum > 0){
  6634. $text_num = Project::where('website_id',$data['website_id'])
  6635. ->where('status',1)
  6636. ->select('project.id','project.title','project.description','project.updated_at',
  6637. 'project.category_id','project.cat_arr_id','project.website_id','project.updated_at',
  6638. 'project.created_at')
  6639. ->orderBy('updated_at', 'desc')
  6640. ->limit($textnum)
  6641. ->get()->all();
  6642. }
  6643. if(!empty($imgnum) && $imgnum > 0){
  6644. $img_num = Project::where('website_id',$data['website_id'])
  6645. ->where('status',1)
  6646. ->where('imgurl','!=', '')
  6647. ->whereNotNull('imgurl')
  6648. ->select('project.id','project.title','project.description','project.updated_at',
  6649. 'project.imgurl as imgs','project.category_id','project.cat_arr_id')
  6650. ->orderBy('updated_at', 'desc')
  6651. ->limit($imgnum)
  6652. ->get()->all();
  6653. }
  6654. }
  6655. }
  6656. if(isset($val['id'][0]) && !empty($val['id'][0])){
  6657. $category_ids = explode(',', $val['id'])[0];
  6658. $cat_imgnum = explode(',', $val['id'])[1] ?? null;
  6659. $cat_textnum = explode(',', $val['id'])[2] ?? null;
  6660. $category_arr = array_merge([$category_ids], $cat_1st_arr[$category_ids] ?? [0]);
  6661. if(!empty($cat_textnum) && $cat_textnum > 0){
  6662. $text_num = Project::whereIn('category_id', $category_arr)
  6663. ->where('website_id',$data['website_id'])
  6664. ->where('status',1)
  6665. ->select('project.id','project.title','project.description','project.updated_at',
  6666. 'project.category_id','project.cat_arr_id')
  6667. ->orderBy('updated_at', 'desc')
  6668. ->limit($cat_textnum)
  6669. ->get()->all();
  6670. }
  6671. if(!empty($cat_imgnum) && $cat_imgnum > 0){
  6672. $img_num = Project::whereIn('category_id', $category_arr)
  6673. ->where('website_id',$data['website_id'])
  6674. ->where('status',1)
  6675. ->where('imgurl','!=', '')
  6676. ->whereNotNull('imgurl')
  6677. ->select('project.id','project.title','project.description','project.updated_at',
  6678. 'project.imgurl as imgs','project.category_id','project.cat_arr_id')
  6679. ->orderBy('updated_at', 'desc')
  6680. ->limit($cat_imgnum)
  6681. ->get()->all();
  6682. }
  6683. }
  6684. if(!empty($img_num)){
  6685. foreach ($img_num as $k => $v) {
  6686. $img_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  6687. $imgurl = json_decode($v['imgs'], true);
  6688. if(!empty($imgurl)){
  6689. $img_num[$k]->imgurl = $imgurl[0];
  6690. }
  6691. $img_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  6692. }
  6693. }
  6694. if(!empty($text_num)){
  6695. foreach ($text_num as $k => $v) {
  6696. $text_num[$k]->category_name = $catiall[$v->category_id]['alias'];
  6697. $text_num[$k]->pinyin = $catiall[$v->category_id]['pinyin'];
  6698. }
  6699. }
  6700. $project[$key]['img_num'] = $img_num ?? [];
  6701. $project[$key]['text_num'] = $text_num ?? [];
  6702. }
  6703. }
  6704. if(empty($project)){
  6705. return Result::error("暂无相关项目信息", 0);
  6706. }
  6707. return Result::success($project);
  6708. }
  6709. /**
  6710. * @param array $data
  6711. * @return array
  6712. */
  6713. public function getWebsiteProjectInfo(array $data): array
  6714. {
  6715. $project = Project::where('id', $data['id'])
  6716. ->where('status', 1)
  6717. ->where('website_id', $data['website_id'])
  6718. ->select('project.*')
  6719. ->first();
  6720. if(empty($project)){
  6721. return Result::error("暂无相关项目信息", 0);
  6722. }
  6723. return Result::success($project);
  6724. }
  6725. /**
  6726. * @param array $data
  6727. * @return array
  6728. */
  6729. public function getWebsiteProjectList(array $data): array
  6730. {
  6731. $where = [];
  6732. if(isset($data['category_id']) && !empty($data['category_id'])){
  6733. $where['category_id'] = $data['category_id'];
  6734. }
  6735. if(isset($data['keyword']) && !empty($data['keyword'])){
  6736. $where[] = ['title','like', '%' . $data['keyword'] . '%'];
  6737. }
  6738. $query = Project::where($where)
  6739. ->where('status', 1)
  6740. ->where('website_id', $data['website_id'])
  6741. ->select('project.id','project.title','project.introduce','project.imgurl as imgs',
  6742. 'project.category_id','project.cat_arr_id')
  6743. ->orderBy('updated_at', 'desc');
  6744. $count = $query->count();
  6745. $project = $query->clone()
  6746. ->offset(($data['page'] - 1) * $data['pageSize'])
  6747. ->limit($data['pageSize'])
  6748. ->get()->all();
  6749. if(empty($project)){
  6750. return Result::error("暂无相关项目信息", 0);
  6751. }
  6752. $categorys = $this->processArticlePro($data['website_id']);
  6753. $catiall = $categorys['catiall'];
  6754. foreach($project as $key => $val){
  6755. $project[$key]->category_name = $catiall[$val->category_id]['alias'];
  6756. if(!empty($val['imgs'])){
  6757. $imgurl = json_decode($val['imgs'], true);
  6758. if(!empty($imgurl)){
  6759. $project[$key]->imgurl = $imgurl[0];
  6760. }
  6761. }else{
  6762. $project[$key]->imgurl = '';
  6763. }
  6764. $project[$key]->pinyin = $catiall[$val->category_id]['pinyin'];
  6765. }
  6766. $result = [
  6767. 'rows' => $project,
  6768. 'count' => $count,
  6769. ];
  6770. return Result::success($result);
  6771. }
  6772. /**
  6773. * 发送消息
  6774. * @param array $messageData
  6775. * @return void
  6776. */
  6777. public function sendMessage($messageData){
  6778. $msg =[
  6779. 'talk_type'=>$messageData['talk_type'],
  6780. 'title'=>$messageData['title'],
  6781. 'content'=>$messageData['content'],
  6782. 'messageType'=>$messageData['messageType'],
  6783. 'user_id'=>$messageData['user_id']??'',
  6784. ];
  6785. $message = new MqProducer($msg);
  6786. $producer = ContextApplicationContext::getContainer()->get(Producer::class);
  6787. $producer->produce($message);
  6788. }
  6789. }