NewsService.php 226 KB

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