NewsService.php 244 KB

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