NewsService.php 229 KB

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