NewsService.php 224 KB

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