NewsService.php 230 KB

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