NewsService.php 230 KB

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